Skip to content

Commit c6088f7

Browse files
committed
RawTy to LoweredTy
1 parent a58ec8f commit c6088f7

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::callee::{self, DeferredCallResolution};
22
use crate::errors::CtorIsPrivate;
33
use crate::method::{self, MethodCallee, SelfSource};
44
use crate::rvalue_scopes;
5-
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, RawTy};
5+
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
66
use rustc_data_structures::captures::Captures;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_errors::{Applicability, Diagnostic, ErrorGuaranteed, MultiSpan, StashKey};
@@ -373,14 +373,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
373373
}
374374
}
375375

376-
pub fn handle_raw_ty(&self, span: Span, ty: Ty<'tcx>) -> RawTy<'tcx> {
377-
RawTy { raw: ty, normalized: self.normalize(span, ty) }
378-
}
379-
380-
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> RawTy<'tcx> {
376+
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
381377
let t = self.astconv().ast_ty_to_ty(ast_t);
382378
self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None));
383-
self.handle_raw_ty(ast_t.span, t)
379+
LoweredTy::from_raw(self, ast_t.span, t)
384380
}
385381

386382
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> {
396392
ty.normalized
397393
}
398394

399-
pub(super) fn user_args_for_adt(ty: RawTy<'tcx>) -> UserArgs<'tcx> {
395+
pub(super) fn user_args_for_adt(ty: LoweredTy<'tcx>) -> UserArgs<'tcx> {
400396
match (ty.raw.kind(), ty.normalized.kind()) {
401397
(ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
402398
(_, ty::Adt(adt, args)) => UserArgs {
@@ -801,7 +797,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
801797
hir_id: hir::HirId,
802798
span: Span,
803799
args: Option<&'tcx [hir::Expr<'tcx>]>,
804-
) -> (Res, Option<RawTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
800+
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
805801
debug!(
806802
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
807803
qpath, hir_id, span
@@ -825,7 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
825821
// We manually call `register_wf_obligation` in the success path
826822
// below.
827823
let ty = self.astconv().ast_ty_to_ty_in_path(qself);
828-
(self.handle_raw_ty(span, ty), qself, segment)
824+
(LoweredTy::from_raw(self, span, ty), qself, segment)
829825
}
830826
QPath::LangItem(..) => {
831827
bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`")
@@ -1074,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10741070
pub fn instantiate_value_path(
10751071
&self,
10761072
segments: &'tcx [hir::PathSegment<'tcx>],
1077-
self_ty: Option<RawTy<'tcx>>,
1073+
self_ty: Option<LoweredTy<'tcx>>,
10781074
res: Res,
10791075
span: Span,
10801076
hir_id: hir::HirId,
@@ -1201,8 +1197,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12011197
path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self);
12021198

12031199
let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res {
1204-
let ty =
1205-
self.handle_raw_ty(span, tcx.at(span).type_of(impl_def_id).instantiate_identity());
1200+
let ty = LoweredTy::from_raw(
1201+
self,
1202+
span,
1203+
tcx.at(span).type_of(impl_def_id).instantiate_identity(),
1204+
);
12061205
match ty.normalized.ty_adt_def() {
12071206
Some(adt_def) if adt_def.has_ctor() => {
12081207
let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::method::MethodCallee;
66
use crate::TupleArgumentsFlag::*;
77
use crate::{errors, Expectation::*};
88
use crate::{
9-
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
9+
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy, Needs,
1010
TupleArgumentsFlag,
1111
};
1212
use itertools::Itertools;
@@ -1786,12 +1786,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17861786
qpath: &QPath<'tcx>,
17871787
path_span: Span,
17881788
hir_id: hir::HirId,
1789-
) -> (Res, RawTy<'tcx>) {
1789+
) -> (Res, LoweredTy<'tcx>) {
17901790
match *qpath {
17911791
QPath::Resolved(ref maybe_qself, path) => {
17921792
let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw);
17931793
let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true);
1794-
(path.res, self.handle_raw_ty(path_span, ty))
1794+
(path.res, LoweredTy::from_raw(self, path_span, ty))
17951795
}
17961796
QPath::TypeRelative(qself, segment) => {
17971797
let ty = self.to_ty(qself);
@@ -1802,7 +1802,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18021802
let ty = result
18031803
.map(|(ty, _, _)| ty)
18041804
.unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
1805-
let ty = self.handle_raw_ty(path_span, ty);
1805+
let ty = LoweredTy::from_raw(self, path_span, ty);
18061806
let result = result.map(|(_, kind, def_id)| (kind, def_id));
18071807

18081808
// Write back the new resolution.
@@ -1812,7 +1812,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18121812
}
18131813
QPath::LangItem(lang_item, span) => {
18141814
let (res, ty) = self.resolve_lang_item_path(lang_item, span, hir_id);
1815-
(res, self.handle_raw_ty(path_span, ty))
1815+
(res, LoweredTy::from_raw(self, path_span, ty))
18161816
}
18171817
}
18181818
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,22 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
344344
}
345345
}
346346

347-
/// Represents a user-provided type in the raw form (never normalized).
347+
/// The `ty` representation of a user-provided type. Depending on the use-site
348+
/// we want to either use the unnormalized or the normalized form of this type.
348349
///
349350
/// This is a bridge between the interface of `AstConv`, which outputs a raw `Ty`,
350351
/// and the API in this module, which expect `Ty` to be fully normalized.
351352
#[derive(Clone, Copy, Debug)]
352-
pub struct RawTy<'tcx> {
353+
pub struct LoweredTy<'tcx> {
354+
/// The unnormalized type provided by the user.
353355
pub raw: Ty<'tcx>,
354356

355357
/// The normalized form of `raw`, stored here for efficiency.
356358
pub normalized: Ty<'tcx>,
357359
}
360+
361+
impl<'tcx> LoweredTy<'tcx> {
362+
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
363+
LoweredTy { raw, normalized: fcx.normalize(span, raw) }
364+
}
365+
}

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use crate::check::check_fn;
4949
use crate::coercion::DynamicCoerceMany;
5050
use crate::diverges::Diverges;
5151
use crate::expectation::Expectation;
52-
use crate::fn_ctxt::RawTy;
52+
use crate::fn_ctxt::LoweredTy;
5353
use crate::gather_locals::GatherLocalsVisitor;
5454
use rustc_data_structures::unord::UnordSet;
5555
use rustc_errors::{struct_span_code_err, ErrorGuaranteed};

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::gather_locals::DeclOrigin;
2-
use crate::{errors, FnCtxt, RawTy};
2+
use crate::{errors, FnCtxt, LoweredTy};
33
use rustc_ast as ast;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_errors::{
@@ -891,7 +891,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
891891
&self,
892892
pat: &Pat<'tcx>,
893893
qpath: &hir::QPath<'_>,
894-
path_resolution: (Res, Option<RawTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
894+
path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
895895
expected: Ty<'tcx>,
896896
ti: TopInfo<'tcx>,
897897
) -> Ty<'tcx> {

0 commit comments

Comments
 (0)