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::errors::CtorIsPrivate;
use crate::method::{self, MethodCallee, SelfSource};
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::fx::FxHashSet;
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan, StashKey};
@ -373,14 +373,10 @@ pub fn register_bound(
}
}
pub fn handle_raw_ty(&self, span: Span, ty: Ty<'tcx>) -> RawTy<'tcx> {
RawTy { raw: ty, normalized: self.normalize(span, ty) }
}
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> RawTy<'tcx> {
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
let t = self.astconv().ast_ty_to_ty(ast_t);
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> {
@ -396,7 +392,7 @@ pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx>
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()) {
(ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
(_, ty::Adt(adt, args)) => UserArgs {
@ -801,7 +797,7 @@ pub fn resolve_ty_and_res_fully_qualified_call(
hir_id: hir::HirId,
span: Span,
args: Option<&'tcx [hir::Expr<'tcx>]>,
) -> (Res, Option<RawTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
debug!(
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
qpath, hir_id, span
@ -825,7 +821,7 @@ pub fn resolve_ty_and_res_fully_qualified_call(
// We manually call `register_wf_obligation` in the success path
// below.
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(..) => {
bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`")
@ -1074,7 +1070,7 @@ pub(in super::super) fn note_internal_mutation_in_method(
pub fn instantiate_value_path(
&self,
segments: &'tcx [hir::PathSegment<'tcx>],
self_ty: Option<RawTy<'tcx>>,
self_ty: Option<LoweredTy<'tcx>>,
res: Res,
span: Span,
hir_id: hir::HirId,
@ -1201,8 +1197,11 @@ pub fn instantiate_value_path(
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 ty =
self.handle_raw_ty(span, tcx.at(span).type_of(impl_def_id).instantiate_identity());
let ty = LoweredTy::from_raw(
self,
span,
tcx.at(span).type_of(impl_def_id).instantiate_identity(),
);
match ty.normalized.ty_adt_def() {
Some(adt_def) if adt_def.has_ctor() => {
let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();

View File

@ -6,7 +6,7 @@
use crate::TupleArgumentsFlag::*;
use crate::{errors, Expectation::*};
use crate::{
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy, Needs,
TupleArgumentsFlag,
};
use itertools::Itertools;
@ -1792,12 +1792,12 @@ fn finish_resolving_struct_path(
qpath: &QPath<'tcx>,
path_span: Span,
hir_id: hir::HirId,
) -> (Res, RawTy<'tcx>) {
) -> (Res, LoweredTy<'tcx>) {
match *qpath {
QPath::Resolved(ref maybe_qself, path) => {
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);
(path.res, self.handle_raw_ty(path_span, ty))
(path.res, LoweredTy::from_raw(self, path_span, ty))
}
QPath::TypeRelative(qself, segment) => {
let ty = self.to_ty(qself);
@ -1808,7 +1808,7 @@ fn finish_resolving_struct_path(
let ty = result
.map(|(ty, _, _)| ty)
.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));
// Write back the new resolution.
@ -1818,7 +1818,7 @@ fn finish_resolving_struct_path(
}
QPath::LangItem(lang_item, span) => {
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 @@ fn infcx(&self) -> Option<&infer::InferCtxt<'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`,
/// and the API in this module, which expect `Ty` to be fully normalized.
#[derive(Clone, Copy, Debug)]
pub struct RawTy<'tcx> {
pub struct LoweredTy<'tcx> {
/// The unnormalized type provided by the user.
pub raw: Ty<'tcx>,
/// The normalized form of `raw`, stored here for efficiency.
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::coercion::DynamicCoerceMany;
use crate::diverges::Diverges;
use crate::expectation::Expectation;
use crate::fn_ctxt::RawTy;
use crate::fn_ctxt::LoweredTy;
use crate::gather_locals::GatherLocalsVisitor;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{struct_span_code_err, ErrorGuaranteed};

View File

@ -1,5 +1,5 @@
use crate::gather_locals::DeclOrigin;
use crate::{errors, FnCtxt, RawTy};
use crate::{errors, FnCtxt, LoweredTy};
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{
@ -891,7 +891,7 @@ fn check_pat_path(
&self,
pat: &Pat<'tcx>,
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>,
ti: TopInfo<'tcx>,
) -> Ty<'tcx> {