From 63671c495bf16dc0f9e1c97fa11af8a895b5ed24 Mon Sep 17 00:00:00 2001 From: Andrea Corradi Date: Sun, 28 Aug 2016 12:57:38 +0200 Subject: [PATCH] Update E0496 to new format --- src/librustc/middle/resolve_lifetime.rs | 6 ++-- src/test/compile-fail/E0496.rs | 2 ++ .../loops-reject-duplicate-labels-2.rs | 33 ++++++++--------- .../loops-reject-duplicate-labels.rs | 32 +++++++++-------- ...loops-reject-labels-shadowing-lifetimes.rs | 36 ++++++++++++------- .../loops-reject-lifetime-shadowing-label.rs | 3 +- src/test/compile-fail/shadowed-lifetime.rs | 6 ++-- 7 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index ebe40500221..747f6982ad7 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -395,9 +395,9 @@ fn signal_shadowing_problem(sess: &Session, name: ast::Name, orig: Original, sha {} name that is already in scope", shadower.kind.desc(), name, orig.kind.desc())) }; - err.span_note(orig.span, - &format!("shadowed {} `{}` declared here", - orig.kind.desc(), name)); + err.span_label(orig.span, &"first declared here"); + err.span_label(shadower.span, + &format!("lifetime {} already in scope", name)); err.emit(); } diff --git a/src/test/compile-fail/E0496.rs b/src/test/compile-fail/E0496.rs index 4ca3cd9c13d..8aeeeebcb56 100644 --- a/src/test/compile-fail/E0496.rs +++ b/src/test/compile-fail/E0496.rs @@ -13,7 +13,9 @@ struct Foo<'a> { } impl<'a> Foo<'a> { + //~^ NOTE first declared here fn f<'a>(x: &'a i32) { //~ ERROR E0496 + //~^ NOTE lifetime 'a already in scope } } diff --git a/src/test/compile-fail/loops-reject-duplicate-labels-2.rs b/src/test/compile-fail/loops-reject-duplicate-labels-2.rs index 4a3338c4bf6..ca18ca3796a 100644 --- a/src/test/compile-fail/loops-reject-duplicate-labels-2.rs +++ b/src/test/compile-fail/loops-reject-duplicate-labels-2.rs @@ -19,30 +19,31 @@ // https://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833 pub fn foo() { - { 'fl: for _ in 0..10 { break; } } //~ NOTE shadowed label `'fl` declared here + { 'fl: for _ in 0..10 { break; } } //~ NOTE first declared here { 'fl: loop { break; } } //~ WARN label name `'fl` shadows a label name that is already in scope - - { 'lf: loop { break; } } //~ NOTE shadowed label `'lf` declared here + //~^ NOTE lifetime 'fl already in scope + { 'lf: loop { break; } } //~ NOTE first declared here { 'lf: for _ in 0..10 { break; } } //~ WARN label name `'lf` shadows a label name that is already in scope - - { 'wl: while 2 > 1 { break; } } //~ NOTE shadowed label `'wl` declared here + //~^ NOTE lifetime 'lf already in scope + { 'wl: while 2 > 1 { break; } } //~ NOTE first declared here { 'wl: loop { break; } } //~ WARN label name `'wl` shadows a label name that is already in scope - - { 'lw: loop { break; } } //~ NOTE shadowed label `'lw` declared here + //~^ NOTE lifetime 'wl already in scope + { 'lw: loop { break; } } //~ NOTE first declared here { 'lw: while 2 > 1 { break; } } //~ WARN label name `'lw` shadows a label name that is already in scope - - { 'fw: for _ in 0..10 { break; } } //~ NOTE shadowed label `'fw` declared here + //~^ NOTE lifetime 'lw already in scope + { 'fw: for _ in 0..10 { break; } } //~ NOTE first declared here { 'fw: while 2 > 1 { break; } } //~ WARN label name `'fw` shadows a label name that is already in scope - - { 'wf: while 2 > 1 { break; } } //~ NOTE shadowed label `'wf` declared here + //~^ NOTE lifetime 'fw already in scope + { 'wf: while 2 > 1 { break; } } //~ NOTE first declared here { 'wf: for _ in 0..10 { break; } } //~ WARN label name `'wf` shadows a label name that is already in scope - - { 'tl: while let Some(_) = None:: { break; } } //~ NOTE shadowed label `'tl` declared here + //~^ NOTE lifetime 'wf already in scope + { 'tl: while let Some(_) = None:: { break; } } //~ NOTE first declared here { 'tl: loop { break; } } //~ WARN label name `'tl` shadows a label name that is already in scope - - { 'lt: loop { break; } } //~ NOTE shadowed label `'lt` declared here + //~^ NOTE lifetime 'tl already in scope + { 'lt: loop { break; } } //~ NOTE first declared here { 'lt: while let Some(_) = None:: { break; } } - //~^ WARN label name `'lt` shadows a label name that is already in scope + //~^ WARN label name `'lt` shadows a label name that is already in scope + //~| NOTE lifetime 'lt already in scope } #[rustc_error] diff --git a/src/test/compile-fail/loops-reject-duplicate-labels.rs b/src/test/compile-fail/loops-reject-duplicate-labels.rs index 15446bf642d..31f89493896 100644 --- a/src/test/compile-fail/loops-reject-duplicate-labels.rs +++ b/src/test/compile-fail/loops-reject-duplicate-labels.rs @@ -16,30 +16,32 @@ // This is testing the exact cases that are in the issue description. fn foo() { - 'fl: for _ in 0..10 { break; } //~ NOTE shadowed label `'fl` declared here + 'fl: for _ in 0..10 { break; } //~ NOTE first declared here 'fl: loop { break; } //~ WARN label name `'fl` shadows a label name that is already in scope + //~^ NOTE lifetime 'fl already in scope - 'lf: loop { break; } //~ NOTE shadowed label `'lf` declared here + 'lf: loop { break; } //~ NOTE first declared here 'lf: for _ in 0..10 { break; } //~ WARN label name `'lf` shadows a label name that is already in scope - - 'wl: while 2 > 1 { break; } //~ NOTE shadowed label `'wl` declared here + //~^ NOTE lifetime 'lf already in scope + 'wl: while 2 > 1 { break; } //~ NOTE first declared here 'wl: loop { break; } //~ WARN label name `'wl` shadows a label name that is already in scope - - 'lw: loop { break; } //~ NOTE shadowed label `'lw` declared here + //~^ NOTE lifetime 'wl already in scope + 'lw: loop { break; } //~ NOTE first declared here 'lw: while 2 > 1 { break; } //~ WARN label name `'lw` shadows a label name that is already in scope - - 'fw: for _ in 0..10 { break; } //~ NOTE shadowed label `'fw` declared here + //~^ NOTE lifetime 'lw already in scope + 'fw: for _ in 0..10 { break; } //~ NOTE first declared here 'fw: while 2 > 1 { break; } //~ WARN label name `'fw` shadows a label name that is already in scope - - 'wf: while 2 > 1 { break; } //~ NOTE shadowed label `'wf` declared here + //~^ NOTE lifetime 'fw already in scope + 'wf: while 2 > 1 { break; } //~ NOTE first declared here 'wf: for _ in 0..10 { break; } //~ WARN label name `'wf` shadows a label name that is already in scope - - 'tl: while let Some(_) = None:: { break; } //~ NOTE shadowed label `'tl` declared here + //~^ NOTE lifetime 'wf already in scope + 'tl: while let Some(_) = None:: { break; } //~ NOTE first declared here 'tl: loop { break; } //~ WARN label name `'tl` shadows a label name that is already in scope - - 'lt: loop { break; } //~ NOTE shadowed label `'lt` declared here + //~^ NOTE lifetime 'tl already in scope + 'lt: loop { break; } //~ NOTE first declared here 'lt: while let Some(_) = None:: { break; } - //~^ WARN label name `'lt` shadows a label name that is already in scope + //~^ WARN label name `'lt` shadows a label name that is already in scope + //~| NOTE lifetime 'lt already in scope } // Note however that it is okay for the same label to be reused in diff --git a/src/test/compile-fail/loops-reject-labels-shadowing-lifetimes.rs b/src/test/compile-fail/loops-reject-labels-shadowing-lifetimes.rs index bbdd0774ed9..9a735f9c97c 100644 --- a/src/test/compile-fail/loops-reject-labels-shadowing-lifetimes.rs +++ b/src/test/compile-fail/loops-reject-labels-shadowing-lifetimes.rs @@ -16,9 +16,10 @@ #![allow(dead_code, unused_variables)] fn foo() { - fn foo<'a>() { //~ NOTE shadowed lifetime `'a` declared here + fn foo<'a>() { //~ NOTE first declared here 'a: loop { break 'a; } //~^ WARN label name `'a` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'a already in scope } struct Struct<'b, 'c> { _f: &'b i8, _g: &'c i8 } @@ -40,76 +41,87 @@ fn foo() { } } - impl<'bad, 'c> Struct<'bad, 'c> { //~ NOTE shadowed lifetime `'bad` declared here + impl<'bad, 'c> Struct<'bad, 'c> { //~ NOTE first declared here fn meth_bad(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } - impl<'b, 'bad> Struct<'b, 'bad> { //~ NOTE shadowed lifetime `'bad` declared here + impl<'b, 'bad> Struct<'b, 'bad> { //~ NOTE first declared here fn meth_bad2(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } impl<'b, 'c> Struct<'b, 'c> { - fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here + fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE first declared here 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } fn meth_bad4<'a,'bad>(x: &'a i8, y: &'bad i8) { - //~^ NOTE shadowed lifetime `'bad` declared here + //~^ NOTE first declared here 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } - impl <'bad, 'e> Enum<'bad, 'e> { //~ NOTE shadowed lifetime `'bad` declared here + impl <'bad, 'e> Enum<'bad, 'e> { //~ NOTE first declared here fn meth_bad(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } - impl <'d, 'bad> Enum<'d, 'bad> { //~ NOTE shadowed lifetime `'bad` declared here + impl <'d, 'bad> Enum<'d, 'bad> { //~ NOTE first declared here fn meth_bad2(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } impl <'d, 'e> Enum<'d, 'e> { - fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here + fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE first declared here 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } - fn meth_bad4<'a,'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here + fn meth_bad4<'a,'bad>(x: &'bad i8) { //~ NOTE first declared here 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } - trait HasDefaultMethod1<'bad> { //~ NOTE shadowed lifetime `'bad` declared here + trait HasDefaultMethod1<'bad> { //~ NOTE first declared here fn meth_okay() { 'c: loop { break 'c; } } fn meth_bad(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } - trait HasDefaultMethod2<'a,'bad> { //~ NOTE shadowed lifetime `'bad` declared here + trait HasDefaultMethod2<'a,'bad> { //~ NOTE first declared here fn meth_bad(&self) { 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } trait HasDefaultMethod3<'a,'b> { - fn meth_bad<'bad>(&self) { //~ NOTE shadowed lifetime `'bad` declared here + fn meth_bad<'bad>(&self) { //~ NOTE first declared here 'bad: loop { break 'bad; } //~^ WARN label name `'bad` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'bad already in scope } } } diff --git a/src/test/compile-fail/loops-reject-lifetime-shadowing-label.rs b/src/test/compile-fail/loops-reject-lifetime-shadowing-label.rs index 2344d251c9a..0a90917d975 100644 --- a/src/test/compile-fail/loops-reject-lifetime-shadowing-label.rs +++ b/src/test/compile-fail/loops-reject-lifetime-shadowing-label.rs @@ -27,9 +27,10 @@ fn foo() { let z = 3_i8; - 'a: loop { //~ NOTE shadowed label `'a` declared here + 'a: loop { //~ NOTE first declared here let b = Box::new(|x: &i8| *x) as Box Fn(&'a i8) -> i8>; //~^ WARN lifetime name `'a` shadows a label name that is already in scope + //~| NOTE lifetime 'a already in scope assert_eq!((*b)(&z), z); break 'a; } diff --git a/src/test/compile-fail/shadowed-lifetime.rs b/src/test/compile-fail/shadowed-lifetime.rs index 8cbab5f8308..31283623a3c 100644 --- a/src/test/compile-fail/shadowed-lifetime.rs +++ b/src/test/compile-fail/shadowed-lifetime.rs @@ -13,16 +13,18 @@ struct Foo<'a>(&'a isize); impl<'a> Foo<'a> { - //~^ NOTE shadowed lifetime `'a` declared here + //~^ NOTE first declared here fn shadow_in_method<'a>(&'a self) -> &'a isize { //~^ ERROR lifetime name `'a` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'a already in scope self.0 } fn shadow_in_type<'b>(&'b self) -> &'b isize { - //~^ NOTE shadowed lifetime `'b` declared here + //~^ NOTE first declared here let x: for<'b> fn(&'b isize) = panic!(); //~^ ERROR lifetime name `'b` shadows a lifetime name that is already in scope + //~| NOTE lifetime 'b already in scope self.0 }