Skip to content

Commit

Permalink
Rollup merge of #123103 - compiler-errors:inherited-is-a-weird-name, …
Browse files Browse the repository at this point in the history
…r=oli-obk

Rename `Inherited` -> `TypeckRootCtxt`

`Inherited` is a confusing name. Rename it to `TypeckRootCtxt`.

I don't think this needs a type MCP or anything since it's not nearly as pervasive as `FnCtxt` , for example.

r? ``@lcnr`` ``@oli-obk``
  • Loading branch information
workingjubilee authored Mar 26, 2024
2 parents 2e010f6 + bf7a745 commit b24c54e
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let can_coerce_to_return_ty = match self.ret_coercion.as_ref() {
Some(ret_coercion) => {
let ret_ty = ret_coercion.borrow().expected_ty();
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
let ret_ty = self.infcx.shallow_resolve(ret_ty);
self.can_coerce(arm_ty, ret_ty)
&& prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty))
// The match arms need to unify for the case of `impl Trait`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bound_vars,
);

let c_result = self.inh.infcx.canonicalize_response(result);
let c_result = self.infcx.canonicalize_response(result);
self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);

// Normalize only after registering in `user_provided_sigs`.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
.any(|n| roots_reachable_from_non_diverging.visited(n));

let infer_var_infos: UnordBag<_> = self
.inh
.infer_var_info
.borrow()
.items()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(in super::super) fn resolve_rvalue_scopes(&self, def_id: DefId) {
let scope_tree = self.tcx.region_scope_tree(def_id);
let rvalue_scopes = { rvalue_scopes::resolve_rvalue_scopes(self, scope_tree, def_id) };
let mut typeck_results = self.inh.typeck_results.borrow_mut();
let mut typeck_results = self.typeck_results.borrow_mut();
typeck_results.rvalue_scopes = rvalue_scopes;
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod suggestions;
use crate::coercion::DynamicCoerceMany;
use crate::fallback::DivergingFallbackBehavior;
use crate::fn_ctxt::checks::DivergingBlockBehavior;
use crate::{CoroutineTypes, Diverges, EnclosingBreakables, Inherited};
use crate::{CoroutineTypes, Diverges, EnclosingBreakables, TypeckRootCtxt};
use hir::def_id::CRATE_DEF_ID;
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
use rustc_hir as hir;
Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct FnCtxt<'a, 'tcx> {

pub(super) enclosing_breakables: RefCell<EnclosingBreakables<'tcx>>,

pub(super) inh: &'a Inherited<'tcx>,
pub(super) root_ctxt: &'a TypeckRootCtxt<'tcx>,

pub(super) fallback_has_occurred: Cell<bool>,

Expand All @@ -118,12 +118,12 @@ pub struct FnCtxt<'a, 'tcx> {

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn new(
inh: &'a Inherited<'tcx>,
root_ctxt: &'a TypeckRootCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
) -> FnCtxt<'a, 'tcx> {
let (diverging_fallback_behavior, diverging_block_behavior) =
parse_never_type_options_attr(inh.tcx);
parse_never_type_options_attr(root_ctxt.tcx);
FnCtxt {
body_id,
param_env,
Expand All @@ -137,7 +137,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
stack: Vec::new(),
by_id: Default::default(),
}),
inh,
root_ctxt,
fallback_has_occurred: Cell::new(false),
diverging_fallback_behavior,
diverging_block_behavior,
Expand Down Expand Up @@ -206,9 +206,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> {
type Target = Inherited<'tcx>;
type Target = TypeckRootCtxt<'tcx>;
fn deref(&self) -> &Self::Target {
self.inh
self.root_ctxt
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/gather_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
Some(ref ty) => {
let o_ty = self.fcx.lower_ty(ty);

let c_ty =
self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw));
let c_ty = self.fcx.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw));
debug!("visit_local: ty.hir_id={:?} o_ty={:?} c_ty={:?}", ty.hir_id, o_ty, c_ty);
self.fcx
.typeck_results
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ pub mod expr_use_visitor;
mod fallback;
mod fn_ctxt;
mod gather_locals;
mod inherited;
mod intrinsicck;
mod mem_categorization;
mod method;
mod op;
mod pat;
mod place_op;
mod rvalue_scopes;
mod typeck_root_ctxt;
mod upvar;
mod writeback;

pub use fn_ctxt::FnCtxt;
pub use inherited::Inherited;
pub use typeck_root_ctxt::TypeckRootCtxt;

use crate::check::check_fn;
use crate::coercion::DynamicCoerceMany;
Expand Down Expand Up @@ -170,11 +170,11 @@ fn typeck_with_fallback<'tcx>(

let param_env = tcx.param_env(def_id);

let inh = Inherited::new(tcx, def_id);
let root_ctxt = TypeckRootCtxt::new(tcx, def_id);
if let Some(inspector) = inspector {
inh.infcx.attach_obligation_inspector(inspector);
root_ctxt.infcx.attach_obligation_inspector(inspector);
}
let mut fcx = FnCtxt::new(&inh, param_env, def_id);
let mut fcx = FnCtxt::new(&root_ctxt, param_env, def_id);

if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if !pat_adjustments.is_empty() {
debug!("default binding mode is now {:?}", def_bm);
self.inh
.typeck_results
self.typeck_results
.borrow_mut()
.pat_adjustments_mut()
.insert(pat.hir_id, pat_adjustments);
Expand Down Expand Up @@ -614,7 +613,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => BindingMode::convert(ba),
};
// ...and store it in a side table:
self.inh.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm);
self.typeck_results.borrow_mut().pat_binding_modes_mut().insert(pat.hir_id, bm);

debug!("check_pat_ident: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ use rustc_trait_selection::traits::{self, PredicateObligation, TraitEngine, Trai
use std::cell::RefCell;
use std::ops::Deref;

/// Closures defined within the function. For example:
// Data shared between a "typeck root" and its nested bodies,
/// e.g. closures defined within the function. For example:
/// ```ignore (illustrative)
/// fn foo() {
/// bar(move|| { ... })
/// }
/// ```
/// Here, the function `foo()` and the closure passed to
/// `bar()` will each have their own `FnCtxt`, but they will
/// share the inherited fields.
pub struct Inherited<'tcx> {
/// share the inference context, will process obligations together,
/// can access each other's local types (scoping permitted), etc.
pub struct TypeckRootCtxt<'tcx> {
pub(super) infcx: InferCtxt<'tcx>,

pub(super) typeck_results: RefCell<ty::TypeckResults<'tcx>>,
Expand Down Expand Up @@ -65,14 +67,14 @@ pub struct Inherited<'tcx> {
pub(super) infer_var_info: RefCell<UnordMap<ty::TyVid, ty::InferVarInfo>>,
}

impl<'tcx> Deref for Inherited<'tcx> {
impl<'tcx> Deref for TypeckRootCtxt<'tcx> {
type Target = InferCtxt<'tcx>;
fn deref(&self) -> &Self::Target {
&self.infcx
}
}

impl<'tcx> Inherited<'tcx> {
impl<'tcx> TypeckRootCtxt<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;

Expand All @@ -83,7 +85,7 @@ impl<'tcx> Inherited<'tcx> {
.build();
let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner));

Inherited {
TypeckRootCtxt {
typeck_results,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(&infcx)),
infcx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
use rustc_hir_typeck::{FnCtxt, Inherited};
use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::mir::Mutability;
Expand Down Expand Up @@ -438,8 +438,8 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
Node::Item(item) => {
if let ItemKind::Fn(_, _, body_id) = &item.kind
&& let output_ty = return_ty(cx, item.owner_id)
&& let inherited = Inherited::new(cx.tcx, item.owner_id.def_id)
&& let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.owner_id.def_id)
&& let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id)
&& let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id)
&& fn_ctxt.can_coerce(ty, output_ty)
{
if has_lifetime(output_ty) && has_lifetime(ty) {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/transmute/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_hir as hir;
use rustc_hir::Expr;
use rustc_hir_typeck::{cast, FnCtxt, Inherited};
use rustc_hir_typeck::{cast, FnCtxt, TypeckRootCtxt};
use rustc_lint::LateContext;
use rustc_middle::ty::cast::CastKind;
use rustc_middle::ty::Ty;
Expand Down Expand Up @@ -34,8 +34,8 @@ pub(super) fn check_cast<'tcx>(
let hir_id = e.hir_id;
let local_def_id = hir_id.owner.def_id;

let inherited = Inherited::new(cx.tcx, local_def_id);
let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, local_def_id);
let root_ctxt = TypeckRootCtxt::new(cx.tcx, local_def_id);
let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, local_def_id);

if let Ok(check) = cast::CastCheck::new(
&fn_ctxt,
Expand Down

0 comments on commit b24c54e

Please sign in to comment.