diff options
| author | lcnr <rust@lcnr.de> | 2024-11-15 13:53:31 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2024-11-18 10:38:56 +0100 |
| commit | 9cba14b95bb07a5b31ed1aac2bf4eadd248232da (patch) | |
| tree | 60791c9abdfdc19133ab67c41a6d2872dfce745b /compiler/rustc_lint/src/context.rs | |
| parent | bf6adec108e83c5ddfcbb443a9177203db5eb945 (diff) | |
| download | rust-9cba14b95bb07a5b31ed1aac2bf4eadd248232da.tar.gz rust-9cba14b95bb07a5b31ed1aac2bf4eadd248232da.zip | |
use `TypingEnv` when no `infcx` is available
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
Diffstat (limited to 'compiler/rustc_lint/src/context.rs')
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index aa7ec2659d0..6eec32beab0 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -19,7 +19,7 @@ use rustc_middle::bug; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths}; -use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingMode}; +use rustc_middle::ty::{self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode}; use rustc_session::lint::{ BuiltinLintDiag, FutureIncompatibleInfo, Level, Lint, LintBuffer, LintExpectationId, LintId, }; @@ -708,6 +708,10 @@ impl<'tcx> LateContext<'tcx> { TypingMode::non_body_analysis() } + pub fn typing_env(&self) -> TypingEnv<'tcx> { + TypingEnv { typing_mode: self.typing_mode(), param_env: self.param_env } + } + /// Gets the type-checking results for the current body, /// or `None` if outside a body. pub fn maybe_typeck_results(&self) -> Option<&'tcx ty::TypeckResults<'tcx>> { @@ -906,7 +910,7 @@ impl<'tcx> LateContext<'tcx> { .find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) .and_then(|assoc| { let proj = Ty::new_projection(tcx, assoc.def_id, [self_ty]); - tcx.try_normalize_erasing_regions(self.param_env, proj).ok() + tcx.try_normalize_erasing_regions(self.typing_env(), proj).ok() }) } @@ -1010,10 +1014,10 @@ impl<'tcx> ty::layout::HasTyCtxt<'tcx> for LateContext<'tcx> { } } -impl<'tcx> ty::layout::HasParamEnv<'tcx> for LateContext<'tcx> { +impl<'tcx> ty::layout::HasTypingEnv<'tcx> for LateContext<'tcx> { #[inline] - fn param_env(&self) -> ty::ParamEnv<'tcx> { - self.param_env + fn typing_env(&self) -> ty::TypingEnv<'tcx> { + self.typing_env() } } |
