@@ -30,7 +30,7 @@ use rustc_errors::{
3030 Applicability , Diag , DiagCtxtHandle , ErrorGuaranteed , FatalError , struct_span_code_err,
3131} ;
3232use rustc_hir as hir;
33- use rustc_hir:: def:: { CtorOf , DefKind , Namespace , Res } ;
33+ use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Namespace , Res } ;
3434use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3535use rustc_hir:: { GenericArg , GenericArgs , HirId } ;
3636use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -2076,12 +2076,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20762076 qpath. span ( ) ,
20772077 "fn's cannot be used as const args" ,
20782078 ) ,
2079- hir:: QPath :: Resolved ( _, path @ & hir:: Path { res : Res :: Def ( _, did) , .. } ) => {
2080- let ( item_segment, _) = path. segments . split_last ( ) . unwrap ( ) ;
2081- let args = self . lower_generic_args_of_path_segment ( path. span , did, item_segment) ;
2082- ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2079+ // hir::QPath::Resolved(_, path @ &hir::Path { res: Res::Def(_, did), .. }) => {
2080+ // let (item_segment, _) = path.segments.split_last().unwrap();
2081+ // let args = self.lower_generic_args_of_path_segment(path.span, did, item_segment);
2082+ // ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
2083+ // }
2084+ // // TODO: type-relative paths
2085+ // _ => ty::Const::new_error_with_message(
2086+ // tcx,
2087+ // qpath.span(),
2088+ // "Const::lower_const_arg_path: invalid qpath",
2089+ // ),
2090+ hir:: QPath :: Resolved ( maybe_qself, path) => {
2091+ debug ! ( ?maybe_qself, ?path) ;
2092+ let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2093+ self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
20832094 }
2095+
20842096 // TODO: type-relative paths
2097+ // hir::QPath::TypeRelative(qself, segment) => {
2098+ // debug!(?qself, ?segment);
2099+ // let ty = self.lower_ty(qself);
2100+ // self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
2101+ // .map(|(ty, _, _)| ty)
2102+ // .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
2103+ // }
20852104 _ => ty:: Const :: new_error_with_message (
20862105 tcx,
20872106 qpath. span ( ) ,
@@ -2090,6 +2109,44 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20902109 }
20912110 }
20922111
2112+ fn lower_const_path_resolved (
2113+ & self ,
2114+ opt_self_ty : Option < Ty < ' tcx > > ,
2115+ path : & hir:: Path < ' tcx > ,
2116+ hir_id : HirId ,
2117+ ) -> Const < ' tcx > {
2118+ let tcx = self . tcx ( ) ;
2119+ let span = path. span ;
2120+ match path. res {
2121+ Res :: Def ( DefKind :: ConstParam , def_id) => {
2122+ assert_eq ! ( opt_self_ty, None ) ;
2123+ let _ = self . prohibit_generic_args (
2124+ path. segments . iter ( ) ,
2125+ GenericsArgsErrExtend :: Param ( def_id) ,
2126+ ) ;
2127+ self . lower_const_arg_param ( def_id, hir_id)
2128+ }
2129+ Res :: Def ( DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) , did) => {
2130+ assert_eq ! ( opt_self_ty, None ) ;
2131+ let _ = self . prohibit_generic_args (
2132+ path. segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) ,
2133+ GenericsArgsErrExtend :: None ,
2134+ ) ;
2135+ let args = self . lower_generic_args_of_path_segment (
2136+ span,
2137+ did,
2138+ path. segments . last ( ) . unwrap ( ) ,
2139+ ) ;
2140+ ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2141+ }
2142+ // TODO: DefKind::AssocConst?
2143+ _ => Const :: new_error (
2144+ tcx,
2145+ tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
2146+ ) ,
2147+ }
2148+ }
2149+
20932150 /// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
20942151 /// FIXME: dedup with lower_const_param
20952152 fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
0 commit comments