@@ -383,7 +383,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
383383 has_self_arg
384384 }
385385
386- fn followed_by_brace ( & self , span : Span ) -> ( bool , Option < ( Span , String ) > ) {
386+ fn followed_by_brace ( & self , span : Span ) -> ( bool , Option < Span > ) {
387387 // HACK(estebank): find a better way to figure out that this was a
388388 // parser issue where a struct literal is being used on an expression
389389 // where a brace being opened means a block is being started. Look
@@ -406,18 +406,15 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
406406 _ => false ,
407407 } ;
408408 // In case this could be a struct literal that needs to be surrounded
409- // by parenthesis , find the appropriate span.
409+ // by parentheses , find the appropriate span.
410410 let mut i = 0 ;
411411 let mut closing_brace = None ;
412412 loop {
413413 sp = sm. next_point ( sp) ;
414414 match sm. span_to_snippet ( sp) {
415415 Ok ( ref snippet) => {
416416 if snippet == "}" {
417- let sp = span. to ( sp) ;
418- if let Ok ( snippet) = sm. span_to_snippet ( sp) {
419- closing_brace = Some ( ( sp, snippet) ) ;
420- }
417+ closing_brace = Some ( span. to ( sp) ) ;
421418 break ;
422419 }
423420 }
@@ -479,17 +476,23 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
479476 suggested = path_sep ( err, & parent) ;
480477 }
481478 PathSource :: Expr ( None ) if followed_by_brace => {
482- if let Some ( ( sp, snippet) ) = closing_brace {
483- err. span_suggestion (
484- sp,
485- "surround the struct literal with parenthesis" ,
486- format ! ( "({})" , snippet) ,
479+ if let Some ( sp) = closing_brace {
480+ err. multipart_suggestion (
481+ "surround the struct literal with parentheses" ,
482+ vec ! [
483+ ( sp. shrink_to_lo( ) , "(" . to_string( ) ) ,
484+ ( sp. shrink_to_hi( ) , ")" . to_string( ) ) ,
485+ ] ,
487486 Applicability :: MaybeIncorrect ,
488487 ) ;
489488 } else {
490489 err. span_label (
491- span, // Note the parenthesis surrounding the suggestion below
492- format ! ( "did you mean `({} {{ /* fields */ }})`?" , path_str) ,
490+ span, // Note the parentheses surrounding the suggestion below
491+ format ! (
492+ "you might want to surround a struct literal with parentheses: \
493+ `({} {{ /* fields */ }})`?",
494+ path_str
495+ ) ,
493496 ) ;
494497 }
495498 suggested = true ;
@@ -516,10 +519,16 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
516519 err. note ( "if you want the `try` keyword, you need to be in the 2018 edition" ) ;
517520 }
518521 }
519- ( Res :: Def ( DefKind :: TyAlias , _ ) , PathSource :: Trait ( _) ) => {
522+ ( Res :: Def ( DefKind :: TyAlias , def_id ) , PathSource :: Trait ( _) ) => {
520523 err. span_label ( span, "type aliases cannot be used as traits" ) ;
521524 if nightly_options:: is_nightly_build ( ) {
522- err. note ( "did you mean to use a trait alias?" ) ;
525+ let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
526+ `type` alias";
527+ if let Some ( span) = self . r . definitions . opt_span ( def_id) {
528+ err. span_help ( span, msg) ;
529+ } else {
530+ err. help ( msg) ;
531+ }
523532 }
524533 }
525534 ( Res :: Def ( DefKind :: Mod , _) , PathSource :: Expr ( Some ( parent) ) ) => {
0 commit comments