From 0edca66a905d4c9c7292a2f89421a07389c8ade6 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 6 Jan 2023 05:34:56 +0000 Subject: Tiny formatting fix --- compiler/rustc_parse/src/parser/expr.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 1fc1ffd6cb6..9f436783ced 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1503,12 +1503,13 @@ impl<'a> Parser<'a> { prior_type_ascription: self.last_type_ascription, }); (lo.to(self.prev_token.span), ExprKind::MacCall(mac)) - } else if self.check(&token::OpenDelim(Delimiter::Brace)) && - let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) { - if qself.is_some() { - self.sess.gated_spans.gate(sym::more_qualified_paths, path.span); - } - return expr; + } else if self.check(&token::OpenDelim(Delimiter::Brace)) + && let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) + { + if qself.is_some() { + self.sess.gated_spans.gate(sym::more_qualified_paths, path.span); + } + return expr; } else { (path.span, ExprKind::Path(qself, path)) }; -- cgit 1.4.1-3-g733a5 From 6fdb54d2f103dc21197037e6b1ad0b51073b9627 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sun, 8 Jan 2023 22:27:13 +0000 Subject: Do not emit structured suggestion for turbofish with wrong span Fix #79161. --- compiler/rustc_parse/src/parser/diagnostics.rs | 12 ++++++++++-- src/test/ui/parser/nested-bad-turbofish.rs | 3 +++ src/test/ui/parser/nested-bad-turbofish.stderr | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/parser/nested-bad-turbofish.rs create mode 100644 src/test/ui/parser/nested-bad-turbofish.stderr (limited to 'compiler/rustc_parse/src/parser') 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)), diff --git a/src/test/ui/parser/nested-bad-turbofish.rs b/src/test/ui/parser/nested-bad-turbofish.rs new file mode 100644 index 00000000000..02099fde212 --- /dev/null +++ b/src/test/ui/parser/nested-bad-turbofish.rs @@ -0,0 +1,3 @@ +fn main() { + foo<::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 index 00000000000..d82fa80e594 --- /dev/null +++ b/src/test/ui/parser/nested-bad-turbofish.stderr @@ -0,0 +1,11 @@ +error: comparison operators cannot be chained + --> $DIR/nested-bad-turbofish.rs:2:16 + | +LL | foo<::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 + -- cgit 1.4.1-3-g733a5