@@ -153,7 +153,7 @@ pub enum ResolutionError<'a> {
153153 /// error E0413: declaration shadows an enum variant or unit-like struct in scope
154154 DeclarationShadowsEnumVariantOrUnitLikeStruct ( Name ) ,
155155 /// error E0414: only irrefutable patterns allowed here
156- OnlyIrrefutablePatternsAllowedHere ,
156+ OnlyIrrefutablePatternsAllowedHere ( DefId , Name ) ,
157157 /// error E0415: identifier is bound more than once in this parameter list
158158 IdentifierBoundMoreThanOnceInParameterList ( & ' a str ) ,
159159 /// 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
283283 scope",
284284 name) ;
285285 } ,
286- ResolutionError :: OnlyIrrefutablePatternsAllowedHere => {
286+ ResolutionError :: OnlyIrrefutablePatternsAllowedHere ( did , name ) => {
287287 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+ }
288296 } ,
289297 ResolutionError :: IdentifierBoundMoreThanOnceInParameterList ( identifier) => {
290298 span_err ! ( resolver. session, span, E0415 ,
@@ -632,7 +640,7 @@ enum NameSearchType {
632640#[ derive( Copy , Clone ) ]
633641enum BareIdentifierPatternResolution {
634642 FoundStructOrEnumVariant ( Def , LastPrivate ) ,
635- FoundConst ( Def , LastPrivate ) ,
643+ FoundConst ( Def , LastPrivate , Name ) ,
636644 BareIdentifierPatternUnresolved
637645}
638646
@@ -2685,7 +2693,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26852693 renamed)
26862694 ) ;
26872695 }
2688- FoundConst ( def, lp) if const_ok => {
2696+ FoundConst ( def, lp, _ ) if const_ok => {
26892697 debug ! ( "(resolving pattern) resolving `{}` to \
26902698 constant",
26912699 renamed) ;
@@ -2700,11 +2708,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27002708 depth : 0
27012709 } ) ;
27022710 }
2703- FoundConst ( .. ) => {
2711+ FoundConst ( def , _ , name ) => {
27042712 resolve_error (
27052713 self ,
27062714 pattern. span ,
2707- ResolutionError :: OnlyIrrefutablePatternsAllowedHere
2715+ ResolutionError :: OnlyIrrefutablePatternsAllowedHere ( def . def_id ( ) , name )
27082716 ) ;
27092717 }
27102718 BareIdentifierPatternUnresolved => {
@@ -2929,7 +2937,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29292937 return FoundStructOrEnumVariant ( def, LastMod ( AllPublic ) ) ;
29302938 }
29312939 def @ DefConst ( ..) | def @ DefAssociatedConst ( ..) => {
2932- return FoundConst ( def, LastMod ( AllPublic ) ) ;
2940+ return FoundConst ( def, LastMod ( AllPublic ) , name ) ;
29332941 }
29342942 DefStatic ( ..) => {
29352943 resolve_error ( self ,
0 commit comments