about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas-Baron <nicholas.baron.ten@gmail.com>2020-10-12 11:57:29 -0700
committerNicholas-Baron <nicholas.baron.ten@gmail.com>2020-10-12 12:18:24 -0700
commitce7c73c5a58017fb84b97bda4a87bae0f831f6ea (patch)
tree0bf2a7164feb5bf5e7af10d23c9e667797f6bf1f
parent84878794edf0d60248be578943f9edbb5c0174ab (diff)
downloadrust-ce7c73c5a58017fb84b97bda4a87bae0f831f6ea.tar.gz
rust-ce7c73c5a58017fb84b97bda4a87bae0f831f6ea.zip
Made a submodule for fn_ctxt
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs (renamed from compiler/rustc_typeck/src/check/fn_ctxt_impl.rs)62
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs (renamed from compiler/rustc_typeck/src/check/fn_ctxt_checks.rs)28
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/mod.rs (renamed from compiler/rustc_typeck/src/check/fn_ctxt.rs)13
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs (renamed from compiler/rustc_typeck/src/check/fn_ctxt_suggestions.rs)16
-rw-r--r--compiler/rustc_typeck/src/check/mod.rs8
5 files changed, 69 insertions, 58 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
index 0a1cf76e5ae..017b0abd1d6 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
@@ -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;
@@ -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() {
@@ -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.
@@ -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>,
@@ -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>> {
@@ -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>,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
+            );
         }
     }
 
@@ -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};
 
@@ -685,7 +687,7 @@ 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);
@@ -693,7 +695,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     }
 
     /// 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>>),
@@ -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> {
@@ -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>)>
@@ -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>,
@@ -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,
@@ -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)> {
@@ -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<'_>,
@@ -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>,
@@ -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>,
@@ -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>,
@@ -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>,
@@ -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) =
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt_checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 829ad21faf1..3224e04ee49 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt_checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -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};
@@ -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>,
@@ -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>,
@@ -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 {
@@ -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>,
@@ -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,
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
index dff54cae4df..72c3b233ed9 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
@@ -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;
@@ -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,
 
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt_suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
index 19988938a49..9bad02c41b4 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt_suggestions.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
@@ -18,7 +18,11 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _
 use std::iter;
 
 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
-    pub(super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut DiagnosticBuilder<'_>) {
+    pub(in super::super) fn suggest_semicolon_at_end(
+        &self,
+        span: Span,
+        err: &mut DiagnosticBuilder<'_>,
+    ) {
         err.span_suggestion_short(
             span.shrink_to_hi(),
             "consider using a semicolon here",
@@ -251,7 +255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
     /// When encountering the expected boxed value allocated in the stack, suggest allocating it
     /// in the heap by calling `Box::new()`.
-    pub(super) fn suggest_boxing_when_appropriate(
+    pub(in super::super) fn suggest_boxing_when_appropriate(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         expr: &hir::Expr<'_>,
@@ -286,7 +290,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     }
 
     /// When encountering an `impl Future` where `BoxFuture` is expected, suggest `Box::pin`.
-    pub(super) fn suggest_calling_boxed_future_when_appropriate(
+    pub(in super::super) fn suggest_calling_boxed_future_when_appropriate(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         expr: &hir::Expr<'_>,
@@ -381,7 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     /// This routine checks if the return type is left as default, the method is not part of an
     /// `impl` block and that it isn't the `main` method. If so, it suggests setting the return
     /// type.
-    pub(super) fn suggest_missing_return_type(
+    pub(in super::super) fn suggest_missing_return_type(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         fn_decl: &hir::FnDecl<'_>,
@@ -447,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     /// This routine checks if the found type `T` implements `Future<Output=U>` where `U` is the
     /// expected type. If this is the case, and we are inside of an async body, it suggests adding
     /// `.await` to the tail of the expression.
-    pub(super) fn suggest_missing_await(
+    pub(in super::super) fn suggest_missing_await(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         expr: &hir::Expr<'_>,
@@ -510,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         }
     }
 
-    pub(super) fn suggest_missing_parentheses(
+    pub(in super::super) fn suggest_missing_parentheses(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         expr: &hir::Expr<'_>,
diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs
index b9e1b742650..2dc769486c2 100644
--- a/compiler/rustc_typeck/src/check/mod.rs
+++ b/compiler/rustc_typeck/src/check/mod.rs
@@ -76,9 +76,6 @@ pub mod dropck;
 mod expectation;
 mod expr;
 mod fn_ctxt;
-mod fn_ctxt_checks;
-mod fn_ctxt_impl;
-mod fn_ctxt_suggestions;
 mod gather_locals;
 mod generator_interior;
 mod inherited;
@@ -99,10 +96,7 @@ use check::{
 pub use check::{check_item_type, check_wf_new};
 pub use diverges::Diverges;
 pub use expectation::Expectation;
-pub use fn_ctxt::FnCtxt;
-pub use fn_ctxt_checks::*;
-pub use fn_ctxt_impl::*;
-pub use fn_ctxt_suggestions::*;
+pub use fn_ctxt::*;
 pub use inherited::{Inherited, InheritedBuilder};
 
 use crate::astconv::AstConv;