Skip to content

Trait methods inherit trait const stability, do not inherit const stability from their own regular stability #136319

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

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

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jan 30, 2025

Needed to constify PartialEq:

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "none")]
#[const_trait]
pub trait PartialEq<Rhs: ?Sized = Self> {
    #[stable(feature = "rust1", since = "1.0.0")]
    fn eq(&self, other: &Rhs) -> bool;

    #[stable(feature = "rust1", since = "1.0.0")]
    fn ne(&self, other: &Rhs) -> bool {
        !self.eq(other)
    }
}

Since currently, we get const stability errors in fn ne, since it's currently considered to be const stable via inheriting const stability from its own regular stability, rather than from the parent trait, and thus we can't call Self::eq b/c it requires the const_trait_impl and const_cmp features.

We do two changes:

  1. Do not inherit const stability from regular stability if there's parent stability.
  2. Make sure to set InheritConstStability::Yes for trait items.

cc @rust-lang/project-const-generics
r? RalfJung

This stability computation code is kinda jank, maybe it should get rewritten :S

@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. labels Jan 30, 2025
@RalfJung
Copy link
Member

This stability computation code is kinda jank, maybe it should get rewritten :S

It definitely should get rewritten, this code is a mess and I was hoping I don't have to see it again.^^

@RalfJung
Copy link
Member

RalfJung commented Feb 2, 2025

@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 2, 2025
@rustbot

This comment was marked as resolved.

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Feb 5, 2025
@compiler-errors
Copy link
Member Author

gah rebase error

@compiler-errors compiler-errors removed the has-merge-commits PR has merge commits, merge with caution. label Feb 5, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…bility from their own regular stability
@compiler-errors
Copy link
Member 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 5, 2025
fn_sig.is_none_or(|s| !s.header.is_const()),
"should never have parent const stability for a const fn"
);
self.index.const_stab_map.insert(def_id, parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be const_stab = parent?

Right now, it seems like we could then enter the if below which actually sets const_stab to Some and then that gets inserted into the table.

&& let Some(parent) = self.parent_const_stab
&& parent.is_const_unstable()
{
// For now, `const fn` in const traits/trait impls does not exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For now, `const fn` in const traits/trait impls does not exist.
// For now, `const fn` in const traits/trait impls does not exist.
// If we ever support that, the logic here and also the const-stability enforcement
// logic needs some re-thinking.

@RalfJung
Copy link
Member

@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 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants