@@ -223,13 +223,31 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
223
223
if candidates. is_empty ( ) && is_expected ( Res :: Def ( DefKind :: Enum , crate_def_id) ) {
224
224
let enum_candidates =
225
225
self . r . lookup_import_candidates ( ident, ns, & self . parent_scope , is_enum_variant) ;
226
- let mut enum_candidates = enum_candidates
227
- . iter ( )
228
- . map ( |suggestion| import_candidate_to_enum_paths ( & suggestion) )
229
- . collect :: < Vec < _ > > ( ) ;
230
- enum_candidates. sort ( ) ;
231
226
232
227
if !enum_candidates. is_empty ( ) {
228
+ if let ( PathSource :: Type , Some ( Expr { kind : ExprKind :: Type ( expr, ty) , .. } ) ) =
229
+ ( source, self . diagnostic_metadata . current_expr )
230
+ {
231
+ if self
232
+ . r
233
+ . session
234
+ . parse_sess
235
+ . type_ascription_path_suggestions
236
+ . borrow ( )
237
+ . contains ( & expr. span . between ( ty. span ) )
238
+ {
239
+ // Already reported this issue on the lhs of the type ascription.
240
+ err. delay_as_bug ( ) ;
241
+ return ( err, candidates) ;
242
+ }
243
+ }
244
+
245
+ let mut enum_candidates = enum_candidates
246
+ . iter ( )
247
+ . map ( |suggestion| import_candidate_to_enum_paths ( & suggestion) )
248
+ . collect :: < Vec < _ > > ( ) ;
249
+ enum_candidates. sort ( ) ;
250
+
233
251
// Contextualize for E0412 "cannot find type", but don't belabor the point
234
252
// (that it's a variant) for E0573 "expected type, found variant".
235
253
let preamble = if res. is_none ( ) {
@@ -484,10 +502,21 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
484
502
match source {
485
503
PathSource :: Expr ( Some (
486
504
parent @ Expr { kind : ExprKind :: Field ( ..) | ExprKind :: MethodCall ( ..) , .. } ,
487
- ) ) => {
488
- path_sep ( err, & parent) ;
489
- }
490
- PathSource :: Expr ( None ) if followed_by_brace => {
505
+ ) ) if path_sep ( err, & parent) => { }
506
+ PathSource :: Expr (
507
+ None
508
+ | Some ( Expr {
509
+ kind :
510
+ ExprKind :: Path ( ..)
511
+ | ExprKind :: Binary ( ..)
512
+ | ExprKind :: Unary ( ..)
513
+ | ExprKind :: If ( ..)
514
+ | ExprKind :: While ( ..)
515
+ | ExprKind :: ForLoop ( ..)
516
+ | ExprKind :: Match ( ..) ,
517
+ ..
518
+ } ) ,
519
+ ) if followed_by_brace => {
491
520
if let Some ( sp) = closing_brace {
492
521
err. multipart_suggestion (
493
522
"surround the struct literal with parentheses" ,
@@ -508,11 +537,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
508
537
) ;
509
538
}
510
539
}
511
- PathSource :: Expr (
512
- None | Some ( Expr { kind : ExprKind :: Call ( ..) | ExprKind :: Path ( ..) , .. } ) ,
513
- )
514
- | PathSource :: TupleStruct ( _)
515
- | PathSource :: Pat => {
540
+ PathSource :: Expr ( _) | PathSource :: TupleStruct ( _) | PathSource :: Pat => {
516
541
let span = match & source {
517
542
PathSource :: Expr ( Some ( Expr {
518
543
span, kind : ExprKind :: Call ( _, _) , ..
@@ -609,7 +634,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
609
634
) ;
610
635
}
611
636
} else {
612
- err. note ( "did you mean to use one of the enum's variants? " ) ;
637
+ err. note ( "you might have meant to use one of the enum's variants" ) ;
613
638
}
614
639
}
615
640
( Res :: Def ( DefKind :: Struct , def_id) , _) if ns == ValueNS => {
0 commit comments