@@ -1372,37 +1372,48 @@ impl<'hir> LoweringContext<'_, 'hir> {
1372
1372
generics : & Generics ,
1373
1373
itctx : ImplTraitContext < ' _ , ' hir > ,
1374
1374
) -> GenericsCtor < ' hir > {
1375
- // Collect `?Trait` bounds in where clause and move them to parameter definitions.
1375
+ // Collect `?Trait` bounds in where clause and move them to parameter
1376
+ // definitions. Currently, the decision to add the predicate for the
1377
+ // implicit `Sized` bound only examines the generic parameters, not the
1378
+ // where clauses, to discover any `?Sized` bounds. (e.g.,
1379
+ // `AstConv::is_unsized`)
1376
1380
let mut add_bounds: NodeMap < Vec < _ > > = Default :: default ( ) ;
1377
1381
for pred in & generics. where_clause . predicates {
1378
- if let WherePredicate :: BoundPredicate ( ref bound_pred) = * pred {
1379
- ' next_bound: for bound in & bound_pred. bounds {
1380
- if let GenericBound :: Trait ( _, TraitBoundModifier :: Maybe ) = * bound {
1381
- // Check if the where clause type is a plain type parameter.
1382
- match self
1383
- . resolver
1384
- . get_partial_res ( bound_pred. bounded_ty . id )
1385
- . map ( |d| ( d. base_res ( ) , d. unresolved_segments ( ) ) )
1382
+ let bound_pred = match * pred {
1383
+ WherePredicate :: BoundPredicate ( ref bound_pred) => bound_pred,
1384
+ _ => continue ,
1385
+ } ;
1386
+ for bound in & bound_pred. bounds {
1387
+ if !matches ! ( * bound, GenericBound :: Trait ( _, TraitBoundModifier :: Maybe ) ) {
1388
+ continue ;
1389
+ }
1390
+ // Check if the where clause type is a plain type parameter.
1391
+ match self
1392
+ . resolver
1393
+ . get_partial_res ( bound_pred. bounded_ty . id )
1394
+ . map ( |d| ( d. base_res ( ) , d. unresolved_segments ( ) ) )
1395
+ {
1396
+ Some ( ( Res :: Def ( DefKind :: TyParam , def_id) , 0 ) )
1397
+ if bound_pred. bound_generic_params . is_empty ( ) =>
1398
+ {
1399
+ if let Some ( param) = generics
1400
+ . params
1401
+ . iter ( )
1402
+ . find ( |p| def_id == self . resolver . local_def_id ( p. id ) . to_def_id ( ) )
1386
1403
{
1387
- Some ( ( Res :: Def ( DefKind :: TyParam , def_id) , 0 ) )
1388
- if bound_pred. bound_generic_params . is_empty ( ) =>
1389
- {
1390
- for param in & generics. params {
1391
- if def_id == self . resolver . local_def_id ( param. id ) . to_def_id ( ) {
1392
- add_bounds. entry ( param. id ) . or_default ( ) . push ( bound. clone ( ) ) ;
1393
- continue ' next_bound;
1394
- }
1395
- }
1396
- }
1397
- _ => { }
1404
+ add_bounds. entry ( param. id ) . or_default ( ) . push ( bound. clone ( ) ) ;
1405
+ continue ;
1398
1406
}
1399
- self . diagnostic ( ) . span_err (
1400
- bound_pred. bounded_ty . span ,
1401
- "`?Trait` bounds are only permitted at the \
1402
- point where a type parameter is declared",
1403
- ) ;
1404
1407
}
1408
+ _ => { }
1405
1409
}
1410
+ // Either the `bounded_ty` is not a plain type parameter, or
1411
+ // it's not found in the generic type parameters list.
1412
+ self . diagnostic ( ) . span_err (
1413
+ bound_pred. bounded_ty . span ,
1414
+ "`?Trait` bounds are only permitted at the \
1415
+ point where a type parameter is declared",
1416
+ ) ;
1406
1417
}
1407
1418
}
1408
1419
0 commit comments