mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 19:23:50 +00:00
Rollup merge of #108230 - LittleFall:enhance/warning, r=estebank
Convert a hard-warning about named static lifetimes into lint "unused_lifetimes" Fixes https://github.com/rust-lang/rust/issues/96956. Some changes are ported from https://github.com/rust-lang/rust/pull/98079, thanks to jeremydavis519. r? `@estebank` `@petrochenkov` Any feedback is appreciated! ## Actions - [x] resolve conflicts - [x] fix build - [x] address review comments in last pr - [x] update tests
This commit is contained in:
commit
a32c500400
@ -18,6 +18,7 @@ use rustc_middle::bug;
|
|||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::middle::resolve_bound_vars::*;
|
use rustc_middle::middle::resolve_bound_vars::*;
|
||||||
use rustc_middle::ty::{self, ir::TypeVisitor, DefIdTree, TyCtxt, TypeSuperVisitable};
|
use rustc_middle::ty::{self, ir::TypeVisitor, DefIdTree, TyCtxt, TypeSuperVisitable};
|
||||||
|
use rustc_session::lint;
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
use rustc_span::symbol::{sym, Ident};
|
use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -923,17 +924,16 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||||||
origin,
|
origin,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
|
let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
|
||||||
bound_generic_params
|
bound_generic_params
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(late_bound_idx, param)| {
|
.map(|(late_bound_idx, param)| {
|
||||||
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
let pair = ResolvedArg::late(late_bound_idx as u32, param);
|
||||||
let r = late_arg_as_bound_arg(this.tcx, &pair.1, param);
|
let r = late_arg_as_bound_arg(this.tcx, &pair.1, param);
|
||||||
(pair, r)
|
(pair, r)
|
||||||
})
|
})
|
||||||
.unzip();
|
.unzip();
|
||||||
this.record_late_bound_vars(hir_id, binders.clone());
|
this.record_late_bound_vars(hir_id, binders.clone());
|
||||||
// Even if there are no lifetimes defined here, we still wrap it in a binder
|
// Even if there are no lifetimes defined here, we still wrap it in a binder
|
||||||
// scope. If there happens to be a nested poly trait ref (an error), that
|
// scope. If there happens to be a nested poly trait ref (an error), that
|
||||||
@ -968,20 +968,22 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.insert_lifetime(lt, ResolvedArg::StaticLifetime);
|
this.insert_lifetime(lt, ResolvedArg::StaticLifetime);
|
||||||
this.tcx
|
this.tcx.struct_span_lint_hir(
|
||||||
.sess
|
lint::builtin::UNUSED_LIFETIMES,
|
||||||
.struct_span_warn(
|
lifetime.hir_id,
|
||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
&format!(
|
format!(
|
||||||
"unnecessary lifetime parameter `{}`",
|
"unnecessary lifetime parameter `{}`",
|
||||||
|
lifetime.ident
|
||||||
|
),
|
||||||
|
|lint| {
|
||||||
|
let help = &format!(
|
||||||
|
"you can use the `'static` lifetime directly, in place of `{}`",
|
||||||
lifetime.ident,
|
lifetime.ident,
|
||||||
),
|
);
|
||||||
)
|
lint.help(help)
|
||||||
.help(&format!(
|
},
|
||||||
"you can use the `'static` lifetime directly, in place of `{}`",
|
);
|
||||||
lifetime.ident,
|
|
||||||
))
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied
|
error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied
|
||||||
--> $DIR/method-unsatified-assoc-type-predicate.rs:28:7
|
--> $DIR/method-unsatisfied-assoc-type-predicate.rs:28:7
|
||||||
|
|
|
|
||||||
LL | struct S;
|
LL | struct S;
|
||||||
| --------
|
| --------
|
||||||
@ -12,7 +12,7 @@ LL | a.f();
|
|||||||
| ^ method cannot be called on `S` due to unsatisfied trait bounds
|
| ^ method cannot be called on `S` due to unsatisfied trait bounds
|
||||||
|
|
|
|
||||||
note: trait bound `<S as X>::Y<i32> = i32` was not satisfied
|
note: trait bound `<S as X>::Y<i32> = i32` was not satisfied
|
||||||
--> $DIR/method-unsatified-assoc-type-predicate.rs:12:11
|
--> $DIR/method-unsatisfied-assoc-type-predicate.rs:12:11
|
||||||
|
|
|
|
||||||
LL | impl<T: X<Y<i32> = i32>> M for T {}
|
LL | impl<T: X<Y<i32> = i32>> M for T {}
|
||||||
| ^^^^^^^^^^^^ - -
|
| ^^^^^^^^^^^^ - -
|
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(unused_lifetimes)]
|
||||||
|
|
||||||
pub trait X {
|
pub trait X {
|
||||||
type Y<'a: 'static>;
|
type Y<'a: 'static>;
|
||||||
//~^ WARNING unnecessary lifetime parameter
|
//~^ WARNING unnecessary lifetime parameter
|
@ -1,45 +1,50 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
warning: unnecessary lifetime parameter `'a`
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:2:12
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:4:12
|
||||||
|
|
|
|
||||||
LL | type Y<'a: 'static>;
|
LL | type Y<'a: 'static>;
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
= help: you can use the `'static` lifetime directly, in place of `'a`
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![warn(unused_lifetimes)]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0478]: lifetime bound not satisfied
|
error[E0478]: lifetime bound not satisfied
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:11:8
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:13:8
|
||||||
|
|
|
|
||||||
LL | f: <T as X>::Y<'a>,
|
LL | f: <T as X>::Y<'a>,
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:10:10
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:12:10
|
||||||
|
|
|
|
||||||
LL | struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> {
|
LL | struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> {
|
||||||
| ^^
|
| ^^
|
||||||
= note: but lifetime parameter must outlive the static lifetime
|
= note: but lifetime parameter must outlive the static lifetime
|
||||||
|
|
||||||
error[E0478]: lifetime bound not satisfied
|
error[E0478]: lifetime bound not satisfied
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:16:8
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:18:8
|
||||||
|
|
|
|
||||||
LL | f: <T as X>::Y<'a>,
|
LL | f: <T as X>::Y<'a>,
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:15:10
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:17:10
|
||||||
|
|
|
|
||||||
LL | struct C<'a, T: X> {
|
LL | struct C<'a, T: X> {
|
||||||
| ^^
|
| ^^
|
||||||
= note: but lifetime parameter must outlive the static lifetime
|
= note: but lifetime parameter must outlive the static lifetime
|
||||||
|
|
||||||
error[E0478]: lifetime bound not satisfied
|
error[E0478]: lifetime bound not satisfied
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:21:8
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:23:8
|
||||||
|
|
|
|
||||||
LL | f: <() as X>::Y<'a>,
|
LL | f: <() as X>::Y<'a>,
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
||||||
--> $DIR/unsatified-item-lifetime-bound.rs:20:10
|
--> $DIR/unsatisfied-item-lifetime-bound.rs:22:10
|
||||||
|
|
|
|
||||||
LL | struct D<'a> {
|
LL | struct D<'a> {
|
||||||
| ^^
|
| ^^
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
// `'a == 'static` so `&'a i32` is fine as the return type
|
// `'a == 'static` so `&'a i32` is fine as the return type
|
||||||
fn equal_regions_static<'a: 'static>(x: &'a i32) -> impl Sized {
|
fn equal_regions_static<'a: 'static>(x: &'a i32) -> impl Sized {
|
||||||
//~^ WARNING unnecessary lifetime parameter `'a`
|
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/equal-hidden-lifetimes.rs:7:25
|
|
||||||
|
|
|
||||||
LL | fn equal_regions_static<'a: 'static>(x: &'a i32) -> impl Sized {
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
warning: 1 warning emitted
|
|
||||||
|
|
@ -5,7 +5,6 @@ trait Trait { type Out; }
|
|||||||
struct Test<'a> { s: &'a str }
|
struct Test<'a> { s: &'a str }
|
||||||
|
|
||||||
fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
|
fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
|
||||||
//~^ WARN unnecessary lifetime parameter `'z`
|
|
||||||
let x = Test { s: "this cannot last" };
|
let x = Test { s: "this cannot last" };
|
||||||
&x
|
&x
|
||||||
//~^ ERROR: cannot return reference to local variable `x`
|
//~^ ERROR: cannot return reference to local variable `x`
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
warning: unnecessary lifetime parameter `'z`
|
|
||||||
--> $DIR/issue-30438-c.rs:7:74
|
|
||||||
|
|
|
||||||
LL | fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'z`
|
|
||||||
|
|
||||||
error[E0515]: cannot return reference to local variable `x`
|
error[E0515]: cannot return reference to local variable `x`
|
||||||
--> $DIR/issue-30438-c.rs:10:5
|
--> $DIR/issue-30438-c.rs:9:5
|
||||||
|
|
|
|
||||||
LL | &x
|
LL | &x
|
||||||
| ^^ returns a reference to data owned by the current function
|
| ^^ returns a reference to data owned by the current function
|
||||||
|
|
||||||
error: aborting due to previous error; 1 warning emitted
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0515`.
|
For more information about this error, try `rustc --explain E0515`.
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
//
|
//
|
||||||
// 'a : 'b
|
// 'a : 'b
|
||||||
|
|
||||||
|
#![warn(unused_lifetimes)]
|
||||||
|
|
||||||
fn test<'a,'b>(x: &'a i32) -> &'b i32
|
fn test<'a,'b>(x: &'a i32) -> &'b i32
|
||||||
where 'a: 'static //~ WARN unnecessary lifetime parameter `'a`
|
where 'a: 'static //~ WARN unnecessary lifetime parameter `'a`
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
warning: unnecessary lifetime parameter `'a`
|
||||||
--> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:12:11
|
--> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:14:11
|
||||||
|
|
|
|
||||||
LL | where 'a: 'static
|
LL | where 'a: 'static
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
= help: you can use the `'static` lifetime directly, in place of `'a`
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:11:9
|
||||||
|
|
|
||||||
|
LL | #![warn(unused_lifetimes)]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: 1 warning emitted
|
warning: 1 warning emitted
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
|
#![warn(unused_lifetimes)]
|
||||||
|
|
||||||
fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
|
fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
|
||||||
where 'a: 'static { t }
|
where 'a: 'static { t }
|
||||||
//~^ WARN unnecessary lifetime parameter `'a`
|
//~^ WARN unnecessary lifetime parameter `'a`
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
warning: unnecessary lifetime parameter `'a`
|
||||||
--> $DIR/regions-static-bound-rpass.rs:4:11
|
--> $DIR/regions-static-bound-rpass.rs:6:11
|
||||||
|
|
|
|
||||||
LL | where 'a: 'static { t }
|
LL | where 'a: 'static { t }
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
= help: you can use the `'static` lifetime directly, in place of `'a`
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/regions-static-bound-rpass.rs:3:9
|
||||||
|
|
|
||||||
|
LL | #![warn(unused_lifetimes)]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: unnecessary lifetime parameter `'a`
|
warning: unnecessary lifetime parameter `'a`
|
||||||
--> $DIR/regions-static-bound-rpass.rs:8:11
|
--> $DIR/regions-static-bound-rpass.rs:10:11
|
||||||
|
|
|
|
||||||
LL | where 'a: 'static { t }
|
LL | where 'a: 'static { t }
|
||||||
| ^^
|
| ^^
|
||||||
@ -15,7 +20,7 @@ LL | where 'a: 'static { t }
|
|||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
= help: you can use the `'static` lifetime directly, in place of `'a`
|
||||||
|
|
||||||
warning: unnecessary lifetime parameter `'b`
|
warning: unnecessary lifetime parameter `'b`
|
||||||
--> $DIR/regions-static-bound-rpass.rs:12:19
|
--> $DIR/regions-static-bound-rpass.rs:14:19
|
||||||
|
|
|
|
||||||
LL | where 'a: 'b, 'b: 'static { t }
|
LL | where 'a: 'b, 'b: 'static { t }
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
fn static_id<'a,'b>(t: &'a ()) -> &'static ()
|
#![warn(unused_lifetimes)]
|
||||||
where 'a: 'static { t }
|
|
||||||
//~^ WARN unnecessary lifetime parameter `'a`
|
fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
|
||||||
|
//~^ WARN lifetime parameter `'b` never used
|
||||||
|
//~| WARN unnecessary lifetime parameter `'a`
|
||||||
|
|
||||||
fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
|
fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
|
||||||
where 'a: 'b, 'b: 'static { t }
|
where 'a: 'b, 'b: 'static { t }
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
warning: lifetime parameter `'b` never used
|
||||||
--> $DIR/regions-static-bound.rs:2:11
|
--> $DIR/regions-static-bound.rs:3:17
|
||||||
|
|
|
|
||||||
LL | where 'a: 'static { t }
|
LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
|
||||||
| ^^
|
| -^^
|
||||||
|
| |
|
||||||
|
| help: elide the unused lifetime
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/regions-static-bound.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![warn(unused_lifetimes)]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: unnecessary lifetime parameter `'a`
|
||||||
|
--> $DIR/regions-static-bound.rs:3:53
|
||||||
|
|
|
||||||
|
LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
|
||||||
|
| ^^
|
||||||
|
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
= help: you can use the `'static` lifetime directly, in place of `'a`
|
||||||
|
|
||||||
warning: unnecessary lifetime parameter `'b`
|
warning: unnecessary lifetime parameter `'b`
|
||||||
--> $DIR/regions-static-bound.rs:6:19
|
--> $DIR/regions-static-bound.rs:8:19
|
||||||
|
|
|
|
||||||
LL | where 'a: 'b, 'b: 'static { t }
|
LL | where 'a: 'b, 'b: 'static { t }
|
||||||
| ^^
|
| ^^
|
||||||
@ -15,7 +29,7 @@ LL | where 'a: 'b, 'b: 'static { t }
|
|||||||
= help: you can use the `'static` lifetime directly, in place of `'b`
|
= help: you can use the `'static` lifetime directly, in place of `'b`
|
||||||
|
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/regions-static-bound.rs:10:5
|
--> $DIR/regions-static-bound.rs:12:5
|
||||||
|
|
|
|
||||||
LL | fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
|
LL | fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
|
||||||
| -- lifetime `'a` defined here
|
| -- lifetime `'a` defined here
|
||||||
@ -23,7 +37,7 @@ LL | t
|
|||||||
| ^ returning this value requires that `'a` must outlive `'static`
|
| ^ returning this value requires that `'a` must outlive `'static`
|
||||||
|
|
||||||
error[E0521]: borrowed data escapes outside of function
|
error[E0521]: borrowed data escapes outside of function
|
||||||
--> $DIR/regions-static-bound.rs:15:5
|
--> $DIR/regions-static-bound.rs:17:5
|
||||||
|
|
|
|
||||||
LL | fn error(u: &(), v: &()) {
|
LL | fn error(u: &(), v: &()) {
|
||||||
| - - let's call the lifetime of this reference `'1`
|
| - - let's call the lifetime of this reference `'1`
|
||||||
@ -36,7 +50,7 @@ LL | static_id(&u);
|
|||||||
| argument requires that `'1` must outlive `'static`
|
| argument requires that `'1` must outlive `'static`
|
||||||
|
|
||||||
error[E0521]: borrowed data escapes outside of function
|
error[E0521]: borrowed data escapes outside of function
|
||||||
--> $DIR/regions-static-bound.rs:17:5
|
--> $DIR/regions-static-bound.rs:19:5
|
||||||
|
|
|
|
||||||
LL | fn error(u: &(), v: &()) {
|
LL | fn error(u: &(), v: &()) {
|
||||||
| - - let's call the lifetime of this reference `'2`
|
| - - let's call the lifetime of this reference `'2`
|
||||||
@ -49,6 +63,6 @@ LL | static_id_indirect(&v);
|
|||||||
| `v` escapes the function body here
|
| `v` escapes the function body here
|
||||||
| argument requires that `'2` must outlive `'static`
|
| argument requires that `'2` must outlive `'static`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors; 2 warnings emitted
|
error: aborting due to 3 previous errors; 3 warnings emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0521`.
|
For more information about this error, try `rustc --explain E0521`.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
fn f<'a: 'static>(_: &'a i32) {} //~WARN unnecessary lifetime parameter `'a`
|
fn f<'a: 'static>(_: &'a i32) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 0;
|
let x = 0;
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/static-lifetime-bound.rs:1:6
|
|
||||||
|
|
|
||||||
LL | fn f<'a: 'static>(_: &'a i32) {}
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
error[E0597]: `x` does not live long enough
|
error[E0597]: `x` does not live long enough
|
||||||
--> $DIR/static-lifetime-bound.rs:5:7
|
--> $DIR/static-lifetime-bound.rs:5:7
|
||||||
|
|
|
|
||||||
@ -19,6 +11,6 @@ LL | f(&x);
|
|||||||
LL | }
|
LL | }
|
||||||
| - `x` dropped here while still borrowed
|
| - `x` dropped here while still borrowed
|
||||||
|
|
||||||
error: aborting due to previous error; 1 warning emitted
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0597`.
|
For more information about this error, try `rustc --explain E0597`.
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
type X<'a> = impl Into<&'static str> + From<&'a str>;
|
type X<'a> = impl Into<&'static str> + From<&'a str>;
|
||||||
|
|
||||||
fn f<'a: 'static>(t: &'a str) -> X<'a> {
|
fn f<'a: 'static>(t: &'a str) -> X<'a> {
|
||||||
//~^ WARNING unnecessary lifetime parameter
|
|
||||||
t
|
t
|
||||||
//~^ ERROR expected generic lifetime parameter, found `'static`
|
//~^ ERROR expected generic lifetime parameter, found `'static`
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/bounds-are-checked.rs:8:6
|
|
||||||
|
|
|
||||||
LL | fn f<'a: 'static>(t: &'a str) -> X<'a> {
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
error[E0792]: expected generic lifetime parameter, found `'static`
|
error[E0792]: expected generic lifetime parameter, found `'static`
|
||||||
--> $DIR/bounds-are-checked.rs:10:5
|
--> $DIR/bounds-are-checked.rs:9:5
|
||||||
|
|
|
|
||||||
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
|
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
|
||||||
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
|
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
|
||||||
@ -15,6 +7,6 @@ LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
|
|||||||
LL | t
|
LL | t
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error; 1 warning emitted
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0792`.
|
For more information about this error, try `rustc --explain E0792`.
|
||||||
|
@ -4,7 +4,6 @@ mod test_lifetime_param {
|
|||||||
type Ty<'a> = impl Sized + 'a;
|
type Ty<'a> = impl Sized + 'a;
|
||||||
fn defining(a: &str) -> Ty<'_> { a }
|
fn defining(a: &str) -> Ty<'_> { a }
|
||||||
fn assert_static<'a: 'static>() {}
|
fn assert_static<'a: 'static>() {}
|
||||||
//~^ WARN: unnecessary lifetime parameter `'a`
|
|
||||||
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
|
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
|
||||||
//~^ ERROR: lifetime may not live long enough
|
//~^ ERROR: lifetime may not live long enough
|
||||||
}
|
}
|
||||||
@ -13,14 +12,12 @@ mod test_higher_kinded_lifetime_param {
|
|||||||
type Ty<'a> = impl Sized + 'a;
|
type Ty<'a> = impl Sized + 'a;
|
||||||
fn defining(a: &str) -> Ty<'_> { a }
|
fn defining(a: &str) -> Ty<'_> { a }
|
||||||
fn assert_static<'a: 'static>() {}
|
fn assert_static<'a: 'static>() {}
|
||||||
//~^ WARN: unnecessary lifetime parameter `'a`
|
|
||||||
fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
|
fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
|
||||||
//~^ ERROR: lifetime may not live long enough
|
//~^ ERROR: lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
||||||
mod test_higher_kinded_lifetime_param2 {
|
mod test_higher_kinded_lifetime_param2 {
|
||||||
fn assert_static<'a: 'static>() {}
|
fn assert_static<'a: 'static>() {}
|
||||||
//~^ WARN: unnecessary lifetime parameter `'a`
|
|
||||||
fn test<'a>() { assert_static::<'a>() }
|
fn test<'a>() { assert_static::<'a>() }
|
||||||
//~^ ERROR: lifetime may not live long enough
|
//~^ ERROR: lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,17 @@
|
|||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:6:22
|
|
||||||
|
|
|
||||||
LL | fn assert_static<'a: 'static>() {}
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:15:22
|
|
||||||
|
|
|
||||||
LL | fn assert_static<'a: 'static>() {}
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
warning: unnecessary lifetime parameter `'a`
|
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:22:22
|
|
||||||
|
|
|
||||||
LL | fn assert_static<'a: 'static>() {}
|
|
||||||
| ^^
|
|
||||||
|
|
|
||||||
= help: you can use the `'static` lifetime directly, in place of `'a`
|
|
||||||
|
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:8:43
|
--> $DIR/implied_lifetime_wf_check3.rs:7:43
|
||||||
|
|
|
|
||||||
LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
|
LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
|
||||||
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
||||||
|
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:17:46
|
--> $DIR/implied_lifetime_wf_check3.rs:15:46
|
||||||
|
|
|
|
||||||
LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
|
LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
|
||||||
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
| -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
||||||
|
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:24:21
|
--> $DIR/implied_lifetime_wf_check3.rs:21:21
|
||||||
|
|
|
|
||||||
LL | fn test<'a>() { assert_static::<'a>() }
|
LL | fn test<'a>() { assert_static::<'a>() }
|
||||||
| -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
| -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
||||||
@ -43,7 +19,7 @@ LL | fn test<'a>() { assert_static::<'a>() }
|
|||||||
| lifetime `'a` defined here
|
| lifetime `'a` defined here
|
||||||
|
|
||||||
error[E0310]: the parameter type `A` may not live long enough
|
error[E0310]: the parameter type `A` may not live long enough
|
||||||
--> $DIR/implied_lifetime_wf_check3.rs:32:41
|
--> $DIR/implied_lifetime_wf_check3.rs:29:41
|
||||||
|
|
|
|
||||||
LL | fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
|
LL | fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
|
||||||
| ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
|
| ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
|
||||||
@ -53,6 +29,6 @@ help: consider adding an explicit lifetime bound...
|
|||||||
LL | fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
|
LL | fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
|
||||||
| +++++++++
|
| +++++++++
|
||||||
|
|
||||||
error: aborting due to 4 previous errors; 3 warnings emitted
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0310`.
|
For more information about this error, try `rustc --explain E0310`.
|
||||||
|
Loading…
Reference in New Issue
Block a user