Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
let lo = start + BytePos(possible_offset);
let hi = lo + BytePos(found_terminators);
let span = self.mk_sp(lo, hi);
err.span_suggestion(
err.span_suggestion_verbose(
span,
"consider terminating the string here",
"#".repeat(n_hashes as usize),
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub(crate) fn emit_unescape_error(
);
} else {
if mode == Mode::Str || mode == Mode::Char {
diag.span_suggestion(
diag.span_suggestion_verbose(
full_lit_span,
"if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal",
format!("r\"{lit}\""),
Expand Down Expand Up @@ -204,7 +204,7 @@ pub(crate) fn emit_unescape_error(
// Note: the \\xHH suggestions are not given for raw byte string
// literals, because they are araw and so cannot use any escapes.
if (c as u32) <= 0xFF && mode != Mode::RawByteStr {
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!(
"if you meant to use the unicode code point for {c:?}, use a \\xHH escape"
Expand All @@ -217,7 +217,7 @@ pub(crate) fn emit_unescape_error(
} else if mode != Mode::RawByteStr {
let mut utf8 = String::new();
utf8.push(c);
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!("if you meant to use the UTF-8 encoding of {c:?}, use \\xHH escapes"),
utf8.as_bytes()
Expand Down Expand Up @@ -313,7 +313,7 @@ fn foreign_escape_suggestion(
err_span: Span,
) {
if escaped_char == "?" {
diag.span_suggestion(
diag.span_suggestion_verbose(
err_span,
"if you meant to write a literal question mark, don't escape the character",
"?",
Expand All @@ -336,7 +336,7 @@ fn foreign_escape_suggestion(
_ => return,
};

diag.span_suggestion(
diag.span_suggestion_verbose(
escape_span,
format!("if you meant to write {name}, use a hex escape"),
format!("x{hex}"),
Expand Down
24 changes: 16 additions & 8 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ impl<'a> Parser<'a> {
.iter()
.any(|tok| matches!(tok, TokenType::FatArrow | TokenType::CloseBrace))
{
err.span_suggestion(
err.span_suggestion_verbose(
self.token.span,
"you might have meant to write a \"greater than or equal to\" comparison",
">=",
Expand Down Expand Up @@ -942,7 +942,7 @@ impl<'a> Parser<'a> {
count += 1;
}
err.span(span);
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!("remove the extra `#`{}", pluralize!(count)),
"",
Expand Down Expand Up @@ -2062,7 +2062,15 @@ impl<'a> Parser<'a> {
Applicability::MachineApplicable,
);
}
err.span_suggestion(lo.shrink_to_lo(), format!("{prefix}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax"), "r#", Applicability::MachineApplicable);
err.span_suggestion_verbose(
lo.shrink_to_lo(),
format!(
"{prefix}you can still access the deprecated `try!()` macro using the \
\"raw identifier\" syntax"
),
"r#",
Applicability::MachineApplicable,
);
let guar = err.emit();
Ok(self.mk_expr_err(lo.to(hi), guar))
} else {
Expand Down Expand Up @@ -2243,7 +2251,7 @@ impl<'a> Parser<'a> {
let ident = self.parse_ident_common(true).unwrap();
let span = pat.span.with_hi(ident.span.hi());

err.span_suggestion(
err.span_suggestion_verbose(
span,
"declare the type after the parameter binding",
"<identifier>: <type>",
Expand Down Expand Up @@ -2641,7 +2649,7 @@ impl<'a> Parser<'a> {
Ok((expr, _)) => {
// Find a mistake like `MyTrait<Assoc == S::Assoc>`.
if snapshot.token == token::EqEq {
err.span_suggestion(
err.span_suggestion_verbose(
snapshot.token.span,
"if you meant to use an associated type binding, replace `==` with `=`",
"=",
Expand All @@ -2655,7 +2663,7 @@ impl<'a> Parser<'a> {
&& matches!(expr.kind, ExprKind::Path(..))
{
// Find a mistake like "foo::var:A".
err.span_suggestion(
err.span_suggestion_verbose(
snapshot.token.span,
"write a path separator here",
"::",
Expand Down Expand Up @@ -2938,7 +2946,7 @@ impl<'a> Parser<'a> {
Applicability::MachineApplicable,
);
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
err.span_suggestion(
err.span_suggestion_verbose(
comma_span,
"...or a vertical bar to match on alternatives",
" |",
Expand Down Expand Up @@ -2975,7 +2983,7 @@ impl<'a> Parser<'a> {
&& (self.expected_token_types.contains(TokenType::Gt)
|| matches!(self.token.kind, token::Literal(..)))
{
err.span_suggestion(
err.span_suggestion_verbose(
maybe_lt.span,
"remove the `<` to write an exclusive range",
"",
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,12 @@ impl<'a> Parser<'a> {
// directly adjacent (i.e. '=<')
if maybe_eq_tok == TokenKind::Eq && maybe_eq_tok.span.hi() == lt_span.lo() {
let eq_lt = maybe_eq_tok.span.to(lt_span);
err.span_suggestion(eq_lt, "did you mean", "<=", Applicability::Unspecified);
err.span_suggestion_verbose(
eq_lt,
"you might have meant to write a \"less than or equal to\" comparison",
"<=",
Applicability::Unspecified,
);
}
err
})?;
Expand Down Expand Up @@ -2755,7 +2760,7 @@ impl<'a> Parser<'a> {
&& let maybe_let = self.look_ahead(1, |t| t.clone())
&& maybe_let.is_keyword(kw::Let)
{
err.span_suggestion(
err.span_suggestion_verbose(
self.prev_token.span,
"consider removing this semicolon to parse the `let` as part of the same chain",
"",
Expand All @@ -2767,7 +2772,7 @@ impl<'a> Parser<'a> {
} else {
// Look for usages of '=>' where '>=' might be intended
if maybe_fatarrow == token::FatArrow {
err.span_suggestion(
err.span_suggestion_verbose(
maybe_fatarrow.span,
"you might have meant to write a \"greater than or equal to\" comparison",
">=",
Expand Down Expand Up @@ -3381,7 +3386,7 @@ impl<'a> Parser<'a> {
if let Err(mut err) = this.expect(exp!(FatArrow)) {
// We might have a `=>` -> `=` or `->` typo (issue #89396).
if is_almost_fat_arrow {
err.span_suggestion(
err.span_suggestion_verbose(
this.token.span,
"use a fat arrow to start a match arm",
"=>",
Expand Down
49 changes: 29 additions & 20 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl<'a> Parser<'a> {
&& let [segment] = path.segments.as_slice()
&& edit_distance("macro_rules", &segment.ident.to_string(), 2).is_some()
{
err.span_suggestion(
err.span_suggestion_verbose(
path.span,
"perhaps you meant to define a macro",
"macro_rules",
Expand All @@ -626,13 +626,16 @@ impl<'a> Parser<'a> {
let mut err = self.dcx().struct_span_err(end.span, msg);
if end.is_doc_comment() {
err.span_label(end.span, "this doc comment doesn't document anything");
} else if self.token == TokenKind::Semi {
err.span_suggestion_verbose(
self.token.span,
"consider removing this semicolon",
"",
Applicability::MaybeIncorrect,
);
} else {
err.span_label(end.span, "expected an item after this");
if self.token == TokenKind::Semi {
err.span_suggestion_verbose(
self.token.span,
"remove the semicolon after the attribute",
"",
Applicability::MaybeIncorrect,
);
}
}
if let [.., penultimate, _] = attrs {
err.span_label(start.span.to(penultimate.span), "other attributes here");
Expand Down Expand Up @@ -2429,16 +2432,19 @@ impl<'a> Parser<'a> {
&inherited_vis,
Case::Insensitive,
) {
Ok(_) => {
self.dcx().struct_span_err(
Ok(_) => self
.dcx()
.struct_span_err(
lo.to(self.prev_token.span),
format!("functions are not allowed in {adt_ty} definitions"),
)
.with_help(
"unlike in C++, Java, and C#, functions are declared in `impl` blocks",
)
.with_help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information")
}
.with_help(
"see https://doc.rust-lang.org/book/ch05-03-method-syntax.html \
for more information",
),
Err(err) => {
err.cancel();
self.restore_snapshot(snapshot);
Expand Down Expand Up @@ -2474,14 +2480,17 @@ impl<'a> Parser<'a> {
.map_err(|err| err.cancel())
&& self.token == TokenKind::Colon
{
err.span_suggestion(
err.span_suggestion_verbose(
removal_span,
"remove this `let` keyword",
"remove the `let` keyword",
String::new(),
Applicability::MachineApplicable,
);
err.note("the `let` keyword is not allowed in `struct` fields");
err.note("see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information");
err.note(
"see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> \
for more information",
);
err.emit();
return Ok(ident);
} else {
Expand Down Expand Up @@ -2632,7 +2641,7 @@ impl<'a> Parser<'a> {
vec![(open, "{".to_string()), (close, '}'.to_string())],
Applicability::MaybeIncorrect,
);
err.span_suggestion(
err.span_suggestion_verbose(
span.with_neighbor(self.token.span).shrink_to_hi(),
"add a semicolon",
';',
Expand Down Expand Up @@ -3248,7 +3257,7 @@ impl<'a> Parser<'a> {
.span_to_snippet(original_sp)
.expect("Span extracted directly from keyword should always work");

err.span_suggestion(
err.span_suggestion_verbose(
self.token_uninterpolated_span(),
format!("`{original_kw}` already used earlier, remove this one"),
"",
Expand All @@ -3263,7 +3272,7 @@ impl<'a> Parser<'a> {
let misplaced_qual_sp = self.token_uninterpolated_span();
let misplaced_qual = self.span_to_snippet(misplaced_qual_sp).unwrap();

err.span_suggestion(
err.span_suggestion_verbose(
correct_pos_sp.to(misplaced_qual_sp),
format!("`{misplaced_qual}` must come before `{current_qual}`"),
format!("{misplaced_qual} {current_qual}"),
Expand All @@ -3287,7 +3296,7 @@ impl<'a> Parser<'a> {

// There was no explicit visibility
if matches!(orig_vis.kind, VisibilityKind::Inherited) {
err.span_suggestion(
err.span_suggestion_verbose(
sp_start.to(self.prev_token.span),
format!("visibility `{vs}` must come before `{snippet}`"),
format!("{vs} {snippet}"),
Expand All @@ -3296,7 +3305,7 @@ impl<'a> Parser<'a> {
}
// There was an explicit visibility
else {
err.span_suggestion(
err.span_suggestion_verbose(
current_vis.span,
"there is already a visibility modifier, remove one",
"",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ impl<'a> Parser<'a> {
format!("the {kind_desc} was parsed as having {op_desc} binary expression"),
);

err.span_suggestion(
err.span_suggestion_verbose(
lhs_end_span,
format!("you may have meant to write a `;` to terminate the {kind_desc} earlier"),
";",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,13 @@ impl<'a> Parser<'a> {
.dcx()
.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`");
if matches!(self.token.kind, token::Comma | token::Gt) {
err.span_suggestion(
err.span_suggestion_verbose(
self.psess.source_map().next_point(eq_span).to(before_next),
"to constrain the associated type, add a type after `=`",
" TheType",
Applicability::HasPlaceholders,
);
err.span_suggestion(
err.span_suggestion_verbose(
prev_token_span.shrink_to_hi().to(before_next),
format!("remove the `=` if `{ident}` is a type"),
"",
Expand Down
11 changes: 7 additions & 4 deletions tests/ui/async-await/in-trait/bad-signatures.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ error: expected one of `:`, `@`, or `|`, found keyword `self`
--> $DIR/bad-signatures.rs:5:23
|
LL | async fn bar(&abc self);
| -----^^^^
| | |
| | expected one of `:`, `@`, or `|`
| help: declare the type after the parameter binding: `<identifier>: <type>`
| ^^^^ expected one of `:`, `@`, or `|`
|
help: declare the type after the parameter binding
|
LL - async fn bar(&abc self);
LL + async fn bar(<identifier>: <type>);
|

error: aborting due to 2 previous errors

10 changes: 6 additions & 4 deletions tests/ui/async-await/no-async-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ error: expected one of `extern`, `fn`, `safe`, or `unsafe`, found keyword `const
--> $DIR/no-async-const.rs:4:11
|
LL | pub async const fn x() {}
| ------^^^^^
| | |
| | expected one of `extern`, `fn`, `safe`, or `unsafe`
| help: `const` must come before `async`: `const async`
| ^^^^^ expected one of `extern`, `fn`, `safe`, or `unsafe`
|
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
help: `const` must come before `async`
|
LL - pub async const fn x() {}
LL + pub const async fn x() {}
|

error: functions cannot be both `const` and `async`
--> $DIR/no-async-const.rs:4:5
Expand Down
20 changes: 12 additions & 8 deletions tests/ui/async-await/no-unsafe-async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:7:12
|
LL | unsafe async fn g() {}
| -------^^^^^
| | |
| | expected one of `extern` or `fn`
| help: `async` must come before `unsafe`: `async unsafe`
| ^^^^^ expected one of `extern` or `fn`
|
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
help: `async` must come before `unsafe`
|
LL - unsafe async fn g() {}
LL + async unsafe fn g() {}
|

error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:11:8
|
LL | unsafe async fn f() {}
| -------^^^^^
| | |
| | expected one of `extern` or `fn`
| help: `async` must come before `unsafe`: `async unsafe`
| ^^^^^ expected one of `extern` or `fn`
|
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
help: `async` must come before `unsafe`
|
LL - unsafe async fn f() {}
LL + async unsafe fn f() {}
|

error: aborting due to 2 previous errors

Loading
Loading