Skip to content

Commit 9bd1145

Browse files
author
Jonas Schievink
committed
Revert "Auto merge of rust-lang#12149 - jonas-schievink:literally-just-a-literal, r=jonas-schievink"
This reverts commit cc9ae2b, reversing changes made to 7dfd1cb.
1 parent 2287ae2 commit 9bd1145

36 files changed

+121
-502
lines changed

crates/hir-def/src/body/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl From<ast::LiteralKind> for Literal {
972972
}
973973
}
974974
LiteralKind::FloatNumber(lit) => {
975-
let ty = lit.suffix().and_then(|s| BuiltinFloat::from_suffix(&s));
975+
let ty = lit.suffix().and_then(BuiltinFloat::from_suffix);
976976
Literal::Float(Default::default(), ty)
977977
}
978978
LiteralKind::ByteString(bs) => {

crates/hir-expand/src/builtin_fn_macro.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use base_db::{AnchoredPath, Edition, FileId};
44
use cfg::CfgExpr;
55
use either::Either;
66
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
7-
use syntax::{ast, SmolStr};
7+
use syntax::{
8+
ast::{self, AstToken},
9+
SmolStr,
10+
};
811

912
use crate::{db::AstDatabase, name, quote, ExpandError, ExpandResult, MacroCallId, MacroCallLoc};
1013

@@ -355,7 +358,14 @@ fn unreachable_expand(
355358
}
356359

357360
fn unquote_str(lit: &tt::Literal) -> Option<String> {
358-
let token = ast::make::literal(&lit.to_string()).as_string()?;
361+
let lit = ast::make::tokens::literal(&lit.to_string());
362+
let token = ast::String::cast(lit)?;
363+
token.value().map(|it| it.into_owned())
364+
}
365+
366+
fn unquote_byte_string(lit: &tt::Literal) -> Option<Vec<u8>> {
367+
let lit = ast::make::tokens::literal(&lit.to_string());
368+
let token = ast::ByteString::cast(lit)?;
359369
token.value().map(|it| it.into_owned())
360370
}
361371

@@ -432,16 +442,12 @@ fn concat_bytes_expand(
432442
for (i, t) in tt.token_trees.iter().enumerate() {
433443
match t {
434444
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
435-
let lit = ast::make::literal(&lit.to_string());
436-
match lit.kind() {
437-
ast::LiteralKind::ByteString(s) => {
438-
s.value()
439-
.unwrap_or_default()
440-
.into_iter()
441-
.for_each(|x| bytes.push(x.to_string()));
442-
}
443-
ast::LiteralKind::Byte(_) => {
444-
bytes.push(lit.to_string());
445+
let token = ast::make::tokens::literal(&lit.to_string());
446+
match token.kind() {
447+
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
448+
syntax::SyntaxKind::BYTE_STRING => {
449+
let components = unquote_byte_string(lit).unwrap_or_else(Vec::new);
450+
components.into_iter().for_each(|x| bytes.push(x.to_string()));
445451
}
446452
_ => {
447453
err.get_or_insert(mbe::ExpandError::UnexpectedToken.into());
@@ -475,10 +481,10 @@ fn concat_bytes_expand_subtree(
475481
for (ti, tt) in tree.token_trees.iter().enumerate() {
476482
match tt {
477483
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
478-
let lit = ast::make::literal(&lit.to_string());
484+
let lit = ast::make::tokens::literal(&lit.to_string());
479485
match lit.kind() {
480-
ast::LiteralKind::IntNumber(_) | ast::LiteralKind::Byte(_) => {
481-
bytes.push(lit.to_string());
486+
syntax::SyntaxKind::BYTE | syntax::SyntaxKind::INT_NUMBER => {
487+
bytes.push(lit.text().to_string())
482488
}
483489
_ => {
484490
return Err(mbe::ExpandError::UnexpectedToken.into());

crates/hir-ty/src/tests/simple.rs

-11
Original file line numberDiff line numberDiff line change
@@ -2733,14 +2733,3 @@ fn f() {
27332733
"#,
27342734
);
27352735
}
2736-
2737-
#[test]
2738-
fn nested_tuple_index() {
2739-
check_no_mismatches(
2740-
r#"
2741-
fn main() {
2742-
let fld: i32 = ((0,),).0.0;
2743-
}
2744-
"#,
2745-
);
2746-
}

crates/ide-completion/src/completions/dot.rs

-20
Original file line numberDiff line numberDiff line change
@@ -793,24 +793,4 @@ fn main() {
793793
",
794794
)
795795
}
796-
797-
#[test]
798-
fn tuple_index_completion() {
799-
check(
800-
r#"
801-
struct I;
802-
impl I {
803-
fn i_method(&self) {}
804-
}
805-
struct S((), I);
806-
807-
fn f(s: S) {
808-
s.1.$0
809-
}
810-
"#,
811-
expect![[r#"
812-
me i_method() fn(&self)
813-
"#]],
814-
);
815-
}
816796
}

crates/ide-completion/src/completions/postfix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod format_like;
55
use hir::{Documentation, HasAttrs};
66
use ide_db::{imports::insert_use::ImportScope, ty_filter::TryEnum, SnippetCap};
77
use syntax::{
8-
ast::{self, AstNode, LiteralKind},
8+
ast::{self, AstNode, AstToken},
99
SyntaxKind::{EXPR_STMT, STMT_LIST},
1010
TextRange, TextSize,
1111
};
@@ -194,7 +194,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
194194
}
195195

196196
if let ast::Expr::Literal(literal) = dot_receiver.clone() {
197-
if let LiteralKind::String(literal_text) = literal.kind() {
197+
if let Some(literal_text) = ast::String::cast(literal.token()) {
198198
add_format_like_completions(acc, ctx, &dot_receiver, cap, &literal_text);
199199
}
200200
}

crates/ide/src/syntax_highlighting/highlight.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ pub(super) fn token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Optio
3030
INT_NUMBER if token.ancestors().nth(1).map(|it| it.kind()) == Some(FIELD_EXPR) => {
3131
SymbolKind::Field.into()
3232
}
33-
INT_NUMBER | FLOAT_NUMBER_PART | FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1
34-
| FLOAT_NUMBER_START_2 => HlTag::NumericLiteral.into(),
35-
DOT if matches!(
36-
token.prev_token().map(|n| n.kind()),
37-
Some(FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2)
38-
) =>
39-
{
40-
HlTag::NumericLiteral.into()
41-
}
33+
INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(),
4234
BYTE => HlTag::ByteLiteral.into(),
4335
CHAR => HlTag::CharLiteral.into(),
4436
IDENT if token.parent().and_then(ast::TokenTree::cast).is_some() => {

0 commit comments

Comments
 (0)