@@ -49,7 +49,7 @@ use rustc_data_structures::sorted_map::SortedMap;
4949use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5050use rustc_data_structures:: sync:: Lrc ;
5151use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
52- use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
52+ use rustc_hir:: def:: { CtorKind , DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5353use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
5454use rustc_hir:: {
5555 self as hir, ConstArg , GenericArg , HirId , ItemLocalMap , LangItem , ParamName , TraitCandidate ,
@@ -2060,19 +2060,60 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20602060 ty_id : NodeId ,
20612061 span : Span ,
20622062 ) -> & ' hir hir:: ConstArg < ' hir > {
2063- let qpath = self . lower_qpath (
2064- ty_id,
2065- & None ,
2066- path,
2067- ParamMode :: Optional ,
2068- AllowReturnTypeNotation :: No ,
2069- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
2070- None ,
2071- ) ;
2063+ let ct_kind = match res {
2064+ // FIXME(min_generic_const_args): only allow one-segment const paths for now
2065+ Res :: Def (
2066+ DefKind :: ConstParam | DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) ,
2067+ _,
2068+ ) if path. is_potential_trivial_const_arg ( ) => {
2069+ let qpath = self . lower_qpath (
2070+ ty_id,
2071+ & None ,
2072+ path,
2073+ ParamMode :: Optional ,
2074+ AllowReturnTypeNotation :: No ,
2075+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
2076+ None ,
2077+ ) ;
2078+ hir:: ConstArgKind :: Path ( qpath)
2079+ }
2080+ _ => {
2081+ // Construct an AnonConst where the expr is the "ty"'s path.
2082+
2083+ let parent_def_id = self . current_def_id_parent ;
2084+ let node_id = self . next_node_id ( ) ;
2085+ let span = self . lower_span ( span) ;
2086+
2087+ // Add a definition for the in-band const def.
2088+ let def_id =
2089+ self . create_def ( parent_def_id, node_id, kw:: Empty , DefKind :: AnonConst , span) ;
2090+ let hir_id = self . lower_node_id ( node_id) ;
2091+
2092+ let path_expr = Expr {
2093+ id : ty_id,
2094+ kind : ExprKind :: Path ( None , path. clone ( ) ) ,
2095+ span,
2096+ attrs : AttrVec :: new ( ) ,
2097+ tokens : None ,
2098+ } ;
2099+
2100+ let ct = self . with_new_scopes ( span, |this| {
2101+ self . arena . alloc ( hir:: AnonConst {
2102+ def_id,
2103+ hir_id,
2104+ body : this. with_def_id_parent ( def_id, |this| {
2105+ this. lower_const_body ( path_expr. span , Some ( & path_expr) )
2106+ } ) ,
2107+ span,
2108+ } )
2109+ } ) ;
2110+ hir:: ConstArgKind :: Anon ( ct)
2111+ }
2112+ } ;
20722113
20732114 self . arena . alloc ( hir:: ConstArg {
20742115 hir_id : self . next_id ( ) ,
2075- kind : hir :: ConstArgKind :: Path ( qpath ) ,
2116+ kind : ct_kind ,
20762117 is_desugared_from_effects : false ,
20772118 } )
20782119 }
@@ -2096,7 +2137,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20962137 } else {
20972138 & anon. value
20982139 } ;
2099- if let ExprKind :: Path ( qself, path) = & expr. kind {
2140+ let maybe_res =
2141+ self . resolver . get_partial_res ( expr. id ) . and_then ( |partial_res| partial_res. full_res ( ) ) ;
2142+ debug ! ( "res={:?}" , maybe_res) ;
2143+ // FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
2144+ if let Some ( res) = maybe_res
2145+ && let ExprKind :: Path ( qself, path) = & expr. kind
2146+ && let Res :: Def ( DefKind :: ConstParam , _) = res
2147+ // FIXME(min_generic_const_args): only allow one-segment const paths for now
2148+ && let Res :: Def (
2149+ DefKind :: ConstParam | DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) ,
2150+ _,
2151+ ) = res
2152+ && path. is_potential_trivial_const_arg ( )
2153+ {
21002154 let qpath = self . lower_qpath (
21012155 expr. id ,
21022156 qself,
0 commit comments