@@ -383,7 +383,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
383
383
has_self_arg
384
384
}
385
385
386
- fn followed_by_brace ( & self , span : Span ) -> ( bool , Option < ( Span , String ) > ) {
386
+ fn followed_by_brace ( & self , span : Span ) -> ( bool , Option < Span > ) {
387
387
// HACK(estebank): find a better way to figure out that this was a
388
388
// parser issue where a struct literal is being used on an expression
389
389
// where a brace being opened means a block is being started. Look
@@ -406,18 +406,15 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
406
406
_ => false ,
407
407
} ;
408
408
// 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.
410
410
let mut i = 0 ;
411
411
let mut closing_brace = None ;
412
412
loop {
413
413
sp = sm. next_point ( sp) ;
414
414
match sm. span_to_snippet ( sp) {
415
415
Ok ( ref snippet) => {
416
416
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) ) ;
421
418
break ;
422
419
}
423
420
}
@@ -479,17 +476,23 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
479
476
suggested = path_sep ( err, & parent) ;
480
477
}
481
478
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
+ ] ,
487
486
Applicability :: MaybeIncorrect ,
488
487
) ;
489
488
} else {
490
489
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
+ ) ,
493
496
) ;
494
497
}
495
498
suggested = true ;
@@ -516,10 +519,16 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
516
519
err. note ( "if you want the `try` keyword, you need to be in the 2018 edition" ) ;
517
520
}
518
521
}
519
- ( Res :: Def ( DefKind :: TyAlias , _ ) , PathSource :: Trait ( _) ) => {
522
+ ( Res :: Def ( DefKind :: TyAlias , def_id ) , PathSource :: Trait ( _) ) => {
520
523
err. span_label ( span, "type aliases cannot be used as traits" ) ;
521
524
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
+ }
523
532
}
524
533
}
525
534
( Res :: Def ( DefKind :: Mod , _) , PathSource :: Expr ( Some ( parent) ) ) => {
0 commit comments