@@ -12,10 +12,6 @@ use crate::{path_names_to_string, BindingError, Finalize, LexicalScopeBinding};
12
12
use crate :: { Module , ModuleOrUniformRoot , NameBinding , ParentScope , PathResult } ;
13
13
use crate :: { ResolutionError , Resolver , Segment , UseError } ;
14
14
15
- use diagnostics:: {
16
- original_label, original_lifetime, original_lifetime_param, shadower_label, shadower_lifetime,
17
- } ;
18
-
19
15
use rustc_ast:: ptr:: P ;
20
16
use rustc_ast:: visit:: { self , AssocCtxt , BoundKind , FnCtxt , FnKind , Visitor } ;
21
17
use rustc_ast:: * ;
@@ -1902,6 +1898,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1902
1898
let mut function_value_rib = Rib :: new ( kind) ;
1903
1899
let mut function_lifetime_rib = LifetimeRib :: new ( lifetime_kind) ;
1904
1900
let mut seen_bindings = FxHashMap :: default ( ) ;
1901
+ // Store all seen lifetimes names, and whether they were created in the currently processed
1902
+ // parameter set.
1905
1903
let mut seen_lifetimes = FxHashMap :: default ( ) ;
1906
1904
1907
1905
// We also can't shadow bindings from the parent item
@@ -1920,20 +1918,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1920
1918
1921
1919
// Forbid shadowing lifetime bindings
1922
1920
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 ) ) ) ;
1926
1922
if let LifetimeRibKind :: Item = rib. kind {
1927
1923
break ;
1928
1924
}
1929
1925
}
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
- }
1937
1926
1938
1927
for param in params {
1939
1928
let ident = param. ident . normalize_to_macros_2_0 ( ) ;
@@ -1942,16 +1931,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1942
1931
if let GenericParamKind :: Lifetime = param. kind {
1943
1932
match seen_lifetimes. entry ( ident) {
1944
1933
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 (
1947
1937
self . r . session ,
1948
- ident. name ,
1949
1938
original,
1950
- shadower_lifetime ( param. ident . span ) ,
1951
- )
1939
+ param. ident ,
1940
+ orig_is_param,
1941
+ ) ;
1952
1942
}
1953
1943
Entry :: Vacant ( entry) => {
1954
- entry. insert ( original_lifetime_param ( param . ident . span ) ) ;
1944
+ entry. insert ( true ) ;
1955
1945
}
1956
1946
}
1957
1947
} else {
@@ -3155,26 +3145,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
3155
3145
self . diagnostic_metadata . unused_labels . insert ( id, label. ident . span ) ;
3156
3146
}
3157
3147
3158
- // Forbid shadowing lifetime bindings
3159
3148
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
- }
3170
3149
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 )
3178
3152
}
3179
3153
if rib. kind . is_label_barrier ( ) {
3180
3154
rib. bindings . insert ( ident, id) ;
0 commit comments