File tree 2 files changed +43
-2
lines changed
compiler/rustc_next_trait_solver/src/solve
tests/ui/traits/next-solver/normalization-shadowing
2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -1212,8 +1212,28 @@ where
1212
1212
// (including global ones) over everything else.
1213
1213
let has_non_global_where_bounds = candidates. iter ( ) . any ( |c| match c. source {
1214
1214
CandidateSource :: ParamEnv ( idx) => {
1215
- let where_bound = goal. param_env . caller_bounds ( ) . get ( idx) ;
1216
- where_bound. has_bound_vars ( ) || !where_bound. is_global ( )
1215
+ let where_bound = goal. param_env . caller_bounds ( ) . get ( idx) . unwrap ( ) ;
1216
+ let ty:: ClauseKind :: Trait ( trait_pred) = where_bound. kind ( ) . skip_binder ( ) else {
1217
+ unreachable ! ( "expected trait-bound: {where_bound:?}" ) ;
1218
+ } ;
1219
+
1220
+ if trait_pred. has_bound_vars ( ) || !trait_pred. is_global ( ) {
1221
+ return true ;
1222
+ }
1223
+
1224
+ // We don't consider a trait-bound global if it has a projection bound.
1225
+ //
1226
+ // See ui/traits/next-solver/normalization-shadowing/global-trait-with-project.rs
1227
+ // for an example where this is necessary.
1228
+ for p in goal. param_env . caller_bounds ( ) . iter ( ) {
1229
+ if let ty:: ClauseKind :: Projection ( proj) = p. kind ( ) . skip_binder ( ) {
1230
+ if proj. projection_term . trait_ref ( self . cx ( ) ) == trait_pred. trait_ref {
1231
+ return true ;
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ false
1217
1237
}
1218
1238
_ => false ,
1219
1239
} ) ;
Original file line number Diff line number Diff line change
1
+ //@ compile-flags: -Znext-solver
2
+ //@ check-pass
3
+
4
+ // `(): Trait` is a global where-bound with a projection bound.
5
+ // This previously resulted in ambiguity as we considered both
6
+ // the impl and the where-bound while normalizing.
7
+
8
+ trait Trait {
9
+ type Assoc ;
10
+ }
11
+ impl Trait for ( ) {
12
+ type Assoc = & ' static ( ) ;
13
+ }
14
+
15
+ fn foo < ' a > ( x : <( ) as Trait >:: Assoc )
16
+ where
17
+ ( ) : Trait < Assoc = & ' a ( ) > ,
18
+ {
19
+ }
20
+
21
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments