Skip to content

Commit bb6d11d

Browse files
author
Ype Kingma
committed
Update from dev branch with recently merged master:
- follow master on changed capturing args from TyKind::ImplTrait() to GenericBound::Use(), capturing args are unused here. - some renames, a.o. to follow api guidelines. - added/improved code docs, a.o. mention trait implementation declaration. - remove some unused code, - derive PartialEq and friends, - use Spans.to().
1 parent b012421 commit bb6d11d

9 files changed

+873
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5357,6 +5357,7 @@ Released 2018-09-13
53575357
[`explicit_deref_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_deref_methods
53585358
[`explicit_into_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop
53595359
[`explicit_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop
5360+
[`explicit_lifetimes_bound_nested_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_lifetimes_bound_nested_ref
53605361
[`explicit_write`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_write
53615362
[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice
53625363
[`extend_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_with_drain
@@ -5418,6 +5419,7 @@ Released 2018-09-13
54185419
[`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params
54195420
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
54205421
[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
5422+
[`implicit_lifetimes_bound_nested_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_lifetimes_bound_nested_ref
54215423
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
54225424
[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add
54235425
[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub

clippy_lints/src/declared_lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
267267
crate::let_with_type_underscore::LET_WITH_TYPE_UNDERSCORE_INFO,
268268
crate::lifetimes::EXTRA_UNUSED_LIFETIMES_INFO,
269269
crate::lifetimes::NEEDLESS_LIFETIMES_INFO,
270+
crate::lifetimes_bound_nested_ref::IMPLICIT_LIFETIMES_BOUND_INFO,
271+
crate::lifetimes_bound_nested_ref::EXPLICIT_LIFETIMES_BOUND_INFO,
270272
crate::lines_filter_map_ok::LINES_FILTER_MAP_OK_INFO,
271273
crate::literal_representation::DECIMAL_LITERAL_REPRESENTATION_INFO,
272274
crate::literal_representation::INCONSISTENT_DIGIT_GROUPING_INFO,

clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ mod let_if_seq;
196196
mod let_underscore;
197197
mod let_with_type_underscore;
198198
mod lifetimes;
199+
mod lifetimes_bound_nested_ref;
199200
mod lines_filter_map_ok;
200201
mod literal_representation;
201202
mod loops;
@@ -1164,6 +1165,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
11641165
store.register_late_pass(move |_| Box::new(assigning_clones::AssigningClones::new(msrv())));
11651166
store.register_late_pass(|_| Box::new(zero_repeat_side_effects::ZeroRepeatSideEffects));
11661167
store.register_late_pass(|_| Box::new(manual_unwrap_or_default::ManualUnwrapOrDefault));
1168+
store.register_early_pass(|| Box::new(lifetimes_bound_nested_ref::LifetimesBoundNestedRef));
11671169
store.register_late_pass(|_| Box::new(integer_division_remainder_used::IntegerDivisionRemainderUsed));
11681170
store.register_late_pass(move |_| {
11691171
Box::new(macro_metavars_in_unsafe::ExprMetavarsInUnsafe {

clippy_lints/src/lifetimes_bound_nested_ref.rs

+530
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![warn(clippy::explicit_lifetimes_bound)]
2+
use core::mem::MaybeUninit;
3+
4+
// issue 25860, missing implicit bound
5+
pub fn lifetime_translator_1<'lfta, 'lftb: 'lfta, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
6+
val_a
7+
}
8+
9+
// helper declarations for issue 84591
10+
trait Supertrait<'a, 'b> {
11+
fn convert<T: ?Sized>(x: &'a T) -> &'b T;
12+
}
13+
14+
struct MyStruct;
15+
16+
impl<'a: 'b, 'b> Supertrait<'a, 'b> for MyStruct {
17+
fn convert<T: ?Sized>(x: &'a T) -> &'b T {
18+
x
19+
}
20+
}
21+
22+
trait Subtrait<'a, 'b, R>: Supertrait<'a, 'b> {}
23+
24+
// issue 84591, missing implicit bound:
25+
impl<'a: 'b, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
26+
27+
// helper declarations for issue 100051
28+
trait Trait1 {
29+
type Type1;
30+
}
31+
32+
impl<T1> Trait1 for T1 {
33+
type Type1 = ();
34+
}
35+
36+
trait Extend1<'a, 'b> {
37+
fn extend(self, s: &'a str) -> &'b str;
38+
}
39+
40+
// issue 100051, missing implicit bound
41+
impl<'a: 'b, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
42+
fn extend(self, s: &'a str) -> &'b str {
43+
s
44+
}
45+
}
46+
47+
// from the httparse crate, lib.rs: bounds implied by argument and return types are the same
48+
// missing implicit bound:
49+
unsafe fn deinit_slice_mut<'a, 'b: 'a, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
50+
let s: *mut &mut [T] = s;
51+
let s = s as *mut &mut [MaybeUninit<T>];
52+
&mut *s
53+
}
54+
55+
// test case for unnamed references.
56+
// helper declarations:
57+
struct Thing1<'a> {
58+
ref_u8: &'a u8,
59+
}
60+
struct Thing2<'a> {
61+
ref_u16: &'a u16,
62+
}
63+
// missing implicit bound
64+
fn test_unnamed_ref<'a: 'b, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
65+
let _ = w2;
66+
w1.ref_u8
67+
}
68+
69+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![warn(clippy::explicit_lifetimes_bound)]
2+
use core::mem::MaybeUninit;
3+
4+
// issue 25860, missing implicit bound
5+
pub fn lifetime_translator_1<'lfta, 'lftb, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
6+
val_a
7+
}
8+
9+
// helper declarations for issue 84591
10+
trait Supertrait<'a, 'b> {
11+
fn convert<T: ?Sized>(x: &'a T) -> &'b T;
12+
}
13+
14+
struct MyStruct;
15+
16+
impl<'a: 'b, 'b> Supertrait<'a, 'b> for MyStruct {
17+
fn convert<T: ?Sized>(x: &'a T) -> &'b T {
18+
x
19+
}
20+
}
21+
22+
trait Subtrait<'a, 'b, R>: Supertrait<'a, 'b> {}
23+
24+
// issue 84591, missing implicit bound:
25+
impl<'a, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
26+
27+
// helper declarations for issue 100051
28+
trait Trait1 {
29+
type Type1;
30+
}
31+
32+
impl<T1> Trait1 for T1 {
33+
type Type1 = ();
34+
}
35+
36+
trait Extend1<'a, 'b> {
37+
fn extend(self, s: &'a str) -> &'b str;
38+
}
39+
40+
// issue 100051, missing implicit bound
41+
impl<'a, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
42+
fn extend(self, s: &'a str) -> &'b str {
43+
s
44+
}
45+
}
46+
47+
// from the httparse crate, lib.rs: bounds implied by argument and return types are the same
48+
// missing implicit bound:
49+
unsafe fn deinit_slice_mut<'a, 'b, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
50+
let s: *mut &mut [T] = s;
51+
let s = s as *mut &mut [MaybeUninit<T>];
52+
&mut *s
53+
}
54+
55+
// test case for unnamed references.
56+
// helper declarations:
57+
struct Thing1<'a> {
58+
ref_u8: &'a u8,
59+
}
60+
struct Thing2<'a> {
61+
ref_u16: &'a u16,
62+
}
63+
// missing implicit bound
64+
fn test_unnamed_ref<'a, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
65+
let _ = w2;
66+
w1.ref_u8
67+
}
68+
69+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
error: missing lifetimes bound declaration: 'lftb: 'lfta
2+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:5:37
3+
|
4+
LL | pub fn lifetime_translator_1<'lfta, 'lftb, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
5+
| ^^^^^ help: try: `'lftb: 'lfta`
6+
|
7+
note: this lifetimes bound is implied here:
8+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:5:55
9+
|
10+
LL | pub fn lifetime_translator_1<'lfta, 'lftb, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
11+
| ^^^^^^^^^^^^
12+
= note: `-D clippy::explicit-lifetimes-bound` implied by `-D warnings`
13+
= help: to override `-D warnings` add `#[allow(clippy::explicit_lifetimes_bound)]`
14+
15+
error: missing lifetimes bound declaration: 'a: 'b
16+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:25:6
17+
|
18+
LL | impl<'a, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
19+
| ^^ help: try: `'a: 'b`
20+
|
21+
note: this lifetimes bound is implied here:
22+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:25:32
23+
|
24+
LL | impl<'a, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
25+
| ^^^^^^
26+
27+
error: missing lifetimes bound declaration: 'a: 'b
28+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:41:6
29+
|
30+
LL | impl<'a, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
31+
| ^^ help: try: `'a: 'b`
32+
|
33+
note: this lifetimes bound is implied here:
34+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:41:36
35+
|
36+
LL | impl<'a, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
37+
| ^^^^^^
38+
39+
error: missing lifetimes bound declaration: 'b: 'a
40+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:49:32
41+
|
42+
LL | unsafe fn deinit_slice_mut<'a, 'b, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
43+
| ^^ help: try: `'b: 'a`
44+
|
45+
note: this lifetimes bound is implied here:
46+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:49:43
47+
|
48+
LL | unsafe fn deinit_slice_mut<'a, 'b, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
49+
| ^^^^^^^^^^
50+
51+
error: missing lifetimes bound declaration: 'a: 'b
52+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:64:21
53+
|
54+
LL | fn test_unnamed_ref<'a, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
55+
| ^^ help: try: `'a: 'b`
56+
|
57+
note: this lifetimes bound is implied here:
58+
--> tests/ui/lifetimes_bound_nested_ref_expl.rs:64:34
59+
|
60+
LL | fn test_unnamed_ref<'a, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
61+
| ^^^^^^^^^^^^^^^^^^^^^
62+
63+
error: aborting due to 5 previous errors
64+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// This was started as a copy from the fixed output of lifetimes_bound_nested_ref_expl.fixed
2+
// Adapted: the lint name and the code comments.
3+
#![warn(clippy::implicit_lifetimes_bound)]
4+
use core::mem::MaybeUninit;
5+
6+
// issue 25860, with declared bound
7+
pub fn lifetime_translator_1<'lfta, 'lftb: 'lfta, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
8+
val_a
9+
}
10+
11+
// helper declarations for issue 84591
12+
trait Supertrait<'a, 'b> {
13+
fn convert<T: ?Sized>(x: &'a T) -> &'b T;
14+
}
15+
16+
struct MyStruct;
17+
18+
impl<'a: 'b, 'b> Supertrait<'a, 'b> for MyStruct {
19+
fn convert<T: ?Sized>(x: &'a T) -> &'b T {
20+
x
21+
}
22+
}
23+
24+
trait Subtrait<'a, 'b, R>: Supertrait<'a, 'b> {}
25+
26+
// issue 84591, with declared bound:
27+
impl<'a: 'b, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
28+
29+
// helper declarations for issue 100051
30+
trait Trait1 {
31+
type Type1;
32+
}
33+
34+
impl<T1> Trait1 for T1 {
35+
type Type1 = ();
36+
}
37+
38+
trait Extend1<'a, 'b> {
39+
fn extend(self, s: &'a str) -> &'b str;
40+
}
41+
42+
// issue 100051, with declared bound
43+
impl<'a: 'b, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
44+
fn extend(self, s: &'a str) -> &'b str {
45+
s
46+
}
47+
}
48+
49+
// from the httparse crate, lib.rs: bounds implied by argument and return types are the same
50+
// with declared bound:
51+
unsafe fn deinit_slice_mut<'a, 'b: 'a, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
52+
let s: *mut &mut [T] = s;
53+
let s = s as *mut &mut [MaybeUninit<T>];
54+
&mut *s
55+
}
56+
57+
// test case for unnamed references.
58+
// helper declarations:
59+
struct Thing1<'a> {
60+
ref_u8: &'a u8,
61+
}
62+
struct Thing2<'a> {
63+
ref_u16: &'a u16,
64+
}
65+
// with declared bound
66+
fn test_unnamed_ref<'a: 'b, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
67+
let _ = w2;
68+
w1.ref_u8
69+
}
70+
71+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
error: declared lifetimes bound: 'lftb: 'lfta is redundant, but do not remove it
2+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:7:42
3+
|
4+
LL | pub fn lifetime_translator_1<'lfta, 'lftb: 'lfta, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
5+
| ^^^^^^^
6+
|
7+
note: this lifetimes bound is implied here:
8+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:7:62
9+
|
10+
LL | pub fn lifetime_translator_1<'lfta, 'lftb: 'lfta, T>(val_a: &'lfta &'lftb T, _val_b: &'lftb T) -> &'lfta T {
11+
| ^^^^^^^^^^^^
12+
= note: `-D clippy::implicit-lifetimes-bound` implied by `-D warnings`
13+
= help: to override `-D warnings` add `#[allow(clippy::implicit_lifetimes_bound)]`
14+
15+
error: declared lifetimes bound: 'a: 'b is redundant, but do not remove it
16+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:27:8
17+
|
18+
LL | impl<'a: 'b, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
19+
| ^^^^
20+
|
21+
note: this lifetimes bound is implied here:
22+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:27:36
23+
|
24+
LL | impl<'a: 'b, 'b> Subtrait<'a, 'b, &'b &'a ()> for MyStruct {}
25+
| ^^^^^^
26+
27+
error: declared lifetimes bound: 'a: 'b is redundant, but do not remove it
28+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:43:8
29+
|
30+
LL | impl<'a: 'b, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
31+
| ^^^^
32+
|
33+
note: this lifetimes bound is implied here:
34+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:43:40
35+
|
36+
LL | impl<'a: 'b, 'b> Extend1<'a, 'b> for <&'b &'a () as Trait1>::Type1 {
37+
| ^^^^^^
38+
39+
error: declared lifetimes bound: 'b: 'a is redundant, but do not remove it
40+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:51:34
41+
|
42+
LL | unsafe fn deinit_slice_mut<'a, 'b: 'a, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
43+
| ^^^^
44+
|
45+
note: this lifetimes bound is implied here:
46+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:51:47
47+
|
48+
LL | unsafe fn deinit_slice_mut<'a, 'b: 'a, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
49+
| ^^^^^^^^^^
50+
51+
error: declared lifetimes bound: 'a: 'b is redundant, but do not remove it
52+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:66:23
53+
|
54+
LL | fn test_unnamed_ref<'a: 'b, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
55+
| ^^^^
56+
|
57+
note: this lifetimes bound is implied here:
58+
--> tests/ui/lifetimes_bound_nested_ref_impl.rs:66:38
59+
|
60+
LL | fn test_unnamed_ref<'a: 'b, 'b>(w1: &'b mut &mut Thing1<'a>, w2: &mut Thing2<'b>) -> &'a u8 {
61+
| ^^^^^^^^^^^^^^^^^^^^^
62+
63+
error: aborting due to 5 previous errors
64+

0 commit comments

Comments
 (0)