@@ -40,9 +40,8 @@ use crate::errors::{
4040 HelpIdentifierStartsWithNumber , HelpUseLatestEdition , InInTypo , IncorrectAwait ,
4141 IncorrectSemicolon , IncorrectUseOfAwait , IncorrectUseOfUse , PatternMethodParamWithoutBody ,
4242 QuestionMarkInType , QuestionMarkInTypeSugg , SelfParamNotFirst , StructLiteralBodyWithoutPath ,
43- StructLiteralBodyWithoutPathSugg , StructLiteralNeedingParens , StructLiteralNeedingParensSugg ,
44- SuggAddMissingLetStmt , SuggEscapeIdentifier , SuggRemoveComma , TernaryOperator ,
45- UnexpectedConstInGenericParam , UnexpectedConstParamDeclaration ,
43+ StructLiteralBodyWithoutPathSugg , SuggAddMissingLetStmt , SuggEscapeIdentifier , SuggRemoveComma ,
44+ TernaryOperator , UnexpectedConstInGenericParam , UnexpectedConstParamDeclaration ,
4645 UnexpectedConstParamDeclarationSugg , UnmatchedAngleBrackets , UseEqInstead , WrapType ,
4746} ;
4847use crate :: parser:: attr:: InnerAttrPolicy ;
@@ -949,7 +948,6 @@ impl<'a> Parser<'a> {
949948 lo : Span ,
950949 s : BlockCheckMode ,
951950 maybe_struct_name : token:: Token ,
952- can_be_struct_literal : bool ,
953951 ) -> Option < PResult < ' a , P < Block > > > {
954952 if self . token . is_ident ( ) && self . look_ahead ( 1 , |t| t == & token:: Colon ) {
955953 // We might be having a struct literal where people forgot to include the path:
@@ -971,49 +969,27 @@ impl<'a> Parser<'a> {
971969 // fn foo() -> Foo {
972970 // field: value,
973971 // }
974- let guar = err. delay_as_bug ( ) ;
972+ // Suggest:
973+ // fn foo() -> Foo { Path {
974+ // field: value,
975+ // } }
976+ err. cancel ( ) ;
975977 self . restore_snapshot ( snapshot) ;
976- if maybe_struct_name. is_ident ( ) && can_be_struct_literal {
977- // Account for `if Example { a: one(), }.is_pos() {}`.
978- // expand `before` so that we take care of module path such as:
979- // `foo::Bar { ... } `
980- // we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })`
981- let sm = self . psess . source_map ( ) ;
982- let before = maybe_struct_name. span . shrink_to_lo ( ) ;
983- if let Ok ( extend_before) = sm. span_extend_prev_while ( before, |t| {
984- t. is_alphanumeric ( ) || t == ':' || t == '_'
985- } ) {
986- Err ( self . dcx ( ) . create_err ( StructLiteralNeedingParens {
987- span : maybe_struct_name. span . to ( expr. span ) ,
988- sugg : StructLiteralNeedingParensSugg {
989- before : extend_before. shrink_to_lo ( ) ,
990- after : expr. span . shrink_to_hi ( ) ,
991- } ,
992- } ) )
993- } else {
994- return None ;
995- }
996- } else {
997- // Suggest:
998- // fn foo() -> Foo { Path {
999- // field: value,
1000- // } }
1001- self . dcx ( ) . emit_err ( StructLiteralBodyWithoutPath {
1002- span : expr. span ,
1003- sugg : StructLiteralBodyWithoutPathSugg {
1004- before : expr. span . shrink_to_lo ( ) ,
1005- after : expr. span . shrink_to_hi ( ) ,
1006- } ,
1007- } ) ;
1008- Ok ( self . mk_block (
1009- thin_vec ! [ self . mk_stmt_err( expr. span, guar) ] ,
1010- s,
1011- lo. to ( self . prev_token . span ) ,
1012- ) )
1013- }
978+ let guar = self . dcx ( ) . emit_err ( StructLiteralBodyWithoutPath {
979+ span : expr. span ,
980+ sugg : StructLiteralBodyWithoutPathSugg {
981+ before : expr. span . shrink_to_lo ( ) ,
982+ after : expr. span . shrink_to_hi ( ) ,
983+ } ,
984+ } ) ;
985+ Ok ( self . mk_block (
986+ thin_vec ! [ self . mk_stmt_err( expr. span, guar) ] ,
987+ s,
988+ lo. to ( self . prev_token . span ) ,
989+ ) )
1014990 }
1015991 ( Err ( err) , Ok ( tail) ) => {
1016- // We have a block tail that contains a somehow valid type ascription expr.
992+ // We have a block tail that contains a somehow valid expr.
1017993 err. cancel ( ) ;
1018994 Ok ( tail)
1019995 }
0 commit comments