-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Allow specifying multiple bounds for same associated item, except in trait objects #146593
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
HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
Nobody knows what E0719 is when they're just scrolling by and reading the title, it's as if you put a GH issue number there; please make the title more descriptive. |
r? BoxyUwU |
Over in #143146, we had proposed FCP and then filed a concern related to @rfcbot fcp merge cc @rust-lang/types |
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@rfcbot ping |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
☔ The latest upstream changes (presumably #146698) made this pull request unmergeable. Please resolve the merge conflicts. |
type MustFail = dyn Iterator<Item = i32, Item = u32>; | ||
//~^ ERROR [E0719] | ||
//~| ERROR conflicting associated type bounds |
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.
Having two errors here seems unfortunate :( pre-existing though so no need to fix in this PR but it would be nice if it would be at some point
|
||
fn callable(_: impl Iterator<Item = i32, Item = i32>) {} | ||
|
||
fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {} |
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.
It feels weird to me that we would accept such code without linting on it, defining functions/ADTs/whatever that can never have their where clauses satisfied doesn't seem like the kind of thing people would want to intentionally do.
I would like us to add some unsatisfiable_bounds
lint to detect this kind of case and warn people on it 🤔
@rust-lang/lang what are your thoughts on the fact that this PR causes us to accept this code without any lints: trait Trait {
type Assoc;
}
pub fn foo<T: Trait<Assoc = u32, Assoc = u64>>() {} Here the function Even though it was previously possibly to write I think in theory this would have a types FCP, but given 3 of us already looked at the previous PR and don't anticipate any type system interactions here it seems perfectly fine to me to skip the FCP 👍 (especially since there's a t-types reviewer for this PR :3) |
For my part, it doesn't change what I want to do here, but I'd be separately open to seeing a proposal for a lint that would flag both |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@bors r+ I think this is fine lang wise and we don't need to get Official:tm: sign off on this happening before some kind of lint. My understanding from the previous PR is that this also doesn't need any reference docs as we never documented this restriction in the first place :') |
@rfcbot reviewed I agree that if we can write it in the other form anyway we might as well just accept this. I also agree with @BoxyUwU that this seems like a place where it might be interesting to lint, but I don't think the PR needs to be blocked on that. (Indeed, I'd generally rather it not be the same PR for separation of concern reasons.) |
@rfcbot reviewed |
…BoxyUwU Allow specifying multiple bounds for same associated item, except in trait objects Supersedes rust-lang#143146, fixes rust-lang#143143. This PR proposes to stop enforcing E0719 in all contexts other than trait object types. E0719 forbids constraining the same associated item twice within the same angle-bracket delimited associated item bound list (the `…` inside `T: Trait<…>`). For example, the following are forbidden: | Forbidden | Working alternative | |--------------------------------------------|--------------------------------------------------------------------| | `T: Trait<Gat<u32> = u32, Gat<u64> = u64>` | `T: Trait<Gat<u32> = u32> + Trait<Gat<u64> = u64>` | | `T: Iterator<Item = u32, Item = i32>` | `T: Iterator<Item = u32> + Iterator<Item = i32>` (trivially false) | | `T: Iterator<Item = u32, Item = u32>` | `T: Iterator<Item = u32>` | | `T: Iterator<Item: Send, Item: Sync>` | `T: Iterator<Item: Send + Sync>` | | `T: Trait<ASSOC = 3, ASSOC = 4>` | `T: Trait<ASSOC = 3> + Trait<ASSOC = 4>` (trivially false) | | `T: Trait<ASSOC = 3, ASSOC = 3>` | `T: Trait<ASSOC = 3>` | With this PR, all those previously forbidden examples would start working, as well as their APIT and RPIT equivalents. Types like `dyn Iterator<Item = u32, Item = u32>` will continue to be rejected, however. See rust-lang#143146 (comment) for the reason why. `@rustbot` label T-lang T-types needs-fcp
…BoxyUwU Allow specifying multiple bounds for same associated item, except in trait objects Supersedes rust-lang#143146, fixes rust-lang#143143. This PR proposes to stop enforcing E0719 in all contexts other than trait object types. E0719 forbids constraining the same associated item twice within the same angle-bracket delimited associated item bound list (the `…` inside `T: Trait<…>`). For example, the following are forbidden: | Forbidden | Working alternative | |--------------------------------------------|--------------------------------------------------------------------| | `T: Trait<Gat<u32> = u32, Gat<u64> = u64>` | `T: Trait<Gat<u32> = u32> + Trait<Gat<u64> = u64>` | | `T: Iterator<Item = u32, Item = i32>` | `T: Iterator<Item = u32> + Iterator<Item = i32>` (trivially false) | | `T: Iterator<Item = u32, Item = u32>` | `T: Iterator<Item = u32>` | | `T: Iterator<Item: Send, Item: Sync>` | `T: Iterator<Item: Send + Sync>` | | `T: Trait<ASSOC = 3, ASSOC = 4>` | `T: Trait<ASSOC = 3> + Trait<ASSOC = 4>` (trivially false) | | `T: Trait<ASSOC = 3, ASSOC = 3>` | `T: Trait<ASSOC = 3>` | With this PR, all those previously forbidden examples would start working, as well as their APIT and RPIT equivalents. Types like `dyn Iterator<Item = u32, Item = u32>` will continue to be rejected, however. See rust-lang#143146 (comment) for the reason why. ``@rustbot`` label T-lang T-types needs-fcp
Rollup of 8 pull requests Successful merges: - #146593 (Allow specifying multiple bounds for same associated item, except in trait objects) - #147177 ([DebugInfo] Fix MSVC tuple child creation) - #147195 (iter repeat: add tests for new count and last behavior) - #147202 (Swap order of `resolve_coroutine_interiors` and `handle_opaque_type_uses`) - #147204 (Refactor ArrayWindows to use a slice) - #147219 (Add proper error handling for closure in impl) - #147226 (include `outer_inclusive_binder` of pattern types) - #147230 (Fix typo in 'unfulfilled_lint_expectation' to plural) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146593 - Jules-Bertholet:restrict-e0719, r=BoxyUwU Allow specifying multiple bounds for same associated item, except in trait objects Supersedes #143146, fixes #143143. This PR proposes to stop enforcing E0719 in all contexts other than trait object types. E0719 forbids constraining the same associated item twice within the same angle-bracket delimited associated item bound list (the `…` inside `T: Trait<…>`). For example, the following are forbidden: | Forbidden | Working alternative | |--------------------------------------------|--------------------------------------------------------------------| | `T: Trait<Gat<u32> = u32, Gat<u64> = u64>` | `T: Trait<Gat<u32> = u32> + Trait<Gat<u64> = u64>` | | `T: Iterator<Item = u32, Item = i32>` | `T: Iterator<Item = u32> + Iterator<Item = i32>` (trivially false) | | `T: Iterator<Item = u32, Item = u32>` | `T: Iterator<Item = u32>` | | `T: Iterator<Item: Send, Item: Sync>` | `T: Iterator<Item: Send + Sync>` | | `T: Trait<ASSOC = 3, ASSOC = 4>` | `T: Trait<ASSOC = 3> + Trait<ASSOC = 4>` (trivially false) | | `T: Trait<ASSOC = 3, ASSOC = 3>` | `T: Trait<ASSOC = 3>` | With this PR, all those previously forbidden examples would start working, as well as their APIT and RPIT equivalents. Types like `dyn Iterator<Item = u32, Item = u32>` will continue to be rejected, however. See #143146 (comment) for the reason why. ```@rustbot``` label T-lang T-types needs-fcp
Supersedes #143146, fixes #143143.
This PR proposes to stop enforcing E0719 in all contexts other than trait object types.
E0719 forbids constraining the same associated item twice within the same angle-bracket delimited associated item bound list (the
…
insideT: Trait<…>
). For example, the following are forbidden:T: Trait<Gat<u32> = u32, Gat<u64> = u64>
T: Trait<Gat<u32> = u32> + Trait<Gat<u64> = u64>
T: Iterator<Item = u32, Item = i32>
T: Iterator<Item = u32> + Iterator<Item = i32>
(trivially false)T: Iterator<Item = u32, Item = u32>
T: Iterator<Item = u32>
T: Iterator<Item: Send, Item: Sync>
T: Iterator<Item: Send + Sync>
T: Trait<ASSOC = 3, ASSOC = 4>
T: Trait<ASSOC = 3> + Trait<ASSOC = 4>
(trivially false)T: Trait<ASSOC = 3, ASSOC = 3>
T: Trait<ASSOC = 3>
With this PR, all those previously forbidden examples would start working, as well as their APIT and RPIT equivalents.
Types like
dyn Iterator<Item = u32, Item = u32>
will continue to be rejected, however. See #143146 (comment) for the reason why.@rustbot label T-lang T-types needs-fcp