Skip to content

Commit fc31898

Browse files
authored
Rollup merge of #148292 - adwinwhite:assemble_object_candidate, r=lcnr
Un-shadow object bound candidate in `NormalizesTo` goal if self_ty is trait object Fixes rust-lang/trait-system-refactor-initiative#244 r? lcnr
2 parents 7b766e0 + d2cfc47 commit fc31898

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,16 @@ where
454454
self.assemble_object_bound_candidates(goal, &mut candidates);
455455
}
456456
}
457-
AssembleCandidatesFrom::EnvAndBounds => {}
457+
AssembleCandidatesFrom::EnvAndBounds => {
458+
// This is somewhat inconsistent and may make #57893 slightly easier to exploit.
459+
// However, it matches the behavior of the old solver. See
460+
// `tests/ui/traits/next-solver/normalization-shadowing/use_object_if_empty_env.rs`.
461+
if matches!(normalized_self_ty.kind(), ty::Dynamic(..))
462+
&& !candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_)))
463+
{
464+
self.assemble_object_bound_candidates(goal, &mut candidates);
465+
}
466+
}
458467
}
459468

460469
(candidates, failed_candidate_info)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
// Regression test for trait-system-refactor-initiative#244
5+
6+
trait Trait {
7+
type Assoc;
8+
}
9+
10+
// We have param env candidate for the trait goal but not the projection.
11+
// Under such circumstance, consider object candidate if the self_ty is trait object.
12+
fn foo<T>(x: <dyn Trait<Assoc = T> as Trait>::Assoc) -> T
13+
where
14+
dyn Trait<Assoc = T>: Trait,
15+
{
16+
x
17+
}
18+
19+
trait Id<'a> {
20+
type This: ?Sized;
21+
}
22+
impl<T: ?Sized> Id<'_> for T {
23+
type This = T;
24+
}
25+
26+
// Ensure that we properly normalize alias self_ty before evaluating the goal.
27+
fn alias_foo<T>(x: for<'a> fn(
28+
<<dyn Trait<Assoc = T> as Id<'a>>::This as Trait>::Assoc
29+
)) -> fn(T)
30+
where
31+
dyn Trait<Assoc = T>: Trait,
32+
{
33+
x
34+
}
35+
36+
fn main() {}

0 commit comments

Comments
 (0)