@@ -1373,50 +1373,37 @@ impl<'hir> LoweringContext<'_, 'hir> {
1373
1373
itctx : ImplTraitContext < ' _ , ' hir > ,
1374
1374
) -> GenericsCtor < ' hir > {
1375
1375
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
1376
- // FIXME: this could probably be done with less rightward drift. It also looks like two
1377
- // control paths where `report_error` is called are the only paths that advance to after the
1378
- // match statement, so the error reporting could probably just be moved there.
1379
1376
let mut add_bounds: NodeMap < Vec < _ > > = Default :: default ( ) ;
1380
1377
for pred in & generics. where_clause . predicates {
1381
1378
if let WherePredicate :: BoundPredicate ( ref bound_pred) = * pred {
1382
1379
' next_bound: for bound in & bound_pred. bounds {
1383
1380
if let GenericBound :: Trait ( _, TraitBoundModifier :: Maybe ) = * bound {
1384
- let report_error = |this : & mut Self | {
1385
- this. diagnostic ( ) . span_err (
1386
- bound_pred. bounded_ty . span ,
1387
- "`?Trait` bounds are only permitted at the \
1388
- point where a type parameter is declared",
1389
- ) ;
1390
- } ;
1391
1381
// Check if the where clause type is a plain type parameter.
1392
- match bound_pred. bounded_ty . kind {
1393
- TyKind :: Path ( None , ref path)
1394
- if path. segments . len ( ) == 1
1395
- && bound_pred. bound_generic_params . is_empty ( ) =>
1396
- {
1397
- if let Some ( Res :: Def ( DefKind :: TyParam , def_id) ) = self
1398
- . resolver
1399
- . get_partial_res ( bound_pred. bounded_ty . id )
1400
- . map ( |d| d. base_res ( ) )
1382
+ match self
1383
+ . resolver
1384
+ . get_partial_res ( bound_pred. bounded_ty . id )
1385
+ . map ( |d| ( d. base_res ( ) , d. unresolved_segments ( ) ) )
1386
+ {
1387
+ Some ( ( Res :: Def ( DefKind :: TyParam , def_id) , 0 ) )
1388
+ if bound_pred. bound_generic_params . is_empty ( ) =>
1401
1389
{
1402
- if let Some ( def_id) = def_id. as_local ( ) {
1403
- for param in & generics. params {
1404
- if let GenericParamKind :: Type { .. } = param. kind {
1405
- if def_id == self . resolver . local_def_id ( param. id ) {
1406
- add_bounds
1407
- . entry ( param. id )
1408
- . or_default ( )
1409
- . push ( bound. clone ( ) ) ;
1410
- continue ' next_bound;
1411
- }
1412
- }
1390
+ for param in & generics. params {
1391
+ if def_id == self . resolver . local_def_id ( param. id ) . to_def_id ( ) {
1392
+ add_bounds
1393
+ . entry ( param. id )
1394
+ . or_default ( )
1395
+ . push ( bound. clone ( ) ) ;
1396
+ continue ' next_bound;
1413
1397
}
1414
1398
}
1415
1399
}
1416
- report_error ( self )
1417
- }
1418
- _ => report_error ( self ) ,
1400
+ _ => { }
1419
1401
}
1402
+ self . diagnostic ( ) . span_err (
1403
+ bound_pred. bounded_ty . span ,
1404
+ "`?Trait` bounds are only permitted at the \
1405
+ point where a type parameter is declared",
1406
+ ) ;
1420
1407
}
1421
1408
}
1422
1409
}
0 commit comments