Skip to content

Commit 9ca1f3e

Browse files
committed
rarw
1 parent abf2358 commit 9ca1f3e

File tree

12 files changed

+51
-49
lines changed

12 files changed

+51
-49
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,10 @@ impl<'tcx> InferCtxt<'tcx> {
12871287
u
12881288
}
12891289

1290+
pub fn typing_env(&self, param_env: ty::ParamEnv<'tcx>) -> ty::TypingEnv<'tcx> {
1291+
ty::TypingEnv { typing_mode: self.typing_mode(param_env), param_env }
1292+
}
1293+
12901294
/// Similar to [Self::canonicalize_query], except that it returns
12911295
/// a [PseudoCanonicalInput] and requires both the `value`` and the
12921296
/// `param_env` to not contain any inference variables or placeholders.
@@ -1302,8 +1306,7 @@ impl<'tcx> InferCtxt<'tcx> {
13021306
debug_assert!(!value.has_placeholders());
13031307
debug_assert!(!param_env.has_infer());
13041308
debug_assert!(!param_env.has_placeholders());
1305-
let typing_env = ty::TypingEnv { typing_mode: self.typing_mode(param_env), param_env };
1306-
PseudoCanonicalInput { typing_env, value }
1309+
PseudoCanonicalInput { typing_env: self.typing_env(param_env), value }
13071310
}
13081311

13091312
pub fn try_const_eval_resolve(

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
528528
// Find the method being called.
529529
let Ok(Some(instance)) = ty::Instance::try_resolve(
530530
tcx,
531-
self.cx.typing_mode(ctxt.param_env),
532-
ctxt.param_env,
531+
self.cx.typing_env(ctxt.param_env),
533532
ctxt.assoc_item.def_id,
534533
self.cx.resolve_vars_if_possible(ctxt.args),
535534
) else {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19681968
cand.trait_ref = self
19691969
.tcx
19701970
.try_normalize_erasing_regions(
1971-
self.tcx.param_env(cand.impl_def_id),
1971+
ty::TypingEnv {
1972+
typing_mode: ty::TypingMode::non_body_analysis(),
1973+
param_env: self.tcx.param_env(cand.impl_def_id),
1974+
},
19721975
cand.trait_ref,
19731976
)
19741977
.unwrap_or(cand.trait_ref);

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method:
514514
let method_def_id = method.def_id;
515515
let sig = tcx.fn_sig(method_def_id).instantiate_identity();
516516
let param_env = tcx.param_env(method_def_id);
517+
let typing_env = ty::TypingEnv { typing_mode: ty::TypingMode::non_body_analysis(), param_env };
517518
let receiver_ty = tcx.liberate_late_bound_regions(method_def_id, sig.input(0));
518519

519520
if receiver_ty == tcx.types.self_param {
@@ -523,7 +524,7 @@ fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method:
523524

524525
// e.g., `Rc<()>`
525526
let unit_receiver_ty = receiver_for_self_ty(tcx, receiver_ty, tcx.types.unit, method_def_id);
526-
match tcx.layout_of(param_env.and(unit_receiver_ty)).map(|l| l.backend_repr) {
527+
match tcx.layout_of(typing_env.as_query_input(unit_receiver_ty)).map(|l| l.backend_repr) {
527528
Ok(BackendRepr::Scalar(..)) => (),
528529
abi => {
529530
tcx.dcx().span_delayed_bug(
@@ -538,7 +539,7 @@ fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method:
538539
// e.g., `Rc<dyn Trait>`
539540
let trait_object_receiver =
540541
receiver_for_self_ty(tcx, receiver_ty, trait_object_ty, method_def_id);
541-
match tcx.layout_of(param_env.and(trait_object_receiver)).map(|l| l.backend_repr) {
542+
match tcx.layout_of(typing_env.as_query_input(trait_object_receiver)).map(|l| l.backend_repr) {
542543
Ok(BackendRepr::ScalarPair(..)) => (),
543544
abi => {
544545
tcx.dcx().span_delayed_bug(

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ pub fn normalize_param_env_or_error<'tcx>(
370370
// should actually be okay since without `feature(generic_const_exprs)` the only
371371
// const arguments that have a non-empty param env are array repeat counts. These
372372
// do not appear in the type system though.
373-
c.normalize_internal(
374-
self.0,
375-
ty::TypingMode::non_body_analysis(),
376-
ty::ParamEnv::empty(),
377-
)
373+
c.normalize_internal(self.0, ty::TypingEnv {
374+
typing_mode: TypingMode::non_body_analysis(),
375+
param_env: ty::ParamEnv::empty(),
376+
})
378377
}
379378
}
380379

compiler/rustc_trait_selection/src/traits/normalize.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
419419
&mut self.universes,
420420
constant,
421421
|constant| {
422-
constant.normalize_internal(
423-
tcx,
424-
self.selcx.infcx.typing_mode(self.param_env),
425-
self.param_env,
426-
)
422+
constant.normalize_internal(tcx, self.selcx.infcx.typing_env(self.param_env))
427423
},
428424
)
429425
}

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ pub fn compute_dropck_outlives_inner<'tcx>(
144144
result.overflows.len(),
145145
ty_stack.len()
146146
);
147-
dtorck_constraint_for_ty_inner(tcx, param_env, DUMMY_SP, depth, ty, &mut constraints)?;
147+
dtorck_constraint_for_ty_inner(
148+
tcx,
149+
ocx.infcx.typing_env(param_env),
150+
DUMMY_SP,
151+
depth,
152+
ty,
153+
&mut constraints,
154+
)?;
148155

149156
// "outlives" represent types/regions that may be touched
150157
// by a destructor.
@@ -196,10 +203,10 @@ pub fn compute_dropck_outlives_inner<'tcx>(
196203

197204
/// Returns a set of constraints that needs to be satisfied in
198205
/// order for `ty` to be valid for destruction.
199-
#[instrument(level = "debug", skip(tcx, param_env, span, constraints))]
206+
#[instrument(level = "debug", skip(tcx, typing_env, span, constraints))]
200207
pub fn dtorck_constraint_for_ty_inner<'tcx>(
201208
tcx: TyCtxt<'tcx>,
202-
param_env: ty::ParamEnv<'tcx>,
209+
typing_env: ty::TypingEnv<'tcx>,
203210
span: Span,
204211
depth: usize,
205212
ty: Ty<'tcx>,
@@ -234,20 +241,20 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
234241
ty::Pat(ety, _) | ty::Array(ety, _) | ty::Slice(ety) => {
235242
// single-element containers, behave like their element
236243
rustc_data_structures::stack::ensure_sufficient_stack(|| {
237-
dtorck_constraint_for_ty_inner(tcx, param_env, span, depth + 1, *ety, constraints)
244+
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, *ety, constraints)
238245
})?;
239246
}
240247

241248
ty::Tuple(tys) => rustc_data_structures::stack::ensure_sufficient_stack(|| {
242249
for ty in tys.iter() {
243-
dtorck_constraint_for_ty_inner(tcx, param_env, span, depth + 1, ty, constraints)?;
250+
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints)?;
244251
}
245252
Ok::<_, NoSolution>(())
246253
})?,
247254

248255
ty::Closure(_, args) => rustc_data_structures::stack::ensure_sufficient_stack(|| {
249256
for ty in args.as_closure().upvar_tys() {
250-
dtorck_constraint_for_ty_inner(tcx, param_env, span, depth + 1, ty, constraints)?;
257+
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints)?;
251258
}
252259
Ok::<_, NoSolution>(())
253260
})?,
@@ -257,7 +264,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
257264
for ty in args.as_coroutine_closure().upvar_tys() {
258265
dtorck_constraint_for_ty_inner(
259266
tcx,
260-
param_env,
267+
typing_env,
261268
span,
262269
depth + 1,
263270
ty,
@@ -296,7 +303,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
296303
// While we conservatively assume that all coroutines require drop
297304
// to avoid query cycles during MIR building, we can check the actual
298305
// witness during borrowck to avoid unnecessary liveness constraints.
299-
if args.witness().needs_drop(tcx, tcx.erase_regions(param_env)) {
306+
if args.witness().needs_drop(tcx, tcx.erase_regions(typing_env)) {
300307
constraints.outlives.extend(args.upvar_tys().iter().map(ty::GenericArg::from));
301308
constraints.outlives.push(args.resume_ty().into());
302309
}

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
343343
&mut self.universes,
344344
constant,
345345
|constant| {
346-
constant.normalize_internal(
347-
self.infcx.tcx,
348-
self.infcx.typing_mode(self.param_env),
349-
self.param_env,
350-
)
346+
constant.normalize_internal(self.infcx.tcx, self.infcx.typing_env(self.param_env))
351347
},
352348
);
353349
debug!(?constant, ?self.param_env);

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,16 +1226,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12261226
// The regions of a type don't affect the size of the type
12271227
let tcx = self.tcx();
12281228
let self_ty = tcx.instantiate_bound_regions_with_erased(obligation.predicate.self_ty());
1229-
// We should erase regions from both the param-env and type, since both
1230-
// may have infer regions. Specifically, after canonicalizing and instantiating,
1231-
// early bound regions turn into region vars in both the new and old solver.
1232-
let key = tcx.erase_regions(obligation.param_env.and(self_ty));
1229+
12331230
// But if there are inference variables, we have to wait until it's resolved.
1234-
if key.has_non_region_infer() {
1231+
if (obligation.param_env, self_ty).has_non_region_infer() {
12351232
candidates.ambiguous = true;
12361233
return;
12371234
}
12381235

1236+
// We should erase regions from both the param-env and type, since both
1237+
// may have infer regions. Specifically, after canonicalizing and instantiating,
1238+
// early bound regions turn into region vars in both the new and old solver.
1239+
let key = self.infcx.pseudo_canonicalize_query(
1240+
tcx.erase_regions(obligation.param_env),
1241+
tcx.erase_regions(self_ty),
1242+
);
12391243
if let Ok(layout) = tcx.layout_of(key)
12401244
&& layout.layout.is_pointer_like(&tcx.data_layout)
12411245
{

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
403403
let mut assume = predicate.trait_ref.args.const_at(2);
404404
// FIXME(min_generic_const_exprs): We should shallowly normalize this.
405405
if self.tcx().features().generic_const_exprs() {
406-
assume = assume.normalize_internal(
407-
self.tcx(),
408-
self.infcx.typing_mode(obligation.param_env),
409-
obligation.param_env,
410-
);
406+
assume =
407+
assume.normalize_internal(self.tcx(), self.infcx.typing_env(obligation.param_env));
411408
}
412409
let Some(assume) =
413410
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, assume)

compiler/rustc_trait_selection/src/traits/structural_normalize.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ impl<'tcx> At<'_, 'tcx> {
8383

8484
Ok(self.infcx.resolve_vars_if_possible(new_infer_ct))
8585
} else if self.infcx.tcx.features().generic_const_exprs() {
86-
Ok(ct.normalize_internal(
87-
self.infcx.tcx,
88-
self.infcx.typing_mode(self.param_env),
89-
self.param_env,
90-
))
86+
Ok(ct.normalize_internal(self.infcx.tcx, self.infcx.typing_env(self.param_env)))
9187
} else {
9288
Ok(self.normalize(ct).into_value_registering_obligations(self.infcx, fulfill_cx))
9389
}

compiler/rustc_trait_selection/src/traits/vtable.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ fn vtable_entries<'tcx>(
276276
// The trait type may have higher-ranked lifetimes in it;
277277
// erase them if they appear, so that we get the type
278278
// at some particular call site.
279-
let args =
280-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), args);
279+
let args = tcx.normalize_erasing_late_bound_regions(
280+
ty::TypingEnv::fully_monomorphized(),
281+
args,
282+
);
281283

282284
// It's possible that the method relies on where-clauses that
283285
// do not hold for this particular set of type parameters.
@@ -294,8 +296,7 @@ fn vtable_entries<'tcx>(
294296

295297
let instance = ty::Instance::expect_resolve_for_vtable(
296298
tcx,
297-
ty::TypingMode::PostAnalysis,
298-
ty::ParamEnv::reveal_all(),
299+
ty::TypingEnv::fully_monomorphized(),
299300
def_id,
300301
args,
301302
DUMMY_SP,

0 commit comments

Comments
 (0)