move E0637 to lowering and improve output, add more tests

This commit is contained in:
Niko Matsakis 2018-10-11 15:51:44 -04:00
parent 68da108d56
commit 1f4d100472
36 changed files with 539 additions and 79 deletions

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_`
fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_`
struct Foo<'a: '_>(&'a u8); //~ ERROR cannot be used here
fn foo<'a: '_>(_: &'a u8) {} //~ ERROR cannot be used here
struct Bar<'a>(&'a u8);
impl<'a: '_> Bar<'a> { //~ ERROR invalid lifetime bound name: `'_`
impl<'a: '_> Bar<'a> { //~ ERROR cannot be used here
fn bar() {}
}

View file

@ -1,19 +1,19 @@
error[E0637]: invalid lifetime bound name: `'_`
error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:11:16
|
LL | struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_`
LL | struct Foo<'a: '_>(&'a u8); //~ ERROR cannot be used here
| ^^ `'_` is a reserved lifetime name
error[E0637]: invalid lifetime bound name: `'_`
error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:12:12
|
LL | fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_`
LL | fn foo<'a: '_>(_: &'a u8) {} //~ ERROR cannot be used here
| ^^ `'_` is a reserved lifetime name
error[E0637]: invalid lifetime bound name: `'_`
error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:15:10
|
LL | impl<'a: '_> Bar<'a> { //~ ERROR invalid lifetime bound name: `'_`
LL | impl<'a: '_> Bar<'a> { //~ ERROR cannot be used here
| ^^ `'_` is a reserved lifetime name
error: aborting due to 3 previous errors

View file

@ -0,0 +1,46 @@
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:12:6
|
LL | impl<'_> IceCube<'_> {}
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:17:15
|
LL | struct Struct<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:23:11
|
LL | enum Enum<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:29:13
|
LL | union Union<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:35:13
|
LL | trait Trait<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:40:8
|
LL | fn foo<'_>() {
| ^^ `'_` is a reserved lifetime name
error[E0106]: missing lifetime specifier
--> $DIR/in-binder.rs:12:18
|
LL | impl<'_> IceCube<'_> {}
| ^^ expected lifetime parameter
error: aborting due to 7 previous errors
Some errors occurred: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.

View file

@ -0,0 +1,39 @@
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:12:6
|
LL | impl<'_> IceCube<'_> {}
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:17:15
|
LL | struct Struct<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:23:11
|
LL | enum Enum<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:29:13
|
LL | union Union<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:35:13
|
LL | trait Trait<'_> {
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/in-binder.rs:40:8
|
LL | fn foo<'_>() {
| ^^ `'_` is a reserved lifetime name
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,45 @@
// Check that we error when `'_` appears as the name of a lifetime parameter.
//
// Regression test for #52098.
// revisions: Rust2015 Rust2018
//[Rust2018] edition:2018
struct IceCube<'a> {
v: Vec<&'a char>
}
impl<'_> IceCube<'_> {}
//[Rust2015]~^ ERROR
//[Rust2015]~| ERROR
//[Rust2018]~^^^ ERROR
struct Struct<'_> {
//[Rust2015]~^ ERROR
//[Rust2018]~^^ ERROR
v: Vec<&'static char>
}
enum Enum<'_> {
//[Rust2015]~^ ERROR
//[Rust2018]~^^ ERROR
Variant
}
union Union<'_> {
//[Rust2015]~^ ERROR
//[Rust2018]~^^ ERROR
a: u32
}
trait Trait<'_> {
//[Rust2015]~^ ERROR
//[Rust2018]~^^ ERROR
}
fn foo<'_>() {
//[Rust2015]~^ ERROR
//[Rust2018]~^^ ERROR
}
fn main() {}

View file

@ -0,0 +1,17 @@
// Copyright 2015 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.
// Check that the `'_` used in structs/enums gives an error.
use std::fmt::Debug;
fn foo(x: &u32, y: &u32) -> &'_ u32 { loop { } } //~ ERROR
fn main() { }

View file

