@@ -29,7 +29,7 @@ use rustc_errors::{
29
29
Applicability , Diag , DiagCtxtHandle , ErrorGuaranteed , FatalError , struct_span_code_err,
30
30
} ;
31
31
use rustc_hir as hir;
32
- use rustc_hir:: def:: { CtorOf , DefKind , Namespace , Res } ;
32
+ use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Namespace , Res } ;
33
33
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
34
34
use rustc_hir:: { GenericArg , GenericArgs , HirId } ;
35
35
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -2032,12 +2032,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2032
2032
qpath. span ( ) ,
2033
2033
"fn's cannot be used as const args" ,
2034
2034
) ,
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)
2039
2050
}
2051
+
2040
2052
// 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
+ // }
2041
2060
_ => ty:: Const :: new_error_with_message (
2042
2061
tcx,
2043
2062
qpath. span ( ) ,
@@ -2046,6 +2065,44 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2046
2065
}
2047
2066
}
2048
2067
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
+
2049
2106
/// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
2050
2107
/// FIXME: dedup with lower_const_param
2051
2108
fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
0 commit comments