Skip to content

Commit 7fc0444

Browse files
committed
Add warn(unreachable_pub) to rustc_hir_typeck.
1 parent 3aae994 commit 7fc0444

29 files changed

+183
-174
lines changed

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374374
}
375375
}
376376

377-
pub fn maybe_get_coercion_reason(
377+
pub(crate) fn maybe_get_coercion_reason(
378378
&self,
379379
hir_id: hir::HirId,
380380
sp: Span,
@@ -584,7 +584,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
584584
// (e.g. we're in the tail of a function body)
585585
//
586586
// Returns the `LocalDefId` of the RPIT, which is always identity-substituted.
587-
pub fn return_position_impl_trait_from_match_expectation(
587+
pub(crate) fn return_position_impl_trait_from_match_expectation(
588588
&self,
589589
expectation: Expectation<'tcx>,
590590
) -> Option<LocalDefId> {

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use super::method::MethodCallee;
1313
use super::{FnCtxt, PlaceOp};
1414

1515
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16-
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
16+
pub(crate) fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
1717
Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
1818
}
1919

20-
pub fn try_overloaded_deref(
20+
pub(crate) fn try_overloaded_deref(
2121
&self,
2222
span: Span,
2323
base_ty: Ty<'tcx>,
@@ -26,11 +26,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2626
}
2727

2828
/// Returns the adjustment steps.
29-
pub fn adjust_steps(&self, autoderef: &Autoderef<'a, 'tcx>) -> Vec<Adjustment<'tcx>> {
29+
pub(crate) fn adjust_steps(&self, autoderef: &Autoderef<'a, 'tcx>) -> Vec<Adjustment<'tcx>> {
3030
self.register_infer_ok_obligations(self.adjust_steps_as_infer_ok(autoderef))
3131
}
3232

33-
pub fn adjust_steps_as_infer_ok(
33+
pub(crate) fn adjust_steps_as_infer_ok(
3434
&self,
3535
autoderef: &Autoderef<'a, 'tcx>,
3636
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::errors;
2929
/// Checks that it is legal to call methods of the trait corresponding
3030
/// to `trait_id` (this only cares about the trait, not the specific
3131
/// method that is called).
32-
pub fn check_legal_trait_for_method_call(
32+
pub(crate) fn check_legal_trait_for_method_call(
3333
tcx: TyCtxt<'_>,
3434
span: Span,
3535
receiver: Option<Span>,
@@ -62,7 +62,7 @@ enum CallStep<'tcx> {
6262
}
6363

6464
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
65-
pub fn check_call(
65+
pub(crate) fn check_call(
6666
&self,
6767
call_expr: &'tcx hir::Expr<'tcx>,
6868
callee_expr: &'tcx hir::Expr<'tcx>,
@@ -940,7 +940,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
940940
}
941941

942942
#[derive(Debug)]
943-
pub struct DeferredCallResolution<'tcx> {
943+
pub(crate) struct DeferredCallResolution<'tcx> {
944944
call_expr: &'tcx hir::Expr<'tcx>,
945945
callee_expr: &'tcx hir::Expr<'tcx>,
946946
closure_ty: Ty<'tcx>,
@@ -949,7 +949,7 @@ pub struct DeferredCallResolution<'tcx> {
949949
}
950950

951951
impl<'a, 'tcx> DeferredCallResolution<'tcx> {
952-
pub fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
952+
pub(crate) fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
953953
debug!("DeferredCallResolution::resolve() {:?}", self);
954954

955955
// we should not be invoked until the closure kind has been

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
976976
/// adjusted type of the expression, if successful.
977977
/// Adjustments are only recorded if the coercion succeeded.
978978
/// The expressions *must not* have any preexisting adjustments.
979-
pub fn coerce(
979+
pub(crate) fn coerce(
980980
&self,
981981
expr: &hir::Expr<'_>,
982982
expr_ty: Ty<'tcx>,
@@ -1011,7 +1011,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10111011
///
10121012
/// Returns false if the coercion creates any obligations that result in
10131013
/// errors.
1014-
pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool {
1014+
pub(crate) fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool {
10151015
// FIXME(-Znext-solver): We need to structurally resolve both types here.
10161016
let source = self.resolve_vars_with_obligations(expr_ty);
10171017
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
@@ -1032,7 +1032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10321032
/// Given a type and a target type, this function will calculate and return
10331033
/// how many dereference steps needed to achieve `expr_ty <: target`. If
10341034
/// it's not possible, return `None`.
1035-
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
1035+
pub(crate) fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
10361036
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10371037
// We don't ever need two-phase here since we throw out the result of the coercion
10381038
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
@@ -1047,7 +1047,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10471047
/// This function is for diagnostics only, since it does not register
10481048
/// trait or region sub-obligations. (presumably we could, but it's not
10491049
/// particularly important for diagnostics...)
1050-
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1050+
pub(crate) fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
10511051
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
10521052
self.infcx
10531053
.type_implements_trait(
@@ -1341,7 +1341,7 @@ pub fn can_coerce<'tcx>(
13411341
/// }
13421342
/// let final_ty = coerce.complete(fcx);
13431343
/// ```
1344-
pub struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> {
1344+
pub(crate) struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> {
13451345
expected_ty: Ty<'tcx>,
13461346
final_ty: Option<Ty<'tcx>>,
13471347
expressions: Expressions<'tcx, 'exprs, E>,
@@ -1350,7 +1350,7 @@ pub struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> {
13501350

13511351
/// The type of a `CoerceMany` that is storing up the expressions into
13521352
/// a buffer. We use this in `check/mod.rs` for things like `break`.
1353-
pub type DynamicCoerceMany<'tcx> = CoerceMany<'tcx, 'tcx, &'tcx hir::Expr<'tcx>>;
1353+
pub(crate) type DynamicCoerceMany<'tcx> = CoerceMany<'tcx, 'tcx, &'tcx hir::Expr<'tcx>>;
13541354

13551355
enum Expressions<'tcx, 'exprs, E: AsCoercionSite> {
13561356
Dynamic(Vec<&'tcx hir::Expr<'tcx>>),
@@ -1361,7 +1361,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13611361
/// The usual case; collect the set of expressions dynamically.
13621362
/// If the full set of coercion sites is known before hand,
13631363
/// consider `with_coercion_sites()` instead to avoid allocation.
1364-
pub fn new(expected_ty: Ty<'tcx>) -> Self {
1364+
pub(crate) fn new(expected_ty: Ty<'tcx>) -> Self {
13651365
Self::make(expected_ty, Expressions::Dynamic(vec![]))
13661366
}
13671367

@@ -1370,7 +1370,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13701370
/// expected to pass each element in the slice to `coerce(...)` in
13711371
/// order. This is used with arrays in particular to avoid
13721372
/// needlessly cloning the slice.
1373-
pub fn with_coercion_sites(expected_ty: Ty<'tcx>, coercion_sites: &'exprs [E]) -> Self {
1373+
pub(crate) fn with_coercion_sites(expected_ty: Ty<'tcx>, coercion_sites: &'exprs [E]) -> Self {
13741374
Self::make(expected_ty, Expressions::UpFront(coercion_sites))
13751375
}
13761376

@@ -1386,15 +1386,15 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13861386
/// Typically, this is used as the expected type when
13871387
/// type-checking each of the alternative expressions whose types
13881388
/// we are trying to merge.
1389-
pub fn expected_ty(&self) -> Ty<'tcx> {
1389+
pub(crate) fn expected_ty(&self) -> Ty<'tcx> {
13901390
self.expected_ty
13911391
}
13921392

13931393
/// Returns the current "merged type", representing our best-guess
13941394
/// at the LUB of the expressions we've seen so far (if any). This
13951395
/// isn't *final* until you call `self.complete()`, which will return
13961396
/// the merged type.
1397-
pub fn merged_ty(&self) -> Ty<'tcx> {
1397+
pub(crate) fn merged_ty(&self) -> Ty<'tcx> {
13981398
self.final_ty.unwrap_or(self.expected_ty)
13991399
}
14001400

@@ -1403,7 +1403,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14031403
/// could coerce from. This will record `expression`, and later
14041404
/// calls to `coerce` may come back and add adjustments and things
14051405
/// if necessary.
1406-
pub fn coerce<'a>(
1406+
pub(crate) fn coerce<'a>(
14071407
&mut self,
14081408
fcx: &FnCtxt<'a, 'tcx>,
14091409
cause: &ObligationCause<'tcx>,
@@ -1425,7 +1425,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14251425
/// The `augment_error` gives you a chance to extend the error
14261426
/// message, in case any results (e.g., we use this to suggest
14271427
/// removing a `;`).
1428-
pub fn coerce_forced_unit<'a>(
1428+
pub(crate) fn coerce_forced_unit<'a>(
14291429
&mut self,
14301430
fcx: &FnCtxt<'a, 'tcx>,
14311431
cause: &ObligationCause<'tcx>,
@@ -1920,7 +1920,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19201920
}
19211921
}
19221922

1923-
pub fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> {
1923+
pub(crate) fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> {
19241924
if let Some(final_ty) = self.final_ty {
19251925
final_ty
19261926
} else {
@@ -1934,7 +1934,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
19341934

19351935
/// Something that can be converted into an expression to which we can
19361936
/// apply a coercion.
1937-
pub trait AsCoercionSite {
1937+
pub(crate) trait AsCoercionSite {
19381938
fn as_coercion_site(&self) -> &hir::Expr<'_>;
19391939
}
19401940

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::method::probe;
1818
use crate::FnCtxt;
1919

2020
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21-
pub fn emit_type_mismatch_suggestions(
21+
pub(crate) fn emit_type_mismatch_suggestions(
2222
&self,
2323
err: &mut Diag<'_>,
2424
expr: &hir::Expr<'tcx>,
@@ -70,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7070
}
7171
}
7272

73-
pub fn emit_coerce_suggestions(
73+
pub(crate) fn emit_coerce_suggestions(
7474
&self,
7575
err: &mut Diag<'_>,
7676
expr: &hir::Expr<'tcx>,
@@ -165,13 +165,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
165165

166166
/// Requires that the two types unify, and prints an error message if
167167
/// they don't.
168-
pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
168+
pub(crate) fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
169169
if let Err(e) = self.demand_suptype_diag(sp, expected, actual) {
170170
e.emit();
171171
}
172172
}
173173

174-
pub fn demand_suptype_diag(
174+
pub(crate) fn demand_suptype_diag(
175175
&'a self,
176176
sp: Span,
177177
expected: Ty<'tcx>,
@@ -193,13 +193,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
193193
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
194194
}
195195

196-
pub fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
196+
pub(crate) fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
197197
if let Err(err) = self.demand_eqtype_diag(sp, expected, actual) {
198198
err.emit();
199199
}
200200
}
201201

202-
pub fn demand_eqtype_diag(
202+
pub(crate) fn demand_eqtype_diag(
203203
&'a self,
204204
sp: Span,
205205
expected: Ty<'tcx>,
@@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
208208
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
209209
}
210210

211-
pub fn demand_eqtype_with_origin(
211+
pub(crate) fn demand_eqtype_with_origin(
212212
&'a self,
213213
cause: &ObligationCause<'tcx>,
214214
expected: Ty<'tcx>,
@@ -220,7 +220,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
221221
}
222222

223-
pub fn demand_coerce(
223+
pub(crate) fn demand_coerce(
224224
&self,
225225
expr: &'tcx hir::Expr<'tcx>,
226226
checked_ty: Ty<'tcx>,
@@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279

280280
/// Notes the point at which a variable is constrained to some type incompatible
281281
/// with some expectation given by `source`.
282-
pub fn note_source_of_type_mismatch_constraint(
282+
pub(crate) fn note_source_of_type_mismatch_constraint(
283283
&self,
284284
err: &mut Diag<'_>,
285285
expr: &hir::Expr<'_>,
@@ -558,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
558558

559559
// When encountering a type error on the value of a `break`, try to point at the reason for the
560560
// expected type.
561-
pub fn annotate_loop_expected_due_to_inference(
561+
pub(crate) fn annotate_loop_expected_due_to_inference(
562562
&self,
563563
err: &mut Diag<'_>,
564564
expr: &hir::Expr<'_>,
@@ -964,7 +964,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
964964
);
965965
}
966966

967-
pub fn get_conversion_methods_for_diagnostic(
967+
pub(crate) fn get_conversion_methods_for_diagnostic(
968968
&self,
969969
span: Span,
970970
expected: Ty<'tcx>,
@@ -1186,7 +1186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11861186
}
11871187
}
11881188

1189-
pub enum TypeMismatchSource<'tcx> {
1189+
pub(crate) enum TypeMismatchSource<'tcx> {
11901190
/// Expected the binding to have the given type, but it was found to have
11911191
/// a different type. Find out when that type first became incompatible.
11921192
Ty(Ty<'tcx>),

compiler/rustc_hir_typeck/src/diverges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{Span, DUMMY_SP};
88
/// as diverging), with some manual adjustments for control-flow
99
/// primitives (approximating a CFG).
1010
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
11-
pub enum Diverges {
11+
pub(crate) enum Diverges {
1212
/// Potentially unknown, some cases converge,
1313
/// others require a CFG to determine them.
1414
Maybe,

0 commit comments

Comments
 (0)