Skip to content

Commit

Permalink
Made a submodule for fn_ctxt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas-Baron committed Oct 12, 2020
1 parent 8487879 commit ce7c73c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::callee::{self, DeferredCallResolution};
use super::method::{self, MethodCallee, SelfSource};
use super::{BreakableCtxt, Diverges, Expectation, FallbackMode, FnCtxt, LocalTy};
use crate::astconv::{
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg,
};
use crate::check::callee::{self, DeferredCallResolution};
use crate::check::method::{self, MethodCallee, SelfSource};
use crate::check::{BreakableCtxt, Diverges, Expectation, FallbackMode, FnCtxt, LocalTy};

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -41,7 +41,7 @@ use std::slice;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Produces warning on the given node, if the current point in the
/// function is unreachable, and there hasn't been another warning.
pub(super) fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) {
pub(in super::super) fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) {
// FIXME: Combine these two 'if' expressions into one once
// let chains are implemented
if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() {
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// version (resolve_vars_if_possible), this version will
/// also select obligations if it seems useful, in an effort
/// to get more type information.
pub(super) fn resolve_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
pub(in super::super) fn resolve_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
debug!("resolve_vars_with_obligations(ty={:?})", ty);

// No Infer()? Nothing needs doing.
Expand All @@ -102,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty
}

pub(super) fn record_deferred_call_resolution(
pub(in super::super) fn record_deferred_call_resolution(
&self,
closure_def_id: DefId,
r: DeferredCallResolution<'tcx>,
Expand All @@ -111,7 +111,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
}

pub(super) fn remove_deferred_call_resolutions(
pub(in super::super) fn remove_deferred_call_resolutions(
&self,
closure_def_id: DefId,
) -> Vec<DeferredCallResolution<'tcx>> {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
}

pub(super) fn write_resolution(
pub(in super::super) fn write_resolution(
&self,
hir_id: hir::HirId,
r: Result<(DefKind, DefId), ErrorReported>,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

/// As `instantiate_type_scheme`, but for the bounds found in a
/// generic type scheme.
pub(super) fn instantiate_bounds(
pub(in super::super) fn instantiate_bounds(
&self,
span: Span,
def_id: DefId,
Expand All @@ -355,7 +355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Replaces the opaque types from the given value with type variables,
/// and records the `OpaqueTypeMap` for later use during writeback. See
/// `InferCtxt::instantiate_opaque_types` for more details.
pub(super) fn instantiate_opaque_types_from_value<T: TypeFoldable<'tcx>>(
pub(in super::super) fn instantiate_opaque_types_from_value<T: TypeFoldable<'tcx>>(
&self,
parent_id: hir::HirId,
value: &T,
Expand Down Expand Up @@ -386,14 +386,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
value
}

pub(super) fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
pub(in super::super) fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
where
T: TypeFoldable<'tcx>,
{
self.inh.normalize_associated_types_in(span, self.body_id, self.param_env, value)
}

pub(super) fn normalize_associated_types_in_as_infer_ok<T>(
pub(in super::super) fn normalize_associated_types_in_as_infer_ok<T>(
&self,
span: Span,
value: &T,
Expand Down Expand Up @@ -600,11 +600,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.normalize_associated_types_in(span, &field.ty(self.tcx, substs))
}

pub(super) fn resolve_generator_interiors(&self, def_id: DefId) {
pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) {
let mut generators = self.deferred_generator_interiors.borrow_mut();
for (body_id, interior, kind) in generators.drain(..) {
self.select_obligations_where_possible(false, |_| {});
super::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
crate::check::generator_interior::resolve_interior(
self, def_id, body_id, interior, kind,
);
}
}

Expand All @@ -620,7 +622,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Fallback becomes very dubious if we have encountered type-checking errors.
// In that case, fallback to Error.
// The return value indicates whether fallback has occurred.
pub(super) fn fallback_if_possible(&self, ty: Ty<'tcx>, mode: FallbackMode) -> bool {
pub(in super::super) fn fallback_if_possible(&self, ty: Ty<'tcx>, mode: FallbackMode) -> bool {
use rustc_middle::ty::error::UnconstrainedNumeric::Neither;
use rustc_middle::ty::error::UnconstrainedNumeric::{UnconstrainedFloat, UnconstrainedInt};

Expand Down Expand Up @@ -685,15 +687,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
true
}

pub(super) fn select_all_obligations_or_error(&self) {
pub(in super::super) fn select_all_obligations_or_error(&self) {
debug!("select_all_obligations_or_error");
if let Err(errors) = self.fulfillment_cx.borrow_mut().select_all_or_error(&self) {
self.report_fulfillment_errors(&errors, self.inh.body_id, false);
}
}

/// Select as many obligations as we can at present.
pub(super) fn select_obligations_where_possible(
pub(in super::super) fn select_obligations_where_possible(
&self,
fallback_has_occurred: bool,
mutate_fullfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
Expand All @@ -709,7 +711,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// returns a type of `&T`, but the actual type we assign to the
/// *expression* is `T`. So this function just peels off the return
/// type by one layer to yield `T`.
pub(super) fn make_overloaded_place_return_type(
pub(in super::super) fn make_overloaded_place_return_type(
&self,
method: MethodCallee<'tcx>,
) -> ty::TypeAndMut<'tcx> {
Expand Down Expand Up @@ -742,7 +744,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(super) fn obligations_for_self_ty<'b>(
pub(in super::super) fn obligations_for_self_ty<'b>(
&'b self,
self_ty: ty::TyVid,
) -> impl Iterator<Item = (ty::PolyTraitRef<'tcx>, traits::PredicateObligation<'tcx>)>
Expand Down Expand Up @@ -792,18 +794,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root))
}

pub(super) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
pub(in super::super) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
self.obligations_for_self_ty(self_ty)
.any(|(tr, _)| Some(tr.def_id()) == self.tcx.lang_items().sized_trait())
}

pub(super) fn err_args(&self, len: usize) -> Vec<Ty<'tcx>> {
pub(in super::super) fn err_args(&self, len: usize) -> Vec<Ty<'tcx>> {
vec![self.tcx.ty_error(); len]
}

/// Unifies the output type with the expected type early, for more coercions
/// and forward type information on the input expressions.
pub(super) fn expected_inputs_for_expected_output(
pub(in super::super) fn expected_inputs_for_expected_output(
&self,
call_span: Span,
expected_ret: Expectation<'tcx>,
Expand Down Expand Up @@ -856,7 +858,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expect_args
}

pub(super) fn resolve_lang_item_path(
pub(in super::super) fn resolve_lang_item_path(
&self,
lang_item: hir::LangItem,
span: Span,
Expand Down Expand Up @@ -937,7 +939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

/// Given a function `Node`, return its `FnDecl` if it exists, or `None` otherwise.
pub(super) fn get_node_fn_decl(
pub(in super::super) fn get_node_fn_decl(
&self,
node: Node<'tcx>,
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident, bool)> {
Expand Down Expand Up @@ -973,7 +975,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
}

pub(super) fn note_internal_mutation_in_method(
pub(in super::super) fn note_internal_mutation_in_method(
&self,
err: &mut DiagnosticBuilder<'_>,
expr: &hir::Expr<'_>,
Expand Down Expand Up @@ -1018,7 +1020,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(super) fn note_need_for_fn_pointer(
pub(in super::super) fn note_need_for_fn_pointer(
&self,
err: &mut DiagnosticBuilder<'_>,
expected: Ty<'tcx>,
Expand Down Expand Up @@ -1055,7 +1057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
));
}

pub(super) fn could_remove_semicolon(
pub(in super::super) fn could_remove_semicolon(
&self,
blk: &'tcx hir::Block<'tcx>,
expected_ty: Ty<'tcx>,
Expand Down Expand Up @@ -1404,7 +1406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(super) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
pub(in super::super) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
&self,
id: hir::HirId,
ctxt: BreakableCtxt<'tcx>,
Expand All @@ -1429,7 +1431,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

/// Instantiate a QueryResponse in a probe context, without a
/// good ObligationCause.
pub(super) fn probe_instantiate_query_response(
pub(in super::super) fn probe_instantiate_query_response(
&self,
span: Span,
original_values: &OriginalQueryValues<'tcx>,
Expand All @@ -1444,7 +1446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

/// Returns `true` if an expression is contained inside the LHS of an assignment expression.
pub(super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool {
pub(in super::super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool {
let mut contained_in_place = false;

while let hir::Node::Expr(parent_expr) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::coercion::CoerceMany;
use super::method::MethodCallee;
use super::Expectation::*;
use super::TupleArgumentsFlag::*;
use super::{
use crate::astconv::AstConv;
use crate::check::coercion::CoerceMany;
use crate::check::method::MethodCallee;
use crate::check::Expectation::*;
use crate::check::TupleArgumentsFlag::*;
use crate::check::{
potentially_plural_count, struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt,
LocalTy, Needs, TupleArgumentsFlag,
};
use crate::astconv::AstConv;

use rustc_ast as ast;
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
Expand All @@ -26,14 +26,14 @@ use std::mem::replace;
use std::slice;

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(super) fn check_casts(&self) {
pub(in super::super) fn check_casts(&self) {
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
for cast in deferred_cast_checks.drain(..) {
cast.check(self);
}
}

pub(super) fn check_method_argument_types(
pub(in super::super) fn check_method_argument_types(
&self,
sp: Span,
expr: &'tcx hir::Expr<'tcx>,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

/// Generic function that factors out common logic from function calls,
/// method calls and overloaded operators.
pub(super) fn check_argument_types(
pub(in super::super) fn check_argument_types(
&self,
sp: Span,
expr: &'tcx hir::Expr<'tcx>,
Expand Down Expand Up @@ -377,7 +377,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

// AST fragment checking
pub(super) fn check_lit(&self, lit: &hir::Lit, expected: Expectation<'tcx>) -> Ty<'tcx> {
pub(in super::super) fn check_lit(
&self,
lit: &hir::Lit,
expected: Expectation<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;

match lit.node {
Expand Down Expand Up @@ -563,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(super) fn check_block_with_expected(
pub(in super::super) fn check_block_with_expected(
&self,
blk: &'tcx hir::Block<'tcx>,
expected: Expectation<'tcx>,
Expand Down Expand Up @@ -692,7 +696,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty
}

pub(super) fn check_rustc_args_require_const(
pub(in super::super) fn check_rustc_args_require_const(
&self,
def_id: DefId,
hir_id: hir::HirId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use super::coercion::DynamicCoerceMany;
use super::{Diverges, EnclosingBreakables, Inherited, UnsafetyState};
mod _impl;
mod checks;
mod suggestions;

pub use _impl::*;
pub use checks::*;
pub use suggestions::*;

use crate::astconv::AstConv;
use crate::check::coercion::DynamicCoerceMany;
use crate::check::{Diverges, EnclosingBreakables, Inherited, UnsafetyState};

use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand All @@ -18,7 +26,6 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
use std::cell::{Cell, RefCell};
use std::ops::Deref;

// The impl for this struct lives in fn_ctxt_impl.rs for file length reasons.
pub struct FnCtxt<'a, 'tcx> {
pub(super) body_id: hir::HirId,

Expand Down
Loading

0 comments on commit ce7c73c

Please sign in to comment.