@@ -123,7 +123,7 @@ impl<'a> Resolver<'a> {
123
123
let ( span, found_use) = if let Some ( def_id) = def_id. as_local ( ) {
124
124
UsePlacementFinder :: check ( krate, self . def_id_to_node_id [ def_id] )
125
125
} else {
126
- ( None , false )
126
+ ( None , FoundUse :: No )
127
127
} ;
128
128
if !candidates. is_empty ( ) {
129
129
show_candidates (
@@ -132,9 +132,9 @@ impl<'a> Resolver<'a> {
132
132
& mut err,
133
133
span,
134
134
& candidates,
135
- instead,
135
+ if instead { Instead :: Yes } else { Instead :: No } ,
136
136
found_use,
137
- false ,
137
+ IsPattern :: No ,
138
138
) ;
139
139
} else if let Some ( ( span, msg, sugg, appl) ) = suggestion {
140
140
err. span_suggestion ( span, msg, sugg, appl) ;
@@ -702,9 +702,9 @@ impl<'a> Resolver<'a> {
702
702
& mut err,
703
703
Some ( span) ,
704
704
& import_suggestions,
705
- false ,
706
- true ,
707
- true ,
705
+ Instead :: No ,
706
+ FoundUse :: Yes ,
707
+ IsPattern :: Yes ,
708
708
) ;
709
709
}
710
710
err
@@ -1482,9 +1482,9 @@ impl<'a> Resolver<'a> {
1482
1482
err,
1483
1483
None ,
1484
1484
& import_suggestions,
1485
- false ,
1486
- true ,
1487
- false ,
1485
+ Instead :: No ,
1486
+ FoundUse :: Yes ,
1487
+ IsPattern :: No ,
1488
1488
) ;
1489
1489
1490
1490
if macro_kind == MacroKind :: Derive && ( ident. name == sym:: Send || ident. name == sym:: Sync ) {
@@ -2420,6 +2420,27 @@ fn find_span_immediately_after_crate_name(
2420
2420
( next_left_bracket == after_second_colon, from_second_colon)
2421
2421
}
2422
2422
2423
+ /// A suggestion has already been emitted, change the wording slightly to clarify that both are
2424
+ /// independent options.
2425
+ enum Instead {
2426
+ Yes ,
2427
+ No ,
2428
+ }
2429
+
2430
+ /// Whether an existing place with an `use` item was found.
2431
+ enum FoundUse {
2432
+ Yes ,
2433
+ No ,
2434
+ }
2435
+
2436
+ /// Whether a binding is part of a pattern or an expression. Used for diagnostics.
2437
+ enum IsPattern {
2438
+ /// The binding is part of a pattern
2439
+ Yes ,
2440
+ /// The binding is part of an expression
2441
+ No ,
2442
+ }
2443
+
2423
2444
/// When an entity with a given name is not available in scope, we search for
2424
2445
/// entities with that name in all crates. This method allows outputting the
2425
2446
/// results of this search in a programmer-friendly way
@@ -2430,9 +2451,9 @@ fn show_candidates(
2430
2451
// This is `None` if all placement locations are inside expansions
2431
2452
use_placement_span : Option < Span > ,
2432
2453
candidates : & [ ImportSuggestion ] ,
2433
- instead : bool ,
2434
- found_use : bool ,
2435
- is_pattern : bool ,
2454
+ instead : Instead ,
2455
+ found_use : FoundUse ,
2456
+ is_pattern : IsPattern ,
2436
2457
) {
2437
2458
if candidates. is_empty ( ) {
2438
2459
return ;
@@ -2465,8 +2486,8 @@ fn show_candidates(
2465
2486
( "one of these" , "items" , String :: new ( ) )
2466
2487
} ;
2467
2488
2468
- let instead = if instead { " instead" } else { "" } ;
2469
- let mut msg = if is_pattern {
2489
+ let instead = if let Instead :: Yes = instead { " instead" } else { "" } ;
2490
+ let mut msg = if let IsPattern :: Yes = is_pattern {
2470
2491
format ! (
2471
2492
"if you meant to match on {}{}{}, use the full path in the pattern" ,
2472
2493
kind, instead, name
@@ -2479,7 +2500,7 @@ fn show_candidates(
2479
2500
err. note ( note) ;
2480
2501
}
2481
2502
2482
- if let ( true , Some ( span) ) = ( is_pattern, use_placement_span) {
2503
+ if let ( IsPattern :: Yes , Some ( span) ) = ( is_pattern, use_placement_span) {
2483
2504
err. span_suggestions (
2484
2505
span,
2485
2506
& msg,
@@ -2490,7 +2511,7 @@ fn show_candidates(
2490
2511
for candidate in & mut accessible_path_strings {
2491
2512
// produce an additional newline to separate the new use statement
2492
2513
// from the directly following item.
2493
- let additional_newline = if found_use { "" } else { "\n " } ;
2514
+ let additional_newline = if let FoundUse :: Yes = found_use { "" } else { "\n " } ;
2494
2515
candidate. 0 = format ! ( "use {};\n {}" , & candidate. 0 , additional_newline) ;
2495
2516
}
2496
2517
@@ -2513,15 +2534,16 @@ fn show_candidates(
2513
2534
} else {
2514
2535
assert ! ( !inaccessible_path_strings. is_empty( ) ) ;
2515
2536
2516
- let prefix = if is_pattern { "you might have meant to match on " } else { "" } ;
2537
+ let prefix =
2538
+ if let IsPattern :: Yes = is_pattern { "you might have meant to match on " } else { "" } ;
2517
2539
if inaccessible_path_strings. len ( ) == 1 {
2518
2540
let ( name, descr, def_id, note) = & inaccessible_path_strings[ 0 ] ;
2519
2541
let msg = format ! (
2520
2542
"{}{} `{}`{} exists but is inaccessible" ,
2521
2543
prefix,
2522
2544
descr,
2523
2545
name,
2524
- if is_pattern { ", which" } else { "" }
2546
+ if let IsPattern :: Yes = is_pattern { ", which" } else { "" }
2525
2547
) ;
2526
2548
2527
2549
if let Some ( local_def_id) = def_id. and_then ( |did| did. as_local ( ) ) {
@@ -2589,14 +2611,14 @@ struct UsePlacementFinder {
2589
2611
}
2590
2612
2591
2613
impl UsePlacementFinder {
2592
- fn check ( krate : & Crate , target_module : NodeId ) -> ( Option < Span > , bool ) {
2614
+ fn check ( krate : & Crate , target_module : NodeId ) -> ( Option < Span > , FoundUse ) {
2593
2615
let mut finder =
2594
2616
UsePlacementFinder { target_module, first_legal_span : None , first_use_span : None } ;
2595
2617
finder. visit_crate ( krate) ;
2596
2618
if let Some ( use_span) = finder. first_use_span {
2597
- ( Some ( use_span) , true )
2619
+ ( Some ( use_span) , FoundUse :: Yes )
2598
2620
} else {
2599
- ( finder. first_legal_span , false )
2621
+ ( finder. first_legal_span , FoundUse :: No )
2600
2622
}
2601
2623
}
2602
2624
}
0 commit comments