Use the same message as type & const generics.
This commit is contained in:
parent
86bd99060c
commit
2aa9c703ce
9 changed files with 50 additions and 71 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
#### Note: this error code is no longer emitted by the compiler.
|
||||||
|
|
||||||
A lifetime was declared more than once in the same scope.
|
A lifetime was declared more than once in the same scope.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0263
|
```compile_fail,E0403
|
||||||
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error!
|
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -1885,9 +1885,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
let mut function_value_rib = Rib::new(kind);
|
let mut function_value_rib = Rib::new(kind);
|
||||||
let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
|
let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
|
||||||
let mut seen_bindings = FxHashMap::default();
|
let mut seen_bindings = FxHashMap::default();
|
||||||
// Store all seen lifetimes names, and whether they were created in the currently processed
|
// Store all seen lifetimes names from outer scopes.
|
||||||
// parameter set.
|
let mut seen_lifetimes = FxHashSet::default();
|
||||||
let mut seen_lifetimes = FxHashMap::default();
|
|
||||||
|
|
||||||
// We also can't shadow bindings from the parent item
|
// We also can't shadow bindings from the parent item
|
||||||
if let AssocItemRibKind = kind {
|
if let AssocItemRibKind = kind {
|
||||||
|
@ -1905,7 +1904,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
|
|
||||||
// Forbid shadowing lifetime bindings
|
// Forbid shadowing lifetime bindings
|
||||||
for rib in self.lifetime_ribs.iter().rev() {
|
for rib in self.lifetime_ribs.iter().rev() {
|
||||||
seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| (*ident, false)));
|
seen_lifetimes.extend(rib.bindings.iter().map(|(ident, _)| *ident));
|
||||||
if let LifetimeRibKind::Item = rib.kind {
|
if let LifetimeRibKind::Item = rib.kind {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1915,37 +1914,30 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
let ident = param.ident.normalize_to_macros_2_0();
|
let ident = param.ident.normalize_to_macros_2_0();
|
||||||
debug!("with_generic_param_rib: {}", param.id);
|
debug!("with_generic_param_rib: {}", param.id);
|
||||||
|
|
||||||
if let GenericParamKind::Lifetime = param.kind {
|
if let GenericParamKind::Lifetime = param.kind
|
||||||
match seen_lifetimes.entry(ident) {
|
&& let Some(&original) = seen_lifetimes.get(&ident)
|
||||||
Entry::Occupied(entry) => {
|
{
|
||||||
let original = *entry.key();
|
diagnostics::signal_lifetime_shadowing(self.r.session, original, param.ident);
|
||||||
let orig_is_param = *entry.get();
|
|
||||||
diagnostics::signal_lifetime_shadowing(
|
|
||||||
self.r.session,
|
|
||||||
original,
|
|
||||||
param.ident,
|
|
||||||
orig_is_param,
|
|
||||||
);
|
|
||||||
// Record lifetime res, so lowering knows there is something fishy.
|
// Record lifetime res, so lowering knows there is something fishy.
|
||||||
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Entry::Vacant(entry) => {
|
|
||||||
entry.insert(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match seen_bindings.entry(ident) {
|
match seen_bindings.entry(ident) {
|
||||||
Entry::Occupied(entry) => {
|
Entry::Occupied(entry) => {
|
||||||
let span = *entry.get();
|
let span = *entry.get();
|
||||||
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
|
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
|
||||||
self.report_error(param.ident.span, err);
|
self.report_error(param.ident.span, err);
|
||||||
|
if let GenericParamKind::Lifetime = param.kind {
|
||||||
|
// Record lifetime res, so lowering knows there is something fishy.
|
||||||
|
self.record_lifetime_res(param.id, LifetimeRes::Error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
entry.insert(param.ident.span);
|
entry.insert(param.ident.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if param.ident.name == kw::UnderscoreLifetime {
|
if param.ident.name == kw::UnderscoreLifetime {
|
||||||
rustc_errors::struct_span_err!(
|
rustc_errors::struct_span_err!(
|
||||||
|
|
|
@ -2038,29 +2038,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Report lifetime/lifetime shadowing as an error.
|
/// Report lifetime/lifetime shadowing as an error.
|
||||||
pub fn signal_lifetime_shadowing(
|
pub fn signal_lifetime_shadowing(sess: &Session, orig: Ident, shadower: Ident) {
|
||||||
sess: &Session,
|
let mut err = struct_span_err!(
|
||||||
orig: Ident,
|
|
||||||
shadower: Ident,
|
|
||||||
orig_is_param: bool,
|
|
||||||
) {
|
|
||||||
let mut err = if orig_is_param {
|
|
||||||
struct_span_err!(
|
|
||||||
sess,
|
|
||||||
shadower.span,
|
|
||||||
E0263,
|
|
||||||
"lifetime name `{}` declared twice in the same scope",
|
|
||||||
orig.name,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
struct_span_err!(
|
|
||||||
sess,
|
sess,
|
||||||
shadower.span,
|
shadower.span,
|
||||||
E0496,
|
E0496,
|
||||||
"lifetime name `{}` shadows a lifetime name that is already in scope",
|
"lifetime name `{}` shadows a lifetime name that is already in scope",
|
||||||
orig.name,
|
orig.name,
|
||||||
)
|
);
|
||||||
};
|
|
||||||
err.span_label(orig.span, "first declared here");
|
err.span_label(orig.span, "first declared here");
|
||||||
err.span_label(shadower.span, format!("lifetime `{}` already in scope", orig.name));
|
err.span_label(shadower.span, format!("lifetime `{}` already in scope", orig.name));
|
||||||
err.emit();
|
err.emit();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
|
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
|
||||||
//~^ ERROR E0263
|
//~^ ERROR E0403
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
error[E0263]: lifetime name `'a` declared twice in the same scope
|
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
|
||||||
--> $DIR/E0263.rs:1:16
|
--> $DIR/E0263.rs:1:16
|
||||||
|
|
|
|
||||||
LL | fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
|
LL | fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
|
||||||
| -- ^^ lifetime `'a` already in scope
|
| -- ^^ already used
|
||||||
| |
|
| |
|
||||||
| first declared here
|
| first use of `'a`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0263`.
|
For more information about this error, try `rustc --explain E0403`.
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
#[rustc_macro_transparency = "semitransparent"]
|
#[rustc_macro_transparency = "semitransparent"]
|
||||||
macro m($a:lifetime) {
|
macro m($a:lifetime) {
|
||||||
fn g<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
|
fn g<$a, 'a>() {} //~ ERROR the name `'a` is already used for a generic parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustc_macro_transparency = "transparent"]
|
#[rustc_macro_transparency = "transparent"]
|
||||||
macro n($a:lifetime) {
|
macro n($a:lifetime) {
|
||||||
fn h<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
|
fn h<$a, 'a>() {} //~ ERROR the name `'a` is already used for a generic parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
m!('a);
|
m!('a);
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
error[E0263]: lifetime name `'a` declared twice in the same scope
|
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
|
||||||
--> $DIR/duplicate_lifetimes.rs:8:14
|
--> $DIR/duplicate_lifetimes.rs:8:14
|
||||||
|
|
|
|
||||||
LL | fn g<$a, 'a>() {}
|
LL | fn g<$a, 'a>() {}
|
||||||
| ^^ lifetime `'a` already in scope
|
| ^^ already used
|
||||||
...
|
...
|
||||||
LL | m!('a);
|
LL | m!('a);
|
||||||
| ------
|
| ------
|
||||||
| | |
|
| | |
|
||||||
| | first declared here
|
| | first use of `'a`
|
||||||
| in this macro invocation
|
| in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0263]: lifetime name `'a` declared twice in the same scope
|
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
|
||||||
--> $DIR/duplicate_lifetimes.rs:13:14
|
--> $DIR/duplicate_lifetimes.rs:13:14
|
||||||
|
|
|
|
||||||
LL | fn h<$a, 'a>() {}
|
LL | fn h<$a, 'a>() {}
|
||||||
| ^^ lifetime `'a` already in scope
|
| ^^ already used
|
||||||
...
|
...
|
||||||
LL | n!('a);
|
LL | n!('a);
|
||||||
| ------
|
| ------
|
||||||
| | |
|
| | |
|
||||||
| | first declared here
|
| | first use of `'a`
|
||||||
| in this macro invocation
|
| in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0263`.
|
For more information about this error, try `rustc --explain E0403`.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
struct Foo<'a, 'a> {
|
struct Foo<'a, 'a> {
|
||||||
//~^ ERROR lifetime name `'a` declared twice
|
//~^ ERROR the name `'a` is already used for a generic parameter
|
||||||
x: &'a isize,
|
x: &'a isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
error[E0263]: lifetime name `'a` declared twice in the same scope
|
error[E0403]: the name `'a` is already used for a generic parameter in this item's generic parameters
|
||||||
--> $DIR/regions-name-duplicated.rs:1:16
|
--> $DIR/regions-name-duplicated.rs:1:16
|
||||||
|
|
|
|
||||||
LL | struct Foo<'a, 'a> {
|
LL | struct Foo<'a, 'a> {
|
||||||
| -- ^^ lifetime `'a` already in scope
|
| -- ^^ already used
|
||||||
| |
|
| |
|
||||||
| first declared here
|
| first use of `'a`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0263`.
|
For more information about this error, try `rustc --explain E0403`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue