]> git.lizzy.rs Git - rust.git/commitdiff
Use the same message as type & const generics.
authorCamille GILLOT <gillot.camille@gmail.com>
Thu, 2 Jun 2022 18:46:40 +0000 (20:46 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Fri, 3 Jun 2022 06:26:10 +0000 (08:26 +0200)
compiler/rustc_error_codes/src/error_codes/E0263.md
compiler/rustc_resolve/src/late.rs
compiler/rustc_resolve/src/late/diagnostics.rs
src/test/ui/error-codes/E0263.rs
src/test/ui/error-codes/E0263.stderr
src/test/ui/hygiene/duplicate_lifetimes.rs
src/test/ui/hygiene/duplicate_lifetimes.stderr
src/test/ui/regions/regions-name-duplicated.rs
src/test/ui/regions/regions-name-duplicated.stderr

index 37271ac692d55fdbd1b4921c94a9311cf958ed4a..2d1ac40264de19f4326d5a473ef99842e8920cf5 100644 (file)
@@ -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.
 
 Erroneous code example:
 
-```compile_fail,E0263
+```compile_fail,E0403
 fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error!
 }
 ```
index 5c968655e29ecab27779c4b4a630377f0a4c339a..288c89b0189c440a486356e9470244c828f2d433 100644 (file)
@@ -1885,9 +1885,8 @@ fn with_generic_param_rib<'c, F>(
         let mut function_value_rib = Rib::new(kind);
         let mut function_lifetime_rib = LifetimeRib::new(lifetime_kind);
         let mut seen_bindings = FxHashMap::default();
-        // Store all seen lifetimes names, and whether they were created in the currently processed
-        // parameter set.
-        let mut seen_lifetimes = FxHashMap::default();
+        // Store all seen lifetimes names from outer scopes.
+        let mut seen_lifetimes = FxHashSet::default();
 
         // We also can't shadow bindings from the parent item
         if let AssocItemRibKind = kind {
@@ -1905,7 +1904,7 @@ fn with_generic_param_rib<'c, F>(
 
         // Forbid shadowing lifetime bindings
         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 {
                 break;
             }
@@ -1915,35 +1914,28 @@ fn with_generic_param_rib<'c, F>(
             let ident = param.ident.normalize_to_macros_2_0();
             debug!("with_generic_param_rib: {}", param.id);
 
-            if let GenericParamKind::Lifetime = param.kind {
-                match seen_lifetimes.entry(ident) {
-                    Entry::Occupied(entry) => {
-                        let original = *entry.key();
-                        let orig_is_param = *entry.get();
-                        diagnostics::signal_lifetime_shadowing(
-                            self.r.session,
-                            original,
-                            param.ident,
-                            orig_is_param,
-                        );
+            if let GenericParamKind::Lifetime = param.kind
+                && let Some(&original) = seen_lifetimes.get(&ident)
+            {
+                diagnostics::signal_lifetime_shadowing(self.r.session, original, param.ident);
+                // Record lifetime res, so lowering knows there is something fishy.
+                self.record_lifetime_res(param.id, LifetimeRes::Error);
+                continue;
+            }
+
+            match seen_bindings.entry(ident) {
+                Entry::Occupied(entry) => {
+                    let span = *entry.get();
+                    let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
+                    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.insert(true);
-                    }
                 }
-            } else {
-                match seen_bindings.entry(ident) {
-                    Entry::Occupied(entry) => {
-                        let span = *entry.get();
-                        let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
-                        self.report_error(param.ident.span, err);
-                    }
-                    Entry::Vacant(entry) => {
-                        entry.insert(param.ident.span);
-                    }
+                Entry::Vacant(entry) => {
+                    entry.insert(param.ident.span);
                 }
             }
 
index 6d5318ae6f78099c9dadeb23f005305c3b6c2422..9213652e35f8e0e98a38f38773cebe5cf4e3dffe 100644 (file)
@@ -2038,29 +2038,14 @@ pub(crate) fn maybe_emit_forbidden_non_static_lifetime_error(
 }
 
 /// Report lifetime/lifetime shadowing as an error.
-pub fn signal_lifetime_shadowing(
-    sess: &Session,
-    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,
-            shadower.span,
-            E0496,
-            "lifetime name `{}` shadows a lifetime name that is already in scope",
-            orig.name,
-        )
-    };
+pub fn signal_lifetime_shadowing(sess: &Session, orig: Ident, shadower: Ident) {
+    let mut err = struct_span_err!(
+        sess,
+        shadower.span,
+        E0496,
+        "lifetime name `{}` shadows a lifetime name that is already in scope",
+        orig.name,
+    );
     err.span_label(orig.span, "first declared here");
     err.span_label(shadower.span, format!("lifetime `{}` already in scope", orig.name));
     err.emit();
index 4376437823cf674ede0a89f805f713925e2e0961..92917678e4c02697ac5990a9174838d28f0091b2 100644 (file)
@@ -1,5 +1,5 @@
 fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) {
-    //~^ ERROR E0263
+    //~^ ERROR E0403
 }
 
 fn main() {}
index 56e4ef023794f9accd534d8794831265a30bbc72..e3f9aea296a2c351664c8b824c03dd637fb242d8 100644 (file)
@@ -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
    |
 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
 
-For more information about this error, try `rustc --explain E0263`.
+For more information about this error, try `rustc --explain E0403`.
index e7312b51dbcb8be2d664c84a25599cd6c5e0e284..8971fb62626cbfb99a4a635b4a9eb06c5d684724 100644 (file)
@@ -5,12 +5,12 @@
 
 #[rustc_macro_transparency = "semitransparent"]
 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"]
 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);
index ade411a25442b3af623a3ba60298bf3d8e92acea..9f1a75147272dbb3a9c1c5625e7f015381422967 100644 (file)
@@ -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
    |
 LL |     fn g<$a, 'a>() {}
-   |              ^^ lifetime `'a` already in scope
+   |              ^^ already used
 ...
 LL | m!('a);
    | ------
    | |  |
-   | |  first declared here
+   | |  first use of `'a`
    | in this macro invocation
    |
    = 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
    |
 LL |     fn h<$a, 'a>() {}
-   |              ^^ lifetime `'a` already in scope
+   |              ^^ already used
 ...
 LL | n!('a);
    | ------
    | |  |
-   | |  first declared here
+   | |  first use of `'a`
    | in this macro invocation
    |
    = 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
 
-For more information about this error, try `rustc --explain E0263`.
+For more information about this error, try `rustc --explain E0403`.
index 4cf8b4401925da6652f15080cd6a7b3699d3ba8c..f6616591a3df223db8782e29ff56dffa662e6991 100644 (file)
@@ -1,5 +1,5 @@
 struct Foo<'a, 'a> {
-    //~^ ERROR lifetime name `'a` declared twice
+    //~^ ERROR the name `'a` is already used for a generic parameter
     x: &'a isize,
 }
 
index 303aa3389998be1aad837b149e5a39be38d46fa2..cef73c18d371e458001501012bd26f34fcab1360 100644 (file)
@@ -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
    |
 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
 
-For more information about this error, try `rustc --explain E0263`.
+For more information about this error, try `rustc --explain E0403`.