Skip to content

Commit 91cad0d

Browse files
authored
Rollup merge of rust-lang#151871 - jdonszelmann:no-env-with-infer-vars, r=BoxyUwU
don't use env with infer vars This is a change lcnr added on top of rust-lang@5bd20bb but we decided that it's a separate change for a separate problem. So, filed as a separate PR. Lcnr asked me to r? @BoxyUwU to take a look so hiii boxy :3
2 parents 57d9867 + 642d9c4 commit 91cad0d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,19 @@ fn impl_intersection_has_negative_obligation(
497497
) -> bool {
498498
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);
499499

500-
// N.B. We need to unify impl headers *with* intercrate mode, even if proving negative predicates
501-
// do not need intercrate mode enabled.
500+
// N.B. We need to unify impl headers *with* `TypingMode::Coherence`,
501+
// even if proving negative predicates doesn't need `TypingMode::Coherence`.
502502
let ref infcx = tcx.infer_ctxt().with_next_trait_solver(true).build(TypingMode::Coherence);
503503
let root_universe = infcx.universe();
504504
assert_eq!(root_universe, ty::UniverseIndex::ROOT);
505505

506506
let impl1_header = fresh_impl_header(infcx, impl1_def_id, is_of_trait);
507-
let param_env =
508-
ty::EarlyBinder::bind(tcx.param_env(impl1_def_id)).instantiate(tcx, impl1_header.impl_args);
509-
510507
let impl2_header = fresh_impl_header(infcx, impl2_def_id, is_of_trait);
511508

512509
// Equate the headers to find their intersection (the general type, with infer vars,
513510
// that may apply both impls).
514511
let Some(equate_obligations) =
515-
equate_impl_headers(infcx, param_env, &impl1_header, &impl2_header)
512+
equate_impl_headers(infcx, ty::ParamEnv::empty(), &impl1_header, &impl2_header)
516513
else {
517514
return false;
518515
};
@@ -530,7 +527,16 @@ fn impl_intersection_has_negative_obligation(
530527
root_universe,
531528
(impl1_header.impl_args, impl2_header.impl_args),
532529
);
533-
let param_env = infcx.resolve_vars_if_possible(param_env);
530+
531+
// Right above we plug inference variables with placeholders,
532+
// this gets us new impl1_header_args with the inference variables actually resolved
533+
// to those placeholders.
534+
let impl1_header_args = infcx.resolve_vars_if_possible(impl1_header.impl_args);
535+
// So there are no infer variables left now, except regions which aren't resolved by `resolve_vars_if_possible`.
536+
assert!(!impl1_header_args.has_non_region_infer());
537+
538+
let param_env =
539+
ty::EarlyBinder::bind(tcx.param_env(impl1_def_id)).instantiate(tcx, impl1_header_args);
534540

535541
util::elaborate(tcx, tcx.predicates_of(impl2_def_id).instantiate(tcx, impl2_header.impl_args))
536542
.elaborate_sized()

0 commit comments

Comments
 (0)