Skip to content

Commit a6f9826

Browse files
committed
Add Self: ~const Trait to traits with #[const_trait]
1 parent 2614e43 commit a6f9826

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ define_print_and_forward_display! {
25562556

25572557
ty::TraitPredicate<'tcx> {
25582558
p!(print(self.trait_ref.self_ty()), ": ");
2559-
if let ty::BoundConstness::ConstIfConst = self.constness {
2559+
if let ty::BoundConstness::ConstIfConst = self.constness && cx.tcx().features().const_trait_impl {
25602560
p!("~const ");
25612561
}
25622562
p!(print(self.trait_ref.print_only_trait_path()))

compiler/rustc_typeck/src/collect.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2090,10 +2090,17 @@ fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
20902090
// from the trait itself that *shouldn't* be shown as the source of
20912091
// an obligation and instead be skipped. Otherwise we'd use
20922092
// `tcx.def_span(def_id);`
2093+
2094+
let constness = if tcx.has_attr(def_id, sym::const_trait) {
2095+
ty::BoundConstness::ConstIfConst
2096+
} else {
2097+
ty::BoundConstness::NotConst
2098+
};
2099+
20932100
let span = rustc_span::DUMMY_SP;
20942101
result.predicates =
20952102
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
2096-
ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(tcx),
2103+
ty::TraitRef::identity(tcx, def_id).with_constness(constness).to_predicate(tcx),
20972104
span,
20982105
))));
20992106
}

library/core/src/cmp.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1503,9 +1503,10 @@ mod impls {
15031503
// & pointers
15041504

15051505
#[stable(feature = "rust1", since = "1.0.0")]
1506-
impl<A: ?Sized, B: ?Sized> PartialEq<&B> for &A
1506+
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
1507+
impl<A: ?Sized, B: ?Sized> const PartialEq<&B> for &A
15071508
where
1508-
A: PartialEq<B>,
1509+
A: ~const PartialEq<B>,
15091510
{
15101511
#[inline]
15111512
fn eq(&self, other: &&B) -> bool {

0 commit comments

Comments
 (0)