mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Rollup merge of #122217 - estebank:issue-119685, r=fmease
Handle str literals written with `'` lexed as lifetime Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
This commit is contained in:
commit
1164c2725e
@ -169,7 +169,7 @@ infer_lifetime_param_suggestion_elided = each elided lifetime in input position
|
|||||||
|
|
||||||
infer_meant_byte_literal = if you meant to write a byte literal, prefix with `b`
|
infer_meant_byte_literal = if you meant to write a byte literal, prefix with `b`
|
||||||
infer_meant_char_literal = if you meant to write a `char` literal, use single quotes
|
infer_meant_char_literal = if you meant to write a `char` literal, use single quotes
|
||||||
infer_meant_str_literal = if you meant to write a `str` literal, use double quotes
|
infer_meant_str_literal = if you meant to write a string literal, use double quotes
|
||||||
infer_mismatched_static_lifetime = incompatible lifetime on type
|
infer_mismatched_static_lifetime = incompatible lifetime on type
|
||||||
infer_more_targeted = {$has_param_name ->
|
infer_more_targeted = {$has_param_name ->
|
||||||
[true] `{$param_name}`
|
[true] `{$param_name}`
|
||||||
|
@ -1339,15 +1339,12 @@ pub enum TypeErrorAdditionalDiags {
|
|||||||
span: Span,
|
span: Span,
|
||||||
code: String,
|
code: String,
|
||||||
},
|
},
|
||||||
#[suggestion(
|
#[multipart_suggestion(infer_meant_str_literal, applicability = "machine-applicable")]
|
||||||
infer_meant_str_literal,
|
|
||||||
code = "\"{code}\"",
|
|
||||||
applicability = "machine-applicable"
|
|
||||||
)]
|
|
||||||
MeantStrLiteral {
|
MeantStrLiteral {
|
||||||
#[primary_span]
|
#[suggestion_part(code = "\"")]
|
||||||
span: Span,
|
start: Span,
|
||||||
code: String,
|
#[suggestion_part(code = "\"")]
|
||||||
|
end: Span,
|
||||||
},
|
},
|
||||||
#[suggestion(
|
#[suggestion(
|
||||||
infer_consider_specifying_length,
|
infer_consider_specifying_length,
|
||||||
|
@ -2079,16 +2079,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
// If a string was expected and the found expression is a character literal,
|
// If a string was expected and the found expression is a character literal,
|
||||||
// perhaps the user meant to write `"s"` to specify a string literal.
|
// perhaps the user meant to write `"s"` to specify a string literal.
|
||||||
(ty::Ref(_, r, _), ty::Char) if r.is_str() => {
|
(ty::Ref(_, r, _), ty::Char) if r.is_str() => {
|
||||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
|
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
|
||||||
if let Some(code) =
|
start: span.with_hi(span.lo() + BytePos(1)),
|
||||||
code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
|
end: span.with_lo(span.hi() - BytePos(1)),
|
||||||
{
|
})
|
||||||
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
|
|
||||||
span,
|
|
||||||
code: escape_literal(code),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// For code `if Some(..) = expr `, the type mismatch may be expected `bool` but found `()`,
|
// For code `if Some(..) = expr `, the type mismatch may be expected `bool` but found `()`,
|
||||||
// we try to suggest to add the missing `let` for `if let Some(..) = expr`
|
// we try to suggest to add the missing `let` for `if let Some(..) = expr`
|
||||||
|
@ -46,7 +46,7 @@ impl<'a> Cursor<'a> {
|
|||||||
/// If requested position doesn't exist, `EOF_CHAR` is returned.
|
/// If requested position doesn't exist, `EOF_CHAR` is returned.
|
||||||
/// However, getting `EOF_CHAR` doesn't always mean actual end of file,
|
/// However, getting `EOF_CHAR` doesn't always mean actual end of file,
|
||||||
/// it should be checked with `is_eof` method.
|
/// it should be checked with `is_eof` method.
|
||||||
pub(crate) fn first(&self) -> char {
|
pub fn first(&self) -> char {
|
||||||
// `.next()` optimizes better than `.nth(0)`
|
// `.next()` optimizes better than `.nth(0)`
|
||||||
self.chars.clone().next().unwrap_or(EOF_CHAR)
|
self.chars.clone().next().unwrap_or(EOF_CHAR)
|
||||||
}
|
}
|
||||||
@ -59,6 +59,15 @@ impl<'a> Cursor<'a> {
|
|||||||
iter.next().unwrap_or(EOF_CHAR)
|
iter.next().unwrap_or(EOF_CHAR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Peeks the third symbol from the input stream without consuming it.
|
||||||
|
pub fn third(&self) -> char {
|
||||||
|
// `.next()` optimizes better than `.nth(1)`
|
||||||
|
let mut iter = self.chars.clone();
|
||||||
|
iter.next();
|
||||||
|
iter.next();
|
||||||
|
iter.next().unwrap_or(EOF_CHAR)
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if there is nothing more to consume.
|
/// Checks if there is nothing more to consume.
|
||||||
pub(crate) fn is_eof(&self) -> bool {
|
pub(crate) fn is_eof(&self) -> bool {
|
||||||
self.chars.as_str().is_empty()
|
self.chars.as_str().is_empty()
|
||||||
|
@ -568,7 +568,7 @@ parse_more_than_one_char = character literal may only contain one codepoint
|
|||||||
.remove_non = consider removing the non-printing characters
|
.remove_non = consider removing the non-printing characters
|
||||||
.use_double_quotes = if you meant to write a {$is_byte ->
|
.use_double_quotes = if you meant to write a {$is_byte ->
|
||||||
[true] byte string
|
[true] byte string
|
||||||
*[false] `str`
|
*[false] string
|
||||||
} literal, use double quotes
|
} literal, use double quotes
|
||||||
|
|
||||||
parse_multiple_skipped_lines = multiple lines skipped by escaped newline
|
parse_multiple_skipped_lines = multiple lines skipped by escaped newline
|
||||||
@ -833,6 +833,7 @@ parse_unknown_prefix = prefix `{$prefix}` is unknown
|
|||||||
.label = unknown prefix
|
.label = unknown prefix
|
||||||
.note = prefixed identifiers and literals are reserved since Rust 2021
|
.note = prefixed identifiers and literals are reserved since Rust 2021
|
||||||
.suggestion_br = use `br` for a raw byte string
|
.suggestion_br = use `br` for a raw byte string
|
||||||
|
.suggestion_str = if you meant to write a string literal, use double quotes
|
||||||
.suggestion_whitespace = consider inserting whitespace here
|
.suggestion_whitespace = consider inserting whitespace here
|
||||||
|
|
||||||
parse_unknown_start_of_token = unknown start of token: {$escaped}
|
parse_unknown_start_of_token = unknown start of token: {$escaped}
|
||||||
|
@ -1987,6 +1987,17 @@ pub enum UnknownPrefixSugg {
|
|||||||
style = "verbose"
|
style = "verbose"
|
||||||
)]
|
)]
|
||||||
Whitespace(#[primary_span] Span),
|
Whitespace(#[primary_span] Span),
|
||||||
|
#[multipart_suggestion(
|
||||||
|
parse_suggestion_str,
|
||||||
|
applicability = "maybe-incorrect",
|
||||||
|
style = "verbose"
|
||||||
|
)]
|
||||||
|
MeantStr {
|
||||||
|
#[suggestion_part(code = "\"")]
|
||||||
|
start: Span,
|
||||||
|
#[suggestion_part(code = "\"")]
|
||||||
|
end: Span,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
@ -2198,12 +2209,21 @@ pub enum MoreThanOneCharSugg {
|
|||||||
ch: String,
|
ch: String,
|
||||||
},
|
},
|
||||||
#[suggestion(parse_use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
|
#[suggestion(parse_use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
|
||||||
Quotes {
|
QuotesFull {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
is_byte: bool,
|
is_byte: bool,
|
||||||
sugg: String,
|
sugg: String,
|
||||||
},
|
},
|
||||||
|
#[multipart_suggestion(parse_use_double_quotes, applicability = "machine-applicable")]
|
||||||
|
Quotes {
|
||||||
|
#[suggestion_part(code = "{prefix}\"")]
|
||||||
|
start: Span,
|
||||||
|
#[suggestion_part(code = "\"")]
|
||||||
|
end: Span,
|
||||||
|
is_byte: bool,
|
||||||
|
prefix: &'static str,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
@ -63,6 +63,7 @@ pub(crate) fn parse_token_trees<'psess, 'src>(
|
|||||||
cursor,
|
cursor,
|
||||||
override_span,
|
override_span,
|
||||||
nbsp_is_whitespace: false,
|
nbsp_is_whitespace: false,
|
||||||
|
last_lifetime: None,
|
||||||
};
|
};
|
||||||
let (stream, res, unmatched_delims) =
|
let (stream, res, unmatched_delims) =
|
||||||
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
|
tokentrees::TokenTreesReader::parse_all_token_trees(string_reader);
|
||||||
@ -105,6 +106,10 @@ struct StringReader<'psess, 'src> {
|
|||||||
/// in this file, it's safe to treat further occurrences of the non-breaking
|
/// in this file, it's safe to treat further occurrences of the non-breaking
|
||||||
/// space character as whitespace.
|
/// space character as whitespace.
|
||||||
nbsp_is_whitespace: bool,
|
nbsp_is_whitespace: bool,
|
||||||
|
|
||||||
|
/// Track the `Span` for the leading `'` of the last lifetime. Used for
|
||||||
|
/// diagnostics to detect possible typo where `"` was meant.
|
||||||
|
last_lifetime: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'psess, 'src> StringReader<'psess, 'src> {
|
impl<'psess, 'src> StringReader<'psess, 'src> {
|
||||||
@ -130,6 +135,18 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
|||||||
|
|
||||||
debug!("next_token: {:?}({:?})", token.kind, self.str_from(start));
|
debug!("next_token: {:?}({:?})", token.kind, self.str_from(start));
|
||||||
|
|
||||||
|
if let rustc_lexer::TokenKind::Semi
|
||||||
|
| rustc_lexer::TokenKind::LineComment { .. }
|
||||||
|
| rustc_lexer::TokenKind::BlockComment { .. }
|
||||||
|
| rustc_lexer::TokenKind::CloseParen
|
||||||
|
| rustc_lexer::TokenKind::CloseBrace
|
||||||
|
| rustc_lexer::TokenKind::CloseBracket = token.kind
|
||||||
|
{
|
||||||
|
// Heuristic: we assume that it is unlikely we're dealing with an unterminated
|
||||||
|
// string surrounded by single quotes.
|
||||||
|
self.last_lifetime = None;
|
||||||
|
}
|
||||||
|
|
||||||
// Now "cook" the token, converting the simple `rustc_lexer::TokenKind` enum into a
|
// Now "cook" the token, converting the simple `rustc_lexer::TokenKind` enum into a
|
||||||
// rich `rustc_ast::TokenKind`. This turns strings into interned symbols and runs
|
// rich `rustc_ast::TokenKind`. This turns strings into interned symbols and runs
|
||||||
// additional validation.
|
// additional validation.
|
||||||
@ -247,6 +264,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
|||||||
// expansion purposes. See #12512 for the gory details of why
|
// expansion purposes. See #12512 for the gory details of why
|
||||||
// this is necessary.
|
// this is necessary.
|
||||||
let lifetime_name = self.str_from(start);
|
let lifetime_name = self.str_from(start);
|
||||||
|
self.last_lifetime = Some(self.mk_sp(start, start + BytePos(1)));
|
||||||
if starts_with_number {
|
if starts_with_number {
|
||||||
let span = self.mk_sp(start, self.pos);
|
let span = self.mk_sp(start, self.pos);
|
||||||
self.dcx().struct_err("lifetimes cannot start with a number")
|
self.dcx().struct_err("lifetimes cannot start with a number")
|
||||||
@ -395,10 +413,21 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
|||||||
match kind {
|
match kind {
|
||||||
rustc_lexer::LiteralKind::Char { terminated } => {
|
rustc_lexer::LiteralKind::Char { terminated } => {
|
||||||
if !terminated {
|
if !terminated {
|
||||||
self.dcx()
|
let mut err = self
|
||||||
|
.dcx()
|
||||||
.struct_span_fatal(self.mk_sp(start, end), "unterminated character literal")
|
.struct_span_fatal(self.mk_sp(start, end), "unterminated character literal")
|
||||||
.with_code(E0762)
|
.with_code(E0762);
|
||||||
.emit()
|
if let Some(lt_sp) = self.last_lifetime {
|
||||||
|
err.multipart_suggestion(
|
||||||
|
"if you meant to write a string literal, use double quotes",
|
||||||
|
vec![
|
||||||
|
(lt_sp, "\"".to_string()),
|
||||||
|
(self.mk_sp(start, start + BytePos(1)), "\"".to_string()),
|
||||||
|
],
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
err.emit()
|
||||||
}
|
}
|
||||||
self.cook_unicode(token::Char, Mode::Char, start, end, 1, 1) // ' '
|
self.cook_unicode(token::Char, Mode::Char, start, end, 1, 1) // ' '
|
||||||
}
|
}
|
||||||
@ -669,15 +698,33 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
|
|||||||
let expn_data = prefix_span.ctxt().outer_expn_data();
|
let expn_data = prefix_span.ctxt().outer_expn_data();
|
||||||
|
|
||||||
if expn_data.edition >= Edition::Edition2021 {
|
if expn_data.edition >= Edition::Edition2021 {
|
||||||
|
let mut silence = false;
|
||||||
// In Rust 2021, this is a hard error.
|
// In Rust 2021, this is a hard error.
|
||||||
let sugg = if prefix == "rb" {
|
let sugg = if prefix == "rb" {
|
||||||
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
|
Some(errors::UnknownPrefixSugg::UseBr(prefix_span))
|
||||||
} else if expn_data.is_root() {
|
} else if expn_data.is_root() {
|
||||||
Some(errors::UnknownPrefixSugg::Whitespace(prefix_span.shrink_to_hi()))
|
if self.cursor.first() == '\''
|
||||||
|
&& let Some(start) = self.last_lifetime
|
||||||
|
&& self.cursor.third() != '\''
|
||||||
|
{
|
||||||
|
// An "unclosed `char`" error will be emitted already, silence redundant error.
|
||||||
|
silence = true;
|
||||||
|
Some(errors::UnknownPrefixSugg::MeantStr {
|
||||||
|
start,
|
||||||
|
end: self.mk_sp(self.pos, self.pos + BytePos(1)),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Some(errors::UnknownPrefixSugg::Whitespace(prefix_span.shrink_to_hi()))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
self.dcx().emit_err(errors::UnknownPrefix { span: prefix_span, prefix, sugg });
|
let err = errors::UnknownPrefix { span: prefix_span, prefix, sugg };
|
||||||
|
if silence {
|
||||||
|
self.dcx().create_err(err).delay_as_bug();
|
||||||
|
} else {
|
||||||
|
self.dcx().emit_err(err);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Before Rust 2021, only emit a lint for migration.
|
// Before Rust 2021, only emit a lint for migration.
|
||||||
self.psess.buffer_lint_with_diagnostic(
|
self.psess.buffer_lint_with_diagnostic(
|
||||||
|
@ -95,11 +95,21 @@ pub(crate) fn emit_unescape_error(
|
|||||||
}
|
}
|
||||||
escaped.push(c);
|
escaped.push(c);
|
||||||
}
|
}
|
||||||
let sugg = format!("{prefix}\"{escaped}\"");
|
if escaped.len() != lit.len() || full_lit_span.is_empty() {
|
||||||
MoreThanOneCharSugg::Quotes {
|
let sugg = format!("{prefix}\"{escaped}\"");
|
||||||
span: full_lit_span,
|
MoreThanOneCharSugg::QuotesFull {
|
||||||
is_byte: mode == Mode::Byte,
|
span: full_lit_span,
|
||||||
sugg,
|
is_byte: mode == Mode::Byte,
|
||||||
|
sugg,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MoreThanOneCharSugg::Quotes {
|
||||||
|
start: full_lit_span
|
||||||
|
.with_hi(full_lit_span.lo() + BytePos((prefix.len() + 1) as u32)),
|
||||||
|
end: full_lit_span.with_lo(full_lit_span.hi() - BytePos(1)),
|
||||||
|
is_byte: mode == Mode::Byte,
|
||||||
|
prefix,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dcx.emit_err(UnescapeError::MoreThanOneChar {
|
dcx.emit_err(UnescapeError::MoreThanOneChar {
|
||||||
|
@ -4,7 +4,7 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let _: &str = '"""';
|
LL | let _: &str = '"""';
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _: &str = "\"\"\"";
|
LL | let _: &str = "\"\"\"";
|
||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
@ -15,10 +15,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let _: &str = '\"\"\"';
|
LL | let _: &str = '\"\"\"';
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _: &str = "\"\"\"";
|
LL | let _: &str = "\"\"\"";
|
||||||
| ~~~~~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/str-as-char.rs:10:19
|
--> $DIR/str-as-char.rs:10:19
|
||||||
@ -26,7 +26,7 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let _: &str = '"\"\"\\"\\"';
|
LL | let _: &str = '"\"\"\\"\\"';
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _: &str = "\"\"\\"\\"\\\"";
|
LL | let _: &str = "\"\"\\"\\"\\\"";
|
||||||
| ~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -39,10 +39,10 @@ LL | let _: &str = 'a';
|
|||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _: &str = "a";
|
LL | let _: &str = "a";
|
||||||
| ~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ error[E0308]: mismatched types
|
|||||||
LL | let v: Vec(&str) = vec!['1', '2'];
|
LL | let v: Vec(&str) = vec!['1', '2'];
|
||||||
| ^^^ expected `&str`, found `char`
|
| ^^^ expected `&str`, found `char`
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let v: Vec(&str) = vec!["1", '2'];
|
LL | let v: Vec(&str) = vec!["1", '2'];
|
||||||
| ~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | 'nope'
|
LL | 'nope'
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | "nope"
|
LL | "nope"
|
||||||
| ~~~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | static c: char = '●●';
|
LL | static c: char = '●●';
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | static c: char = "●●";
|
LL | static c: char = "●●";
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/lex-bad-char-literals-3.rs:5:20
|
--> $DIR/lex-bad-char-literals-3.rs:5:20
|
||||||
@ -15,10 +15,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let ch: &str = '●●';
|
LL | let ch: &str = '●●';
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let ch: &str = "●●";
|
LL | let ch: &str = "●●";
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | static c: char = '\x10\x10';
|
LL | static c: char = '\x10\x10';
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | static c: char = "\x10\x10";
|
LL | static c: char = "\x10\x10";
|
||||||
| ~~~~~~~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/lex-bad-char-literals-5.rs:5:20
|
--> $DIR/lex-bad-char-literals-5.rs:5:20
|
||||||
@ -15,10 +15,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let ch: &str = '\x10\x10';
|
LL | let ch: &str = '\x10\x10';
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let ch: &str = "\x10\x10";
|
LL | let ch: &str = "\x10\x10";
|
||||||
| ~~~~~~~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -4,10 +4,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let x: &str = 'ab';
|
LL | let x: &str = 'ab';
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let x: &str = "ab";
|
LL | let x: &str = "ab";
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/lex-bad-char-literals-6.rs:4:19
|
--> $DIR/lex-bad-char-literals-6.rs:4:19
|
||||||
@ -15,10 +15,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let y: char = 'cd';
|
LL | let y: char = 'cd';
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let y: char = "cd";
|
LL | let y: char = "cd";
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/lex-bad-char-literals-6.rs:6:13
|
--> $DIR/lex-bad-char-literals-6.rs:6:13
|
||||||
@ -26,10 +26,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let z = 'ef';
|
LL | let z = 'ef';
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let z = "ef";
|
LL | let z = "ef";
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/lex-bad-char-literals-6.rs:13:20
|
--> $DIR/lex-bad-char-literals-6.rs:13:20
|
||||||
|
6
tests/ui/lexer/lex-bad-str-literal-as-char-1.fixed
Normal file
6
tests/ui/lexer/lex-bad-str-literal-as-char-1.fixed
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
//@ run-rustfix
|
||||||
|
fn main() {
|
||||||
|
println!("1 + 1");
|
||||||
|
//~^ ERROR unterminated character literal
|
||||||
|
//~| ERROR lifetimes cannot start with a number
|
||||||
|
}
|
6
tests/ui/lexer/lex-bad-str-literal-as-char-1.rs
Normal file
6
tests/ui/lexer/lex-bad-str-literal-as-char-1.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
//@ run-rustfix
|
||||||
|
fn main() {
|
||||||
|
println!('1 + 1');
|
||||||
|
//~^ ERROR unterminated character literal
|
||||||
|
//~| ERROR lifetimes cannot start with a number
|
||||||
|
}
|
20
tests/ui/lexer/lex-bad-str-literal-as-char-1.stderr
Normal file
20
tests/ui/lexer/lex-bad-str-literal-as-char-1.stderr
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
error[E0762]: unterminated character literal
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-1.rs:3:20
|
||||||
|
|
|
||||||
|
LL | println!('1 + 1');
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("1 + 1");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: lifetimes cannot start with a number
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-1.rs:3:14
|
||||||
|
|
|
||||||
|
LL | println!('1 + 1');
|
||||||
|
| ^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0762`.
|
4
tests/ui/lexer/lex-bad-str-literal-as-char-2.fixed
Normal file
4
tests/ui/lexer/lex-bad-str-literal-as-char-2.fixed
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
//@ run-rustfix
|
||||||
|
fn main() {
|
||||||
|
println!(" 1 + 1"); //~ ERROR character literal may only contain one codepoint
|
||||||
|
}
|
4
tests/ui/lexer/lex-bad-str-literal-as-char-2.rs
Normal file
4
tests/ui/lexer/lex-bad-str-literal-as-char-2.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
//@ run-rustfix
|
||||||
|
fn main() {
|
||||||
|
println!(' 1 + 1'); //~ ERROR character literal may only contain one codepoint
|
||||||
|
}
|
13
tests/ui/lexer/lex-bad-str-literal-as-char-2.stderr
Normal file
13
tests/ui/lexer/lex-bad-str-literal-as-char-2.stderr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
error: character literal may only contain one codepoint
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-2.rs:3:14
|
||||||
|
|
|
||||||
|
LL | println!(' 1 + 1');
|
||||||
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!(" 1 + 1");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
7
tests/ui/lexer/lex-bad-str-literal-as-char-3.rs
Normal file
7
tests/ui/lexer/lex-bad-str-literal-as-char-3.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
//@ revisions: rust2015 rust2018 rust2021
|
||||||
|
//@[rust2018] edition:2018
|
||||||
|
//@[rust2021] edition:2021
|
||||||
|
fn main() {
|
||||||
|
println!('hello world');
|
||||||
|
//[rust2015,rust2018,rust2021]~^ ERROR unterminated character literal
|
||||||
|
}
|
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2015.stderr
Normal file
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2015.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error[E0762]: unterminated character literal
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0762`.
|
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2018.stderr
Normal file
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2018.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error[E0762]: unterminated character literal
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0762`.
|
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2021.stderr
Normal file
14
tests/ui/lexer/lex-bad-str-literal-as-char-3.rust2021.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error[E0762]: unterminated character literal
|
||||||
|
--> $DIR/lex-bad-str-literal-as-char-3.rs:5:26
|
||||||
|
|
|
||||||
|
LL | println!('hello world');
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
||||||
|
LL | println!("hello world");
|
||||||
|
| ~ ~
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0762`.
|
@ -5,5 +5,5 @@ fn main() {
|
|||||||
//~| HELP if you meant to write a byte string literal, use double quotes
|
//~| HELP if you meant to write a byte string literal, use double quotes
|
||||||
let _bar = 'hello';
|
let _bar = 'hello';
|
||||||
//~^ ERROR character literal may only contain one codepoint
|
//~^ ERROR character literal may only contain one codepoint
|
||||||
//~| HELP if you meant to write a `str` literal, use double quotes
|
//~| HELP if you meant to write a string literal, use double quotes
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ LL | let _foo = b'hello\0';
|
|||||||
help: if you meant to write a byte string literal, use double quotes
|
help: if you meant to write a byte string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _foo = b"hello\0";
|
LL | let _foo = b"hello\0";
|
||||||
| ~~~~~~~~~~
|
| ~~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/issue-64732.rs:6:16
|
--> $DIR/issue-64732.rs:6:16
|
||||||
@ -15,10 +15,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | let _bar = 'hello';
|
LL | let _bar = 'hello';
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _bar = "hello";
|
LL | let _bar = "hello";
|
||||||
| ~~~~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ fn main() {
|
|||||||
let _spade = "♠️";
|
let _spade = "♠️";
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
//~| NOTE: this `♠` is followed by the combining mark `\u{fe0f}`
|
//~| NOTE: this `♠` is followed by the combining mark `\u{fe0f}`
|
||||||
//~| HELP: if you meant to write a `str` literal, use double quotes
|
//~| HELP: if you meant to write a string literal, use double quotes
|
||||||
|
|
||||||
let _s = "ṩ̂̊";
|
let _s = "ṩ̂̊";
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
//~| NOTE: this `s` is followed by the combining marks `\u{323}\u{307}\u{302}\u{30a}`
|
//~| NOTE: this `s` is followed by the combining marks `\u{323}\u{307}\u{302}\u{30a}`
|
||||||
//~| HELP: if you meant to write a `str` literal, use double quotes
|
//~| HELP: if you meant to write a string literal, use double quotes
|
||||||
|
|
||||||
let _a = 'Å';
|
let _a = 'Å';
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
|
@ -7,12 +7,12 @@ fn main() {
|
|||||||
let _spade = '♠️';
|
let _spade = '♠️';
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
//~| NOTE: this `♠` is followed by the combining mark `\u{fe0f}`
|
//~| NOTE: this `♠` is followed by the combining mark `\u{fe0f}`
|
||||||
//~| HELP: if you meant to write a `str` literal, use double quotes
|
//~| HELP: if you meant to write a string literal, use double quotes
|
||||||
|
|
||||||
let _s = 'ṩ̂̊';
|
let _s = 'ṩ̂̊';
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
//~| NOTE: this `s` is followed by the combining marks `\u{323}\u{307}\u{302}\u{30a}`
|
//~| NOTE: this `s` is followed by the combining marks `\u{323}\u{307}\u{302}\u{30a}`
|
||||||
//~| HELP: if you meant to write a `str` literal, use double quotes
|
//~| HELP: if you meant to write a string literal, use double quotes
|
||||||
|
|
||||||
let _a = 'Å';
|
let _a = 'Å';
|
||||||
//~^ ERROR: character literal may only contain one codepoint
|
//~^ ERROR: character literal may only contain one codepoint
|
||||||
|
@ -9,10 +9,10 @@ note: this `♠` is followed by the combining mark `\u{fe0f}`
|
|||||||
|
|
|
|
||||||
LL | let _spade = '♠️';
|
LL | let _spade = '♠️';
|
||||||
| ^
|
| ^
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _spade = "♠️";
|
LL | let _spade = "♠️";
|
||||||
| ~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/unicode-character-literal.rs:12:14
|
--> $DIR/unicode-character-literal.rs:12:14
|
||||||
@ -25,10 +25,10 @@ note: this `s` is followed by the combining marks `\u{323}\u{307}\u{302}\u{30a}`
|
|||||||
|
|
|
|
||||||
LL | let _s = 'ṩ̂̊';
|
LL | let _s = 'ṩ̂̊';
|
||||||
| ^
|
| ^
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | let _s = "ṩ̂̊";
|
LL | let _s = "ṩ̂̊";
|
||||||
| ~~~
|
| ~ ~
|
||||||
|
|
||||||
error: character literal may only contain one codepoint
|
error: character literal may only contain one codepoint
|
||||||
--> $DIR/unicode-character-literal.rs:17:14
|
--> $DIR/unicode-character-literal.rs:17:14
|
||||||
|
@ -4,10 +4,10 @@ error: character literal may only contain one codepoint
|
|||||||
LL | println!('●●');
|
LL | println!('●●');
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
help: if you meant to write a `str` literal, use double quotes
|
help: if you meant to write a string literal, use double quotes
|
||||||
|
|
|
|
||||||
LL | println!("●●");
|
LL | println!("●●");
|
||||||
| ~~~~
|
| ~ ~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user