@ -0,0 +1,11 @@
error[E0106]: missing lifetime specifier
--> $DIR/in-fn-return-illegal.rs:15:30
|
LL | fn foo(x: &u32, y: &u32) -> &'_ u32 { loop { } } //~ ERROR
| ^^ expected lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0106`.

View file

@ -0,0 +1,23 @@
// Copyright 2015 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.
// Check that the `'_` used in structs/enums gives an error.
use std::fmt::Debug;
struct Foo {
x: &'_ u32, //~ ERROR
}
struct Bar {
Variant(&'_ u32), //~ ERROR
}
fn main() { }

View file

@ -0,0 +1,15 @@
error: expected `:`, found `(`
--> $DIR/in-struct.rs:20:12
|
LL | Variant(&'_ u32), //~ ERROR
| ^ expected `:`
error[E0106]: missing lifetime specifier
--> $DIR/in-struct.rs:16:9
|
LL | x: &'_ u32, //~ ERROR
| ^^ expected lifetime parameter
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0106`.

View file

@ -15,13 +15,13 @@ impl Foo<'_> { //~ ERROR missing lifetime specifier
fn x() {}
}
fn foo<'_> //~ ERROR invalid lifetime parameter name: `'_`
fn foo<'_> //~ ERROR cannot be used here
(_: Foo<'_>) {}
trait Meh<'a> {}
impl<'a> Meh<'a> for u8 {}
fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR invalid lifetime parameter name: `'_`
fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR cannot be used here
//~^ ERROR missing lifetime specifier
{
Box::new(5u8)

View file

@ -1,3 +1,15 @@
error[E0637]: `'_` cannot be used here
--> $DIR/underscore-lifetime-binders.rs:18:8
|
LL | fn foo<'_> //~ ERROR cannot be used here
| ^^ `'_` is a reserved lifetime name
error[E0637]: `'_` cannot be used here
--> $DIR/underscore-lifetime-binders.rs:24:21
|
LL | fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR cannot be used here
| ^^ `'_` is a reserved lifetime name
error[E0106]: missing lifetime specifier
--> $DIR/underscore-lifetime-binders.rs:12:17
|
@ -10,22 +22,10 @@ error[E0106]: missing lifetime specifier
LL | impl Foo<'_> { //~ ERROR missing lifetime specifier
| ^^ expected lifetime parameter
error[E0262]: invalid lifetime parameter name: `'_`
--> $DIR/underscore-lifetime-binders.rs:18:8
|
LL | fn foo<'_> //~ ERROR invalid lifetime parameter name: `'_`
| ^^ '_ is a reserved lifetime name
error[E0262]: invalid lifetime parameter name: `'_`
--> $DIR/underscore-lifetime-binders.rs:24:21
|
LL | fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR invalid lifetime parameter name: `'_`
| ^^ '_ is a reserved lifetime name
error[E0106]: missing lifetime specifier
--> $DIR/underscore-lifetime-binders.rs:24:29
|
LL | fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR invalid lifetime parameter name: `'_`
LL | fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR cannot be used here
| ^^ expected lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
@ -41,5 +41,5 @@ LL | fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y } //~ ERROR missing lifetime sp
error: aborting due to 6 previous errors
Some errors occurred: E0106, E0262.
Some errors occurred: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.

View file

@ -0,0 +1,8 @@
// Regression test to check that `'b: '_` gets an error, because it's
// basically useless.
//
// #54902
trait Foo<'a> {}
impl<'b: '_> Foo<'b> for i32 {}
fn main() { }

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/underscore-outlives-bounds.rs:7:10
|
LL | impl<'b: '_> Foo<'b> for i32 {}
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,18 @@
// revisions: rust2015 rust2018
//[rust2018] edition:2018
trait WithType<T> {}
trait WithRegion<'a> { }
struct Foo<T> {
t: T
}
impl<T> Foo<T>
where
T: WithType<&u32>
//[rust2015]~^ ERROR
//[rust2018]~^^ ERROR
{ }
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,9 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,18 @@
// revisions: rust2015 rust2018
//[rust2018] edition:2018
trait WithType<T> {}
trait WithRegion<'a> { }
struct Foo<T> {
t: T
}
impl<T> Foo<T>
where
T: WithRegion<'_>
//[rust2015]~^ ERROR
//[rust2018]~^^ ERROR
{ }
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/where-clause-inherent-impl-underscore.rs:13:19
|
LL | T: WithRegion<'_>
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/where-clause-inherent-impl-underscore.rs:13:19
|
LL | T: WithRegion<'_>
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,16 @@
// revisions: rust2015 rust2018
//[rust2018] edition:2018
trait WithType<T> {}
trait WithRegion<'a> { }
trait Foo { }
impl<T> Foo for Vec<T>
where
T: WithType<&u32>
//[rust2015]~^ ERROR
//[rust2018]~^^ ERROR
{ }
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-trait-impl-region.rs:11:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,9 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-trait-impl-region.rs:11:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,16 @@
// revisions: rust2015 rust2018
//[rust2018] edition:2018
trait WithType<T> {}
trait WithRegion<'a> { }
trait Foo { }
impl<T> Foo for Vec<T>
where
T: WithRegion<'_>
//[rust2015]~^ ERROR
//[rust2018]~^^ ERROR
{ }
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/where-clause-trait-impl-underscore.rs:11:19
|
LL | T: WithRegion<'_>
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/where-clause-trait-impl-underscore.rs:11:19
|
LL | T: WithRegion<'_>
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.

View file

@ -0,0 +1,3 @@
trait Foo<'a> {}
impl<'b: '_> Foo<'b> for i32 {}
fn main() { }

View file

@ -0,0 +1,9 @@
error[E0637]: `'_` cannot be used here
--> $DIR/where-clauses.rs:2:10
|
LL | impl<'b: '_> Foo<'b> for i32 {}
| ^^ `'_` is a reserved lifetime name
error: aborting due to previous error
For more information about this error, try `rustc --explain E0637`.