mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
Check lifetimes in Fn traits in generic bounds.
Add tests.
This commit is contained in:
parent
d761ba78d8
commit
ce1800d599
@ -103,6 +103,11 @@ fn check_fn_inner<'a, 'tcx>(
|
|||||||
let mut bounds_lts = Vec::new();
|
let mut bounds_lts = Vec::new();
|
||||||
for typ in generics.ty_params() {
|
for typ in generics.ty_params() {
|
||||||
for bound in &typ.bounds {
|
for bound in &typ.bounds {
|
||||||
|
let mut visitor = RefVisitor::new(cx);
|
||||||
|
walk_ty_param_bound(&mut visitor, bound);
|
||||||
|
if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if let TraitTyParamBound(ref trait_ref, _) = *bound {
|
if let TraitTyParamBound(ref trait_ref, _) = *bound {
|
||||||
let params = &trait_ref
|
let params = &trait_ref
|
||||||
.trait_ref
|
.trait_ref
|
||||||
|
@ -53,6 +53,10 @@ fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
|
|||||||
where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
|
where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
|
||||||
{ unreachable!() }
|
{ unreachable!() }
|
||||||
|
|
||||||
|
fn fn_bound_3<'a, F: FnOnce(&'a ())>(x: &'a (), f: F) {} // no error, referenced
|
||||||
|
|
||||||
|
fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(x: &'a (), f: F) {} // no error, referenced
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
x: u8,
|
x: u8,
|
||||||
}
|
}
|
||||||
|
@ -45,45 +45,45 @@ error: explicit lifetimes given in parameter types where they could be elided
|
|||||||
| |__________________^
|
| |__________________^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:61:5
|
--> $DIR/lifetimes.rs:65:5
|
||||||
|
|
|
|
||||||
61 | fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
|
65 | fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:65:5
|
--> $DIR/lifetimes.rs:69:5
|
||||||
|
|
|
|
||||||
65 | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
|
69 | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:81:1
|
--> $DIR/lifetimes.rs:85:1
|
||||||
|
|
|
|
||||||
81 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
|
85 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
|
||||||
--> $DIR/lifetimes.rs:101:1
|
|
||||||
|
|
|
||||||
101 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:105:1
|
--> $DIR/lifetimes.rs:105:1
|
||||||
|
|
|
|
||||||
105 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
|
105 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:116:1
|
--> $DIR/lifetimes.rs:109:1
|
||||||
|
|
|
|
||||||
116 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
|
109 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: explicit lifetimes given in parameter types where they could be elided
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
--> $DIR/lifetimes.rs:120:1
|
--> $DIR/lifetimes.rs:120:1
|
||||||
|
|
|
|
||||||
120 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
|
120 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: explicit lifetimes given in parameter types where they could be elided
|
||||||
|
--> $DIR/lifetimes.rs:124:1
|
||||||
|
|
|
||||||
|
124 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 14 previous errors
|
error: aborting due to 14 previous errors
|
||||||
|
Loading…
Reference in New Issue
Block a user