@@ -28,7 +28,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
28
28
use rustc_hir:: intravisit:: { walk_generics, Visitor as _} ;
29
29
use rustc_hir:: { GenericArg , GenericArgs , OpaqueTyOrigin } ;
30
30
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
31
- use rustc_infer:: infer:: { InferCtxt , InferOk , TyCtxtInferExt } ;
31
+ use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
32
32
use rustc_infer:: traits:: ObligationCause ;
33
33
use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
34
34
use rustc_middle:: middle:: stability:: AllowUnstable ;
@@ -42,13 +42,11 @@ use rustc_span::lev_distance::find_best_match_for_name;
42
42
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
43
43
use rustc_span:: { sym, Span , DUMMY_SP } ;
44
44
use rustc_target:: spec:: abi;
45
- use rustc_trait_selection:: traits;
46
45
use rustc_trait_selection:: traits:: error_reporting:: {
47
46
report_object_safety_error, suggestions:: NextTypeParamName ,
48
47
} ;
49
- use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
50
48
use rustc_trait_selection:: traits:: wf:: object_region_bounds;
51
- use rustc_trait_selection:: traits:: { astconv_object_safety_violations, NormalizeExt } ;
49
+ use rustc_trait_selection:: traits:: { self , astconv_object_safety_violations, ObligationCtxt } ;
52
50
53
51
use smallvec:: { smallvec, SmallVec } ;
54
52
use std:: collections:: BTreeSet ;
@@ -1948,7 +1946,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1948
1946
Res :: Err
1949
1947
} ;
1950
1948
1951
- // Check if we have an enum variant.
1949
+ // Check if we have an enum variant or an inherent associated type .
1952
1950
let mut variant_resolution = None ;
1953
1951
if let Some ( adt_def) = self . probe_adt ( span, qself_ty) {
1954
1952
if adt_def. is_enum ( ) {
@@ -2221,62 +2219,37 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2221
2219
2222
2220
let param_env = tcx. param_env ( block. owner . to_def_id ( ) ) ;
2223
2221
let cause = ObligationCause :: misc ( span, block. owner . def_id ) ;
2224
- let mut unsatisfied_predicates = Vec :: new ( ) ;
2222
+ let mut fulfillment_errors = Vec :: new ( ) ;
2225
2223
2226
2224
for & ( impl_, ( assoc_item, def_scope) ) in & candidates {
2227
2225
let infcx = tcx. infer_ctxt ( ) . ignoring_regions ( ) . build ( ) ;
2226
+ let ocx = ObligationCtxt :: new ( & infcx) ;
2228
2227
2229
2228
let impl_ty = tcx. type_of ( impl_) ;
2230
2229
let impl_substs = self . fresh_item_substs ( impl_, & infcx) ;
2231
2230
let impl_ty = impl_ty. subst ( tcx, impl_substs) ;
2232
-
2233
- let InferOk { value : impl_ty, obligations } =
2234
- infcx. at ( & cause, param_env) . normalize ( impl_ty) ;
2231
+ let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
2235
2232
2236
2233
// Check that the Self-types can be related.
2237
- let Ok ( InferOk { obligations : sub_obligations, value : ( ) } ) = infcx
2238
- . at ( & ObligationCause :: dummy ( ) , param_env)
2239
- . define_opaque_types ( false )
2240
- . sup ( impl_ty, self_ty)
2241
- else {
2234
+ // FIXME(fmease): Should we use `eq` here?
2235
+ if ocx. sup ( & ObligationCause :: dummy ( ) , param_env, impl_ty, self_ty) . is_err ( ) {
2242
2236
continue ;
2243
- } ;
2237
+ }
2244
2238
2245
2239
// Check whether the impl imposes obligations we have to worry about.
2246
2240
let impl_bounds = tcx. predicates_of ( impl_) ;
2247
2241
let impl_bounds = impl_bounds. instantiate ( tcx, impl_substs) ;
2248
2242
2249
- let InferOk { value : impl_bounds, obligations : norm_obligations } =
2250
- infcx. at ( & cause, param_env) . normalize ( impl_bounds) ;
2243
+ let impl_bounds = ocx. normalize ( & cause, param_env, impl_bounds) ;
2251
2244
2252
2245
let impl_obligations =
2253
2246
traits:: predicates_for_generics ( |_, _| cause. clone ( ) , param_env, impl_bounds) ;
2254
2247
2255
- let candidate_obligations = impl_obligations
2256
- . chain ( norm_obligations. into_iter ( ) )
2257
- . chain ( obligations. iter ( ) . cloned ( ) ) ;
2258
-
2259
- let mut matches = true ;
2260
-
2261
- // Evaluate those obligations to see if they might possibly hold.
2262
- for o in candidate_obligations {
2263
- let o = infcx. resolve_vars_if_possible ( o) ;
2264
- if !infcx. predicate_may_hold ( & o) {
2265
- matches = false ;
2266
- unsatisfied_predicates. push ( o. predicate ) ;
2267
- }
2268
- }
2248
+ ocx. register_obligations ( impl_obligations) ;
2269
2249
2270
- // Evaluate those obligations to see if they might possibly hold.
2271
- for o in sub_obligations {
2272
- let o = infcx. resolve_vars_if_possible ( o) ;
2273
- if !infcx. predicate_may_hold ( & o) {
2274
- matches = false ;
2275
- unsatisfied_predicates. push ( o. predicate ) ;
2276
- }
2277
- }
2278
-
2279
- if !matches {
2250
+ let errors = ocx. select_where_possible ( ) ;
2251
+ if !errors. is_empty ( ) {
2252
+ fulfillment_errors = errors;
2280
2253
continue ;
2281
2254
}
2282
2255
@@ -2286,19 +2259,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2286
2259
bug ! ( "unreachable: `lookup_inherent_assoc_ty` is only called on ADTs" ) ;
2287
2260
} ;
2288
2261
2289
- let item_substs =
2290
- self . create_substs_for_associated_item ( span, assoc_item, segment, adt_substs) ;
2291
- // FIXME(inherent_associated_types): Check if the obligations arising from the
2292
- // where-clause & the bounds on the associated type and its parameters hold.
2262
+ let item_substs = self . create_substs_for_associated_item (
2263
+ span, assoc_item, segment,
2264
+ // FIXME(fmease, #107468, #105305): Don't use `adt_substs` here but `impl_substs`.
2265
+ adt_substs,
2266
+ ) ;
2267
+
2268
+ // FIXME(fmease, #106722): Check if the bounds on the parameters of the
2269
+ // associated type hold, if any.
2293
2270
let ty = tcx. type_of ( assoc_item) . subst ( tcx, item_substs) ;
2271
+
2272
+ // FIXME(fmease): Don't return early here! There might be multiple applicable candidates.
2294
2273
return Ok ( Some ( ( ty, assoc_item) ) ) ;
2295
2274
}
2296
2275
2297
2276
Err ( self . complain_about_inherent_assoc_type_not_found (
2298
2277
name,
2299
2278
self_ty,
2300
- & candidates. into_iter ( ) . map ( | ( impl_ , _ ) | impl_ ) . collect :: < Vec < _ > > ( ) ,
2301
- unsatisfied_predicates ,
2279
+ candidates,
2280
+ fulfillment_errors ,
2302
2281
span,
2303
2282
) )
2304
2283
}
0 commit comments