Skip to content

Commit 5e8e97f

Browse files
Rollup merge of #106606 - estebank:bad-nested-turbofish, r=compiler-errors
Do not emit structured suggestion for turbofish with wrong span Fix #79161.
2 parents bb6a88a + 6fdb54d commit 5e8e97f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,11 @@ impl<'a> Parser<'a> {
11041104
return if token::ModSep == self.token.kind {
11051105
// We have some certainty that this was a bad turbofish at this point.
11061106
// `foo< bar >::`
1107-
err.suggest_turbofish = Some(op.span.shrink_to_lo());
1107+
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
1108+
err.suggest_turbofish = Some(op.span.shrink_to_lo());
1109+
} else {
1110+
err.help_turbofish = Some(());
1111+
}
11081112

11091113
let snapshot = self.create_snapshot_for_diagnostic();
11101114
self.bump(); // `::`
@@ -1130,7 +1134,11 @@ impl<'a> Parser<'a> {
11301134
} else if token::OpenDelim(Delimiter::Parenthesis) == self.token.kind {
11311135
// We have high certainty that this was a bad turbofish at this point.
11321136
// `foo< bar >(`
1133-
err.suggest_turbofish = Some(op.span.shrink_to_lo());
1137+
if let ExprKind::Binary(o, ..) = inner_op.kind && o.node == BinOpKind::Lt {
1138+
err.suggest_turbofish = Some(op.span.shrink_to_lo());
1139+
} else {
1140+
err.help_turbofish = Some(());
1141+
}
11341142
// Consume the fn call arguments.
11351143
match self.consume_fn_args() {
11361144
Err(()) => Err(err.into_diagnostic(&self.sess.span_diagnostic)),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
foo<<S as T>::V>(); //~ ERROR
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: comparison operators cannot be chained
2+
--> $DIR/nested-bad-turbofish.rs:2:16
3+
|
4+
LL | foo<<S as T>::V>();
5+
| ^ ^
6+
|
7+
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
8+
= help: or use `(...)` if you meant to specify fn arguments
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)