-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
type_complexity: ignore opaque impl Trait bounds
#17463
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -86,4 +86,28 @@ struct D { | |||||
| ), | ||||||
| } | ||||||
|
|
||||||
| // Should not warn, because factoring `impl Trait` into a type alias is not stable (#17195). | ||||||
| fn issue_17195<I, J>( | ||||||
| left: I, | ||||||
| right: J, | ||||||
| ) -> std::iter::Map<std::iter::Zip<I::IntoIter, J::IntoIter>, impl FnMut((I::Item, I::Item)) -> [I::Item; 2]> | ||||||
| where | ||||||
| I: IntoIterator, | ||||||
| J: IntoIterator<Item = I::Item>, | ||||||
| { | ||||||
| left.into_iter().zip(right).map(<[I::Item; 2]>::from) | ||||||
| } | ||||||
|
|
||||||
| // Complexity inside an opaque type cannot be factored into a type alias either. | ||||||
| fn complex_opaque_bound() -> impl Fn(Vec<Vec<Box<(u32, u32, u32, u32)>>>) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Why can't it? Is there maybe a typo in the comment or what do you mean here? |
||||||
| |_| {} | ||||||
| } | ||||||
|
|
||||||
| // The presence of an opaque type must not hide complexity in a sibling type that can be factored | ||||||
| // out. | ||||||
| fn complex_after_opaque() -> (impl Iterator<Item = u32>, Vec<Vec<Box<(u32, u32, u32, u32)>>>) { | ||||||
| //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the rest of the code
Suggested change
|
||||||
| (std::iter::empty(), vec![]) | ||||||
| } | ||||||
|
|
||||||
| fn main() {} | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||
| #![feature(type_alias_impl_trait)] | ||||||
| #![warn(clippy::type_complexity)] | ||||||
|
|
||||||
| fn complex_opaque_bound() -> impl Fn(Vec<Vec<Box<(u32, u32, u32, u32)>>>) { | ||||||
| //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| |_| {} | ||||||
| } | ||||||
|
|
||||||
| fn main() {} | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| error: very complex type used. Consider factoring parts into `type` definitions | ||
| --> tests/ui/type_complexity_type_alias_impl_trait.rs:4:30 | ||
| | | ||
| LL | fn complex_opaque_bound() -> impl Fn(Vec<Vec<Box<(u32, u32, u32, u32)>>>) { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `-D clippy::type-complexity` implied by `-D warnings` | ||
| = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just inline it below?
I think the code would be simpler to read for future readers given the negations of negations going on here.