Skip to content

Commit 2aa9c70

Browse files
committed
Use the same message as type & const generics.
1 parent 86bd990 commit 2aa9c70

File tree

9 files changed

+50
-71
lines changed

9 files changed

+50
-71
lines changed

Diff for: compiler/rustc_error_codes/src/error_codes/E0263.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
A lifetime was declared more than once in the same scope.
24

35
Erroneous code example:
46

5-
```compile_fail,E0263
7+
```compile_fail,E0403
68
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error!
79
}
810
```

Diff for: compiler/rustc_resolve/src/late.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18851885
let mut function_value_rib = Rib::new(kind);
18861886
let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
18871887
let mut seen_bindings = FxHashMap::default();
1888-
// Store all seen lifetimes names, and whether they were created in the currently processed
1889-
// parameter set.
1890-
let mut seen_lifetimes = FxHashMap::default();
1888+
// Store all seen lifetimes names from outer scopes.
1889+
let mut seen_lifetimes = FxHashSet::default();
18911890

18921891
// We also can't shadow bindings from the parent item
18931892
if let AssocItemRibKind = kind {
@@ -1905,7 +1904,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19051904

19061905
// Forbid shadowing lifetime bindings
19071906
for rib in self.lifetime_ribs.iter().rev() {
1908-
seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| (*ident, false)));
1907+
seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| *ident));
19091908
if let LifetimeRibKind::Item = rib.kind {
19101909
break;
19111910
}
@@ -1915,35 +1914,28 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19151914
let ident = param.ident.normalize_to_macros_2_0();
19161915
debug!("with_generic_param_rib: {}", param.id);
19171916

1918-
if let GenericParamKind::Lifetime = param.kind {
1919-
match seen_lifetimes.entry(ident) {
1920-
Entry::Occupied(entry) => {
1921-
let original = *entry.key();
1922-
let orig_is_param = *entry.get();
1923-
diagnostics::signal_lifetime_shadowing(
1924-
self.r.session,
1925-
original,
1926-
param.ident,
1927-
orig_is_param,
1928-
);
1917+
if let GenericParamKind::Lifetime = param.kind
1918+
&& let Some(&original) = seen_lifetimes.get(&ident)
1919+
{
1920+
diagnostics::signal_lifetime_shadowing(self.r.session, original, param.ident);
1921+
// Record lifetime res, so lowering knows there is something fishy.
1922+
self.record_lifetime_res(param.id, LifetimeRes::Error);
1923+
continue;
1924+
}
1925+
1926+
match seen_bindings.entry(ident) {
1927+
Entry::Occupied(entry) => {
1928+
let span = *entry.get();
1929+
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
1930+
self.report_error(param.ident.span, err);
1931+
if let GenericParamKind::Lifetime = param.kind {
19291932
// Record lifetime res, so lowering knows there is something fishy.
19301933
self.record_lifetime_res(param.id, LifetimeRes::Error);
19311934
continue;
19321935
}
1933-
Entry::Vacant(entry) => {
1934-
entry.insert(true);
1935-
}
19361936
}
1937-
} else {
1938-
match seen_bindings.entry(ident) {
1939-
Entry::Occupied(entry) => {
1940-
let span = *entry.get();
1941-
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
1942-
self.report_error(param.ident.span, err);
1943-
}
1944-
Entry::Vacant(entry) => {
1945-
entry.insert(param.ident.span);
1946-
}
1937+
Entry::Vacant(entry) => {
1938+
entry.insert(param.ident.span);
19471939
}
19481940
}
19491941

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -2038,29 +2038,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20382038
}
20392039

20402040
/// Report lifetime/lifetime shadowing as an error.
2041-
pub fn signal_lifetime_shadowing(
2042-
sess: &Session,
2043-
orig: Ident,
2044-
shadower: Ident,
2045-
orig_is_param: bool,
2046-
) {
2047-
let mut err = if orig_is_param {
2048-
struct_span_err!(
2049-
sess,
2050-
shadower.span,
2051-
E0263,
2052-
"lifetime name `{}` declared twice in the same scope",
2053-
orig.name,
2054-
)
2055-
} else {
2056-
struct_span_err!(
2057-
sess,
2058-
shadower.span,
2059-
E0496,
2060-
"lifetime name `{}` shadows a lifetime name that is already in scope",
2061-
orig.name,
2062-
)
2063-
};
2041+
pub fn signal_lifetime_shadowing(sess: &Session, orig: Ident, shadower: Ident) {
2042+
let mut err = struct_span_err!(
2043+
sess,
2044+
shadower.span,
2045+
E0496,
2046+
"lifetime name `{}` shadows a lifetime name that is already in scope",
2047+
orig.name,
2048+
);
20642049
err.span_label(orig.span, "first declared here");
20652050
err.span_label(shadower.span, format!("lifetime `{}` already in scope", orig.name));
20662051
err.emit();

Diff for: src/test/ui/error-codes/E0263.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
2-
//~^ ERROR E0263
2+
//~^ ERROR E0403
33
}
44

55
fn main() {}

Diff for: src/test/ui/error-codes/E0263.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0263]: lifetime name `'a` declared twice in the same scope
1+
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
22
--> $DIR/E0263.rs:1:16
33
|
44
LL | fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
5-
| -- ^^ lifetime `'a` already in scope
5+
| -- ^^ already used
66
| |
7-
| first declared here
7+
| first use of `'a`
88

