Skip to content

Commit 65f9dd2

Browse files
committed
Keep solver region constraints in type ops
Canonical type-op queries don't include NextGen solver region constraints in their response. Run these operations locally under -Zassumptions-on-binders so borrowck gets the constraints.
1 parent 8925ea3 commit 65f9dd2

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ where
146146
root_def_id: LocalDefId,
147147
span: Span,
148148
) -> Result<TypeOpOutput<'tcx, Self>, ErrorGuaranteed> {
149+
// Canonical type-op queries drop NextGen solver region constraints when
150+
// building `QueryResponse`. Evaluate locally so `-Zassumptions-on-binders`
151+
// can attach those constraints to this `InferCtxt` and report them from
152+
// borrowck instead of silently succeeding.
153+
if infcx.tcx.assumptions_on_binders() {
154+
if !infcx.disable_trait_solver_fast_paths()
155+
&& let Some(output) = Q::try_fast_path(infcx.tcx, &self)
156+
{
157+
return Ok(TypeOpOutput { output, constraints: None, error_info: None });
158+
}
159+
160+
let (output, _) =
161+
scrape_region_constraints(infcx, root_def_id, "fully_perform", span, |ocx| {
162+
Q::perform_locally_with_next_solver(ocx, self, span)
163+
})?;
164+
return Ok(output);
165+
}
166+
149167
let mut error_info = None;
150168
let mut region_constraints = QueryRegionConstraints::default();
151169

tests/ui/assumptions_on_binders/alias_outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where
2323
}
2424

2525
fn borrowck_env_fail<'a, T: AliasHaver>()
26-
// FIXME: ^ this should raise an ERROR: unsatisfied lifetime constraint from -Zassumptions-on-binders
26+
//~^ ERROR: unsatisfied lifetime constraint from -Zassumptions-on-binders
2727
where
2828
<T as AliasHaver>::Assoc: 'a,
2929
{

tests/ui/assumptions_on_binders/alias_outlives.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@ LL | const REGIONCK_ENV_FAIL<'a, T: AliasHaver>: ReqTrait<T::Assoc> = todo!()
66
|
77
= note: meoow :c
88

9-
error: aborting due to 1 previous error
9+
error: unsatisfied lifetime constraint from -Zassumptions-on-binders :3
10+
--> $DIR/alias_outlives.rs:25:1
11+
|
12+
LL | / fn borrowck_env_fail<'a, T: AliasHaver>()
13+
LL | |
14+
LL | | where
15+
LL | | <T as AliasHaver>::Assoc: 'a,
16+
| |_________________________________^
17+
|
18+
= note: meoow :c
19+
20+
error: aborting due to 2 previous errors
1021

0 commit comments

Comments
 (0)