-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Pass opaque types for the type_alias_bounds
lint
#108663
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
r? @lcnr |
Could not assign reviewer from: |
r? @oli-obk do we convert the whole type alias to an opaque for |
For this lint, there is not enough information at check time to determine if bounds are needed when opaque types appear on the right side. So I think in this case, the warning should not be emitted for now. |
I think we should still lint if the non-opaque types contain generic params of the type alias. So for example: type Foo<T: Debug> = (impl Foo<T>, T); Also: please add a bunch of tests for various cases (other types using generic params, other types not using them, ...) |
@oli-obk Thanks! I pushed some new commits, only bounds whose ty-params or lifetimes-params are used in non-opaque types would be linted now. And I added some tests. :) |
This comment has been minimized.
This comment has been minimized.
Sorry, some tests failed, I will check the code. |
@oli-obk I have tried to only lint bounds whose ty is a generic parameter used in the non-opaque types if there is an opaque type. You can see the new commits. But it still lead to some false positives. For the following code, the bound #![feature(type_alias_impl_trait)]
#![allow(dead_code)]
use std::fmt::Debug;
type Foo<'a, T: 'a> where &'a T: Debug = (impl Debug + 'a, T);
fn foo<'a, U: Debug + 'a>(v: U) -> Foo<'a, U> where &'a U: Debug {
(Vec::<&'a U>::new(), v)
} So, I think the best way is to not lint the type when meeting opaque types. What do you think? |
just want to throw this out there, but could we change only type aliases with opaque types to actually get treated as alias types and completely disable the lint for those? I think our longterm goal is to check wf for trait aliases anyways, so this feels like a step in the right direction 🤔 |
you mean, adding
I think you mean type aliases, but yes 😆 |
Sounds good, maybe this PR should be closed :) |
Thanks for opening the PR! We found a good design due to it, I'll assign the issue to myself |
Fixes #108617