@@ -2076,38 +2076,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20762076 tcx. feed_anon_const_type ( anon. def_id , tcx. type_of ( param_def_id) ) ;
20772077 }
20782078
2079+ let hir_id = const_arg. hir_id ;
20792080 match const_arg. kind {
2080- hir:: ConstArgKind :: Path ( qpath) => self . lower_const_arg_path ( qpath, const_arg. hir_id ) ,
2081- hir:: ConstArgKind :: Anon ( anon) => Const :: from_anon_const ( tcx, anon. def_id ) ,
2082- }
2083- }
2084-
2085- /// Lower a const path to a [`Const`].
2086- fn lower_const_arg_path ( & self , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Const < ' tcx > {
2087- let tcx = self . tcx ( ) ;
2088-
2089- match qpath {
2090- hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , did) , .. } ) => {
2091- self . lower_const_param ( did, hir_id)
2092- }
2093- hir:: QPath :: Resolved (
2094- _,
2095- & hir:: Path { res : Res :: Def ( DefKind :: Fn | DefKind :: AssocFn , _) , .. } ,
2096- ) => ty:: Const :: new_error_with_message (
2097- tcx,
2098- qpath. span ( ) ,
2099- "fn's cannot be used as const args" ,
2100- ) ,
2101- hir:: QPath :: Resolved ( maybe_qself, path) => {
2081+ hir:: ConstArgKind :: Path ( hir:: QPath :: Resolved ( maybe_qself, path) ) => {
21022082 debug ! ( ?maybe_qself, ?path) ;
21032083 let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
21042084 self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
21052085 }
2106- _ => ty:: Const :: new_error_with_message (
2086+ hir :: ConstArgKind :: Path ( qpath ) => ty:: Const :: new_error_with_message (
21072087 tcx,
21082088 qpath. span ( ) ,
2109- format ! ( "Const::lower_const_arg_path : invalid qpath {qpath:?}" ) ,
2089+ format ! ( "Const::lower_const_arg : invalid qpath {qpath:?}" ) ,
21102090 ) ,
2091+ hir:: ConstArgKind :: Anon ( anon) => Const :: from_anon_const ( tcx, anon. def_id ) ,
21112092 }
21122093 }
21132094
@@ -2141,7 +2122,53 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21412122 ) ;
21422123 ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
21432124 }
2144- _ => Const :: new_error (
2125+ Res :: Def ( DefKind :: Fn | DefKind :: AssocFn , _) => ty:: Const :: new_error_with_message (
2126+ tcx,
2127+ span,
2128+ "fn items cannot be used as const args" ,
2129+ ) ,
2130+
2131+ // Exhaustive match to be clear about what exactly we're considering to be
2132+ // an invalid Res for a const path.
2133+ Res :: Def (
2134+ DefKind :: Mod
2135+ | DefKind :: Static { .. }
2136+ | DefKind :: Enum
2137+ | DefKind :: Variant
2138+ | DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Fn )
2139+ | DefKind :: Struct
2140+ | DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn )
2141+ | DefKind :: OpaqueTy
2142+ | DefKind :: TyAlias
2143+ | DefKind :: TraitAlias
2144+ | DefKind :: AssocTy
2145+ | DefKind :: Union
2146+ | DefKind :: Trait
2147+ | DefKind :: ForeignTy
2148+ | DefKind :: AssocConst
2149+ | DefKind :: TyParam
2150+ | DefKind :: Macro ( _)
2151+ | DefKind :: LifetimeParam
2152+ | DefKind :: Use
2153+ | DefKind :: ForeignMod
2154+ | DefKind :: AnonConst
2155+ | DefKind :: InlineConst
2156+ | DefKind :: Field
2157+ | DefKind :: Impl { .. }
2158+ | DefKind :: Closure
2159+ | DefKind :: ExternCrate
2160+ | DefKind :: GlobalAsm
2161+ | DefKind :: SyntheticCoroutineBody ,
2162+ _,
2163+ )
2164+ | Res :: PrimTy ( _)
2165+ | Res :: SelfTyParam { .. }
2166+ | Res :: SelfTyAlias { .. }
2167+ | Res :: SelfCtor ( _)
2168+ | Res :: Local ( _)
2169+ | Res :: ToolMod
2170+ | Res :: NonMacroAttr ( _)
2171+ | Res :: Err => Const :: new_error (
21452172 tcx,
21462173 tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
21472174 ) ,
0 commit comments