Rollup merge of #106606 - estebank:bad-nested-turbofish, r=compiler-errors

Do not emit structured suggestion for turbofish with wrong span

Fix #79161.
This commit is contained in:
Michael Goulet 2023-01-08 19:57:56 -08:00 committed by GitHub
commit 5e8e97f981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View 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 >::`
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 >(`
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)),

View File

@ -0,0 +1,3 @@
fn main() {
foo<<S as T>::V>(); //~ ERROR
}

View File

@ -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