@@ -2326,8 +2326,20 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2326
2326
2327
2327
ExprKind :: Call ( ref callee, ref arguments) => {
2328
2328
self . resolve_expr ( callee, Some ( expr) ) ;
2329
- for argument in arguments {
2330
- self . resolve_expr ( argument, None ) ;
2329
+ let const_args = self . legacy_const_generic_args ( callee) . unwrap_or ( Vec :: new ( ) ) ;
2330
+ for ( idx, argument) in arguments. iter ( ) . enumerate ( ) {
2331
+ if const_args. contains ( & idx) {
2332
+ self . with_constant_rib (
2333
+ IsRepeatExpr :: No ,
2334
+ argument. is_potential_trivial_const_param ( ) ,
2335
+ None ,
2336
+ |this| {
2337
+ this. resolve_expr ( argument, None ) ;
2338
+ } ,
2339
+ ) ;
2340
+ } else {
2341
+ self . resolve_expr ( argument, None ) ;
2342
+ }
2331
2343
}
2332
2344
}
2333
2345
ExprKind :: Type ( ref type_expr, ref ty) => {
@@ -2406,6 +2418,42 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2406
2418
Some ( ( ident. name , ns) ) ,
2407
2419
)
2408
2420
}
2421
+
2422
+ /// Checks if an expression refers to a function marked with
2423
+ /// `#[rustc_legacy_const_generics]` and returns the argument index list
2424
+ /// from the attribute.
2425
+ fn legacy_const_generic_args ( & mut self , expr : & Expr ) -> Option < Vec < usize > > {
2426
+ if let ExprKind :: Path ( None , path) = & expr. kind {
2427
+ if path. segments . last ( ) . unwrap ( ) . args . is_some ( ) {
2428
+ return None ;
2429
+ }
2430
+ if let Some ( partial_res) = self . r . get_partial_res ( expr. id ) {
2431
+ if partial_res. unresolved_segments ( ) != 0 {
2432
+ return None ;
2433
+ }
2434
+ if let Res :: Def ( def:: DefKind :: Fn , def_id) = partial_res. base_res ( ) {
2435
+ if def_id. is_local ( ) {
2436
+ return None ;
2437
+ }
2438
+ let attrs = self . r . cstore ( ) . item_attrs ( def_id, self . r . session ) ;
2439
+ let attr = attrs
2440
+ . iter ( )
2441
+ . find ( |a| self . r . session . check_name ( a, sym:: rustc_legacy_const_generics) ) ?;
2442
+ let mut ret = vec ! [ ] ;
2443
+ for meta in attr. meta_item_list ( ) ? {
2444
+ match meta. literal ( ) ?. kind {
2445
+ LitKind :: Int ( a, _) => {
2446
+ ret. push ( a as usize ) ;
2447
+ }
2448
+ _ => panic ! ( "invalid arg index" ) ,
2449
+ }
2450
+ }
2451
+ return Some ( ret) ;
2452
+ }
2453
+ }
2454
+ }
2455
+ None
2456
+ }
2409
2457
}
2410
2458
2411
2459
impl < ' a > Resolver < ' a > {
0 commit comments