X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Finherited.rs;h=9d9c77ec072b855c37dbfd5ddd17d8b66ad208ef;hb=7106f8d8ee2574c4fbd9b89e76bc1d177e867876;hp=fb7beae70ba1ea4075a7f83cba657ea4fadc1eb6;hpb=f92a0c8031339b1913e8ca89b1a9311c129c1091;p=rust.git diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index fb7beae70ba..9d9c77ec072 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -52,6 +52,9 @@ pub struct Inherited<'a, 'tcx> { pub(super) deferred_generator_interiors: RefCell, hir::GeneratorKind)>>, + /// Reports whether this is in a const context. + pub(super) constness: hir::Constness, + pub(super) body_id: Option, } @@ -93,6 +96,16 @@ pub fn enter(&mut self, f: F) -> R impl Inherited<'a, 'tcx> { pub(super) fn new(infcx: InferCtxt<'a, 'tcx>, def_id: LocalDefId) -> Self { + let tcx = infcx.tcx; + let item_id = tcx.hir().local_def_id_to_hir_id(def_id); + Self::with_constness(infcx, def_id, tcx.hir().get(item_id).constness()) + } + + pub(super) fn with_constness( + infcx: InferCtxt<'a, 'tcx>, + def_id: LocalDefId, + constness: hir::Constness, + ) -> Self { let tcx = infcx.tcx; let item_id = tcx.hir().local_def_id_to_hir_id(def_id); let body_id = tcx.hir().maybe_body_owned_by(item_id); @@ -108,6 +121,7 @@ pub(super) fn new(infcx: InferCtxt<'a, 'tcx>, def_id: LocalDefId) -> Self { deferred_call_resolutions: RefCell::new(Default::default()), deferred_cast_checks: RefCell::new(Vec::new()), deferred_generator_interiors: RefCell::new(Vec::new()), + constness, body_id, } }