@@ -9,9 +9,7 @@ use rustc_span::{ErrorGuaranteed, Span};
9
9
use rustc_trait_selection:: traits;
10
10
use smallvec:: SmallVec ;
11
11
12
- use crate :: astconv:: {
13
- AstConv , ConvertedBinding , ConvertedBindingKind , OnlySelfBounds , PredicateFilter ,
14
- } ;
12
+ use crate :: astconv:: { AstConv , OnlySelfBounds , PredicateFilter } ;
15
13
use crate :: bounds:: Bounds ;
16
14
use crate :: errors;
17
15
@@ -228,7 +226,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
228
226
& self ,
229
227
hir_ref_id : hir:: HirId ,
230
228
trait_ref : ty:: PolyTraitRef < ' tcx > ,
231
- binding : & ConvertedBinding < ' _ , ' tcx > ,
229
+ binding : & hir :: TypeBinding < ' _ > ,
232
230
bounds : & mut Bounds < ' tcx > ,
233
231
speculative : bool ,
234
232
dup_bindings : & mut FxHashMap < DefId , Span > ,
@@ -255,21 +253,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
255
253
256
254
let tcx = self . tcx ( ) ;
257
255
258
- let assoc_kind =
259
- if binding. gen_args . parenthesized == hir:: GenericArgsParentheses :: ReturnTypeNotation {
260
- ty:: AssocKind :: Fn
261
- } else if let ConvertedBindingKind :: Equality ( term) = binding. kind
262
- && let ty:: TermKind :: Const ( _) = term. node . unpack ( )
263
- {
264
- ty:: AssocKind :: Const
265
- } else {
266
- ty:: AssocKind :: Type
267
- } ;
256
+ let assoc_kind = if binding. gen_args . parenthesized
257
+ == hir:: GenericArgsParentheses :: ReturnTypeNotation
258
+ {
259
+ ty:: AssocKind :: Fn
260
+ } else if let hir:: TypeBindingKind :: Equality { term : hir:: Term :: Const ( _) } = binding. kind {
261
+ ty:: AssocKind :: Const
262
+ } else {
263
+ ty:: AssocKind :: Type
264
+ } ;
268
265
269
266
let candidate = if self . trait_defines_associated_item_named (
270
267
trait_ref. def_id ( ) ,
271
268
assoc_kind,
272
- binding. item_name ,
269
+ binding. ident ,
273
270
) {
274
271
// Simple case: The assoc item is defined in the current trait.
275
272
trait_ref
@@ -281,14 +278,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
281
278
trait_ref. skip_binder ( ) . print_only_trait_name ( ) ,
282
279
None ,
283
280
assoc_kind,
284
- binding. item_name ,
281
+ binding. ident ,
285
282
path_span,
286
- Some ( & binding) ,
283
+ Some ( binding) ,
287
284
) ?
288
285
} ;
289
286
290
287
let ( assoc_ident, def_scope) =
291
- tcx. adjust_ident_and_get_scope ( binding. item_name , candidate. def_id ( ) , hir_ref_id) ;
288
+ tcx. adjust_ident_and_get_scope ( binding. ident , candidate. def_id ( ) , hir_ref_id) ;
292
289
293
290
// We have already adjusted the item name above, so compare with `.normalize_to_macros_2_0()`
294
291
// instead of calling `filter_by_name_and_kind` which would needlessly normalize the
@@ -303,7 +300,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
303
300
tcx. dcx ( )
304
301
. struct_span_err (
305
302
binding. span ,
306
- format ! ( "{} `{}` is private" , assoc_item. kind, binding. item_name ) ,
303
+ format ! ( "{} `{}` is private" , assoc_item. kind, binding. ident ) ,
307
304
)
308
305
. span_label_mv ( binding. span , format ! ( "private {}" , assoc_item. kind) )
309
306
. emit ( ) ;
@@ -317,7 +314,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
317
314
tcx. dcx ( ) . emit_err ( errors:: ValueOfAssociatedStructAlreadySpecified {
318
315
span : binding. span ,
319
316
prev_span : * prev_span,
320
- item_name : binding. item_name ,
317
+ item_name : binding. ident ,
321
318
def_path : tcx. def_path_str ( assoc_item. container_id ( tcx) ) ,
322
319
} ) ;
323
320
} )
@@ -417,7 +414,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
417
414
// parent arguments (the arguments of the trait) and the own arguments (the ones of
418
415
// the associated item itself) and construct an alias type using them.
419
416
candidate. map_bound ( |trait_ref| {
420
- let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
417
+ let ident = Ident :: new ( assoc_item. name , binding. ident . span ) ;
421
418
let item_segment = hir:: PathSegment {
422
419
ident,
423
420
hir_id : binding. hir_id ,
@@ -441,65 +438,66 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
441
438
} )
442
439
} ;
443
440
444
- // FIXME(associated_const_equality): Can this actually ever fail with assoc consts?
445
- if !speculative {
446
- // Find any late-bound regions declared in `ty` that are not
447
- // declared in the trait-ref or assoc_item. These are not well-formed.
448
- //
449
- // Example:
450
- //
451
- // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
452
- // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
453
- if let ConvertedBindingKind :: Equality ( term) = binding. kind {
454
- let late_bound_in_projection_ty =
455
- tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
456
- let late_bound_in_term =
457
- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term. node ) ) ;
458
- debug ! ( ?late_bound_in_projection_ty) ;
459
- debug ! ( ?late_bound_in_term) ;
460
-
461
- // FIXME: point at the type params that don't have appropriate lifetimes:
462
- // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
463
- // ---- ---- ^^^^^^^
464
- self . validate_late_bound_regions (
465
- late_bound_in_projection_ty,
466
- late_bound_in_term,
467
- |br_name| {
468
- struct_span_err ! (
469
- tcx. dcx( ) ,
470
- binding. span,
471
- E0582 ,
472
- "binding for associated type `{}` references {}, \
473
- which does not appear in the trait input types",
474
- binding. item_name,
475
- br_name
476
- )
477
- } ,
478
- ) ;
479
- }
480
- }
481
-
482
441
match binding. kind {
483
- ConvertedBindingKind :: Equality ( .. ) if let ty:: AssocKind :: Fn = assoc_kind => {
442
+ hir :: TypeBindingKind :: Equality { .. } if let ty:: AssocKind :: Fn = assoc_kind => {
484
443
return Err ( tcx. dcx ( ) . emit_err ( crate :: errors:: ReturnTypeNotationEqualityBound {
485
444
span : binding. span ,
486
445
} ) ) ;
487
446
}
488
- ConvertedBindingKind :: Equality ( term) => {
447
+ hir:: TypeBindingKind :: Equality { term } => {
448
+ let term = match term {
449
+ hir:: Term :: Ty ( ty) => self . ast_ty_to_ty ( ty) . into ( ) ,
450
+ hir:: Term :: Const ( ct) => ty:: Const :: from_anon_const ( tcx, ct. def_id ) . into ( ) ,
451
+ } ;
452
+
453
+ // FIXME(associated_const_equality): Can this actually ever fail with assoc consts?
454
+ if !speculative {
455
+ // Find any late-bound regions declared in `ty` that are not
456
+ // declared in the trait-ref or assoc_item. These are not well-formed.
457
+ //
458
+ // Example:
459
+ //
460
+ // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
461
+ // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
462
+ let late_bound_in_projection_ty =
463
+ tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
464
+ let late_bound_in_term =
465
+ tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term) ) ;
466
+ debug ! ( ?late_bound_in_projection_ty) ;
467
+ debug ! ( ?late_bound_in_term) ;
468
+
469
+ // FIXME: point at the type params that don't have appropriate lifetimes:
470
+ // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
471
+ // ---- ---- ^^^^^^^
472
+ self . validate_late_bound_regions (
473
+ late_bound_in_projection_ty,
474
+ late_bound_in_term,
475
+ |br_name| {
476
+ struct_span_err ! (
477
+ tcx. dcx( ) ,
478
+ binding. span,
479
+ E0582 ,
480
+ "binding for associated type `{}` references {}, \
481
+ which does not appear in the trait input types",
482
+ binding. ident,
483
+ br_name
484
+ )
485
+ } ,
486
+ ) ;
487
+ }
488
+
489
489
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
490
490
// the "projection predicate" for:
491
491
//
492
492
// `<T as Iterator>::Item = u32`
493
493
bounds. push_projection_bound (
494
494
tcx,
495
- projection_ty. map_bound ( |projection_ty| ty:: ProjectionPredicate {
496
- projection_ty,
497
- term : term. node ,
498
- } ) ,
495
+ projection_ty
496
+ . map_bound ( |projection_ty| ty:: ProjectionPredicate { projection_ty, term } ) ,
499
497
binding. span ,
500
498
) ;
501
499
}
502
- ConvertedBindingKind :: Constraint ( ast_bounds) => {
500
+ hir :: TypeBindingKind :: Constraint { bounds : ast_bounds } => {
503
501
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
504
502
//
505
503
// `<T as Iterator>::Item: Debug`
0 commit comments