@@ -559,9 +559,7 @@ impl<'a> Parser<'a> {
559559 attrs : & mut AttrVec ,
560560 defaultness : Defaultness ,
561561 ) -> PResult < ' a , ItemKind > {
562- if self . eat_keyword ( exp ! ( Const ) ) {
563- return self . recover_const_impl ( self . prev_token . span , attrs, defaultness) ;
564- }
562+ let mut constness = self . parse_constness ( Case :: Sensitive ) ;
565563 let safety = self . parse_safety ( Case :: Sensitive ) ;
566564 self . expect_keyword ( exp ! ( Impl ) ) ?;
567565
@@ -576,7 +574,11 @@ impl<'a> Parser<'a> {
576574 generics
577575 } ;
578576
579- let constness = self . parse_constness ( Case :: Sensitive ) ;
577+ if let Const :: No = constness {
578+ // FIXME(const_trait_impl): disallow `impl const Trait`
579+ constness = self . parse_constness ( Case :: Sensitive ) ;
580+ }
581+
580582 if let Const :: Yes ( span) = constness {
581583 self . psess . gated_spans . gate ( sym:: const_trait_impl, span) ;
582584 }
@@ -1345,46 +1347,6 @@ impl<'a> Parser<'a> {
13451347 }
13461348 }
13471349
1348- /// Recover on `const impl` with `const` already eaten.
1349- fn recover_const_impl (
1350- & mut self ,
1351- const_span : Span ,
1352- attrs : & mut AttrVec ,
1353- defaultness : Defaultness ,
1354- ) -> PResult < ' a , ItemKind > {
1355- let impl_span = self . token . span ;
1356- let err = self . expected_ident_found_err ( ) ;
1357-
1358- // Only try to recover if this is implementing a trait for a type
1359- let mut item_kind = match self . parse_item_impl ( attrs, defaultness) {
1360- Ok ( item_kind) => item_kind,
1361- Err ( recovery_error) => {
1362- // Recovery failed, raise the "expected identifier" error
1363- recovery_error. cancel ( ) ;
1364- return Err ( err) ;
1365- }
1366- } ;
1367-
1368- match & mut item_kind {
1369- ItemKind :: Impl ( Impl { of_trait : Some ( of_trait) , .. } ) => {
1370- of_trait. constness = Const :: Yes ( const_span) ;
1371-
1372- let before_trait = of_trait. trait_ref . path . span . shrink_to_lo ( ) ;
1373- let const_up_to_impl = const_span. with_hi ( impl_span. lo ( ) ) ;
1374- err. with_multipart_suggestion (
1375- "you might have meant to write a const trait impl" ,
1376- vec ! [ ( const_up_to_impl, "" . to_owned( ) ) , ( before_trait, "const " . to_owned( ) ) ] ,
1377- Applicability :: MaybeIncorrect ,
1378- )
1379- . emit ( ) ;
1380- }
1381- ItemKind :: Impl { .. } => return Err ( err) ,
1382- _ => unreachable ! ( ) ,
1383- }
1384-
1385- Ok ( item_kind)
1386- }
1387-
13881350 /// Parse a static item with the prefix `"static" "mut"?` already parsed and stored in
13891351 /// `mutability`.
13901352 ///
0 commit comments