@@ -29,7 +29,7 @@ use rustc_errors::{
2929 Applicability , Diag , DiagCtxtHandle , ErrorGuaranteed , FatalError , struct_span_code_err,
3030} ;
3131use rustc_hir as hir;
32- use rustc_hir:: def:: { CtorOf , DefKind , Namespace , Res } ;
32+ use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Namespace , Res } ;
3333use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3434use rustc_hir:: { GenericArg , GenericArgs , HirId } ;
3535use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -2032,12 +2032,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20322032 qpath. span ( ) ,
20332033 "fn's cannot be used as const args" ,
20342034 ) ,
2035- hir:: QPath :: Resolved ( _, path @ & hir:: Path { res : Res :: Def ( _, did) , .. } ) => {
2036- let ( item_segment, _) = path. segments . split_last ( ) . unwrap ( ) ;
2037- let args = self . lower_generic_args_of_path_segment ( path. span , did, item_segment) ;
2038- ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2035+ // hir::QPath::Resolved(_, path @ &hir::Path { res: Res::Def(_, did), .. }) => {
2036+ // let (item_segment, _) = path.segments.split_last().unwrap();
2037+ // let args = self.lower_generic_args_of_path_segment(path.span, did, item_segment);
2038+ // ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
2039+ // }
2040+ // // TODO: type-relative paths
2041+ // _ => ty::Const::new_error_with_message(
2042+ // tcx,
2043+ // qpath.span(),
2044+ // "Const::lower_const_arg_path: invalid qpath",
2045+ // ),
2046+ hir:: QPath :: Resolved ( maybe_qself, path) => {
2047+ debug ! ( ?maybe_qself, ?path) ;
2048+ let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
2049+ self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
20392050 }
2051+
20402052 // TODO: type-relative paths
2053+ // hir::QPath::TypeRelative(qself, segment) => {
2054+ // debug!(?qself, ?segment);
2055+ // let ty = self.lower_ty(qself);
2056+ // self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
2057+ // .map(|(ty, _, _)| ty)
2058+ // .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
2059+ // }
20412060 _ => ty:: Const :: new_error_with_message (
20422061 tcx,
20432062 qpath. span ( ) ,
@@ -2046,6 +2065,44 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20462065 }
20472066 }
20482067
2068+ fn lower_const_path_resolved (
2069+ & self ,
2070+ opt_self_ty : Option < Ty < ' tcx > > ,
2071+ path : & hir:: Path < ' tcx > ,
2072+ hir_id : HirId ,
2073+ ) -> Const < ' tcx > {
2074+ let tcx = self . tcx ( ) ;
2075+ let span = path. span ;
2076+ match path. res {
2077+ Res :: Def ( DefKind :: ConstParam , def_id) => {
2078+ assert_eq ! ( opt_self_ty, None ) ;
2079+ let _ = self . prohibit_generic_args (
2080+ path. segments . iter ( ) ,
2081+ GenericsArgsErrExtend :: Param ( def_id) ,
2082+ ) ;
2083+ self . lower_const_arg_param ( def_id, hir_id)
2084+ }
2085+ Res :: Def ( DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) , did) => {
2086+ assert_eq ! ( opt_self_ty, None ) ;
2087+ let _ = self . prohibit_generic_args (
2088+ path. segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) ,
2089+ GenericsArgsErrExtend :: None ,
2090+ ) ;
2091+ let args = self . lower_generic_args_of_path_segment (
2092+ span,
2093+ did,
2094+ path. segments . last ( ) . unwrap ( ) ,
2095+ ) ;
2096+ ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
2097+ }
2098+ // TODO: DefKind::AssocConst?
2099+ _ => Const :: new_error (
2100+ tcx,
2101+ tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
2102+ ) ,
2103+ }
2104+ }
2105+
20492106 /// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
20502107 /// FIXME: dedup with lower_const_param
20512108 fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
0 commit comments