Skip to content

Commit 22f8bde

Browse files
committed
Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again Closes #91489. Closes #89432. Reverts #91491. Reverts #89450. r? `@spastorino`
2 parents 6bda5b3 + ffc9082 commit 22f8bde

File tree

69 files changed

+622
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+622
-458
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_middle::ty::fold::TypeFoldable;
3131
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
3232
use rustc_middle::ty::{
3333
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueTypeKey, RegionVid,
34-
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
34+
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3535
};
3636
use rustc_span::def_id::CRATE_DEF_ID;
3737
use rustc_span::{Span, DUMMY_SP};

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::interpret::{
77
};
88

99
use rustc_errors::ErrorReported;
10+
use rustc_hir as hir;
1011
use rustc_hir::def::DefKind;
1112
use rustc_middle::mir;
1213
use rustc_middle::mir::interpret::ErrorHandled;
@@ -215,6 +216,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
215216
tcx: TyCtxt<'tcx>,
216217
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
217218
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
219+
assert!(key.param_env.constness() == hir::Constness::Const);
218220
// see comment in eval_to_allocation_raw_provider for what we're doing here
219221
if key.param_env.reveal() == Reveal::All {
220222
let mut key = key;
@@ -249,6 +251,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
249251
tcx: TyCtxt<'tcx>,
250252
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
251253
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
254+
assert!(key.param_env.constness() == hir::Constness::Const);
252255
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
253256
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
254257
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
929929
} else {
930930
self.param_env
931931
};
932+
let param_env = param_env.with_const();
932933
let val = self.tcx.eval_to_allocation_raw(param_env.and(gid))?;
933934
self.raw_const_to_mplace(val)
934935
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
817817
);
818818

819819
let implsrc = tcx.infer_ctxt().enter(|infcx| {
820-
let mut selcx =
821-
SelectionContext::with_constness(&infcx, hir::Constness::Const);
820+
let mut selcx = SelectionContext::new(&infcx);
822821
selcx.select(&obligation)
823822
});
824823

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! See the `Qualif` trait for more info.
44
55
use rustc_errors::ErrorReported;
6-
use rustc_hir as hir;
76
use rustc_infer::infer::TyCtxtInferExt;
87
use rustc_middle::mir::*;
98
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
@@ -167,7 +166,7 @@ impl Qualif for NeedsNonConstDrop {
167166
);
168167

169168
let implsrc = cx.tcx.infer_ctxt().enter(|infcx| {
170-
let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const);
169+
let mut selcx = SelectionContext::new(&infcx);
171170
selcx.select(&obligation)
172171
});
173172
!matches!(

compiler/rustc_data_structures/src/tagged_ptr/copy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ where
9494
// SAFETY: pointer_raw returns the original pointer
9595
unsafe { std::mem::transmute_copy(&self.pointer_raw()) }
9696
}
97+
#[inline]
9798
pub fn tag(&self) -> T {
9899
unsafe { T::from_usize(self.packed.get() >> Self::TAG_BIT_SHIFT) }
99100
}
101+
#[inline]
100102
pub fn set_tag(&mut self, tag: T) {
101103
let mut packed = self.packed.get();
102104
let new_tag = T::into_usize(tag) << Self::TAG_BIT_SHIFT;

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,31 +3208,6 @@ impl<'hir> Node<'hir> {
32083208
}
32093209
}
32103210

3211-
/// Returns `Constness::Const` when this node is a const fn/impl/item.
3212-
pub fn constness_for_typeck(&self) -> Constness {
3213-
match self {
3214-
Node::Item(Item {
3215-
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3216-
..
3217-
})
3218-
| Node::TraitItem(TraitItem {
3219-
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3220-
..
3221-
})
3222-
| Node::ImplItem(ImplItem {
3223-
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3224-
..
3225-
})
3226-
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
3227-
3228-
Node::Item(Item { kind: ItemKind::Const(..), .. })
3229-
| Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
3230-
| Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => Constness::Const,
3231-
3232-
_ => Constness::NotConst,
3233-
}
3234-
}
3235-
32363211
pub fn as_owner(self) -> Option<OwnerNode<'hir>> {
32373212
match self {
32383213
Node::Item(i) => Some(OwnerNode::Item(i)),

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::infer::InferCtxt;
22
use crate::traits::Obligation;
33
use rustc_data_structures::fx::FxHashMap;
4-
use rustc_hir as hir;
54
use rustc_hir::def_id::DefId;
6-
use rustc_middle::ty::{self, ToPredicate, Ty, WithConstness};
5+
use rustc_middle::ty::{self, ToPredicate, Ty};
76

87
use super::FulfillmentError;
98
use super::{ObligationCause, PredicateObligation};
@@ -48,26 +47,9 @@ pub trait TraitEngine<'tcx>: 'tcx {
4847

4948
fn select_all_or_error(&mut self, infcx: &InferCtxt<'_, 'tcx>) -> Vec<FulfillmentError<'tcx>>;
5049

51-
fn select_all_with_constness_or_error(
52-
&mut self,
53-
infcx: &InferCtxt<'_, 'tcx>,
54-
_constness: hir::Constness,
55-
) -> Vec<FulfillmentError<'tcx>> {
56-
self.select_all_or_error(infcx)
57-
}
58-
5950
fn select_where_possible(&mut self, infcx: &InferCtxt<'_, 'tcx>)
6051
-> Vec<FulfillmentError<'tcx>>;
6152

62-
// FIXME(fee1-dead) this should not provide a default body for chalk as chalk should be updated
63-
fn select_with_constness_where_possible(
64-
&mut self,
65-
infcx: &InferCtxt<'_, 'tcx>,
66-
_constness: hir::Constness,
67-
) -> Vec<FulfillmentError<'tcx>> {
68-
self.select_where_possible(infcx)
69-
}
70-
7153
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
7254

7355
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ impl PredicateObligation<'tcx> {
6969
}
7070
}
7171

72+
impl TraitObligation<'tcx> {
73+
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
74+
pub fn is_const(&self) -> bool {
75+
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
76+
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true,
77+
_ => false,
78+
}
79+
}
80+
}
81+
7282
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
7383
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
7484
static_assert_size!(PredicateObligation<'_>, 32);

compiler/rustc_infer/src/traits/util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use smallvec::smallvec;
33
use crate::infer::outlives::components::{push_outlives_components, Component};
44
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
55
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
6-
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
6+
use rustc_middle::ty::{self, ToPredicate, TyCtxt};
77
use rustc_span::symbol::Ident;
88
use rustc_span::Span;
99

@@ -328,8 +328,8 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
328328
));
329329
for (super_predicate, _) in super_predicates.predicates {
330330
let subst_predicate = super_predicate.subst_supertrait(tcx, &trait_ref);
331-
if let Some(binder) = subst_predicate.to_opt_poly_trait_ref() {
332-
stack.push(binder.value);
331+
if let Some(binder) = subst_predicate.to_opt_poly_trait_pred() {
332+
stack.push(binder.map_bound(|t| t.trait_ref));
333333
}
334334
}
335335

@@ -362,8 +362,8 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
362362

363363
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
364364
while let Some(obligation) = self.base_iterator.next() {
365-
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
366-
return Some(data.value);
365+
if let Some(data) = obligation.predicate.to_opt_poly_trait_pred() {
366+
return Some(data.map_bound(|t| t.trait_ref));
367367
}
368368
}
369369
None

0 commit comments

Comments
 (0)