99
error: aborting due to previous error
1010

11-
For more information about this error, try `rustc --explain E0263`.
11+
For more information about this error, try `rustc --explain E0403`.

Diff for: src/test/ui/hygiene/duplicate_lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
#[rustc_macro_transparency = "semitransparent"]
77
macro m($a:lifetime) {
8-
fn g<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
8+
fn g<$a, 'a>() {} //~ ERROR the name `'a` is already used for a generic parameter
99
}
1010

1111
#[rustc_macro_transparency = "transparent"]
1212
macro n($a:lifetime) {
13-
fn h<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
13+
fn h<$a, 'a>() {} //~ ERROR the name `'a` is already used for a generic parameter
1414
}
1515

1616
m!('a);

Diff for: src/test/ui/hygiene/duplicate_lifetimes.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
error[E0263]: lifetime name `'a` declared twice in the same scope
1+
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
22
--> $DIR/duplicate_lifetimes.rs:8:14
33
|
44
LL | fn g<$a, 'a>() {}
5-
| ^^ lifetime `'a` already in scope
5+
| ^^ already used
66
...
77
LL | m!('a);
88
| ------
99
| | |
10-
| | first declared here
10+
| | first use of `'a`
1111
| in this macro invocation
1212
|
1313
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

15-
error[E0263]: lifetime name `'a` declared twice in the same scope
15+
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
1616
--> $DIR/duplicate_lifetimes.rs:13:14
1717
|
1818
LL | fn h<$a, 'a>() {}
19-
| ^^ lifetime `'a` already in scope
19+
| ^^ already used
2020
...
2121
LL | n!('a);
2222
| ------
2323
| | |
24-
| | first declared here
24+
| | first use of `'a`
2525
| in this macro invocation
2626
|
2727
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

2929
error: aborting due to 2 previous errors
3030

31-
For more information about this error, try `rustc --explain E0263`.
31+
For more information about this error, try `rustc --explain E0403`.

Diff for: src/test/ui/regions/regions-name-duplicated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Foo<'a, 'a> {
2-
//~^ ERROR lifetime name `'a` declared twice
2+
//~^ ERROR the name `'a` is already used for a generic parameter
33
x: &'a isize,
44
}
55

Diff for: src/test/ui/regions/regions-name-duplicated.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0263]: lifetime name `'a` declared twice in the same scope
1+
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
22
--> $DIR/regions-name-duplicated.rs:1:16
33
|
44
LL | struct Foo<'a, 'a> {
5-
| -- ^^ lifetime `'a` already in scope
5+
| -- ^^ already used
66
| |
7-
| first declared here
7+
| first use of `'a`
88

99
error: aborting due to previous error
1010

11-
For more information about this error, try `rustc --explain E0263`.
11+
For more information about this error, try `rustc --explain E0403`.

0 commit comments

Comments
 (0)