File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
compiler/rustc_next_trait_solver/src/solve/assembly
tests/ui/traits/next-solver/normalization-shadowing Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change 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 ( ) { }
You can’t perform that action at this time.
0 commit comments