@@ -52,7 +52,7 @@ use rustc_data_structures::sorted_map::SortedMap;
5252use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5353use rustc_data_structures:: sync:: Lrc ;
5454use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
55- use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
55+ use rustc_hir:: def:: { CtorKind , DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5656use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId , LocalDefIdMap } ;
5757use rustc_hir:: {
5858 self as hir, ConstArg , GenericArg , HirId , ItemLocalMap , LangItem , MissingLifetimeKind ,
@@ -2298,19 +2298,60 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22982298 ty_id : NodeId ,
22992299 span : Span ,
23002300 ) -> & ' hir hir:: ConstArg < ' hir > {
2301- let qpath = self . lower_qpath (
2302- ty_id,
2303- & None ,
2304- path,
2305- ParamMode :: Optional ,
2306- AllowReturnTypeNotation :: No ,
2307- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
2308- None ,
2309- ) ;
2301+ let ct_kind = match res {
2302+ // FIXME(min_generic_const_args): only allow one-segment const paths for now
2303+ Res :: Def (
2304+ DefKind :: ConstParam | DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) ,
2305+ _,
2306+ ) if path. is_potential_trivial_const_arg ( ) => {
2307+ let qpath = self . lower_qpath (
2308+ ty_id,
2309+ & None ,
2310+ path,
2311+ ParamMode :: Optional ,
2312+ AllowReturnTypeNotation :: No ,
2313+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
2314+ None ,
2315+ ) ;
2316+ hir:: ConstArgKind :: Path ( qpath)
2317+ }
2318+ _ => {
2319+ // Construct an AnonConst where the expr is the "ty"'s path.
2320+
2321+ let parent_def_id = self . current_def_id_parent ;
2322+ let node_id = self . next_node_id ( ) ;
2323+ let span = self . lower_span ( span) ;
2324+
2325+ // Add a definition for the in-band const def.
2326+ let def_id =
2327+ self . create_def ( parent_def_id, node_id, kw:: Empty , DefKind :: AnonConst , span) ;
2328+ let hir_id = self . lower_node_id ( node_id) ;
2329+
2330+ let path_expr = Expr {
2331+ id : ty_id,
2332+ kind : ExprKind :: Path ( None , path. clone ( ) ) ,
2333+ span,
2334+ attrs : AttrVec :: new ( ) ,
2335+ tokens : None ,
2336+ } ;
2337+
2338+ let ct = self . with_new_scopes ( span, |this| {
2339+ self . arena . alloc ( hir:: AnonConst {
2340+ def_id,
2341+ hir_id,
2342+ body : this. with_def_id_parent ( def_id, |this| {
2343+ this. lower_const_body ( path_expr. span , Some ( & path_expr) )
2344+ } ) ,
2345+ span,
2346+ } )
2347+ } ) ;
2348+ hir:: ConstArgKind :: Anon ( ct)
2349+ }
2350+ } ;
23102351
23112352 self . arena . alloc ( hir:: ConstArg {
23122353 hir_id : self . next_id ( ) ,
2313- kind : hir :: ConstArgKind :: Path ( qpath ) ,
2354+ kind : ct_kind ,
23142355 is_desugared_from_effects : false ,
23152356 } )
23162357 }
@@ -2334,7 +2375,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23342375 } else {
23352376 & anon. value
23362377 } ;
2337- if let ExprKind :: Path ( qself, path) = & expr. kind {
2378+ let maybe_res =
2379+ self . resolver . get_partial_res ( expr. id ) . and_then ( |partial_res| partial_res. full_res ( ) ) ;
2380+ debug ! ( "res={:?}" , maybe_res) ;
2381+ // FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
2382+ if let Some ( res) = maybe_res
2383+ && let ExprKind :: Path ( qself, path) = & expr. kind
2384+ && let Res :: Def ( DefKind :: ConstParam , _) = res
2385+ // FIXME(min_generic_const_args): only allow one-segment const paths for now
2386+ && let Res :: Def (
2387+ DefKind :: ConstParam | DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) ,
2388+ _,
2389+ ) = res
2390+ && path. is_potential_trivial_const_arg ( )
2391+ {
23382392 let qpath = self . lower_qpath (
23392393 expr. id ,
23402394 qself,
0 commit comments