Skip to content

Commit 8227c4f

Browse files
authored
Rollup merge of #111880 - compiler-errors:pointer-like-param-env, r=jackh726
Don't ICE when computing PointerLike trait when region vars are in param-env Fixes #111877
2 parents 783bea9 + 3a2710c commit 8227c4f

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,18 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
177177
return Err(NoSolution);
178178
}
179179

180-
if goal.predicate.self_ty().has_non_region_infer() {
180+
// The regions of a type don't affect the size of the type
181+
let tcx = ecx.tcx();
182+
// We should erase regions from both the param-env and type, since both
183+
// may have infer regions. Specifically, after canonicalizing and instantiating,
184+
// early bound regions turn into region vars in both the new and old solver.
185+
let key = tcx.erase_regions(goal.param_env.and(goal.predicate.self_ty()));
186+
// But if there are inference variables, we have to wait until it's resolved.
187+
if key.has_non_region_infer() {
181188
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
182189
}
183190

184-
let tcx = ecx.tcx();
185-
let self_ty = tcx.erase_regions(goal.predicate.self_ty());
186-
187-
if let Ok(layout) = tcx.layout_of(goal.param_env.and(self_ty))
191+
if let Ok(layout) = tcx.layout_of(key)
188192
&& layout.layout.is_pointer_like(&tcx.data_layout)
189193
{
190194
// FIXME: We could make this faster by making a no-constraints response

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -967,16 +967,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
967967
) {
968968
// The regions of a type don't affect the size of the type
969969
let tcx = self.tcx();
970-
let self_ty =
971-
tcx.erase_regions(tcx.erase_late_bound_regions(obligation.predicate.self_ty()));
972-
970+
let self_ty = tcx.erase_late_bound_regions(obligation.predicate.self_ty());
971+
// We should erase regions from both the param-env and type, since both
972+
// may have infer regions. Specifically, after canonicalizing and instantiating,
973+
// early bound regions turn into region vars in both the new and old solver.
974+
let key = tcx.erase_regions(obligation.param_env.and(self_ty));
973975
// But if there are inference variables, we have to wait until it's resolved.
974-
if self_ty.has_non_region_infer() {
976+
if key.has_non_region_infer() {
975977
candidates.ambiguous = true;
976978
return;
977979
}
978980

979-
if let Ok(layout) = tcx.layout_of(obligation.param_env.and(self_ty))
981+
if let Ok(layout) = tcx.layout_of(key)
980982
&& layout.layout.is_pointer_like(&tcx.data_layout)
981983
{
982984
candidates.vec.push(BuiltinCandidate { has_nested: false });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/param-env-infer.rs:5:12
3+
|
4+
LL | #![feature(dyn_star, pointer_like_trait)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/param-env-infer.rs:12:10
12+
|
13+
LL | t as _
14+
| ^ cannot infer type
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/param-env-infer.rs:5:12
3+
|
4+
LL | #![feature(dyn_star, pointer_like_trait)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/param-env-infer.rs:12:10
12+
|
13+
LL | t as _
14+
| ^ cannot infer type
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0282`.

tests/ui/dyn-star/param-env-infer.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
// incremental
4+
5+
#![feature(dyn_star, pointer_like_trait)]
6+
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
7+
8+
use std::fmt::Debug;
9+
use std::marker::PointerLike;
10+
11+
fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
12+
t as _
13+
//~^ ERROR type annotations needed
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)