Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_const_eval/src/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ pub fn rustc_allow_const_fn_unstable(
/// unstable features, not even recursively), and those that are not.
pub fn is_fn_or_trait_safe_to_expose_on_stable(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
// A default body in a `const trait` is const-stable when the trait is const-stable.
if tcx.is_const_default_method(def_id) {
return is_fn_or_trait_safe_to_expose_on_stable(tcx, tcx.parent(def_id));
if let Some(trait_id) = tcx.trait_of_assoc(def_id)
&& tcx.is_const_trait(trait_id)
{
return is_fn_or_trait_safe_to_expose_on_stable(tcx, trait_id);
}

match tcx.lookup_const_stability(def_id) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,7 @@ fn should_encode_mir(
&& (generics.requires_monomorphization(tcx)
|| tcx.cross_crate_inlinable(def_id)));
// The function has a `const` modifier or is in a `const trait`.
let is_const_fn = tcx.is_const_fn(def_id.to_def_id())
|| tcx.is_const_default_method(def_id.to_def_id());
let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
(is_const_fn, opt)
}
// The others don't have MIR.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ impl<'tcx> TyCtxt<'tcx> {
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
ConstContext::ConstFn
}
BodyOwnerKind::Fn if self.is_const_default_method(def_id) => ConstContext::ConstFn,
BodyOwnerKind::Fn | BodyOwnerKind::Closure | BodyOwnerKind::GlobalAsm => return None,
};

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,11 +2224,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.trait_def(def_id).constness == hir::Constness::Const
}

#[inline]
pub fn is_const_default_method(self, def_id: DefId) -> bool {
matches!(self.trait_of_assoc(def_id), Some(trait_id) if self.is_const_trait(trait_id))
}

pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
if self.def_kind(def_id) != DefKind::AssocFn {
return false;
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ fn mir_promoted(

let const_qualifs = match tcx.def_kind(def) {
DefKind::Fn | DefKind::AssocFn | DefKind::Closure
if tcx.constness(def) == hir::Constness::Const
|| tcx.is_const_default_method(def.to_def_id()) =>
if tcx.constness(def) == hir::Constness::Const =>
{
tcx.mir_const_qualif(def)
}
Expand Down
Loading