@@ -12,10 +12,6 @@ use crate::{path_names_to_string, BindingError, Finalize, LexicalScopeBinding};
1212use crate :: { Module , ModuleOrUniformRoot , NameBinding , ParentScope , PathResult } ;
1313use crate :: { ResolutionError , Resolver , Segment , UseError } ;
1414
15- use diagnostics:: {
16- original_label, original_lifetime, original_lifetime_param, shadower_label, shadower_lifetime,
17- } ;
18-
1915use rustc_ast:: ptr:: P ;
2016use rustc_ast:: visit:: { self , AssocCtxt , BoundKind , FnCtxt , FnKind , Visitor } ;
2117use rustc_ast:: * ;
@@ -1902,6 +1898,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19021898 let mut function_value_rib = Rib :: new ( kind) ;
19031899 let mut function_lifetime_rib = LifetimeRib :: new ( lifetime_kind) ;
19041900 let mut seen_bindings = FxHashMap :: default ( ) ;
1901+ // Store all seen lifetimes names, and whether they were created in the currently processed
1902+ // parameter set.
19051903 let mut seen_lifetimes = FxHashMap :: default ( ) ;
19061904
19071905 // We also can't shadow bindings from the parent item
@@ -1920,20 +1918,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19201918
19211919 // Forbid shadowing lifetime bindings
19221920 for rib in self . lifetime_ribs . iter ( ) . rev ( ) {
1923- seen_lifetimes. extend (
1924- rib. bindings . iter ( ) . map ( |( ident, _) | ( * ident, original_lifetime ( ident. span ) ) ) ,
1925- ) ;
1921+ seen_lifetimes. extend ( rib. bindings . iter ( ) . map ( |( ident, _) | ( * ident, false ) ) ) ;
19261922 if let LifetimeRibKind :: Item = rib. kind {
19271923 break ;
19281924 }
19291925 }
1930- for rib in self . label_ribs . iter ( ) . rev ( ) {
1931- if rib. kind . is_label_barrier ( ) {
1932- break ;
1933- }
1934- seen_lifetimes
1935- . extend ( rib. bindings . iter ( ) . map ( |( ident, _) | ( * ident, original_label ( ident. span ) ) ) ) ;
1936- }
19371926
19381927 for param in params {
19391928 let ident = param. ident . normalize_to_macros_2_0 ( ) ;
@@ -1942,16 +1931,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19421931 if let GenericParamKind :: Lifetime = param. kind {
19431932 match seen_lifetimes. entry ( ident) {
19441933 Entry :: Occupied ( entry) => {
1945- let original = * entry. get ( ) ;
1946- diagnostics:: signal_shadowing_problem (
1934+ let original = * entry. key ( ) ;
1935+ let orig_is_param = * entry. get ( ) ;
1936+ diagnostics:: signal_lifetime_shadowing (
19471937 self . r . session ,
1948- ident. name ,
19491938 original,
1950- shadower_lifetime ( param. ident . span ) ,
1951- )
1939+ param. ident ,
1940+ orig_is_param,
1941+ ) ;
19521942 }
19531943 Entry :: Vacant ( entry) => {
1954- entry. insert ( original_lifetime_param ( param . ident . span ) ) ;
1944+ entry. insert ( true ) ;
19551945 }
19561946 }
19571947 } else {
@@ -3155,26 +3145,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
31553145 self . diagnostic_metadata . unused_labels . insert ( id, label. ident . span ) ;
31563146 }
31573147
3158- // Forbid shadowing lifetime bindings
31593148 let ident = label. ident . normalize_to_macro_rules ( ) ;
3160- for rib in self . lifetime_ribs . iter ( ) . rev ( ) {
3161- if let Some ( ( orig_ident, _) ) = rib. bindings . get_key_value ( & ident) {
3162- diagnostics:: signal_shadowing_problem (
3163- self . r . session ,
3164- label. ident . name ,
3165- original_lifetime ( orig_ident. span ) ,
3166- shadower_label ( label. ident . span ) ,
3167- )
3168- }
3169- }
31703149 for rib in self . label_ribs . iter_mut ( ) . rev ( ) {
3171- if let Some ( ( orig_ident, _) ) = rib. bindings . get_key_value ( & ident) {
3172- diagnostics:: signal_shadowing_problem (
3173- self . r . session ,
3174- label. ident . name ,
3175- original_label ( orig_ident. span ) ,
3176- shadower_label ( label. ident . span ) ,
3177- )
3150+ if let Some ( ( & orig_ident, _) ) = rib. bindings . get_key_value ( & ident) {
3151+ diagnostics:: signal_label_shadowing ( self . r . session , orig_ident, label. ident )
31783152 }
31793153 if rib. kind . is_label_barrier ( ) {
31803154 rib. bindings . insert ( ident, id) ;
0 commit comments