mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 22:13:27 +00:00
Add more tests
This commit is contained in:
parent
4f97ab54c4
commit
805397c16f
23
tests/ui/consts/static-default-lifetime/elided-lifetime.rs
Normal file
23
tests/ui/consts/static-default-lifetime/elided-lifetime.rs
Normal file
@ -0,0 +1,23 @@
|
||||
#![deny(elided_lifetimes_in_associated_constant)]
|
||||
|
||||
struct Foo<'a>(&'a ());
|
||||
|
||||
impl Foo<'_> {
|
||||
const STATIC: &str = "";
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
||||
trait Bar {
|
||||
const STATIC: &'static str;
|
||||
// TODO^
|
||||
}
|
||||
|
||||
impl Bar for Foo<'_> {
|
||||
const STATIC: &str = "";
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
//~| ERROR const not compatible with trait
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,59 @@
|
||||
error: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/elided-lifetime.rs:6:19
|
||||
|
|
||||
LL | const STATIC: &str = "";
|
||||
| ^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
|
||||
note: cannot automatically infer `'static` because of other lifetimes in scope
|
||||
--> $DIR/elided-lifetime.rs:5:10
|
||||
|
|
||||
LL | impl Foo<'_> {
|
||||
| ^^
|
||||
note: the lint level is defined here
|
||||
--> $DIR/elided-lifetime.rs:1:9
|
||||
|
|
||||
LL | #![deny(elided_lifetimes_in_associated_constant)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: use the `'static` lifetime
|
||||
|
|
||||
LL | const STATIC: &'static str = "";
|
||||
| +++++++
|
||||
|
||||
error: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/elided-lifetime.rs:17:19
|
||||
|
|
||||
LL | const STATIC: &str = "";
|
||||
| ^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
|
||||
note: cannot automatically infer `'static` because of other lifetimes in scope
|
||||
--> $DIR/elided-lifetime.rs:16:18
|
||||
|
|
||||
LL | impl Bar for Foo<'_> {
|
||||
| ^^
|
||||
help: use the `'static` lifetime
|
||||
|
|
||||
LL | const STATIC: &'static str = "";
|
||||
| +++++++
|
||||
|
||||
error[E0308]: const not compatible with trait
|
||||
--> $DIR/elided-lifetime.rs:17:5
|
||||
|
|
||||
LL | const STATIC: &str = "";
|
||||
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&'static _`
|
||||
found reference `&_`
|
||||
note: the anonymous lifetime as defined here...
|
||||
--> $DIR/elided-lifetime.rs:16:18
|
||||
|
|
||||
LL | impl Bar for Foo<'_> {
|
||||
| ^^
|
||||
= note: ...does not necessarily outlive the static lifetime
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -0,0 +1,20 @@
|
||||
#![deny(elided_lifetimes_in_associated_constant)]
|
||||
#![feature(generic_const_items)]
|
||||
//~^ WARN the feature `generic_const_items` is incomplete
|
||||
|
||||
struct A;
|
||||
impl A {
|
||||
const GAC_TYPE<T>: &str = "";
|
||||
const GAC_LIFETIME<'a>: &str = "";
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
const GAC_TYPE<T>: &str = "";
|
||||
//~^ ERROR missing lifetime specifier
|
||||
const GAC_LIFETIME<'a>: &str = "";
|
||||
//~^ ERROR missing lifetime specifier
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,57 @@
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/generic-associated-const.rs:14:24
|
||||
|
|
||||
LL | const GAC_TYPE<T>: &str = "";
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
help: consider introducing a named lifetime parameter
|
||||
|
|
||||
LL | const GAC_TYPE<'a, T>: &'a str = "";
|
||||
| +++ ++
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/generic-associated-const.rs:16:29
|
||||
|
|
||||
LL | const GAC_LIFETIME<'a>: &str = "";
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | const GAC_LIFETIME<'a>: &'a str = "";
|
||||
| ++
|
||||
|
||||
warning: the feature `generic_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/generic-associated-const.rs:2:12
|
||||
|
|
||||
LL | #![feature(generic_const_items)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/generic-associated-const.rs:8:29
|
||||
|
|
||||
LL | const GAC_LIFETIME<'a>: &str = "";
|
||||
| ^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
|
||||
note: cannot automatically infer `'static` because of other lifetimes in scope
|
||||
--> $DIR/generic-associated-const.rs:8:24
|
||||
|
|
||||
LL | const GAC_LIFETIME<'a>: &str = "";
|
||||
| ^^
|
||||
note: the lint level is defined here
|
||||
--> $DIR/generic-associated-const.rs:1:9
|
||||
|
|
||||
LL | #![deny(elided_lifetimes_in_associated_constant)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: use the `'static` lifetime
|
||||
|
|
||||
LL | const GAC_LIFETIME<'a>: &'static str = "";
|
||||
| +++++++
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0106`.
|
21
tests/ui/consts/static-default-lifetime/inner-item.rs
Normal file
21
tests/ui/consts/static-default-lifetime/inner-item.rs
Normal file
@ -0,0 +1,21 @@
|
||||
//@ check-pass
|
||||
|
||||
struct Foo<'a>(&'a ());
|
||||
|
||||
impl<'a> Foo<'a> {
|
||||
fn hello(self) {
|
||||
const INNER: &str = "";
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo<'_> {
|
||||
fn implicit(self) {
|
||||
const INNER: &str = "";
|
||||
}
|
||||
|
||||
fn fn_lifetime(&self) {
|
||||
const INNER: &str = "";
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
20
tests/ui/consts/static-default-lifetime/static-trait-impl.rs
Normal file
20
tests/ui/consts/static-default-lifetime/static-trait-impl.rs
Normal file
@ -0,0 +1,20 @@
|
||||
#![deny(elided_lifetimes_in_associated_constant)]
|
||||
|
||||
trait Bar<'a> {
|
||||
const STATIC: &'a str;
|
||||
}
|
||||
|
||||
struct A;
|
||||
impl Bar<'_> for A {
|
||||
const STATIC: &str = "";
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
//~| ERROR const not compatible with trait
|
||||
}
|
||||
|
||||
struct B;
|
||||
impl Bar<'static> for B {
|
||||
const STATIC: &str = "";
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,45 @@
|
||||
error: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/static-trait-impl.rs:9:19
|
||||
|
|
||||
LL | const STATIC: &str = "";
|
||||
| ^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
|
||||
note: cannot automatically infer `'static` because of other lifetimes in scope
|
||||
--> $DIR/static-trait-impl.rs:8:10
|
||||
|
|
||||
LL | impl Bar<'_> for A {
|
||||
| ^^
|
||||
note: the lint level is defined here
|
||||
--> $DIR/static-trait-impl.rs:1:9
|
||||
|
|
||||
LL | #![deny(elided_lifetimes_in_associated_constant)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: use the `'static` lifetime
|
||||
|
|
||||
LL | const STATIC: &'static str = "";
|
||||
| +++++++
|
||||
|
||||
error[E0308]: const not compatible with trait
|
||||
--> $DIR/static-trait-impl.rs:9:5
|
||||
|
|
||||
LL | const STATIC: &str = "";
|
||||
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&_`
|
||||
found reference `&_`
|
||||
note: the anonymous lifetime as defined here...
|
||||
--> $DIR/static-trait-impl.rs:8:10
|
||||
|
|
||||
LL | impl Bar<'_> for A {
|
||||
| ^^
|
||||
note: ...does not necessarily outlive the anonymous lifetime as defined here
|
||||
--> $DIR/static-trait-impl.rs:8:10
|
||||
|
|
||||
LL | impl Bar<'_> for A {
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user