@@ -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
@@ -217,7 +215,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
217
215
& self ,
218
216
hir_ref_id : hir:: HirId ,
219
217
trait_ref : ty:: PolyTraitRef < ' tcx > ,
220
- binding : & ConvertedBinding < ' _ , ' tcx > ,
218
+ binding : & hir :: TypeBinding < ' _ > ,
221
219
bounds : & mut Bounds < ' tcx > ,
222
220
speculative : bool ,
223
221
dup_bindings : & mut FxHashMap < DefId , Span > ,
@@ -244,21 +242,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
244
242
245
243
let tcx = self . tcx ( ) ;
246
244
247
- let assoc_kind =
248
- if binding. gen_args . parenthesized == hir:: GenericArgsParentheses :: ReturnTypeNotation {
249
- ty:: AssocKind :: Fn
250
- } else if let ConvertedBindingKind :: Equality ( term) = binding. kind
251
- && let ty:: TermKind :: Const ( _) = term. node . unpack ( )
252
- {
253
- ty:: AssocKind :: Const
254
- } else {
255
- ty:: AssocKind :: Type
256
- } ;
245
+ let assoc_kind = if binding. gen_args . parenthesized
246
+ == hir:: GenericArgsParentheses :: ReturnTypeNotation
247
+ {
248
+ ty:: AssocKind :: Fn
249
+ } else if let hir:: TypeBindingKind :: Equality { term : hir:: Term :: Const ( _) } = binding. kind {
250
+ ty:: AssocKind :: Const
251
+ } else {
252
+ ty:: AssocKind :: Type
253
+ } ;
257
254
258
255
let candidate = if self . trait_defines_associated_item_named (
259
256
trait_ref. def_id ( ) ,
260
257
assoc_kind,
261
- binding. item_name ,
258
+ binding. ident ,
262
259
) {
263
260
// Simple case: The assoc item is defined in the current trait.
264
261
trait_ref
@@ -270,14 +267,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
270
267
trait_ref. skip_binder ( ) . print_only_trait_name ( ) ,
271
268
None ,
272
269
assoc_kind,
273
- binding. item_name ,
270
+ binding. ident ,
274
271
path_span,
275
- Some ( & binding) ,
272
+ Some ( binding) ,
276
273
) ?
277
274
} ;
278
275
279
276
let ( assoc_ident, def_scope) =
280
- tcx. adjust_ident_and_get_scope ( binding. item_name , candidate. def_id ( ) , hir_ref_id) ;
277
+ tcx. adjust_ident_and_get_scope ( binding. ident , candidate. def_id ( ) , hir_ref_id) ;
281
278
282
279
// We have already adjusted the item name above, so compare with `.normalize_to_macros_2_0()`
283
280
// instead of calling `filter_by_name_and_kind` which would needlessly normalize the
@@ -292,7 +289,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
292
289
tcx. dcx ( )
293
290
. struct_span_err (
294
291
binding. span ,
295
- format ! ( "{} `{}` is private" , assoc_item. kind, binding. item_name ) ,
292
+ format ! ( "{} `{}` is private" , assoc_item. kind, binding. ident ) ,
296
293
)
297
294
. span_label ( binding. span , format ! ( "private {}" , assoc_item. kind) )
298
295
. emit ( ) ;
@@ -306,7 +303,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
306
303
tcx. dcx ( ) . emit_err ( errors:: ValueOfAssociatedStructAlreadySpecified {
307
304
span : binding. span ,
308
305
prev_span : * prev_span,
309
- item_name : binding. item_name ,
306
+ item_name : binding. ident ,
310
307
def_path : tcx. def_path_str ( assoc_item. container_id ( tcx) ) ,
311
308
} ) ;
312
309
} )
@@ -406,7 +403,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
406
403
} else {
407
404
// Append the generic arguments of the associated type or const to the `trait_ref`.
408
405
candidate. map_bound ( |trait_ref| {
409
- let ident = Ident :: new ( assoc_item. name , binding. item_name . span ) ;
406
+ let ident = Ident :: new ( assoc_item. name , binding. ident . span ) ;
410
407
let item_segment = hir:: PathSegment {
411
408
ident,
412
409
hir_id : binding. hir_id ,
@@ -430,67 +427,68 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
430
427
} )
431
428
} ;
432
429
433
- // FIXME(fmease): This doesn't check actually seem to work for assoc consts.
434
- // We want to deny escaping late-bound vars in general anyways for assoc consts.
435
- // If the diagnostic *is* reachable, update it (“type” → “term” or similar).
436
- if !speculative {
437
- // Find any late-bound regions declared in `ty` that are not
438
- // declared in the trait-ref or assoc_item. These are not well-formed.
439
- //
440
- // Example:
441
- //
442
- // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
443
- // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
444
- if let ConvertedBindingKind :: Equality ( term) = binding. kind {
445
- let late_bound_in_projection_ty =
446
- tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
447
- let late_bound_in_term =
448
- tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term. node ) ) ;
449
- debug ! ( ?late_bound_in_projection_ty) ;
450
- debug ! ( ?late_bound_in_term) ;
451
-
452
- // FIXME: point at the type params that don't have appropriate lifetimes:
453
- // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
454
- // ---- ---- ^^^^^^^
455
- self . validate_late_bound_regions (
456
- late_bound_in_projection_ty,
457
- late_bound_in_term,
458
- |br_name| {
459
- struct_span_err ! (
460
- tcx. dcx( ) ,
461
- binding. span,
462
- E0582 ,
463
- "binding for associated type `{}` references {}, \
464
- which does not appear in the trait input types",
465
- binding. item_name,
466
- br_name
467
- )
468
- } ,
469
- ) ;
470
- }
471
- }
472
-
473
430
match binding. kind {
474
- ConvertedBindingKind :: Equality ( .. ) if let ty:: AssocKind :: Fn = assoc_kind => {
431
+ hir :: TypeBindingKind :: Equality { .. } if let ty:: AssocKind :: Fn = assoc_kind => {
475
432
return Err ( self . tcx ( ) . dcx ( ) . emit_err (
476
433
crate :: errors:: ReturnTypeNotationEqualityBound { span : binding. span } ,
477
434
) ) ;
478
435
}
479
- ConvertedBindingKind :: Equality ( term) => {
436
+ hir:: TypeBindingKind :: Equality { term } => {
437
+ let term = match term {
438
+ hir:: Term :: Ty ( ty) => self . ast_ty_to_ty ( ty) . into ( ) ,
439
+ hir:: Term :: Const ( ct) => ty:: Const :: from_anon_const ( tcx, ct. def_id ) . into ( ) ,
440
+ } ;
441
+
442
+ // FIXME(fmease): This doesn't check actually seem to work for assoc consts.
443
+ // We want to deny escaping late-bound vars in general anyways for assoc consts.
444
+ // If the diagnostic *is* reachable, update it (“type” → “term” or similar).
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
+ let late_bound_in_projection_ty =
454
+ tcx. collect_constrained_late_bound_regions ( & projection_ty) ;
455
+ let late_bound_in_term =
456
+ tcx. collect_referenced_late_bound_regions ( & trait_ref. rebind ( term) ) ;
457
+ debug ! ( ?late_bound_in_projection_ty) ;
458
+ debug ! ( ?late_bound_in_term) ;
459
+
460
+ // FIXME: point at the type params that don't have appropriate lifetimes:
461
+ // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
462
+ // ---- ---- ^^^^^^^
463
+ self . validate_late_bound_regions (
464
+ late_bound_in_projection_ty,
465
+ late_bound_in_term,
466
+ |br_name| {
467
+ struct_span_err ! (
468
+ tcx. dcx( ) ,
469
+ binding. span,
470
+ E0582 ,
471
+ "binding for associated type `{}` references {}, \
472
+ which does not appear in the trait input types",
473
+ binding. ident,
474
+ br_name
475
+ )
476
+ } ,
477
+ ) ;
478
+ }
479
+
480
480
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
481
481
// the "projection predicate" for:
482
482
//
483
483
// `<T as Iterator>::Item = u32`
484
484
bounds. push_projection_bound (
485
485
tcx,
486
- projection_ty. map_bound ( |projection_ty| ty:: ProjectionPredicate {
487
- projection_ty,
488
- term : term. node ,
489
- } ) ,
486
+ projection_ty
487
+ . map_bound ( |projection_ty| ty:: ProjectionPredicate { projection_ty, term } ) ,
490
488
binding. span ,
491
489
) ;
492
490
}
493
- ConvertedBindingKind :: Constraint ( ast_bounds) => {
491
+ hir :: TypeBindingKind :: Constraint { bounds : ast_bounds } => {
494
492
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
495
493
//
496
494
// `<T as Iterator>::Item: Debug`
0 commit comments