Skip to content

Commit e2ac9d9

Browse files
committed
Apply suggestions
1 parent 2fbb751 commit e2ac9d9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
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)
@@ -1143,12 +1152,6 @@ where
11431152
// See `tests/ui/winnowing/norm-where-bound-gt-alias-bound.rs`.
11441153
if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
11451154
candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
1146-
} else if matches!(goal.predicate.self_ty().kind(), ty::Dynamic(..)) {
1147-
// Object candidate may be shadowed by where-bound for the trait goal, see
1148-
// `tests/ui/traits/next-solver/normalization-shadowing/use_object_if_empty_env.rs`.
1149-
// Trait objects always have their associated types specified so `candidates`
1150-
// won't be empty.
1151-
self.assemble_object_bound_candidates(goal, &mut candidates);
11521155
} else if candidates.is_empty() {
11531156
// If the trait goal has been proven by using the environment, we want to treat
11541157
// aliases as rigid if there are no applicable projection bounds in the environment.

tests/ui/traits/next-solver/normalization-shadowing/use_object_if_empty_env.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ compile-flags: -Znext-solver
22
//@ check-pass
33

4+
// Regression test for trait-system-refactor-initiative#244
5+
46
trait Trait {
57
type Assoc;
68
}

0 commit comments

Comments
 (0)