@@ -538,8 +538,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
538
538
self . error = Err ( report_non_exhaustive_match (
539
539
& cx,
540
540
self . thir ,
541
- scrut. ty ,
542
- scrut. span ,
541
+ scrut,
543
542
witnesses,
544
543
arms,
545
544
braces_span,
@@ -1205,12 +1204,13 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
1205
1204
fn report_non_exhaustive_match < ' p , ' tcx > (
1206
1205
cx : & PatCtxt < ' p , ' tcx > ,
1207
1206
thir : & Thir < ' tcx > ,
1208
- scrut_ty : Ty < ' tcx > ,
1209
- sp : Span ,
1207
+ scrut : & Expr < ' tcx > ,
1210
1208
witnesses : Vec < WitnessPat < ' p , ' tcx > > ,
1211
1209
arms : & [ ArmId ] ,
1212
1210
braces_span : Option < Span > ,
1213
1211
) -> ErrorGuaranteed {
1212
+ let scrut_ty = scrut. ty ;
1213
+ let sp = scrut. span ;
1214
1214
let is_empty_match = arms. is_empty ( ) ;
1215
1215
let non_empty_enum = match scrut_ty. kind ( ) {
1216
1216
ty:: Adt ( def, _) => def. is_enum ( ) && !def. variants ( ) . is_empty ( ) ,
@@ -1323,7 +1323,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
1323
1323
let suggested_arm = if suggest_the_witnesses {
1324
1324
let pattern = witnesses
1325
1325
. iter ( )
1326
- . map ( |witness| cx . print_witness_pat ( witness) )
1326
+ . map ( |witness| erase_path_if_local ( cx , witness , scrut , cx . print_witness_pat ( witness) ) )
1327
1327
. collect :: < Vec < String > > ( )
1328
1328
. join ( " | " ) ;
1329
1329
if witnesses. iter ( ) . all ( |p| p. is_never_pattern ( ) ) && cx. tcx . features ( ) . never_patterns ( ) {
@@ -1436,6 +1436,33 @@ fn report_non_exhaustive_match<'p, 'tcx>(
1436
1436
err. emit ( )
1437
1437
}
1438
1438
1439
+ fn erase_path_if_local < ' p , ' tcx > (
1440
+ cx : & PatCtxt < ' p , ' tcx > ,
1441
+ pat : & WitnessPat < ' p , ' tcx > ,
1442
+ scrut : & Expr < ' tcx > ,
1443
+ mut pat_str : String ,
1444
+ ) -> String {
1445
+ if let ty:: Adt ( adt_def, _) = * pat. ty ( ) . kind ( )
1446
+ && adt_def. is_enum ( )
1447
+ {
1448
+ let enum_parent_def_id = cx. tcx . parent ( adt_def. did ( ) ) ;
1449
+ let scrut_parent_def_id = if let ExprKind :: Scope { region_scope : _, lint_level, value : _ } =
1450
+ scrut. kind
1451
+ && let LintLevel :: Explicit ( hir_id) = lint_level
1452
+ {
1453
+ Some ( hir_id. owner . to_def_id ( ) )
1454
+ } else {
1455
+ None
1456
+ } ;
1457
+ if scrut_parent_def_id == Some ( enum_parent_def_id) {
1458
+ let segments: Vec < & str > = pat_str. split ( "::" ) . collect ( ) ;
1459
+ let enum_name = segments[ segments. len ( ) - 2 ] ;
1460
+ let variant_name = segments[ segments. len ( ) - 1 ] ;
1461
+ pat_str = String :: from ( format ! ( "{}::{}" , enum_name, variant_name) ) ;
1462
+ }
1463
+ }
1464
+ pat_str
1465
+ }
1439
1466
fn joined_uncovered_patterns < ' p , ' tcx > (
1440
1467
cx : & PatCtxt < ' p , ' tcx > ,
1441
1468
witnesses : & [ WitnessPat < ' p , ' tcx > ] ,
0 commit comments