Rollup merge of #120252 - lcnr:rename-astconv-ty, r=compiler-errors

rename `RawTy` to `LoweredTy`

I believe this name to more closely match its purpose

r? ``@compiler-errors``
This commit is contained in:
León Orell Valerian Liehr 2024-01-23 21:19:55 +01:00 committed by GitHub
commit 0c769cc8ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 23 deletions

View File

@ -2,7 +2,7 @@ use crate::callee::{self, DeferredCallResolution};
use crate::errors::CtorIsPrivate; use crate::errors::CtorIsPrivate;
use crate::method::{self, MethodCallee, SelfSource}; use crate::method::{self, MethodCallee, SelfSource};
use crate::rvalue_scopes; use crate::rvalue_scopes;
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, RawTy}; use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan, StashKey}; use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan, StashKey};
@ -373,14 +373,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn handle_raw_ty(&self, span: Span, ty: Ty<'tcx>) -> RawTy<'tcx> { pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
RawTy { raw: ty, normalized: self.normalize(span, ty) }
}
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> RawTy<'tcx> {
let t = self.astconv().ast_ty_to_ty(ast_t); let t = self.astconv().ast_ty_to_ty(ast_t);
self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None)); self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None));
self.handle_raw_ty(ast_t.span, t) LoweredTy::from_raw(self, ast_t.span, t)
} }
pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
@ -396,7 +392,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty.normalized ty.normalized
} }
pub(super) fn user_args_for_adt(ty: RawTy<'tcx>) -> UserArgs<'tcx> { pub(super) fn user_args_for_adt(ty: LoweredTy<'tcx>) -> UserArgs<'tcx> {
match (ty.raw.kind(), ty.normalized.kind()) { match (ty.raw.kind(), ty.normalized.kind()) {
(ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None }, (ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
(_, ty::Adt(adt, args)) => UserArgs { (_, ty::Adt(adt, args)) => UserArgs {
@ -801,7 +797,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir_id: hir::HirId, hir_id: hir::HirId,
span: Span, span: Span,
args: Option<&'tcx [hir::Expr<'tcx>]>, args: Option<&'tcx [hir::Expr<'tcx>]>,
) -> (Res, Option<RawTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) { ) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
debug!( debug!(
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}", "resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
qpath, hir_id, span qpath, hir_id, span
@ -825,7 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We manually call `register_wf_obligation` in the success path // We manually call `register_wf_obligation` in the success path
// below. // below.
let ty = self.astconv().ast_ty_to_ty_in_path(qself); let ty = self.astconv().ast_ty_to_ty_in_path(qself);
(self.handle_raw_ty(span, ty), qself, segment) (LoweredTy::from_raw(self, span, ty), qself, segment)
} }
QPath::LangItem(..) => { QPath::LangItem(..) => {
bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`") bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`")
@ -1074,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn instantiate_value_path( pub fn instantiate_value_path(
&self, &self,
segments: &'tcx [hir::PathSegment<'tcx>], segments: &'tcx [hir::PathSegment<'tcx>],
self_ty: Option<RawTy<'tcx>>, self_ty: Option<LoweredTy<'tcx>>,
res: Res, res: Res,
span: Span, span: Span,
hir_id: hir::HirId, hir_id: hir::HirId,
@ -1201,8 +1197,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self); path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self);
let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res { let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res {
let ty = let ty = LoweredTy::from_raw(
self.handle_raw_ty(span, tcx.at(span).type_of(impl_def_id).instantiate_identity()); self,
span,
tcx.at(span).type_of(impl_def_id).instantiate_identity(),
);
match ty.normalized.ty_adt_def() { match ty.normalized.ty_adt_def() {
Some(adt_def) if adt_def.has_ctor() => { Some(adt_def) if adt_def.has_ctor() => {
let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap(); let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();

View File

@ -6,7 +6,7 @@ use crate::method::MethodCallee;
use crate::TupleArgumentsFlag::*; use crate::TupleArgumentsFlag::*;
use crate::{errors, Expectation::*}; use crate::{errors, Expectation::*};
use crate::{ use crate::{
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy, Needs,
TupleArgumentsFlag, TupleArgumentsFlag,
}; };
use itertools::Itertools; use itertools::Itertools;
@ -1792,12 +1792,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath: &QPath<'tcx>, qpath: &QPath<'tcx>,
path_span: Span, path_span: Span,
hir_id: hir::HirId, hir_id: hir::HirId,
) -> (Res, RawTy<'tcx>) { ) -> (Res, LoweredTy<'tcx>) {
match *qpath { match *qpath {
QPath::Resolved(ref maybe_qself, path) => { QPath::Resolved(ref maybe_qself, path) => {
let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw); let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw);
let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true); let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true);
(path.res, self.handle_raw_ty(path_span, ty)) (path.res, LoweredTy::from_raw(self, path_span, ty))
} }
QPath::TypeRelative(qself, segment) => { QPath::TypeRelative(qself, segment) => {
let ty = self.to_ty(qself); let ty = self.to_ty(qself);
@ -1808,7 +1808,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = result let ty = result
.map(|(ty, _, _)| ty) .map(|(ty, _, _)| ty)
.unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar)); .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
let ty = self.handle_raw_ty(path_span, ty); let ty = LoweredTy::from_raw(self, path_span, ty);
let result = result.map(|(_, kind, def_id)| (kind, def_id)); let result = result.map(|(_, kind, def_id)| (kind, def_id));
// Write back the new resolution. // Write back the new resolution.
@ -1818,7 +1818,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
QPath::LangItem(lang_item, span) => { QPath::LangItem(lang_item, span) => {
let (res, ty) = self.resolve_lang_item_path(lang_item, span, hir_id); let (res, ty) = self.resolve_lang_item_path(lang_item, span, hir_id);
(res, self.handle_raw_ty(path_span, ty)) (res, LoweredTy::from_raw(self, path_span, ty))
} }
} }
} }

View File

@ -353,14 +353,22 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
} }
} }
/// Represents a user-provided type in the raw form (never normalized). /// The `ty` representation of a user-provided type. Depending on the use-site
/// we want to either use the unnormalized or the normalized form of this type.
/// ///
/// This is a bridge between the interface of `AstConv`, which outputs a raw `Ty`, /// This is a bridge between the interface of `AstConv`, which outputs a raw `Ty`,
/// and the API in this module, which expect `Ty` to be fully normalized. /// and the API in this module, which expect `Ty` to be fully normalized.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct RawTy<'tcx> { pub struct LoweredTy<'tcx> {
/// The unnormalized type provided by the user.
pub raw: Ty<'tcx>, pub raw: Ty<'tcx>,
/// The normalized form of `raw`, stored here for efficiency. /// The normalized form of `raw`, stored here for efficiency.
pub normalized: Ty<'tcx>, pub normalized: Ty<'tcx>,
} }
impl<'tcx> LoweredTy<'tcx> {
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
LoweredTy { raw, normalized: fcx.normalize(span, raw) }
}
}

