diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-09 19:32:51 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-03-14 03:10:19 +0000 |
| commit | 0160c60c7883910fbd9eb59dc2b7bad2b5a3e01a (patch) | |
| tree | 81d3c22a9d1a727315178979c42b0c2571bd8524 /compiler/rustc_borrowck/src | |
| parent | cbfdf0b014cb04982a9cbeec1578001001167f6e (diff) | |
| download | rust-0160c60c7883910fbd9eb59dc2b7bad2b5a3e01a.tar.gz rust-0160c60c7883910fbd9eb59dc2b7bad2b5a3e01a.zip | |
Check type of const param correctly in MIR typeck
Diffstat (limited to 'compiler/rustc_borrowck/src')
| -rw-r--r-- | compiler/rustc_borrowck/src/type_check/mod.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/universal_regions.rs | 14 |
2 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d2eb7a52f78..d6a80e22602 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1773,6 +1773,22 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { { span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr); } + } else if let Const::Ty(_, ct) = constant.const_ + && let ty::ConstKind::Param(p) = ct.kind() + { + let body_def_id = self.universal_regions.defining_ty.def_id(); + let const_param = tcx.generics_of(body_def_id).const_param(p, tcx); + self.ascribe_user_type( + constant.const_.ty(), + ty::UserType::new(ty::UserTypeKind::TypeOf( + const_param.def_id, + UserArgs { + args: self.universal_regions.defining_ty.args(), + user_self_ty: None, + }, + )), + locations.span(self.body), + ); } if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() { diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index cfac9b36832..994a5ad32b3 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -184,6 +184,20 @@ impl<'tcx> DefiningTy<'tcx> { | DefiningTy::GlobalAsm(def_id) => def_id, } } + + /// Returns the args of the `DefiningTy`. These are equivalent to the identity + /// substs of the body, but replaced with region vids. + pub(crate) fn args(&self) -> ty::GenericArgsRef<'tcx> { + match *self { + DefiningTy::Closure(_, args) + | DefiningTy::Coroutine(_, args) + | DefiningTy::CoroutineClosure(_, args) + | DefiningTy::FnDef(_, args) + | DefiningTy::Const(_, args) + | DefiningTy::InlineConst(_, args) => args, + DefiningTy::GlobalAsm(_) => ty::List::empty(), + } + } } #[derive(Debug)] |
