@@ -562,9 +562,7 @@ impl<'a> Parser<'a> {
562562 attrs : & mut AttrVec ,
563563 defaultness : Defaultness ,
564564 ) -> PResult < ' a , ItemKind > {
565- if self . eat_keyword ( exp ! ( Const ) ) {
566- return self . recover_const_impl ( self . prev_token . span , attrs, defaultness) ;
567- }
565+ let mut constness = self . parse_constness ( Case :: Sensitive ) ;
568566 let safety = self . parse_safety ( Case :: Sensitive ) ;
569567 self . expect_keyword ( exp ! ( Impl ) ) ?;
570568
@@ -579,7 +577,11 @@ impl<'a> Parser<'a> {
579577 generics
580578 } ;
581579
582- let constness = self . parse_constness ( Case :: Sensitive ) ;
580+ if let Const :: No = constness {
581+ // FIXME(const_trait_impl): disallow `impl const Trait`
582+ constness = self . parse_constness ( Case :: Sensitive ) ;
583+ }
584+
583585 if let Const :: Yes ( span) = constness {
584586 self . psess . gated_spans . gate ( sym:: const_trait_impl, span) ;
585587 }
@@ -1355,46 +1357,6 @@ impl<'a> Parser<'a> {
13551357 }
13561358 }
13571359
1358- /// Recover on `const impl` with `const` already eaten.
1359- fn recover_const_impl (
1360- & mut self ,
1361- const_span : Span ,
1362- attrs : & mut AttrVec ,
1363- defaultness : Defaultness ,
1364- ) -> PResult < ' a , ItemKind > {
1365- let impl_span = self . token . span ;
1366- let err = self . expected_ident_found_err ( ) ;
1367-
1368- // Only try to recover if this is implementing a trait for a type
1369- let mut item_kind = match self . parse_item_impl ( attrs, defaultness) {
1370- Ok ( item_kind) => item_kind,
1371- Err ( recovery_error) => {
1372- // Recovery failed, raise the "expected identifier" error
1373- recovery_error. cancel ( ) ;
1374- return Err ( err) ;
1375- }
1376- } ;
1377-
1378- match & mut item_kind {
1379- ItemKind :: Impl ( Impl { of_trait : Some ( of_trait) , .. } ) => {
1380- of_trait. constness = Const :: Yes ( const_span) ;
1381-
1382- let before_trait = of_trait. trait_ref . path . span . shrink_to_lo ( ) ;
1383- let const_up_to_impl = const_span. with_hi ( impl_span. lo ( ) ) ;
1384- err. with_multipart_suggestion (
1385- "you might have meant to write a const trait impl" ,
1386- vec ! [ ( const_up_to_impl, "" . to_owned( ) ) , ( before_trait, "const " . to_owned( ) ) ] ,
1387- Applicability :: MaybeIncorrect ,
1388- )
1389- . emit ( ) ;
1390- }
1391- ItemKind :: Impl { .. } => return Err ( err) ,
1392- _ => unreachable ! ( ) ,
1393- }
1394-
1395- Ok ( item_kind)
1396- }
1397-
13981360 /// Parse a static item with the prefix `"static" "mut"?` already parsed and stored in
13991361 /// `mutability`.
14001362 ///
0 commit comments