about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-01-08 19:57:56 -0800
committerGitHub <noreply@github.com>2023-01-08 19:57:56 -0800
commit5e8e97f98115191bca09600491d3687e9cf2e8fb (patch)
tree70970b8d512c1f88c62d13cfbec27794a1879f02 /compiler/rustc_parse/src/parser
parentbb6a88ad5edee0812f61b41a5d41ca794eb3f979 (diff)
parent6fdb54d2f103dc21197037e6b1ad0b51073b9627 (diff)
downloadrust-5e8e97f98115191bca09600491d3687e9cf2e8fb.tar.gz
rust-5e8e97f98115191bca09600491d3687e9cf2e8fb.zip
Rollup merge of #106606 - estebank:bad-nested-turbofish, r=compiler-errors
Do not emit structured suggestion for turbofish with wrong span

Fix #79161.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index b3231f55bc6..d9fa3e31db9 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -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(); // `::`
@@ -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)),