diff options
| author | lcnr <rust@lcnr.de> | 2025-01-20 13:09:09 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2025-01-20 18:51:45 +0100 |
| commit | 09b784fac560d725ffc37b6fad1037615f63b232 (patch) | |
| tree | 199e33700e1bac78f5fdf56115834dd8969c1a8d /compiler/rustc_next_trait_solver/src | |
| parent | 7171fee4ec77eeeae6e90f5c35d33c43495a4ecd (diff) | |
| download | rust-09b784fac560d725ffc37b6fad1037615f63b232.tar.gz rust-09b784fac560d725ffc37b6fad1037615f63b232.zip | |
handle global trait bounds defining assoc type
Diffstat (limited to 'compiler/rustc_next_trait_solver/src')
| -rw-r--r-- | compiler/rustc_next_trait_solver/src/solve/trait_goals.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index f059a6fb785..513fc9355c8 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -1212,8 +1212,28 @@ where // (including global ones) over everything else. let has_non_global_where_bounds = candidates.iter().any(|c| match c.source { CandidateSource::ParamEnv(idx) => { - let where_bound = goal.param_env.caller_bounds().get(idx); - where_bound.has_bound_vars() || !where_bound.is_global() + let where_bound = goal.param_env.caller_bounds().get(idx).unwrap(); + let ty::ClauseKind::Trait(trait_pred) = where_bound.kind().skip_binder() else { + unreachable!("expected trait-bound: {where_bound:?}"); + }; + + if trait_pred.has_bound_vars() || !trait_pred.is_global() { + return true; + } + + // We don't consider a trait-bound global if it has a projection bound. + // + // See ui/traits/next-solver/normalization-shadowing/global-trait-with-project.rs + // for an example where this is necessary. + for p in goal.param_env.caller_bounds().iter() { + if let ty::ClauseKind::Projection(proj) = p.kind().skip_binder() { + if proj.projection_term.trait_ref(self.cx()) == trait_pred.trait_ref { + return true; + } + } + } + + false } _ => false, }); |
