Skip to content

Commit

Permalink
Rollup merge of rust-lang#106606 - estebank:bad-nested-turbofish, r=c…
Browse files Browse the repository at this point in the history
…ompiler-errors

Do not emit structured suggestion for turbofish with wrong span

Fix rust-lang#79161.
  • Loading branch information
compiler-errors authored Jan 9, 2023
2 parents 5d11325 + 6fdb54d commit 71b8514
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,11 @@ impl<'a> Parser<'a> {
return if token::ModSep == self.token.kind {
// We have some certainty that this was a bad turbofish at this point.
// `foo< bar >::`
err.suggest_turbofish = Some(op.span.shrink_to_lo());
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
err.suggest_turbofish = Some(op.span.shrink_to_lo());
} else {
err.help_turbofish = Some(());
}

let snapshot = self.create_snapshot_for_diagnostic();
self.bump(); // `::`
Expand All @@ -1130,7 +1134,11 @@ impl<'a> Parser<'a> {
} else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind {
// We have high certainty that this was a bad turbofish at this point.
// `foo< bar >(`
err.suggest_turbofish = Some(op.span.shrink_to_lo());
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
err.suggest_turbofish = Some(op.span.shrink_to_lo());
} else {
err.help_turbofish = Some(());
}
// Consume the fn call arguments.
match self.consume_fn_args() {
Err(()) => Err(err.into_diagnostic(&self.sess.span_diagnostic)),
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/parser/nested-bad-turbofish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
foo<<S as T>::V>(); //~ ERROR
}
11 changes: 11 additions & 0 deletions src/test/ui/parser/nested-bad-turbofish.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: comparison operators cannot be chained
--> $DIR/nested-bad-turbofish.rs:2:16
|
LL | foo<<S as T>::V>();
| ^ ^
|
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
= help: or use `(...)` if you meant to specify fn arguments

error: aborting due to previous error

0 comments on commit 71b8514

Please sign in to comment.