View File

@ -49,7 +49,7 @@ use crate::check::check_fn;
use crate::coercion::DynamicCoerceMany; use crate::coercion::DynamicCoerceMany;
use crate::diverges::Diverges; use crate::diverges::Diverges;
use crate::expectation::Expectation; use crate::expectation::Expectation;
use crate::fn_ctxt::RawTy; use crate::fn_ctxt::LoweredTy;
use crate::gather_locals::GatherLocalsVisitor; use crate::gather_locals::GatherLocalsVisitor;
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_errors::{struct_span_code_err, ErrorGuaranteed}; use rustc_errors::{struct_span_code_err, ErrorGuaranteed};

View File

@ -1,5 +1,5 @@
use crate::gather_locals::DeclOrigin; use crate::gather_locals::DeclOrigin;
use crate::{errors, FnCtxt, RawTy}; use crate::{errors, FnCtxt, LoweredTy};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{ use rustc_errors::{
@ -891,7 +891,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
pat: &Pat<'tcx>, pat: &Pat<'tcx>,
qpath: &hir::QPath<'_>, qpath: &hir::QPath<'_>,
path_resolution: (Res, Option<RawTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]), path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
expected: Ty<'tcx>, expected: Ty<'tcx>,
ti: TopInfo<'tcx>, ti: TopInfo<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {