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

Support ?Trait bounds in supertraits and dyn Trait under a feature gate #121676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bryanskiy
Copy link
Contributor

@Bryanskiy Bryanskiy commented Feb 27, 2024

This patch allows maybe polarity bounds under a feature gate. The only language change here is that corresponding hard errors are replaced by feature gates. Example:

#![feature(allow_maybe_polarity)]
...
trait Trait1 : ?Trait { ... } // ok
fn foo(_: Box<(dyn Trait2 + ?Trait)>) {} // ok
fn bar<T: ?Sized + ?Trait>(_: &T) {} // ok

Maybe bounds still don't do anything (except for Sized trait), however this patch will allow us to experiment with default auto traits.

This is a part of the MCP: Low level components for async drop

@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2024

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 27, 2024
@Nilstrieb
Copy link
Member

for reference, is there any language team shepherd for all of this default bound experimentation? I only ever see random work and don't remember seeing design documents or anything like that

@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

@Nilstrieb
I'll make a compiler team MCP for core components for async drop enabling library experimentation soon.
@traviscross is currently the Async WG liaison for this stuff (I actually assumed he was on lang team as well, but apparently not).

@Bryanskiy Bryanskiy changed the title allow_maybe_polarity feature Support ?Trait bounds in supertraits and dyn Trait under a feature gate Feb 27, 2024
@Bryanskiy
Copy link
Contributor Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 29, 2024

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

compiler/rustc_feature/src/unstable.rs Outdated Show resolved Hide resolved
compiler/rustc_feature/src/unstable.rs Outdated Show resolved Hide resolved
compiler/rustc_hir/src/intravisit.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_passes/src/feature_gate.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_passes/src/feature_gate.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_analysis/src/astconv/bounds.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

Need to link to rust-lang/compiler-team#727 from this PR description.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2024
@Bryanskiy Bryanskiy force-pushed the polarity branch 2 times, most recently from d84587a to 540fde9 Compare March 1, 2024 17:06
@petrochenkov
Copy link
Contributor

Implementation LGTM, except the commit message needs to be more human oriented.

I'm going to pass this to r? @traviscross in cases some additional lang team approval is needed, but otherwise r=me.

@rustbot rustbot assigned traviscross and unassigned petrochenkov Mar 1, 2024
@Bryanskiy Bryanskiy force-pushed the polarity branch 2 times, most recently from 3112584 to cf7262c Compare March 5, 2024 15:28
@Bryanskiy
Copy link
Contributor Author

In the last update MisplacedRelaxTraitBound was replaced by feature gate.

@traviscross
Copy link
Contributor

traviscross commented Mar 7, 2024

@rustbot labels +T-lang +I-lang-nominated

We'll need to discuss this in a lang meeting for visibility and to ensure this experiment is properly approved, so let's nominate this.

https://lang-team.rust-lang.org/how_to/experiment.html

@Bryanskiy / @petrochenkov: If you could perhaps write up a summary for the lang team to review as part of this nomination about the nature of this part of the experiment, what the motivation for it is, and how this fits into the larger body of work, that work be helpful.

@rustbot rustbot added I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Mar 7, 2024
@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 7, 2024

Summary:

  • Initial support for auto traits with default bounds #120706 introduces a way to add new auto traits that are appended to all bound lists by default, similarly to existing Sized. Such traits may include Leak, SyncDrop or similar, see Initial support for auto traits with default bounds #120706 (comment) for more detailed motivation.
  • To opt out from bounds added by default the ?Trait syntax is used, but such "maybe" bounds are not supported in some contexts like supertrait lists and dyn Trait + ... lists, because Sized is not added by default in those context.
  • This PR adds a feature for supporting trait Trait1: ?Trait2, dyn Trait1 + ?Trait2 and also multiple maybe bounds in the same list ?Trait1 + ?Trait2, because the new traits need to be added by default in those contexts too, and ?Sized + ?Leak may also make sense.
  • We need this to be available in bootstrap compiler, to make experiments on standard library without adding too many #[cfg(not(bootstrap))]s
  • Larger compiler team MCP including this feature - MCP: Low level components for async drop compiler-team#727, it gives some more context

@bors
Copy link
Contributor

bors commented Mar 11, 2024

☔ The latest upstream changes (presumably #122132) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@Bryanskiy
Copy link
Contributor Author

In the last update #120706 (comment) was fixed.

@bors
Copy link
Contributor

bors commented Mar 18, 2024

☔ The latest upstream changes (presumably #122713) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@Bryanskiy what's the status of this? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants