Skip to content

Commit bebca64

Browse files
Merge HostPolarity and BoundConstness
1 parent 2dece5b commit bebca64

File tree

16 files changed

+65
-80
lines changed

16 files changed

+65
-80
lines changed

compiler/rustc_hir_analysis/src/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> Bounds<'tcx> {
8484
&mut self,
8585
tcx: TyCtxt<'tcx>,
8686
bound_trait_ref: ty::PolyTraitRef<'tcx>,
87-
host: ty::HostPolarity,
87+
host: ty::BoundConstness,
8888
span: Span,
8989
) {
9090
if tcx.is_const_trait(bound_trait_ref.def_id()) {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn compare_method_predicate_entailment<'tcx>(
218218
tcx.const_conditions(trait_m.def_id).instantiate_own(tcx, trait_to_impl_args),
219219
)
220220
.map(|(trait_ref, _)| {
221-
trait_ref.to_host_effect_clause(tcx, ty::HostPolarity::Maybe)
221+
trait_ref.to_host_effect_clause(tcx, ty::BoundConstness::Maybe)
222222
}),
223223
);
224224
}
@@ -272,7 +272,7 @@ fn compare_method_predicate_entailment<'tcx>(
272272
tcx,
273273
cause,
274274
param_env,
275-
const_condition.to_host_effect_clause(tcx, ty::HostPolarity::Maybe),
275+
const_condition.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
276276
));
277277
}
278278
}
@@ -1942,7 +1942,7 @@ fn compare_type_predicate_entailment<'tcx>(
19421942
tcx.const_conditions(trait_ty.def_id).instantiate_own(tcx, trait_to_impl_args),
19431943
)
19441944
.map(|(trait_ref, _)| {
1945-
trait_ref.to_host_effect_clause(tcx, ty::HostPolarity::Maybe)
1945+
trait_ref.to_host_effect_clause(tcx, ty::BoundConstness::Maybe)
19461946
}),
19471947
);
19481948
}
@@ -1985,7 +1985,7 @@ fn compare_type_predicate_entailment<'tcx>(
19851985
tcx,
19861986
cause,
19871987
param_env,
1988-
const_condition.to_host_effect_clause(tcx, ty::HostPolarity::Maybe),
1988+
const_condition.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
19891989
));
19901990
}
19911991
}
@@ -2091,7 +2091,7 @@ pub(super) fn check_type_bounds<'tcx>(
20912091
tcx,
20922092
mk_cause(span),
20932093
param_env,
2094-
c.to_host_effect_clause(tcx, ty::HostPolarity::Maybe),
2094+
c.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
20952095
)
20962096
}),
20972097
);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ fn check_impl<'tcx>(
13891389
ObligationCauseCode::WellFormed(None),
13901390
),
13911391
wfcx.param_env,
1392-
bound.to_host_effect_clause(tcx, ty::HostPolarity::Maybe),
1392+
bound.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
13931393
))
13941394
}
13951395
}

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
716716
match clause.kind().skip_binder() {
717717
ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
718718
trait_ref: _,
719-
host: ty::HostPolarity::Maybe,
719+
constness: ty::BoundConstness::Maybe,
720720
}) => {}
721721
_ => {
722722
bug!(
@@ -732,8 +732,8 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
732732
match clause.kind().skip_binder() {
733733
ty::ClauseKind::HostEffect(pred) => {
734734
assert_eq!(
735-
pred.host,
736-
ty::HostPolarity::Maybe,
735+
pred.constness,
736+
ty::BoundConstness::Maybe,
737737
"expected `~const` predicate when computing `{filter:?}` \
738738
implied bounds: {clause:?}",
739739
);
@@ -943,7 +943,7 @@ pub(super) fn const_conditions<'tcx>(
943943
bounds.push_const_bound(
944944
tcx,
945945
ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id())),
946-
ty::HostPolarity::Maybe,
946+
ty::BoundConstness::Maybe,
947947
DUMMY_SP,
948948
);
949949

@@ -963,7 +963,7 @@ pub(super) fn const_conditions<'tcx>(
963963
clause.kind().map_bound(|clause| match clause {
964964
ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
965965
trait_ref,
966-
host: ty::HostPolarity::Maybe,
966+
constness: ty::BoundConstness::Maybe,
967967
}) => trait_ref,
968968
_ => bug!("converted {clause:?}"),
969969
}),
@@ -1001,7 +1001,7 @@ pub(super) fn implied_const_bounds<'tcx>(
10011001
clause.kind().map_bound(|clause| match clause {
10021002
ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
10031003
trait_ref,
1004-
host: ty::HostPolarity::Maybe,
1004+
constness: ty::BoundConstness::Maybe,
10051005
}) => trait_ref,
10061006
_ => bug!("converted {clause:?}"),
10071007
}),

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
713713
bounds.push_const_bound(
714714
tcx,
715715
poly_trait_ref,
716-
ty::HostPolarity::Const,
716+
ty::BoundConstness::Const,
717717
span,
718718
);
719719
}
@@ -736,7 +736,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
736736
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => match constness {
737737
hir::BoundConstness::Maybe(span) => {
738738
if polarity == ty::PredicatePolarity::Positive {
739-
bounds.push_const_bound(tcx, poly_trait_ref, ty::HostPolarity::Maybe, span);
739+
bounds.push_const_bound(
740+
tcx,
741+
poly_trait_ref,
742+
ty::BoundConstness::Maybe,
743+
span,
744+
);
740745
}
741746
}
742747
hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}

compiler/rustc_hir_typeck/src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
853853

854854
let host = match self.tcx.hir().body_const_context(self.body_id) {
855855
Some(hir::ConstContext::Const { .. } | hir::ConstContext::Static(_)) => {
856-
ty::HostPolarity::Const
856+
ty::BoundConstness::Const
857857
}
858-
Some(hir::ConstContext::ConstFn) => ty::HostPolarity::Maybe,
858+
Some(hir::ConstContext::ConstFn) => ty::BoundConstness::Maybe,
859859
None => return,
860860
};
861861

compiler/rustc_middle/src/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ use crate::traits::solve::{
7777
};
7878
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
7979
use crate::ty::{
80-
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
81-
GenericArgsRef, GenericParamDefKind, HostPolarity, ImplPolarity, List, ListWithCachedTypeInfo,
80+
self, AdtDef, AdtDefData, AdtKind, Binder, BoundConstness, Clause, Clauses, Const, GenericArg,
81+
GenericArgs, GenericArgsRef, GenericParamDefKind, ImplPolarity, List, ListWithCachedTypeInfo,
8282
ParamConst, ParamTy, Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate,
8383
PredicateKind, PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty,
8484
TyKind, TyVid, Visibility,
@@ -2211,7 +2211,7 @@ macro_rules! nop_slice_lift {
22112211
nop_slice_lift! {ty::ValTree<'a> => ty::ValTree<'tcx>}
22122212

22132213
TrivialLiftImpls! {
2214-
ImplPolarity, PredicatePolarity, Promoted, HostPolarity,
2214+
ImplPolarity, PredicatePolarity, Promoted, BoundConstness,
22152215
}
22162216

22172217
macro_rules! sty_debug_print {

compiler/rustc_middle/src/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl FlagComputation {
267267
}
268268
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
269269
trait_ref,
270-
host: _,
270+
constness: _,
271271
})) => {
272272
self.add_args(trait_ref.args);
273273
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
19591959
ty::BoundConstness::Const => {
19601960
p!("const ");
19611961
}
1962-
ty::BoundConstness::ConstIfConst => {
1962+
ty::BoundConstness::Maybe => {
19631963
p!("~const ");
19641964
}
19651965
}
@@ -3076,9 +3076,9 @@ define_print! {
30763076
}
30773077

30783078
ty::HostEffectPredicate<'tcx> {
3079-
let constness = match self.host {
3080-
ty::HostPolarity::Const => { "const" }
3081-
ty::HostPolarity::Maybe => { "~const" }
3079+
let constness = match self.constness {
3080+
ty::BoundConstness::Const => { "const" }
3081+
ty::BoundConstness::Maybe => { "~const" }
30823082
};
30833083
p!(print(self.trait_ref.self_ty()), ": {constness} ");
30843084
p!(print(self.trait_ref.print_trait_sugared()))

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ where
4444
) -> Result<Candidate<I>, NoSolution> {
4545
if let Some(host_clause) = assumption.as_host_effect_clause() {
4646
if host_clause.def_id() == goal.predicate.def_id()
47-
&& host_clause.host().satisfies(goal.predicate.host)
47+
&& host_clause.host().satisfies(goal.predicate.constness)
4848
{
4949
if !DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
5050
goal.predicate.trait_ref.args,
@@ -91,7 +91,7 @@ where
9191
cx,
9292
cx.implied_const_bounds(alias_ty.def_id)
9393
.iter_instantiated(cx, alias_ty.args)
94-
.map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.host)),
94+
.map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.constness)),
9595
) {
9696
candidates.extend(Self::probe_and_match_goal_against_assumption(
9797
ecx,
@@ -107,7 +107,7 @@ where
107107
.map(|trait_ref| {
108108
goal.with(
109109
cx,
110-
trait_ref.to_host_effect_clause(cx, goal.predicate.host),
110+
trait_ref.to_host_effect_clause(cx, goal.predicate.constness),
111111
)
112112
}),
113113
);
@@ -163,7 +163,10 @@ where
163163
.const_conditions(impl_def_id)
164164
.iter_instantiated(cx, impl_args)
165165
.map(|bound_trait_ref| {
166-
goal.with(cx, bound_trait_ref.to_host_effect_clause(cx, goal.predicate.host))
166+
goal.with(
167+
cx,
168+
bound_trait_ref.to_host_effect_clause(cx, goal.predicate.constness),
169+
)
167170
});
168171
ecx.add_goals(GoalSource::ImplWhereBound, const_conditions);
169172

compiler/rustc_privacy/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ where
139139
}
140140
ty::ClauseKind::HostEffect(pred) => {
141141
try_visit!(self.visit_trait(pred.trait_ref));
142-
pred.host.visit_with(self)
142+
pred.constness.visit_with(self)
143143
}
144144
ty::ClauseKind::Projection(ty::ProjectionPredicate {
145145
projection_term: projection_ty,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
545545
polarity: ty::PredicatePolarity::Positive,
546546
}),
547547
None,
548-
Some(match predicate.host {
549-
ty::HostPolarity::Maybe => ty::BoundConstness::ConstIfConst,
550-
ty::HostPolarity::Const => ty::BoundConstness::Const,
551-
}),
548+
Some(predicate.constness),
552549
None,
553550
String::new(),
554551
);
@@ -2238,18 +2235,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
22382235
(None, _) => Some(cannot_do_this),
22392236
// suggested using default post message
22402237
(
2241-
Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst),
2238+
Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe),
22422239
Some(AppendConstMessage::Default),
22432240
) => Some(format!("{cannot_do_this} in const contexts")),
22442241
// overridden post message
22452242
(
2246-
Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst),
2243+
Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe),
22472244
Some(AppendConstMessage::Custom(custom_msg, _)),
22482245
) => Some(format!("{cannot_do_this}{custom_msg}")),
22492246
// fallback to generic message
2250-
(Some(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst), None) => {
2251-
None
2252-
}
2247+
(Some(ty::BoundConstness::Const | ty::BoundConstness::Maybe), None) => None,
22532248
}
22542249
})
22552250
.unwrap_or_else(|| {

compiler/rustc_trait_selection/src/traits/effects.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn match_candidate<'tcx>(
4646
obligation: &HostEffectObligation<'tcx>,
4747
candidate: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
4848
) -> Result<ThinVec<PredicateObligation<'tcx>>, NoSolution> {
49-
if !candidate.skip_binder().host.satisfies(obligation.predicate.host) {
49+
if !candidate.skip_binder().constness.satisfies(obligation.predicate.constness) {
5050
return Err(NoSolution);
5151
}
5252

@@ -134,7 +134,8 @@ fn evaluate_host_effect_from_selection_candiate<'tcx>(
134134
.map(|(trait_ref, _)| {
135135
obligation.with(
136136
tcx,
137-
trait_ref.to_host_effect_clause(tcx, obligation.predicate.host),
137+
trait_ref
138+
.to_host_effect_clause(tcx, obligation.predicate.constness),
138139
)
139140
}),
140141
);

compiler/rustc_ty_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
155155
if tcx.is_conditionally_const(def_id) {
156156
predicates.extend(
157157
tcx.const_conditions(def_id).instantiate_identity(tcx).into_iter().map(
158-
|(trait_ref, _)| trait_ref.to_host_effect_clause(tcx, ty::HostPolarity::Maybe),
158+
|(trait_ref, _)| trait_ref.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
159159
),
160160
);
161161
}

compiler/rustc_type_ir/src/elaborate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<I: Interner, O: Elaboratable<I>> Elaborator<I, O> {
160160
cx.implied_const_bounds(data.def_id()).iter_identity().map(|trait_ref| {
161161
elaboratable.child(
162162
trait_ref
163-
.to_host_effect_clause(cx, data.host)
163+
.to_host_effect_clause(cx, data.constness)
164164
.instantiate_supertrait(cx, bound_clause.rebind(data.trait_ref)),
165165
)
166166
}),

0 commit comments

Comments
 (0)