From c63b6a437eb16d13fbc0e72e091813579895bc9f Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 16 Nov 2022 21:46:06 +0100 Subject: Rip it out My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive! --- compiler/rustc_parse/src/errors.rs | 22 +++++ compiler/rustc_parse/src/parser/diagnostics.rs | 119 +++++++++-------------- compiler/rustc_parse/src/parser/expr.rs | 105 +++++++------------- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 23 ++--- compiler/rustc_parse/src/parser/pat.rs | 10 +- compiler/rustc_parse/src/parser/path.rs | 73 +++++++++++++- compiler/rustc_parse/src/parser/stmt.rs | 127 +++++++++++++++++++++---- compiler/rustc_parse/src/parser/ty.rs | 7 +- 9 files changed, 296 insertions(+), 192 deletions(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index f286707a9c0..b445ccc7ad0 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1340,6 +1340,28 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword { pub fn_token_span: Span, } +#[derive(Diagnostic)] +#[diag(parse_path_single_colon)] +pub(crate) struct PathSingleColon { + #[primary_span] + #[suggestion(applicability = "machine-applicable", code = "::")] + pub span: Span, + + #[note(parse_type_ascription_removed)] + pub type_ascription: Option<()>, +} + +#[derive(Diagnostic)] +#[diag(parse_colon_as_semi)] +pub(crate) struct ColonAsSemi { + #[primary_span] + #[suggestion(applicability = "machine-applicable", code = ";")] + pub span: Span, + + #[note(parse_type_ascription_removed)] + pub type_ascription: Option<()>, +} + #[derive(Diagnostic)] #[diag(parse_where_clause_before_tuple_struct_body)] pub(crate) struct WhereClauseBeforeTupleStructBody { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 0e041df898c..bcc76c20815 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -4,7 +4,7 @@ use super::{ TokenExpectType, TokenType, }; use crate::errors::{ - AmbiguousPlus, AttributeOnParamType, BadQPathStage2, BadTypePlus, BadTypePlusSub, + AmbiguousPlus, AttributeOnParamType, BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg, @@ -84,6 +84,7 @@ impl RecoverQPath for Ty { } impl RecoverQPath for Pat { + const PATH_STYLE: PathStyle = PathStyle::Pat; fn to_ty(&self) -> Option> { self.to_ty() } @@ -237,6 +238,7 @@ impl<'a> DerefMut for SnapshotParser<'a> { impl<'a> Parser<'a> { #[rustc_lint_diagnostics] + #[track_caller] pub fn struct_span_err>( &self, sp: S, @@ -663,7 +665,6 @@ impl<'a> Parser<'a> { err.span_label(sp, label_exp); err.span_label(self.token.span, "unexpected token"); } - self.maybe_annotate_with_ascription(&mut err, false); Err(err) } @@ -788,59 +789,6 @@ impl<'a> Parser<'a> { None } - pub fn maybe_annotate_with_ascription( - &mut self, - err: &mut Diagnostic, - maybe_expected_semicolon: bool, - ) { - if let Some((sp, likely_path)) = self.last_type_ascription.take() { - let sm = self.sess.source_map(); - let next_pos = sm.lookup_char_pos(self.token.span.lo()); - let op_pos = sm.lookup_char_pos(sp.hi()); - - let allow_unstable = self.sess.unstable_features.is_nightly_build(); - - if likely_path { - err.span_suggestion( - sp, - "maybe write a path separator here", - "::", - if allow_unstable { - Applicability::MaybeIncorrect - } else { - Applicability::MachineApplicable - }, - ); - self.sess.type_ascription_path_suggestions.borrow_mut().insert(sp); - } else if op_pos.line != next_pos.line && maybe_expected_semicolon { - err.span_suggestion( - sp, - "try using a semicolon", - ";", - Applicability::MaybeIncorrect, - ); - } else if allow_unstable { - err.span_label(sp, "tried to parse a type due to this type ascription"); - } else { - err.span_label(sp, "tried to parse a type due to this"); - } - if allow_unstable { - // Give extra information about type ascription only if it's a nightly compiler. - err.note( - "`#![feature(type_ascription)]` lets you annotate an expression with a type: \ - `: `", - ); - if !likely_path { - // Avoid giving too much info when it was likely an unrelated typo. - err.note( - "see issue #23416 \ - for more information", - ); - } - } - } - } - /// Eats and discards tokens until one of `kets` is encountered. Respects token trees, /// passes through any errors encountered. Used for error recovery. pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind]) { @@ -1625,9 +1573,40 @@ impl<'a> Parser<'a> { if self.eat(&token::Semi) { return Ok(()); } + + if self.recover_colon_as_semi() { + return Ok(()); + } + self.expect(&token::Semi).map(drop) // Error unconditionally } + pub(super) fn recover_colon_as_semi(&mut self) -> bool { + let line_idx = |span: Span| { + self.sess + .source_map() + .span_to_lines(span) + .ok() + .and_then(|lines| Some(lines.lines.get(0)?.line_index)) + }; + + if self.may_recover() + && self.token == token::Colon + && self.look_ahead(1, |next| line_idx(self.token.span) < line_idx(next.span)) + { + self.sess.emit_err(ColonAsSemi { + span: self.token.span, + type_ascription: self.sess.unstable_features.is_nightly_build().then_some(()), + }); + + self.bump(); + + return true; + } + + false + } + /// Consumes alternative await syntaxes like `await!()`, `await `, /// `await? `, `await()`, and `await { }`. pub(super) fn recover_incorrect_await_syntax( @@ -1790,37 +1769,27 @@ impl<'a> Parser<'a> { } } - pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool { - (self.token == token::Lt && // `foo:` - } - pub(super) fn recover_seq_parse_error( &mut self, delim: Delimiter, lo: Span, result: PResult<'a, P>, ) -> P { + use crate::parser::DUMMY_NODE_ID; match result { Ok(x) => x, Err(mut err) => { err.emit(); // Recover from parse error, callers expect the closing delim to be consumed. self.consume_block(delim, ConsumeClosingDelim::Yes); - self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err) + debug!("recover_seq_parse_error: consumed tokens until {:?} {:?}", lo, self.token); + let res = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err); + if res.id == DUMMY_NODE_ID { + //panic!("debug now ....: {:?}", res); + res + } else { + res + } } } } @@ -1902,7 +1871,7 @@ impl<'a> Parser<'a> { && brace_depth == 0 && bracket_depth == 0 => { - debug!("recover_stmt_ return - Semi"); + debug!("recover_stmt_ return - Comma"); break; } _ => self.bump(), diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index bff9de5c652..7c55ac9cce2 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -174,10 +174,8 @@ impl<'a> Parser<'a> { self.parse_expr_prefix(attrs)? } }; - let last_type_ascription_set = self.last_type_ascription.is_some(); if !self.should_continue_as_assoc_expr(&lhs) { - self.last_type_ascription = None; return Ok(lhs); } @@ -296,14 +294,22 @@ impl<'a> Parser<'a> { continue; } + // Special cases: + if op.node == AssocOp::As { + lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?; + continue; + } else if op.node == AssocOp::DotDot || op.node == AssocOp::DotDotEq { + // If we didn't have to handle `x..`/`x..=`, it would be pretty easy to + // generalise it to the Fixity::None code. + lhs = self.parse_expr_range(prec, lhs, op.node, cur_op_span)?; + break; + } + let op = op.node; // Special cases: if op == AssocOp::As { lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?; continue; - } else if op == AssocOp::Colon { - lhs = self.parse_assoc_op_ascribe(lhs, lhs_span)?; - continue; } else if op == AssocOp::DotDot || op == AssocOp::DotDotEq { // If we didn't have to handle `x..`/`x..=`, it would be pretty easy to // generalise it to the Fixity::None code. @@ -364,7 +370,7 @@ impl<'a> Parser<'a> { let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs); self.mk_expr(span, aopexpr) } - AssocOp::As | AssocOp::Colon | AssocOp::DotDot | AssocOp::DotDotEq => { + AssocOp::As | AssocOp::DotDot | AssocOp::DotDotEq => { self.span_bug(span, "AssocOp should have been handled by special case") } }; @@ -373,9 +379,7 @@ impl<'a> Parser<'a> { break; } } - if last_type_ascription_set { - self.last_type_ascription = None; - } + Ok(lhs) } @@ -615,7 +619,9 @@ impl<'a> Parser<'a> { token::Ident(..) if this.may_recover() && this.is_mistaken_not_ident_negation() => { make_it!(this, attrs, |this, _| this.recover_not_expr(lo)) } - _ => return this.parse_expr_dot_or_call(Some(attrs)), + _ => { + return this.parse_expr_dot_or_call(Some(attrs)); + } } } @@ -743,7 +749,7 @@ impl<'a> Parser<'a> { ( // `foo: ` ExprKind::Path(None, ast::Path { segments, .. }), - TokenKind::Ident(kw::For | kw::Loop | kw::While, false), + token::Ident(kw::For | kw::Loop | kw::While, false), ) if segments.len() == 1 => { let snapshot = self.create_snapshot_for_diagnostic(); let label = Label { @@ -838,21 +844,19 @@ impl<'a> Parser<'a> { &mut self, cast_expr: P, ) -> PResult<'a, P> { + if let ExprKind::Type(_, _) = cast_expr.kind { + panic!("ExprKind::Type must not be parsed"); + } + let span = cast_expr.span; - let (cast_kind, maybe_ascription_span) = - if let ExprKind::Type(ascripted_expr, _) = &cast_expr.kind { - ("type ascription", Some(ascripted_expr.span.shrink_to_hi().with_hi(span.hi()))) - } else { - ("cast", None) - }; let with_postfix = self.parse_expr_dot_or_call_with_(cast_expr, span)?; // Check if an illegal postfix operator has been added after the cast. // If the resulting expression is not a cast, it is an illegal postfix operator. - if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) { + if !matches!(with_postfix.kind, ExprKind::Cast(_, _)) { let msg = format!( - "{cast_kind} cannot be followed by {}", + "cast cannot be followed by {}", match with_postfix.kind { ExprKind::Index(_, _) => "indexing", ExprKind::Try(_) => "`?`", @@ -878,44 +882,13 @@ impl<'a> Parser<'a> { ); }; - // If type ascription is "likely an error", the user will already be getting a useful - // help message, and doesn't need a second. - if self.last_type_ascription.map_or(false, |last_ascription| last_ascription.1) { - self.maybe_annotate_with_ascription(&mut err, false); - } else if let Some(ascription_span) = maybe_ascription_span { - let is_nightly = self.sess.unstable_features.is_nightly_build(); - if is_nightly { - suggest_parens(&mut err); - } - err.span_suggestion( - ascription_span, - &format!( - "{}remove the type ascription", - if is_nightly { "alternatively, " } else { "" } - ), - "", - if is_nightly { - Applicability::MaybeIncorrect - } else { - Applicability::MachineApplicable - }, - ); - } else { - suggest_parens(&mut err); - } + suggest_parens(&mut err); + err.emit(); }; Ok(with_postfix) } - fn parse_assoc_op_ascribe(&mut self, lhs: P, lhs_span: Span) -> PResult<'a, P> { - let maybe_path = self.could_ascription_be_path(&lhs.kind); - self.last_type_ascription = Some((self.prev_token.span, maybe_path)); - let lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Type)?; - self.sess.gated_spans.gate(sym::type_ascription, lhs.span); - Ok(lhs) - } - /// Parse `& mut? ` or `& raw [ const | mut ] `. fn parse_expr_borrow(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { self.expect_and()?; @@ -1010,7 +983,7 @@ impl<'a> Parser<'a> { }; if has_dot { // expr.f - e = self.parse_expr_dot_suffix(lo, e)?; + e = self.parse_dot_suffix_expr(lo, e)?; continue; } if self.expr_is_complete(&e) { @@ -1024,13 +997,7 @@ impl<'a> Parser<'a> { } } - fn look_ahead_type_ascription_as_field(&mut self) -> bool { - self.look_ahead(1, |t| t.is_ident()) - && self.look_ahead(2, |t| t == &token::Colon) - && self.look_ahead(3, |t| t.can_begin_expr()) - } - - fn parse_expr_dot_suffix(&mut self, lo: Span, base: P) -> PResult<'a, P> { + fn parse_dot_suffix_expr(&mut self, lo: Span, base: P) -> PResult<'a, P> { match self.token.uninterpolate().kind { token::Ident(..) => self.parse_dot_suffix(base, lo), token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => { @@ -1183,9 +1150,7 @@ impl<'a> Parser<'a> { /// Parse a function call expression, `expr(...)`. fn parse_expr_fn_call(&mut self, lo: Span, fun: P) -> P { - let snapshot = if self.token.kind == token::OpenDelim(Delimiter::Parenthesis) - && self.look_ahead_type_ascription_as_field() - { + let snapshot = if self.token.kind == token::OpenDelim(Delimiter::Parenthesis) { Some((self.create_snapshot_for_diagnostic(), fun.kind.clone())) } else { None @@ -1216,7 +1181,6 @@ impl<'a> Parser<'a> { if !self.may_recover() { return None; } - match (seq.as_mut(), snapshot) { (Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => { snapshot.bump(); // `(` @@ -1260,9 +1224,7 @@ impl<'a> Parser<'a> { return Some(self.mk_expr_err(span)); } Ok(_) => {} - Err(mut err) => { - err.emit(); - } + Err(err) => err.cancel(), } } _ => {} @@ -1516,7 +1478,6 @@ impl<'a> Parser<'a> { let mac = P(MacCall { path, args: self.parse_delim_args()?, - prior_type_ascription: self.last_type_ascription, }); (lo.to(self.prev_token.span), ExprKind::MacCall(mac)) } else if self.check(&token::OpenDelim(Delimiter::Brace)) @@ -1535,7 +1496,7 @@ impl<'a> Parser<'a> { } /// Parse `'label: $expr`. The label is already parsed. - fn parse_expr_labeled( + pub(super) fn parse_expr_labeled( &mut self, label_: Label, mut consume_colon: bool, @@ -3013,6 +2974,11 @@ impl<'a> Parser<'a> { } else { e.span_label(pth.span, "while parsing this struct"); } + + if !recover { + return Err(e); + } + e.emit(); // If the next token is a comma, then try to parse @@ -3024,6 +2990,7 @@ impl<'a> Parser<'a> { break; } } + None } }; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 9e003bfc097..64ff7f1fb2c 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -443,7 +443,7 @@ impl<'a> Parser<'a> { Ok(args) => { self.eat_semi_for_macro_if_needed(&args); self.complain_if_pub_macro(vis, false); - Ok(MacCall { path, args, prior_type_ascription: self.last_type_ascription }) + Ok(MacCall { path, args }) } Err(mut err) => { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 1c34e491f21..93a01fafa10 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -148,9 +148,6 @@ pub struct Parser<'a> { max_angle_bracket_count: u32, last_unexpected_token_span: Option, - /// Span pointing at the `:` for the last type ascription the parser has seen, and whether it - /// looked like it could have been a mistyped path or literal `Option:Some(42)`). - pub last_type_ascription: Option<(Span, bool /* likely path typo */)>, /// If present, this `Parser` is not parsing Rust code but rather a macro call. subparser_name: Option<&'static str>, capture_state: CaptureState, @@ -165,7 +162,7 @@ pub struct Parser<'a> { // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure // it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Parser<'_>, 288); +rustc_data_structures::static_assert_size!(Parser<'_>, 320); /// Stores span information about a closure. #[derive(Clone)] @@ -470,7 +467,6 @@ impl<'a> Parser<'a> { unmatched_angle_bracket_count: 0, max_angle_bracket_count: 0, last_unexpected_token_span: None, - last_type_ascription: None, subparser_name, capture_state: CaptureState { capturing: Capturing::No, @@ -832,10 +828,11 @@ impl<'a> Parser<'a> { } fn expect_any_with_type(&mut self, kets: &[&TokenKind], expect: TokenExpectType) -> bool { - kets.iter().any(|k| match expect { + let res = kets.iter().any(|k| match expect { TokenExpectType::Expect => self.check(k), TokenExpectType::NoExpect => self.token == **k, - }) + }); + res } fn parse_seq_to_before_tokens( @@ -941,10 +938,14 @@ impl<'a> Parser<'a> { // propagate the help message from sub error 'e' to main error 'expect_err; expect_err.children.push(xx.clone()); } - expect_err.emit(); - e.cancel(); - break; + if self.token == token::Colon { + // we will try to recover in `maybe_recover_struct_lit_bad_delims` + return Err(expect_err); + } else { + expect_err.emit(); + break; + } } } } @@ -959,7 +960,6 @@ impl<'a> Parser<'a> { let t = f(self)?; v.push(t); } - Ok((v, trailing, recovered)) } @@ -1045,6 +1045,7 @@ impl<'a> Parser<'a> { f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec, bool /* trailing */)> { let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?; + if !recovered { self.eat(ket); } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index f2422fe307c..3c4b2977af9 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -406,11 +406,11 @@ impl<'a> Parser<'a> { // Parse pattern starting with a path let (qself, path) = if self.eat_lt() { // Parse a qualified path - let (qself, path) = self.parse_qpath(PathStyle::Expr)?; + let (qself, path) = self.parse_qpath(PathStyle::Pat)?; (Some(qself), path) } else { // Parse an unqualified path - (None, self.parse_path(PathStyle::Expr)?) + (None, self.parse_path(PathStyle::Pat)?) }; let span = lo.to(self.prev_token.span); @@ -666,7 +666,7 @@ impl<'a> Parser<'a> { fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind> { self.bump(); let args = self.parse_delim_args()?; - let mac = P(MacCall { path, args, prior_type_ascription: self.last_type_ascription }); + let mac = P(MacCall { path, args }); Ok(PatKind::MacCall(mac)) } @@ -789,11 +789,11 @@ impl<'a> Parser<'a> { let lo = self.token.span; let (qself, path) = if self.eat_lt() { // Parse a qualified path - let (qself, path) = self.parse_qpath(PathStyle::Expr)?; + let (qself, path) = self.parse_qpath(PathStyle::Pat)?; (Some(qself), path) } else { // Parse an unqualified path - (None, self.parse_path(PathStyle::Expr)?) + (None, self.parse_path(PathStyle::Pat)?) }; let hi = self.prev_token.span; Ok(self.mk_expr(lo.to(hi), ExprKind::Path(qself, path))) diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index ae73760bd8c..323588c4ff5 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -1,5 +1,6 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; use super::{Parser, Restrictions, TokenType}; +use crate::errors::PathSingleColon; use crate::{errors, maybe_whole}; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; @@ -8,7 +9,7 @@ use rustc_ast::{ AssocConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, ParenthesizedArgs, Path, PathSegment, QSelf, }; -use rustc_errors::{Applicability, PResult}; +use rustc_errors::{pluralize, Applicability, IntoDiagnostic, PResult}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym, Ident}; use std::mem; @@ -16,7 +17,7 @@ use thin_vec::ThinVec; use tracing::debug; /// Specifies how to parse a path. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum PathStyle { /// In some contexts, notably in expressions, paths with generic arguments are ambiguous /// with something else. For example, in expressions `segment < ....` can be interpreted @@ -24,7 +25,19 @@ pub enum PathStyle { /// In all such contexts the non-path interpretation is preferred by default for practical /// reasons, but the path interpretation can be forced by the disambiguator `::`, e.g. /// `x` - comparisons, `x::` - unambiguously a path. + /// + /// Also, a path may never be followed by a `:`. This means that we can eagerly recover if + /// we encounter it. Expr, + /// The same as `Expr`, but may be followed by a `:`. + /// For example, this code: + /// ```rust + /// struct S; + /// + /// let S: S; + /// // ^ Followed by a `:` + /// ``` + Pat, /// In other contexts, notably in types, no ambiguity exists and paths can be written /// without the disambiguator, e.g., `x` - unambiguously a path. /// Paths with disambiguators are still accepted, `x::` - unambiguously a path too. @@ -38,6 +51,12 @@ pub enum PathStyle { Mod, } +impl PathStyle { + fn has_generic_ambiguity(&self) -> bool { + matches!(self, Self::Expr | Self::Pat) + } +} + impl<'a> Parser<'a> { /// Parses a qualified path. /// Assumes that the leading `<` has been parsed already. @@ -183,7 +202,9 @@ impl<'a> Parser<'a> { segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); } self.parse_path_segments(&mut segments, style, ty_generics)?; - + if segments.len() > 1 { + //panic!("debug now ..."); + } Ok(Path { segments, span: lo.to(self.prev_token.span), tokens: None }) } @@ -195,7 +216,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, ()> { loop { let segment = self.parse_path_segment(style, ty_generics)?; - if style == PathStyle::Expr { + if style.has_generic_ambiguity() { // In order to check for trailing angle brackets, we must have finished // recursing (`parse_path_segment` can indirectly call this function), // that is, the next token must be the highlighted part of the below example: @@ -217,6 +238,29 @@ impl<'a> Parser<'a> { segments.push(segment); if self.is_import_coupler() || !self.eat(&token::ModSep) { + if style == PathStyle::Expr + && self.may_recover() + && self.token == token::Colon + && self.look_ahead(1, |token| token.is_ident() && !token.is_reserved_ident()) + { + // Emit a special error message for `a::b:c` to help users + // otherwise, `a: c` might have meant to introduce a new binding + if self.token.span.lo() == self.prev_token.span.hi() + && self.look_ahead(1, |token| self.token.span.hi() == token.span.lo()) + { + self.bump(); // bump past the colon + self.sess.emit_err(PathSingleColon { + span: self.prev_token.span, + type_ascription: self + .sess + .unstable_features + .is_nightly_build() + .then_some(()), + }); + } + continue; + } + return Ok(()); } } @@ -270,8 +314,25 @@ impl<'a> Parser<'a> { ty_generics, )?; self.expect_gt().map_err(|mut err| { + // Try to recover a `:` into a `::` + if self.token == token::Colon + && self.look_ahead(1, |token| { + token.is_ident() && !token.is_reserved_ident() + }) + { + err.cancel(); + err = PathSingleColon { + span: self.token.span, + type_ascription: self + .sess + .unstable_features + .is_nightly_build() + .then_some(()), + } + .into_diagnostic(self.diagnostic()); + } // Attempt to find places where a missing `>` might belong. - if let Some(arg) = args + else if let Some(arg) = args .iter() .rev() .find(|arg| !matches!(arg, AngleBracketedArg::Constraint(_))) @@ -679,6 +740,7 @@ impl<'a> Parser<'a> { &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, Option> { + debug!("pain"); let start = self.token.span; let arg = if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. @@ -687,6 +749,7 @@ impl<'a> Parser<'a> { // Parse const argument. GenericArg::Const(self.parse_const_arg()?) } else if self.check_type() { + debug!("type"); // Parse type argument. // Proactively create a parser snapshot enabling us to rewind and try to reparse the diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index fbe5b88c49e..8e8788beeba 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -10,6 +10,8 @@ use super::{ use crate::errors; use crate::maybe_whole; +use crate::errors::MalformedLoopLabel; +use ast::Label; use rustc_ast as ast; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, TokenKind}; @@ -19,7 +21,8 @@ use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, HasAttrs, Local, Stmt}; use rustc_ast::{StmtKind, DUMMY_NODE_ID}; use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult}; use rustc_span::source_map::{BytePos, Span}; -use rustc_span::symbol::{kw, sym}; +use rustc_span::symbol::{kw, sym, Ident}; + use std::mem; use thin_vec::{thin_vec, ThinVec}; @@ -186,7 +189,7 @@ impl<'a> Parser<'a> { _ => MacStmtStyle::NoBraces, }; - let mac = P(MacCall { path, args, prior_type_ascription: self.last_type_ascription }); + let mac = P(MacCall { path, args }); let kind = if (style == MacStmtStyle::Braces && self.token != token::Dot @@ -546,10 +549,36 @@ impl<'a> Parser<'a> { } let stmt = match self.parse_full_stmt(recover) { Err(mut err) if recover.yes() => { - self.maybe_annotate_with_ascription(&mut err, false); if let Some(ref mut snapshot) = snapshot { snapshot.recover_diff_marker(); } + if self.token == token::Colon { + // if next token is following a colon, it's likely a path + // and we can suggest a path separator + let ident_span = self.prev_token.span; + self.bump(); + if self.token.span.lo() == self.prev_token.span.hi() { + err.span_suggestion_verbose( + self.prev_token.span, + "maybe write a path separator here", + "::", + Applicability::MaybeIncorrect, + ); + } + if self.look_ahead(1, |token| token == &token::Eq) { + err.span_suggestion_verbose( + ident_span.shrink_to_lo(), + "you might have meant to introduce a new binding", + "let ", + Applicability::MaybeIncorrect, + ); + } + if self.sess.unstable_features.is_nightly_build() { + // FIXME(Nilstrieb): Remove this again after a few months. + err.note("type ascription syntax has been removed, see issue #101728 "); + } + } + err.emit(); self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); Some(self.mk_stmt_err(self.token.span)) @@ -580,19 +609,25 @@ impl<'a> Parser<'a> { }; let mut eat_semi = true; + let mut add_semi_to_stmt = false; + match &mut stmt.kind { // Expression without semicolon. StmtKind::Expr(expr) if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) => { // Just check for errors and recover; do not eat semicolon yet. // `expect_one_of` returns PResult<'a, bool /* recovered */> - let replace_with_err = - match self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)]) { + + let expect_result = self.expect_one_of(&[], &[token::Semi, token::CloseDelim(Delimiter::Brace)]); + + let replace_with_err = 'break_recover: { + match expect_result { // Recover from parser, skip type error to avoid extra errors. - Ok(true) => true, - Err(mut e) => { - if let TokenKind::DocComment(..) = self.token.kind && - let Ok(snippet) = self.span_to_snippet(self.token.span) { + Ok(true) => true, + Err(mut e) => { + if let TokenKind::DocComment(..) = self.token.kind + && let Ok(snippet) = self.span_to_snippet(self.token.span) + { let sp = self.token.span; let marker = &snippet[..3]; let (comment_marker, doc_comment_marker) = marker.split_at(2); @@ -606,21 +641,72 @@ impl<'a> Parser<'a> { format!("{} {}", comment_marker, doc_comment_marker), Applicability::MaybeIncorrect, ); - } + } + + if self.recover_colon_as_semi() { + // recover_colon_as_semi has already emitted a nicer error. + e.cancel(); + add_semi_to_stmt = true; + eat_semi = false; + + break 'break_recover false; + } + + match &expr.kind { + ExprKind::Path(None, ast::Path { segments, .. }) if segments.len() == 1 => { + if self.token == token::Colon + && self.look_ahead(1, |token| { + token.is_whole_block() || matches!( + token.kind, + token::Ident(kw::For | kw::Loop | kw::While, false) + | token::OpenDelim(Delimiter::Brace) + ) + }) + { + let snapshot = self.create_snapshot_for_diagnostic(); + let label = Label { + ident: Ident::from_str_and_span( + &format!("'{}", segments[0].ident), + segments[0].ident.span, + ), + }; + match self.parse_expr_labeled(label, false) { + Ok(labeled_expr) => { + e.cancel(); + self.sess.emit_err(MalformedLoopLabel { + span: label.ident.span, + correct_label: label.ident, + }); + *expr = labeled_expr; + break 'break_recover false; + } + Err(err) => { + err.cancel(); + self.restore_snapshot(snapshot); + } + } + } + } + _ => {} + } - if let Err(mut e) = - self.check_mistyped_turbofish_with_multiple_type_params(e, expr) - { - if recover.no() { - return Err(e); + if let Err(mut e) = + self.check_mistyped_turbofish_with_multiple_type_params(e, expr) + { + if recover.no() { + return Err(e); + } + e.emit(); + self.recover_stmt(); } - e.emit(); - self.recover_stmt(); + + true + } - true + Ok(false) => false } - _ => false }; + if replace_with_err { // We already emitted an error, so don't emit another type error let sp = expr.span.to(self.prev_token.span); @@ -643,9 +729,10 @@ impl<'a> Parser<'a> { StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false, } - if eat_semi && self.eat(&token::Semi) { + if add_semi_to_stmt || (eat_semi && self.eat(&token::Semi)) { stmt = stmt.add_trailing_semicolon(); } + stmt.span = stmt.span.to(self.prev_token.span); Ok(Some(stmt)) } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 3ceb3a2bef1..37c441fbecb 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -317,7 +317,6 @@ impl<'a> Parser<'a> { let msg = format!("expected type, found {}", super::token_descr(&self.token)); let mut err = self.struct_span_err(self.token.span, &msg); err.span_label(self.token.span, "expected type"); - self.maybe_annotate_with_ascription(&mut err, true); return Err(err); }; @@ -651,11 +650,7 @@ impl<'a> Parser<'a> { let path = self.parse_path_inner(PathStyle::Type, ty_generics)?; if self.eat(&token::Not) { // Macro invocation in type position - Ok(TyKind::MacCall(P(MacCall { - path, - args: self.parse_delim_args()?, - prior_type_ascription: self.last_type_ascription, - }))) + Ok(TyKind::MacCall(P(MacCall { path, args: self.parse_delim_args()? }))) } else if allow_plus == AllowPlus::Yes && self.check_plus() { // `Trait1 + Trait2 + 'a` self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true) -- cgit 1.4.1-3-g733a5 From 1b08eaca200ea5c7f6455b0302e031b479fb33dc Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 14 Mar 2023 23:48:33 +0800 Subject: clean up debug code --- compiler/rustc_parse/src/parser/diagnostics.rs | 11 +---------- compiler/rustc_parse/src/parser/path.rs | 5 ----- compiler/rustc_resolve/src/diagnostics.rs | 4 ---- compiler/rustc_resolve/src/late.rs | 5 ++++- compiler/rustc_resolve/src/late/diagnostics.rs | 1 - 5 files changed, 5 insertions(+), 21 deletions(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index bcc76c20815..aad7d21e1b4 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1775,21 +1775,13 @@ impl<'a> Parser<'a> { lo: Span, result: PResult<'a, P>, ) -> P { - use crate::parser::DUMMY_NODE_ID; match result { Ok(x) => x, Err(mut err) => { err.emit(); // Recover from parse error, callers expect the closing delim to be consumed. self.consume_block(delim, ConsumeClosingDelim::Yes); - debug!("recover_seq_parse_error: consumed tokens until {:?} {:?}", lo, self.token); - let res = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err); - if res.id == DUMMY_NODE_ID { - //panic!("debug now ....: {:?}", res); - res - } else { - res - } + self.mk_expr(lo.to(self.prev_token.span), ExprKind::Err) } } } @@ -1871,7 +1863,6 @@ impl<'a> Parser<'a> { && brace_depth == 0 && bracket_depth == 0 => { - debug!("recover_stmt_ return - Comma"); break; } _ => self.bump(), diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 323588c4ff5..950efc2a9fc 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -202,9 +202,6 @@ impl<'a> Parser<'a> { segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); } self.parse_path_segments(&mut segments, style, ty_generics)?; - if segments.len() > 1 { - //panic!("debug now ..."); - } Ok(Path { segments, span: lo.to(self.prev_token.span), tokens: None }) } @@ -740,7 +737,6 @@ impl<'a> Parser<'a> { &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, Option> { - debug!("pain"); let start = self.token.span; let arg = if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. @@ -749,7 +745,6 @@ impl<'a> Parser<'a> { // Parse const argument. GenericArg::Const(self.parse_const_arg()?) } else if self.check_type() { - debug!("type"); // Parse type argument. // Proactively create a parser snapshot enabling us to rewind and try to reparse the diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index aebd8125e2c..4b7048eac04 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -777,10 +777,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .sess .create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }), ResolutionError::FailedToResolve { label, suggestion } => { - if label.len() > 0 { - //panic!("debug now"); - } - let mut err = struct_span_err!(self.tcx.sess, span, E0433, "failed to resolve: {}", &label); err.span_label(span, label); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ba4fe20703f..547471ca90d 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3715,7 +3715,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } /// Handles paths that may refer to associated items. - #[instrument(level = "debug", skip(self))] fn resolve_qpath( &mut self, qself: &Option>, @@ -3723,6 +3722,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { ns: Namespace, finalize: Finalize, ) -> Result, Spanned>> { + debug!( + "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})", + qself, path, ns, finalize, + ); if let Some(qself) = qself { if qself.position == 0 { // This is a case like `::B`, where there is no diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 6e1b80860ba..383648877c8 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -305,7 +305,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { /// Handles error reporting for `smart_resolve_path_fragment` function. /// Creates base error and amends it with one short label and possibly some longer helps/notes. - #[instrument(level = "debug", skip(self))] pub(crate) fn smart_resolve_report_errors( &mut self, path: &[Segment], -- cgit 1.4.1-3-g733a5 From a4453c20cae5e72073d3cb6180132de2f371d2de Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 15 Mar 2023 00:41:47 +0800 Subject: fix parser size --- compiler/rustc_parse/src/parser/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 93a01fafa10..8cf0f95d90e 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -162,7 +162,7 @@ pub struct Parser<'a> { // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure // it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Parser<'_>, 320); +rustc_data_structures::static_assert_size!(Parser<'_>, 272); /// Stores span information about a closure. #[derive(Clone)] -- cgit 1.4.1-3-g733a5 From f54489978d478797108218fda90e1c929e657937 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 15 Mar 2023 07:10:59 +0800 Subject: fix tests --- compiler/rustc_parse/src/parser/diagnostics.rs | 1 - compiler/rustc_parse/src/parser/expr.rs | 15 +------------- compiler/rustc_parse/src/parser/mod.rs | 7 +++---- compiler/rustc_parse/src/parser/path.rs | 2 +- compiler/rustc_resolve/src/late.rs | 10 ++++++--- src/tools/rustfmt/tests/source/type-ascription.rs | 10 ++++----- .../target/configs/format_macro_bodies/true.rs | 8 ++------ .../target/configs/format_macro_matchers/false.rs | 8 ++------ .../target/configs/format_macro_matchers/true.rs | 8 ++------ src/tools/rustfmt/tests/target/macros.rs | 22 ++++++++------------ src/tools/rustfmt/tests/target/type-ascription.rs | 11 +++++----- src/tools/rustfmt/tests/target/type.rs | 2 +- .../generic-associated-types/equality-bound.stderr | 5 +---- .../ui/macros/builtin-prelude-no-accidents.stderr | 15 ++++++-------- tests/ui/parser/dyn-trait-compatibility.stderr | 24 +++++++++++----------- tests/ui/pattern/pattern-error-continue.stderr | 15 ++++++-------- tests/ui/resolve/resolve-variant-assoc-item.stderr | 14 ------------- .../assoc_type_bound_with_struct.stderr | 12 +++++------ tests/ui/type/type-path-err-node-types.stderr | 12 +++++------ tests/ui/ufcs/ufcs-partially-resolved.stderr | 10 --------- 20 files changed, 76 insertions(+), 135 deletions(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index aad7d21e1b4..da419f06537 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -238,7 +238,6 @@ impl<'a> DerefMut for SnapshotParser<'a> { impl<'a> Parser<'a> { #[rustc_lint_diagnostics] - #[track_caller] pub fn struct_span_err>( &self, sp: S, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 7c55ac9cce2..02db4b095dc 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -294,17 +294,6 @@ impl<'a> Parser<'a> { continue; } - // Special cases: - if op.node == AssocOp::As { - lhs = self.parse_assoc_op_cast(lhs, lhs_span, ExprKind::Cast)?; - continue; - } else if op.node == AssocOp::DotDot || op.node == AssocOp::DotDotEq { - // If we didn't have to handle `x..`/`x..=`, it would be pretty easy to - // generalise it to the Fixity::None code. - lhs = self.parse_expr_range(prec, lhs, op.node, cur_op_span)?; - break; - } - let op = op.node; // Special cases: if op == AssocOp::As { @@ -619,9 +608,7 @@ impl<'a> Parser<'a> { token::Ident(..) if this.may_recover() && this.is_mistaken_not_ident_negation() => { make_it!(this, attrs, |this, _| this.recover_not_expr(lo)) } - _ => { - return this.parse_expr_dot_or_call(Some(attrs)); - } + _ => return this.parse_expr_dot_or_call(Some(attrs)), } } diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 8cf0f95d90e..b294e13402a 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -828,11 +828,10 @@ impl<'a> Parser<'a> { } fn expect_any_with_type(&mut self, kets: &[&TokenKind], expect: TokenExpectType) -> bool { - let res = kets.iter().any(|k| match expect { + kets.iter().any(|k| match expect { TokenExpectType::Expect => self.check(k), TokenExpectType::NoExpect => self.token == **k, - }); - res + }) } fn parse_seq_to_before_tokens( @@ -960,6 +959,7 @@ impl<'a> Parser<'a> { let t = f(self)?; v.push(t); } + Ok((v, trailing, recovered)) } @@ -1045,7 +1045,6 @@ impl<'a> Parser<'a> { f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec, bool /* trailing */)> { let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?; - if !recovered { self.eat(ket); } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 950efc2a9fc..9a863a8eef7 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -17,7 +17,7 @@ use thin_vec::ThinVec; use tracing::debug; /// Specifies how to parse a path. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq)] pub enum PathStyle { /// In some contexts, notably in expressions, paths with generic arguments are ambiguous /// with something else. For example, in expressions `segment < ....` can be interpreted diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 547471ca90d..2ac6fac7f56 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1261,15 +1261,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { opt_ns: Option, // `None` indicates a module path in import finalize: Option, ) -> PathResult<'a> { - let res = self.r.resolve_path_with_ribs( + self.r.resolve_path_with_ribs( path, opt_ns, &self.parent_scope, finalize, Some(&self.ribs), None, - ); - res + ) } // AST resolution @@ -3486,6 +3485,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { // // Similar thing, for types, happens in `report_errors` above. let report_errors_for_call = |this: &mut Self, parent_err: Spanned>| { + if !source.is_call() { + return Some(parent_err); + } + // Before we start looking for candidates, we have to get our hands // on the type user is trying to perform invocation on; basically: // we're transforming `HashMap::new` into just `HashMap`. @@ -3726,6 +3729,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})", qself, path, ns, finalize, ); + if let Some(qself) = qself { if qself.position == 0 { // This is a case like `::B`, where there is no diff --git a/src/tools/rustfmt/tests/source/type-ascription.rs b/src/tools/rustfmt/tests/source/type-ascription.rs index 4874094ccc4..fbdde272cb6 100644 --- a/src/tools/rustfmt/tests/source/type-ascription.rs +++ b/src/tools/rustfmt/tests/source/type-ascription.rs @@ -1,10 +1,10 @@ - +// #101728, we remove type ascription, so this test case is changed to `var as ty` fn main() { - let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy : SomeTrait; + let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy as SomeTrait; - let xxxxxxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + let xxxxxxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy as AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; - let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww): AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww) as AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; - x : u32 - 1u32 / 10f32 : u32 + let _ = x as u32 - 1u32 / (10f32 as u32); } diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs b/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs index 9dc2524c389..17ac1498c93 100644 --- a/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs +++ b/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs @@ -1,10 +1,6 @@ // rustfmt-format_macro_bodies: true macro_rules! foo { - ($a: ident : $b: ty) => { - $a(42): $b; - }; - ($a: ident $b: ident $c: ident) => { - $a = $b + $c; - }; + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; } diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs index 3966d21be75..01ecac9879d 100644 --- a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs +++ b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs @@ -1,10 +1,6 @@ // rustfmt-format_macro_matchers: false macro_rules! foo { - ($a: ident : $b: ty) => { - $a(42): $b; - }; - ($a: ident $b: ident $c: ident) => { - $a = $b + $c; - }; + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; } diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs index e113af96f26..fa0442e228a 100644 --- a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs +++ b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs @@ -1,10 +1,6 @@ // rustfmt-format_macro_matchers: true macro_rules! foo { - ($a:ident : $b:ty) => { - $a(42): $b; - }; - ($a:ident $b:ident $c:ident) => { - $a = $b + $c; - }; + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; } diff --git a/src/tools/rustfmt/tests/target/macros.rs b/src/tools/rustfmt/tests/target/macros.rs index e930b5037d9..7b4574349df 100644 --- a/src/tools/rustfmt/tests/target/macros.rs +++ b/src/tools/rustfmt/tests/target/macros.rs @@ -122,7 +122,7 @@ fn main() { 20, 21, 22); // #1092 - chain!(input, a: take!(max_size), || []); + chain!(input, a:take!(max_size), || []); // #2727 foo!("bar"); @@ -156,17 +156,13 @@ fn issue1178() { } fn issue1739() { - sql_function!( - add_rss_item, - add_rss_item_t, - ( - a: types::Integer, - b: types::Timestamptz, - c: types::Text, - d: types::Text, - e: types::Text - ) - ); + sql_function!(add_rss_item, + add_rss_item_t, + (a: types::Integer, + b: types::Timestamptz, + c: types::Text, + d: types::Text, + e: types::Text)); w.slice_mut(s![ .., @@ -232,7 +228,7 @@ fn issue_3174() { "debugMessage": debug.message, }) } else { - json!({ "errorKind": format!("{:?}", error.err_kind()) }) + json!({"errorKind": format!("{:?}", error.err_kind())}) }; } diff --git a/src/tools/rustfmt/tests/target/type-ascription.rs b/src/tools/rustfmt/tests/target/type-ascription.rs index a2f082ba4b4..99dc0336864 100644 --- a/src/tools/rustfmt/tests/target/type-ascription.rs +++ b/src/tools/rustfmt/tests/target/type-ascription.rs @@ -1,12 +1,13 @@ +// #101728, we remove type ascription, so this test case is changed to `var as ty` fn main() { let xxxxxxxxxxx = - yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait; + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy as SomeTrait; let xxxxxxxxxxxxxxx = - yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy as AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; - let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww): - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww) + as AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; - x: u32 - 1u32 / 10f32: u32 + let _ = x as u32 - 1u32 / (10f32 as u32); } diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 38cf909c258..c789ecb055a 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -129,7 +129,7 @@ fn issue3117() { fn issue3139() { assert_eq!( to_json_value(&None::).unwrap(), - json!({ "test": None:: }) + json!( { "test": None :: } ) ); } diff --git a/tests/ui/generic-associated-types/equality-bound.stderr b/tests/ui/generic-associated-types/equality-bound.stderr index b21ff30a27d..d78f7a7fbce 100644 --- a/tests/ui/generic-associated-types/equality-bound.stderr +++ b/tests/ui/generic-associated-types/equality-bound.stderr @@ -36,10 +36,7 @@ error[E0433]: failed to resolve: use of undeclared type `I` --> $DIR/equality-bound.rs:9:41 | LL | fn sum3(i: J) -> i32 where I::Item = i32 { - | ^ - | | - | use of undeclared type `I` - | help: a type parameter with a similar name exists: `J` + | ^ use of undeclared type `I` error: aborting due to 4 previous errors diff --git a/tests/ui/macros/builtin-prelude-no-accidents.stderr b/tests/ui/macros/builtin-prelude-no-accidents.stderr index 8cd9a63b808..56af618d484 100644 --- a/tests/ui/macros/builtin-prelude-no-accidents.stderr +++ b/tests/ui/macros/builtin-prelude-no-accidents.stderr @@ -4,21 +4,18 @@ error[E0433]: failed to resolve: use of undeclared crate or module `env` LL | env::current_dir; | ^^^ use of undeclared crate or module `env` -error[E0433]: failed to resolve: use of undeclared crate or module `vec` - --> $DIR/builtin-prelude-no-accidents.rs:7:14 - | -LL | type B = vec::Vec; - | ^^^ - | | - | use of undeclared crate or module `vec` - | help: a struct with a similar name exists (notice the capitalization): `Vec` - error[E0433]: failed to resolve: use of undeclared crate or module `panic` --> $DIR/builtin-prelude-no-accidents.rs:6:14 | LL | type A = panic::PanicInfo; | ^^^^^ use of undeclared crate or module `panic` +error[E0433]: failed to resolve: use of undeclared crate or module `vec` + --> $DIR/builtin-prelude-no-accidents.rs:7:14 + | +LL | type B = vec::Vec; + | ^^^ use of undeclared crate or module `vec` + error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/parser/dyn-trait-compatibility.stderr b/tests/ui/parser/dyn-trait-compatibility.stderr index 39f6727bb61..792d788dde7 100644 --- a/tests/ui/parser/dyn-trait-compatibility.stderr +++ b/tests/ui/parser/dyn-trait-compatibility.stderr @@ -1,3 +1,15 @@ +error[E0433]: failed to resolve: use of undeclared crate or module `dyn` + --> $DIR/dyn-trait-compatibility.rs:3:11 + | +LL | type A1 = dyn::dyn; + | ^^^ use of undeclared crate or module `dyn` + +error[E0433]: failed to resolve: use of undeclared crate or module `dyn` + --> $DIR/dyn-trait-compatibility.rs:9:23 + | +LL | type A3 = dyn<::dyn>; + | ^^^ use of undeclared crate or module `dyn` + error[E0412]: cannot find type `dyn` in this scope --> $DIR/dyn-trait-compatibility.rs:1:11 | @@ -40,18 +52,6 @@ error[E0412]: cannot find type `dyn` in this scope LL | type A3 = dyn<::dyn>; | ^^^ not found in this scope -error[E0433]: failed to resolve: use of undeclared crate or module `dyn` - --> $DIR/dyn-trait-compatibility.rs:3:11 - | -LL | type A1 = dyn::dyn; - | ^^^ use of undeclared crate or module `dyn` - -error[E0433]: failed to resolve: use of undeclared crate or module `dyn` - --> $DIR/dyn-trait-compatibility.rs:9:23 - | -LL | type A3 = dyn<::dyn>; - | ^^^ use of undeclared crate or module `dyn` - error: aborting due to 8 previous errors Some errors have detailed explanations: E0405, E0412, E0433. diff --git a/tests/ui/pattern/pattern-error-continue.stderr b/tests/ui/pattern/pattern-error-continue.stderr index 10fcccb0301..e1349fb02ea 100644 --- a/tests/ui/pattern/pattern-error-continue.stderr +++ b/tests/ui/pattern/pattern-error-continue.stderr @@ -1,3 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared type `E` + --> $DIR/pattern-error-continue.rs:33:9 + | +LL | E::V => {} + | ^ use of undeclared type `E` + error[E0532]: expected tuple struct or tuple variant, found unit variant `A::D` --> $DIR/pattern-error-continue.rs:18:9 | @@ -50,15 +56,6 @@ note: function defined here LL | fn f(_c: char) {} | ^ -------- -error[E0433]: failed to resolve: use of undeclared type `E` - --> $DIR/pattern-error-continue.rs:33:9 - | -LL | E::V => {} - | ^ - | | - | use of undeclared type `E` - | help: an enum with a similar name exists: `A` - error: aborting due to 5 previous errors Some errors have detailed explanations: E0023, E0308, E0433, E0532. diff --git a/tests/ui/resolve/resolve-variant-assoc-item.stderr b/tests/ui/resolve/resolve-variant-assoc-item.stderr index ed157197d17..4be1019968b 100644 --- a/tests/ui/resolve/resolve-variant-assoc-item.stderr +++ b/tests/ui/resolve/resolve-variant-assoc-item.stderr @@ -3,26 +3,12 @@ error[E0433]: failed to resolve: `V` is a variant, not a module | LL | E::V::associated_item; | ^ `V` is a variant, not a module - | -help: there is an enum variant `E::V`; try using the variant's enum - | -LL | E; - | ~ error[E0433]: failed to resolve: `V` is a variant, not a module --> $DIR/resolve-variant-assoc-item.rs:6:5 | LL | V::associated_item; | ^ `V` is a variant, not a module - | -help: there is an enum variant `E::V`; try using the variant's enum - | -LL | E; - | ~ -help: an enum with a similar name exists - | -LL | E::associated_item; - | ~ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr index f3cd02be7f0..a39f4a9daaa 100644 --- a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr +++ b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr @@ -1,3 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared type `Unresolved` + --> $DIR/assoc_type_bound_with_struct.rs:19:31 + | +LL | fn issue_95327() where ::Assoc: String {} + | ^^^^^^^^^^ use of undeclared type `Unresolved` + error[E0404]: expected trait, found struct `String` --> $DIR/assoc_type_bound_with_struct.rs:5:46 | @@ -85,12 +91,6 @@ LL | fn issue_95327() where ::Assoc: String {} | = note: similarly named trait `ToString` defined here -error[E0433]: failed to resolve: use of undeclared type `Unresolved` - --> $DIR/assoc_type_bound_with_struct.rs:19:31 - | -LL | fn issue_95327() where ::Assoc: String {} - | ^^^^^^^^^^ use of undeclared type `Unresolved` - error: aborting due to 6 previous errors Some errors have detailed explanations: E0404, E0405. diff --git a/tests/ui/type/type-path-err-node-types.stderr b/tests/ui/type/type-path-err-node-types.stderr index 8b12aa1a393..1aed1dbe4ba 100644 --- a/tests/ui/type/type-path-err-node-types.stderr +++ b/tests/ui/type/type-path-err-node-types.stderr @@ -1,3 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared type `NonExistent` + --> $DIR/type-path-err-node-types.rs:15:5 + | +LL | NonExistent::Assoc::; + | ^^^^^^^^^^^ use of undeclared type `NonExistent` + error[E0412]: cannot find type `Nonexistent` in this scope --> $DIR/type-path-err-node-types.rs:7:12 | @@ -16,12 +22,6 @@ error[E0425]: cannot find value `nonexistent` in this scope LL | nonexistent.nonexistent::(); | ^^^^^^^^^^^ not found in this scope -error[E0433]: failed to resolve: use of undeclared type `NonExistent` - --> $DIR/type-path-err-node-types.rs:15:5 - | -LL | NonExistent::Assoc::; - | ^^^^^^^^^^^ use of undeclared type `NonExistent` - error[E0282]: type annotations needed --> $DIR/type-path-err-node-types.rs:23:14 | diff --git a/tests/ui/ufcs/ufcs-partially-resolved.stderr b/tests/ui/ufcs/ufcs-partially-resolved.stderr index 737e739fceb..923d858b552 100644 --- a/tests/ui/ufcs/ufcs-partially-resolved.stderr +++ b/tests/ui/ufcs/ufcs-partially-resolved.stderr @@ -3,22 +3,12 @@ error[E0433]: failed to resolve: `Y` is a variant, not a module | LL | let _: ::NN; | ^ `Y` is a variant, not a module - | -help: there is an enum variant `E::Y`; try using the variant's enum - | -LL | let _: E; - | ~ error[E0433]: failed to resolve: `Y` is a variant, not a module --> $DIR/ufcs-partially-resolved.rs:50:15 | LL | ::NN; | ^ `Y` is a variant, not a module - | -help: there is an enum variant `E::Y`; try using the variant's enum - | -LL | E; - | ~ error[E0576]: cannot find associated type `N` in trait `Tr` --> $DIR/ufcs-partially-resolved.rs:19:24 -- cgit 1.4.1-3-g733a5 From 5d1796a608d387be784f17c28ec7c81f178a81eb Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 28 Apr 2023 09:55:38 +0800 Subject: soften the wording for removing type ascription --- compiler/rustc_builtin_macros/src/asm.rs | 3 +-- compiler/rustc_parse/messages.ftl | 3 ++- compiler/rustc_parse/src/parser/diagnostics.rs | 9 +-------- compiler/rustc_parse/src/parser/path.rs | 2 +- compiler/rustc_parse/src/parser/stmt.rs | 4 ++-- tests/ui/generics/single-colon-path-not-const-generics.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-method.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-path.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-variant.stderr | 2 +- tests/ui/type/ascription/issue-47666.stderr | 2 +- tests/ui/type/ascription/issue-54516.stderr | 2 +- tests/ui/type/ascription/issue-60933.stderr | 2 +- tests/ui/type/type-ascription-instead-of-statement-end.stderr | 2 +- tests/ui/type/type-ascription-with-fn-call.stderr | 2 +- 14 files changed, 16 insertions(+), 23 deletions(-) (limited to 'compiler/rustc_parse/src') diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 3ccdc8179a5..0ea8454db08 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -68,8 +68,7 @@ pub fn parse_asm_args<'a>( if !p.eat(&token::Comma) { if allow_templates { // After a template string, we always expect *only* a comma... - let mut err = diag.create_err(errors::AsmExpectedComma { span: p.token.span }); - return Err(err); + return Err(diag.create_err(errors::AsmExpectedComma { span: p.token.span })); } else { // ...after that delegate to `expect` to also include the other expected tokens. return Err(p.expect(&token::Comma).err().unwrap()); diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 9c6d00b44ce..9a5232b1bcd 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -426,7 +426,8 @@ parse_path_single_colon = path separator must be a double colon parse_colon_as_semi = statements are terminated with a semicolon .suggestion = use a semicolon instead -parse_type_ascription_removed = type ascription syntax has been removed, see issue #101728 +parse_type_ascription_removed = + if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 parse_where_clause_before_tuple_struct_body = where clauses are not allowed before tuple struct bodies .label = unexpected where clause diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index da419f06537..638a432cea5 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1569,14 +1569,9 @@ impl<'a> Parser<'a> { } pub(super) fn expect_semi(&mut self) -> PResult<'a, ()> { - if self.eat(&token::Semi) { + if self.eat(&token::Semi) || self.recover_colon_as_semi() { return Ok(()); } - - if self.recover_colon_as_semi() { - return Ok(()); - } - self.expect(&token::Semi).map(drop) // Error unconditionally } @@ -1597,9 +1592,7 @@ impl<'a> Parser<'a> { span: self.token.span, type_ascription: self.sess.unstable_features.is_nightly_build().then_some(()), }); - self.bump(); - return true; } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 9a863a8eef7..b9a2b141bce 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -9,7 +9,7 @@ use rustc_ast::{ AssocConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, ParenthesizedArgs, Path, PathSegment, QSelf, }; -use rustc_errors::{pluralize, Applicability, IntoDiagnostic, PResult}; +use rustc_errors::{Applicability, IntoDiagnostic, PResult}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym, Ident}; use std::mem; diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 8e8788beeba..0a571013d44 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -645,7 +645,7 @@ impl<'a> Parser<'a> { if self.recover_colon_as_semi() { // recover_colon_as_semi has already emitted a nicer error. - e.cancel(); + e.delay_as_bug(); add_semi_to_stmt = true; eat_semi = false; @@ -672,7 +672,7 @@ impl<'a> Parser<'a> { }; match self.parse_expr_labeled(label, false) { Ok(labeled_expr) => { - e.cancel(); + e.delay_as_bug(); self.sess.emit_err(MalformedLoopLabel { span: label.ident.span, correct_label: label.ident, diff --git a/tests/ui/generics/single-colon-path-not-const-generics.stderr b/tests/ui/generics/single-colon-path-not-const-generics.stderr index bb34c0ba546..96f07e190c1 100644 --- a/tests/ui/generics/single-colon-path-not-const-generics.stderr +++ b/tests/ui/generics/single-colon-path-not-const-generics.stderr @@ -6,7 +6,7 @@ LL | pub struct Foo { LL | a: Vec, | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-method.stderr b/tests/ui/suggestions/type-ascription-instead-of-method.stderr index 9be8c5ce3c1..b3799101cf0 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-method.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-method.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | let _ = Box:new("foo".to_string()); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-path.stderr b/tests/ui/suggestions/type-ascription-instead-of-path.stderr index d178621b8c6..849630218da 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-path.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-path.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | std:io::stdin(); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-variant.stderr b/tests/ui/suggestions/type-ascription-instead-of-variant.stderr index dfb7d8003fa..11d0f5f527e 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-variant.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-variant.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | let _ = Option:Some(""); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/type/ascription/issue-47666.stderr b/tests/ui/type/ascription/issue-47666.stderr index 2f815041ce1..74d85a75c85 100644 --- a/tests/ui/type/ascription/issue-47666.stderr +++ b/tests/ui/type/ascription/issue-47666.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | let _ = Option:Some(vec![0, 1]); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/type/ascription/issue-54516.stderr b/tests/ui/type/ascription/issue-54516.stderr index 7666864a9bc..a1371432f5a 100644 --- a/tests/ui/type/ascription/issue-54516.stderr +++ b/tests/ui/type/ascription/issue-54516.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | println!("{}", std::mem:size_of::>()); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/type/ascription/issue-60933.stderr b/tests/ui/type/ascription/issue-60933.stderr index 776cc412c32..0ec527ff5a9 100644 --- a/tests/ui/type/ascription/issue-60933.stderr +++ b/tests/ui/type/ascription/issue-60933.stderr @@ -4,7 +4,7 @@ error: path separator must be a double colon LL | let _: usize = std::mem:size_of::(); | ^ help: use a double colon instead: `::` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error diff --git a/tests/ui/type/type-ascription-instead-of-statement-end.stderr b/tests/ui/type/type-ascription-instead-of-statement-end.stderr index 678aed7b144..8c09e78bc5f 100644 --- a/tests/ui/type/type-ascription-instead-of-statement-end.stderr +++ b/tests/ui/type/type-ascription-instead-of-statement-end.stderr @@ -4,7 +4,7 @@ error: statements are terminated with a semicolon LL | println!("test"): | ^ help: use a semicolon instead: `;` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: expected one of `.`, `;`, `?`, `}`, or an operator, found `:` --> $DIR/type-ascription-instead-of-statement-end.rs:7:21 diff --git a/tests/ui/type/type-ascription-with-fn-call.stderr b/tests/ui/type/type-ascription-with-fn-call.stderr index 80fc075383e..e3afa497ac2 100644 --- a/tests/ui/type/type-ascription-with-fn-call.stderr +++ b/tests/ui/type/type-ascription-with-fn-call.stderr @@ -4,7 +4,7 @@ error: statements are terminated with a semicolon LL | f() : | ^ help: use a semicolon instead: `;` | - = note: type ascription syntax has been removed, see issue #101728 + = note: if you meant to annotate an expression with a type, the type ascription syntax has been removed, see issue #101728 error: aborting due to previous error -- cgit 1.4.1-3-g733a5