@@ -2,7 +2,6 @@ use rustc_ast as ast;
22use rustc_ast:: visit:: { self , AssocCtxt , FnCtxt , FnKind , Visitor } ;
33use rustc_ast:: { attr, AssocConstraint , AssocConstraintKind , NodeId } ;
44use rustc_ast:: { PatKind , RangeEnd } ;
5- use rustc_errors:: { Applicability , StashKey } ;
65use rustc_feature:: { AttributeGate , BuiltinAttribute , Features , GateIssue , BUILTIN_ATTRIBUTE_MAP } ;
76use rustc_session:: parse:: { feature_err, feature_err_issue, feature_warn} ;
87use rustc_session:: Session ;
@@ -374,55 +373,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
374373 }
375374 }
376375
377- fn visit_stmt ( & mut self , stmt : & ' a ast:: Stmt ) {
378- if let ast:: StmtKind :: Semi ( expr) = & stmt. kind
379- && let ast:: ExprKind :: Assign ( lhs, _, _) = & expr. kind
380- && let ast:: ExprKind :: Type ( ..) = lhs. kind
381- && self . sess . parse_sess . span_diagnostic . err_count ( ) == 0
382- && !self . features . type_ascription
383- && !lhs. span . allows_unstable ( sym:: type_ascription)
384- {
385- // When we encounter a statement of the form `foo: Ty = val;`, this will emit a type
386- // ascription error, but the likely intention was to write a `let` statement. (#78907).
387- feature_err (
388- & self . sess . parse_sess ,
389- sym:: type_ascription,
390- lhs. span ,
391- "type ascription is experimental" ,
392- ) . span_suggestion_verbose (
393- lhs. span . shrink_to_lo ( ) ,
394- "you might have meant to introduce a new binding" ,
395- "let " ,
396- Applicability :: MachineApplicable ,
397- ) . emit ( ) ;
398- }
399- visit:: walk_stmt ( self , stmt) ;
400- }
401-
402376 fn visit_expr ( & mut self , e : & ' a ast:: Expr ) {
403377 match e. kind {
404- ast:: ExprKind :: Type ( ..) => {
405- if self . sess . parse_sess . span_diagnostic . err_count ( ) == 0 {
406- // To avoid noise about type ascription in common syntax errors,
407- // only emit if it is the *only* error.
408- gate_feature_post ! (
409- & self ,
410- type_ascription,
411- e. span,
412- "type ascription is experimental"
413- ) ;
414- } else {
415- // And if it isn't, cancel the early-pass warning.
416- if let Some ( err) = self
417- . sess
418- . parse_sess
419- . span_diagnostic
420- . steal_diagnostic ( e. span , StashKey :: EarlySyntaxWarning )
421- {
422- err. cancel ( )
423- }
424- }
425- }
426378 ast:: ExprKind :: TryBlock ( _) => {
427379 gate_feature_post ! ( & self , try_blocks, e. span, "`try` expression is experimental" ) ;
428380 }
@@ -629,7 +581,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
629581 gate_all ! ( box_patterns, "box pattern syntax is experimental" ) ;
630582 gate_all ! ( exclusive_range_pattern, "exclusive range pattern syntax is experimental" ) ;
631583 gate_all ! ( try_blocks, "`try` blocks are unstable" ) ;
632- gate_all ! ( type_ascription, "type ascription is experimental" ) ;
633584
634585 visit:: walk_crate ( & mut visitor, krate) ;
635586}
0 commit comments