-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,11 +300,27 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { | |
// const stability: inherit feature gate from regular stability. | ||
let mut const_stab = const_stab.map(|(stab, _span)| stab); | ||
|
||
// `impl const Trait for Type` items forward their const stability to their | ||
// immediate children. | ||
// FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`? | ||
// Currently, once that is set, we do not inherit anything from the parent any more. | ||
if const_stab.is_none() | ||
&& let Some(parent) = self.parent_const_stab | ||
&& parent.is_const_unstable() | ||
{ | ||
// For now, `const fn` in const traits/trait impls does not exist. | ||
assert!( | ||
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); | ||
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. Shouldn't this be Right now, it seems like we could then enter the |
||
} | ||
|
||
// If this is a const fn but not annotated with stability markers, see if we can inherit regular stability. | ||
if fn_sig.is_some_and(|s| s.header.is_const()) && const_stab.is_none() && | ||
if fn_sig.is_some_and(|s| s.header.is_const()) | ||
&& const_stab.is_none() | ||
// We only ever inherit unstable features. | ||
let Some(inherit_regular_stab) = | ||
final_stab.filter(|s| s.is_unstable()) | ||
&& let Some(inherit_regular_stab) = final_stab.filter(|s| s.is_unstable()) | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
const_stab = Some(ConstStability { | ||
// We subject these implicitly-const functions to recursive const stability. | ||
|
@@ -329,19 +345,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { | |
self.index.implications.insert(implied_by, feature); | ||
} | ||
|
||
// `impl const Trait for Type` items forward their const stability to their | ||
// immediate children. | ||
// FIXME(const_trait_impl): how is this supposed to interact with `#[rustc_const_stable_indirect]`? | ||
// Currently, once that is set, we do not inherit anything from the parent any more. | ||
if const_stab.is_none() { | ||
debug!("annotate: const_stab not found, parent = {:?}", self.parent_const_stab); | ||
if let Some(parent) = self.parent_const_stab { | ||
if parent.is_const_unstable() { | ||
self.index.const_stab_map.insert(def_id, parent); | ||
} | ||
} | ||
} | ||
|
||
self.recurse_with_stability_attrs( | ||
depr.map(|(d, _)| DeprecationEntry::local(d, def_id)), | ||
stab, | ||
|
@@ -418,6 +421,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { | |
kind = AnnotationKind::DeprecationProhibited; | ||
const_stab_inherit = InheritConstStability::Yes; | ||
} | ||
hir::ItemKind::Trait(..) => { | ||
const_stab_inherit = InheritConstStability::Yes; | ||
} | ||
hir::ItemKind::Struct(ref sd, _) => { | ||
if let Some(ctor_def_id) = sd.ctor_def_id() { | ||
self.annotate( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.