@@ -153,7 +153,7 @@ pub enum ResolutionError<'a> {
153
153
/// error E0413: declaration shadows an enum variant or unit-like struct in scope
154
154
DeclarationShadowsEnumVariantOrUnitLikeStruct ( Name ) ,
155
155
/// error E0414: only irrefutable patterns allowed here
156
- OnlyIrrefutablePatternsAllowedHere ,
156
+ OnlyIrrefutablePatternsAllowedHere ( DefId , Name ) ,
157
157
/// error E0415: identifier is bound more than once in this parameter list
158
158
IdentifierBoundMoreThanOnceInParameterList ( & ' a str ) ,
159
159
/// error E0416: identifier is bound more than once in the same pattern
@@ -283,8 +283,16 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn
283
283
scope",
284
284
name) ;
285
285
} ,
286
- ResolutionError :: OnlyIrrefutablePatternsAllowedHere => {
286
+ ResolutionError :: OnlyIrrefutablePatternsAllowedHere ( did , name ) => {
287
287
span_err ! ( resolver. session, span, E0414 , "only irrefutable patterns allowed here" ) ;
288
+ resolver. session . span_note ( span, "there already is a constant in scope sharing the same name as this pattern" ) ;
289
+ if let Some ( sp) = resolver. ast_map . span_if_local ( did) {
290
+ resolver. session . span_note ( sp, "constant defined here" ) ;
291
+ }
292
+ if let Some ( directive) = resolver. current_module . import_resolutions . borrow ( ) . get ( & name) {
293
+ let item = resolver. ast_map . expect_item ( directive. value_id ) ;
294
+ resolver. session . span_note ( item. span , "constant imported here" ) ;
295
+ }
288
296
} ,
289
297
ResolutionError :: IdentifierBoundMoreThanOnceInParameterList ( identifier) => {
290
298
span_err ! ( resolver. session, span, E0415 ,
@@ -632,7 +640,7 @@ enum NameSearchType {
632
640
#[ derive( Copy , Clone ) ]
633
641
enum BareIdentifierPatternResolution {
634
642
FoundStructOrEnumVariant ( Def , LastPrivate ) ,
635
- FoundConst ( Def , LastPrivate ) ,
643
+ FoundConst ( Def , LastPrivate , Name ) ,
636
644
BareIdentifierPatternUnresolved
637
645
}
638
646
@@ -2685,7 +2693,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2685
2693
renamed)
2686
2694
) ;
2687
2695
}
2688
- FoundConst ( def, lp) if const_ok => {
2696
+ FoundConst ( def, lp, _ ) if const_ok => {
2689
2697
debug ! ( "(resolving pattern) resolving `{}` to \
2690
2698
constant",
2691
2699
renamed) ;
@@ -2700,11 +2708,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2700
2708
depth : 0
2701
2709
} ) ;
2702
2710
}
2703
- FoundConst ( .. ) => {
2711
+ FoundConst ( def , _ , name ) => {
2704
2712
resolve_error (
2705
2713
self ,
2706
2714
pattern. span ,
2707
- ResolutionError :: OnlyIrrefutablePatternsAllowedHere
2715
+ ResolutionError :: OnlyIrrefutablePatternsAllowedHere ( def . def_id ( ) , name )
2708
2716
) ;
2709
2717
}
2710
2718
BareIdentifierPatternUnresolved => {
@@ -2929,7 +2937,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2929
2937
return FoundStructOrEnumVariant ( def, LastMod ( AllPublic ) ) ;
2930
2938
}
2931
2939
def @ DefConst ( ..) | def @ DefAssociatedConst ( ..) => {
2932
- return FoundConst ( def, LastMod ( AllPublic ) ) ;
2940
+ return FoundConst ( def, LastMod ( AllPublic ) , name ) ;
2933
2941
}
2934
2942
DefStatic ( ..) => {
2935
2943
resolve_error ( self ,
0 commit comments