Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy: Remove TyCtyt::super_traits_of public comment and test behavior #11097

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,15 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc
.iter()
.try_fold(false, |found, p| {
if let ty::ClauseKind::Trait(p) = p.kind().skip_binder()
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
&& ty.index == self_ty.index
{
// This should use `super_traits_of`, but that's a private function.
if p.trait_ref.def_id == fn_once_id {
return Some(true);
} else if p.trait_ref.def_id == fn_mut_id || p.trait_ref.def_id == fn_id {
return None;
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
&& ty.index == self_ty.index
{
if p.trait_ref.def_id == fn_once_id {
return Some(true);
} else if p.trait_ref.def_id == fn_mut_id || p.trait_ref.def_id == fn_id {
return None;
}
}
}
Some(found)
})
.unwrap_or(false)
Expand Down
15 changes: 14 additions & 1 deletion tests/ui/while_let_on_iterator.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,20 @@ fn fn_once_closure() {
break;
}
}
})
});

// Lint if `FnOnce` is a super trait
trait MySpecialFnMut: FnOnce() {}
impl<T: FnOnce()> MySpecialFnMut for T {}
fn f4(_: impl MySpecialFnMut) {}
let mut it = 0..10;
f4(|| {
for x in it {
if x % 2 == 0 {
break;
}
}
});
}

fn main() {
Expand Down
15 changes: 14 additions & 1 deletion tests/ui/while_let_on_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,20 @@ fn fn_once_closure() {
break;
}
}
})
});

// Lint if `FnOnce` is a super trait
trait MySpecialFnMut: FnOnce() {}
impl<T: FnOnce()> MySpecialFnMut for T {}
fn f4(_: impl MySpecialFnMut) {}
let mut it = 0..10;
f4(|| {
while let Some(x) = it.next() {
if x % 2 == 0 {
break;
}
}
});
}

fn main() {
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/while_let_on_iterator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it`

error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:450:5
--> $DIR/while_let_on_iterator.rs:453:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it`

error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:463:5
|
LL | while let Some(..) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it`

error: aborting due to 26 previous errors
error: aborting due to 27 previous errors