Skip to content

Commit ce7c73c

Browse files
Made a submodule for fn_ctxt
1 parent 8487879 commit ce7c73c

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed

compiler/rustc_typeck/src/check/fn_ctxt_impl.rs renamed to compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use super::callee::{self, DeferredCallResolution};
2-
use super::method::{self, MethodCallee, SelfSource};
3-
use super::{BreakableCtxt, Diverges, Expectation, FallbackMode, FnCtxt, LocalTy};
41
use crate::astconv::{
52
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg,
63
};
4+
use crate::check::callee::{self, DeferredCallResolution};
5+
use crate::check::method::{self, MethodCallee, SelfSource};
6+
use crate::check::{BreakableCtxt, Diverges, Expectation, FallbackMode, FnCtxt, LocalTy};
77

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

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

105-
pub(super) fn record_deferred_call_resolution(
105+
pub(in super::super) fn record_deferred_call_resolution(
106106
&self,
107107
closure_def_id: DefId,
108108
r: DeferredCallResolution<'tcx>,
@@ -111,7 +111,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
111111
deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
112112
}
113113

114-
pub(super) fn remove_deferred_call_resolutions(
114+
pub(in super::super) fn remove_deferred_call_resolutions(
115115
&self,
116116
closure_def_id: DefId,
117117
) -> Vec<DeferredCallResolution<'tcx>> {
@@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
149149
self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
150150
}
151151

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

336336
/// As `instantiate_type_scheme`, but for the bounds found in a
337337
/// generic type scheme.
338-
pub(super) fn instantiate_bounds(
338+
pub(in super::super) fn instantiate_bounds(
339339
&self,
340340
span: Span,
341341
def_id: DefId,
@@ -355,7 +355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
355355
/// Replaces the opaque types from the given value with type variables,
356356
/// and records the `OpaqueTypeMap` for later use during writeback. See
357357
/// `InferCtxt::instantiate_opaque_types` for more details.
358-
pub(super) fn instantiate_opaque_types_from_value<T: TypeFoldable<'tcx>>(
358+
pub(in super::super) fn instantiate_opaque_types_from_value<T: TypeFoldable<'tcx>>(
359359
&self,
360360
parent_id: hir::HirId,
361361
value: &T,
@@ -386,14 +386,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
386386
value
387387
}
388388

389-
pub(super) fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
389+
pub(in super::super) fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
390390
where
391391
T: TypeFoldable<'tcx>,
392392
{
393393
self.inh.normalize_associated_types_in(span, self.body_id, self.param_env, value)
394394
}
395395

396-
pub(super) fn normalize_associated_types_in_as_infer_ok<T>(
396+
pub(in super::super) fn normalize_associated_types_in_as_infer_ok<T>(
397397
&self,
398398
span: Span,
399399
value: &T,
@@ -600,11 +600,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600600
self.normalize_associated_types_in(span, &field.ty(self.tcx, substs))
601601
}
602602

603-
pub(super) fn resolve_generator_interiors(&self, def_id: DefId) {
603+
pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) {
604604
let mut generators = self.deferred_generator_interiors.borrow_mut();
605605
for (body_id, interior, kind) in generators.drain(..) {
606606
self.select_obligations_where_possible(false, |_| {});
607-
super::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
607+
crate::check::generator_interior::resolve_interior(
608+
self, def_id, body_id, interior, kind,
609+
);
608610
}
609611
}
610612

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

@@ -685,15 +687,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
685687
true
686688
}
687689

688-
pub(super) fn select_all_obligations_or_error(&self) {
690+
pub(in super::super) fn select_all_obligations_or_error(&self) {
689691
debug!("select_all_obligations_or_error");
690692
if let Err(errors) = self.fulfillment_cx.borrow_mut().select_all_or_error(&self) {
691693
self.report_fulfillment_errors(&errors, self.inh.body_id, false);
692694
}
693695
}
694696

695697
/// Select as many obligations as we can at present.
696-
pub(super) fn select_obligations_where_possible(
698+
pub(in super::super) fn select_obligations_where_possible(
697699
&self,
698700
fallback_has_occurred: bool,
699701
mutate_fullfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
@@ -709,7 +711,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
709711
/// returns a type of `&T`, but the actual type we assign to the
710712
/// *expression* is `T`. So this function just peels off the return
711713
/// type by one layer to yield `T`.
712-
pub(super) fn make_overloaded_place_return_type(
714+
pub(in super::super) fn make_overloaded_place_return_type(
713715
&self,
714716
method: MethodCallee<'tcx>,
715717
) -> ty::TypeAndMut<'tcx> {
@@ -742,7 +744,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
742744
}
743745
}
744746

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

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

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

804806
/// Unifies the output type with the expected type early, for more coercions
805807
/// and forward type information on the input expressions.
806-
pub(super) fn expected_inputs_for_expected_output(
808+
pub(in super::super) fn expected_inputs_for_expected_output(
807809
&self,
808810
call_span: Span,
809811
expected_ret: Expectation<'tcx>,
@@ -856,7 +858,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
856858
expect_args
857859
}
858860

859-
pub(super) fn resolve_lang_item_path(
861+
pub(in super::super) fn resolve_lang_item_path(
860862
&self,
861863
lang_item: hir::LangItem,
862864
span: Span,
@@ -937,7 +939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
937939
}
938940

939941
/// Given a function `Node`, return its `FnDecl` if it exists, or `None` otherwise.
940-
pub(super) fn get_node_fn_decl(
942+
pub(in super::super) fn get_node_fn_decl(
941943
&self,
942944
node: Node<'tcx>,
943945
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident, bool)> {
@@ -973,7 +975,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
973975
})
974976
}
975977

976-
pub(super) fn note_internal_mutation_in_method(
978+
pub(in super::super) fn note_internal_mutation_in_method(
977979
&self,
978980
err: &mut DiagnosticBuilder<'_>,
979981
expr: &hir::Expr<'_>,
@@ -1018,7 +1020,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10181020
}
10191021
}
10201022

1021-
pub(super) fn note_need_for_fn_pointer(
1023+
pub(in super::super) fn note_need_for_fn_pointer(
10221024
&self,
10231025
err: &mut DiagnosticBuilder<'_>,
10241026
expected: Ty<'tcx>,
@@ -1055,7 +1057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10551057
));
10561058
}
10571059

1058-
pub(super) fn could_remove_semicolon(
1060+
pub(in super::super) fn could_remove_semicolon(
10591061
&self,
10601062
blk: &'tcx hir::Block<'tcx>,
10611063
expected_ty: Ty<'tcx>,
@@ -1404,7 +1406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14041406
}
14051407
}
14061408

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

14301432
/// Instantiate a QueryResponse in a probe context, without a
14311433
/// good ObligationCause.
1432-
pub(super) fn probe_instantiate_query_response(
1434+
pub(in super::super) fn probe_instantiate_query_response(
14331435
&self,
14341436
span: Span,
14351437
original_values: &OriginalQueryValues<'tcx>,
@@ -1444,7 +1446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14441446
}
14451447

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

14501452
while let hir::Node::Expr(parent_expr) =

compiler/rustc_typeck/src/check/fn_ctxt_checks.rs renamed to compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use super::coercion::CoerceMany;
2-
use super::method::MethodCallee;
3-
use super::Expectation::*;
4-
use super::TupleArgumentsFlag::*;
5-
use super::{
1+
use crate::astconv::AstConv;
2+
use crate::check::coercion::CoerceMany;
3+
use crate::check::method::MethodCallee;
4+
use crate::check::Expectation::*;
5+
use crate::check::TupleArgumentsFlag::*;
6+
use crate::check::{
67
potentially_plural_count, struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt,
78
LocalTy, Needs, TupleArgumentsFlag,
89
};
9-
use crate::astconv::AstConv;
1010

1111
use rustc_ast as ast;
1212
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
@@ -26,14 +26,14 @@ use std::mem::replace;
2626
use std::slice;
2727

2828
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29-
pub(super) fn check_casts(&self) {
29+
pub(in super::super) fn check_casts(&self) {
3030
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
3131
for cast in deferred_cast_checks.drain(..) {
3232
cast.check(self);
3333
}
3434
}
3535

36-
pub(super) fn check_method_argument_types(
36+
pub(in super::super) fn check_method_argument_types(
3737
&self,
3838
sp: Span,
3939
expr: &'tcx hir::Expr<'tcx>,
@@ -90,7 +90,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9090

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

379379
// AST fragment checking
380-
pub(super) fn check_lit(&self, lit: &hir::Lit, expected: Expectation<'tcx>) -> Ty<'tcx> {
380+
pub(in super::super) fn check_lit(
381+
&self,
382+
lit: &hir::Lit,
383+
expected: Expectation<'tcx>,
384+
) -> Ty<'tcx> {
381385
let tcx = self.tcx;
382386

383387
match lit.node {
@@ -563,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563567
}
564568
}
565569

566-
pub(super) fn check_block_with_expected(
570+
pub(in super::super) fn check_block_with_expected(
567571
&self,
568572
blk: &'tcx hir::Block<'tcx>,
569573
expected: Expectation<'tcx>,
@@ -692,7 +696,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
692696
ty
693697
}
694698

695-
pub(super) fn check_rustc_args_require_const(
699+
pub(in super::super) fn check_rustc_args_require_const(
696700
&self,
697701
def_id: DefId,
698702
hir_id: hir::HirId,

compiler/rustc_typeck/src/check/fn_ctxt.rs renamed to compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
use super::coercion::DynamicCoerceMany;
2-
use super::{Diverges, EnclosingBreakables, Inherited, UnsafetyState};
1+
mod _impl;
2+
mod checks;
3+
mod suggestions;
4+
5+
pub use _impl::*;
6+
pub use checks::*;
7+
pub use suggestions::*;
8+
39
use crate::astconv::AstConv;
10+
use crate::check::coercion::DynamicCoerceMany;
11+
use crate::check::{Diverges, EnclosingBreakables, Inherited, UnsafetyState};
412

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

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

0 commit comments

Comments
 (0)