diff options
| author | bors <bors@rust-lang.org> | 2017-09-10 15:32:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-10 15:32:20 +0000 |
| commit | b413f34087d913b80cf432a66d05ec5be11f3515 (patch) | |
| tree | 57d2e4f0354f455a51f0c971391f6fb51adec6af /src/test | |
| parent | d290dec97f8bace2a2585505518b109b1e368f4c (diff) | |
| parent | 88e4bf6827e256687966db263480c90c33b187ba (diff) | |
| download | rust-b413f34087d913b80cf432a66d05ec5be11f3515.tar.gz rust-b413f34087d913b80cf432a66d05ec5be11f3515.zip | |
Auto merge of #44079 - gaurikholkar:named_conf, r=nikomatsakis
Extend E0623 for LateBound and EarlyBound Regions
This is a fix for #43882
```
fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) {
x.push(y);
}
```
now gives
```
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-latebound-regions.rs:12:12
|
11 | fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) {
| ------ ------ these two types are declared with different lifetimes...
12 | x.push(y);
| ^ ...but data from `y` flows into `x` here
```
cc @nikomatsakis @arielb1
Please ignore the second commit. It will be merged in a separate PR.
Diffstat (limited to 'src/test')
16 files changed, 73 insertions, 20 deletions
diff --git a/src/test/compile-fail/associated-types-subtyping-1.rs b/src/test/compile-fail/associated-types-subtyping-1.rs index f9106ba3960..64dcdd39e7c 100644 --- a/src/test/compile-fail/associated-types-subtyping-1.rs +++ b/src/test/compile-fail/associated-types-subtyping-1.rs @@ -31,7 +31,7 @@ fn method2<'a,'b,T>(x: &'a T, y: &'b T) // Note that &'static T <: &'a T. let a: <T as Trait<'a>>::Type = loop { }; let b: <T as Trait<'b>>::Type = loop { }; - let _: <T as Trait<'b>>::Type = a; //~ ERROR mismatched types + let _: <T as Trait<'b>>::Type = a; //~ ERROR E0623 } fn method3<'a,'b,T>(x: &'a T, y: &'b T) @@ -40,7 +40,7 @@ fn method3<'a,'b,T>(x: &'a T, y: &'b T) // Note that &'static T <: &'a T. let a: <T as Trait<'a>>::Type = loop { }; let b: <T as Trait<'b>>::Type = loop { }; - let _: <T as Trait<'a>>::Type = b; //~ ERROR mismatched types + let _: <T as Trait<'a>>::Type = b; //~ ERROR E0623 } fn method4<'a,'b,T>(x: &'a T, y: &'b T) diff --git a/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs b/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs index 6364db1f4b4..f886c0255cc 100644 --- a/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs @@ -15,7 +15,7 @@ fn a<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) where 'b: 'a { fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. - *x = *y; //~ ERROR E0312 + *x = *y; //~ ERROR E0623 } fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { diff --git a/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs b/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs index 154135eba38..bae9608c3f0 100644 --- a/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs @@ -16,8 +16,8 @@ fn a<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) where fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { // Illegal now because there is no `'b:'a` declaration. - *x = *y; //~ ERROR E0312 - *z = *y; //~ ERROR E0312 + *x = *y; //~ ERROR E0623 + *z = *y; //~ ERROR E0623 } fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index edca3b7ed41..66b16744cc7 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -15,20 +15,16 @@ struct Paramd<'a> { x: &'a usize } fn call2<'a, 'b>(a: &'a usize, b: &'b usize) { - let z: Option<&'b &'a usize> = None; - //~^ ERROR reference has a longer lifetime than the data it references + let z: Option<&'b &'a usize> = None;//~ ERROR E0623 } fn call3<'a, 'b>(a: &'a usize, b: &'b usize) { let y: Paramd<'a> = Paramd { x: a }; - let z: Option<&'b Paramd<'a>> = None; - //~^ ERROR reference has a longer lifetime than the data it references + let z: Option<&'b Paramd<'a>> = None;//~ ERROR E0623 } fn call4<'a, 'b>(a: &'a usize, b: &'b usize) { - let z: Option<&'a &'b usize> = None; - //~^ ERROR reference has a longer lifetime than the data it references + let z: Option<&'a &'b usize> = None;//~ ERROR E0623 } - fn main() {} diff --git a/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs b/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs index b7ef19d1e3b..6e1c765724b 100644 --- a/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs +++ b/src/test/compile-fail/regions-infer-contravariance-due-to-decl.rs @@ -32,7 +32,7 @@ fn use_<'short,'long>(c: Contravariant<'short>, // 'short <= 'long, this would be true if the Contravariant type were // covariant with respect to its parameter 'a. - let _: Contravariant<'long> = c; //~ ERROR mismatched types + let _: Contravariant<'long> = c; //~ ERROR E0623 } fn main() {} diff --git a/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs b/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs index 0d3d9dacbd6..1ab8ba4439b 100644 --- a/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs +++ b/src/test/compile-fail/regions-infer-covariance-due-to-decl.rs @@ -29,7 +29,7 @@ fn use_<'short,'long>(c: Covariant<'long>, // 'short <= 'long, this would be true if the Covariant type were // contravariant with respect to its parameter 'a. - let _: Covariant<'short> = c; //~ ERROR mismatched types + let _: Covariant<'short> = c; //~ ERROR E0623 } fn main() {} diff --git a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs index 89254516ac6..ef1c58bf972 100644 --- a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs +++ b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs @@ -15,7 +15,7 @@ fn a<'a, 'b:'a>(x: &mut &'a isize, y: &mut &'b isize) { fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. - *x = *y; //~ ERROR E0312 + *x = *y; //~ ERROR E0623 } fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { diff --git a/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs b/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs index a7ef3ec9ac1..1dfebd54ec3 100644 --- a/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs +++ b/src/test/compile-fail/regions-variance-contravariant-use-covariant-in-second-position.rs @@ -32,7 +32,7 @@ fn use_<'short,'long>(c: S<'long, 'short>, // 'short <= 'long, this would be true if the Contravariant type were // covariant with respect to its parameter 'a. - let _: S<'long, 'long> = c; //~ ERROR mismatched types + let _: S<'long, 'long> = c; //~ ERROR E0623 } fn main() {} diff --git a/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs b/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs index a79249ade4f..caf6a86fc0b 100644 --- a/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs +++ b/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs @@ -30,7 +30,7 @@ fn use_<'short,'long>(c: Contravariant<'short>, // 'short <= 'long, this would be true if the Contravariant type were // covariant with respect to its parameter 'a. - let _: Contravariant<'long> = c; //~ ERROR mismatched types + let _: Contravariant<'long> = c; //~ ERROR E0623 } fn main() {} diff --git a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs index f42b7027d9e..60dc3d94a2e 100644 --- a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs @@ -30,7 +30,7 @@ fn use_<'short,'long>(c: Covariant<'long>, // 'short <= 'long, this would be true if the Covariant type were // contravariant with respect to its parameter 'a. - let _: Covariant<'short> = c; //~ ERROR mismatched types + let _: Covariant<'short> = c; //~ ERROR E0623 } fn main() {} diff --git a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs index 71023b26c27..96478fa5909 100644 --- a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs @@ -27,7 +27,7 @@ fn use_<'short,'long>(c: Invariant<'long>, // 'short <= 'long, this would be true if the Invariant type were // contravariant with respect to its parameter 'a. - let _: Invariant<'short> = c; //~ ERROR mismatched types + let _: Invariant<'short> = c; //~ ERROR E0623 } fn main() { } diff --git a/src/test/compile-fail/variance-cell-is-invariant.rs b/src/test/compile-fail/variance-cell-is-invariant.rs index b8a8f9ad91c..1ddbcf4ab84 100644 --- a/src/test/compile-fail/variance-cell-is-invariant.rs +++ b/src/test/compile-fail/variance-cell-is-invariant.rs @@ -21,7 +21,7 @@ fn use_<'short,'long>(c: Foo<'short>, s: &'short isize, l: &'long isize, _where:Option<&'short &'long ()>) { - let _: Foo<'long> = c; //~ ERROR mismatched types + let _: Foo<'long> = c; //~ ERROR E0623 } fn main() { diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.rs b/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.rs new file mode 100644 index 00000000000..5d182008209 --- /dev/null +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.rs @@ -0,0 +1,21 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +trait Foo<'a> {} +impl<'a, T> Foo<'a> for T {} + +fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T) + where i32: Foo<'a>, + u32: Foo<'b> +{ + x.push(y); +} +fn main() { +let x = baz; +} diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.stderr new file mode 100644 index 00000000000..58f2cb94cec --- /dev/null +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.stderr @@ -0,0 +1,11 @@ +error[E0623]: lifetime mismatch + --> $DIR/ex3-both-anon-regions-earlybound-regions.rs:17:12 + | +13 | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T) + | ----- -- these two types are declared with different lifetimes... +... +17 | x.push(y); + | ^ ...but data from `y` flows into `x` here + +error: aborting due to previous error + diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.rs b/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.rs new file mode 100644 index 00000000000..5abfc983f88 --- /dev/null +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) { + x.push(y); +} + +fn main() { } \ No newline at end of file diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.stderr new file mode 100644 index 00000000000..be628f226d3 --- /dev/null +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-latebound-regions.stderr @@ -0,0 +1,10 @@ +error[E0623]: lifetime mismatch + --> $DIR/ex3-both-anon-regions-latebound-regions.rs:12:12 + | +11 | fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) { + | ------ ------ these two types are declared with different lifetimes... +12 | x.push(y); + | ^ ...but data from `y` flows into `x` here + +error: aborting due to previous error + |
