]> git.lizzy.rs Git - rust.git/commitdiff
Do not emit structured suggestion for turbofish with wrong span
authorEsteban Küber <esteban@kuber.com.ar>
Sun, 8 Jan 2023 22:27:13 +0000 (22:27 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 8 Jan 2023 22:27:13 +0000 (22:27 +0000)
Fix #79161.

compiler/rustc_parse/src/parser/diagnostics.rs
src/test/ui/parser/nested-bad-turbofish.rs [new file with mode: 0644]
src/test/ui/parser/nested-bad-turbofish.stderr [new file with mode: 0644]

index b3231f55bc6e64375960c8e09b56b2ebccb19587..d9fa3e31db97226cdb4bebcf81cb0d24042c3387 100644 (file)
@@ -1104,7 +1104,11 @@ pub(super) fn check_no_chained_comparison(
                     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 @@ pub(super) fn check_no_chained_comparison(
                     } 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)),
diff --git a/src/test/ui/parser/nested-bad-turbofish.rs b/src/test/ui/parser/nested-bad-turbofish.rs
new file mode 100644 (file)
index 0000000..02099fd
--- /dev/null
@@ -0,0 +1,3 @@
+fn main() {
+    foo<<S as T>::V>(); //~ ERROR
+}
diff --git a/src/test/ui/parser/nested-bad-turbofish.stderr b/src/test/ui/parser/nested-bad-turbofish.stderr
new file mode 100644 (file)
index 0000000..d82fa80
--- /dev/null
@@ -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
+