Add warn(unreachable_pub) to rustc_hir_typeck.

This commit is contained in:
Nicholas Nethercote 2024-08-27 14:22:07 +10:00
parent 3aae994ca2
commit 7fc0444340
29 changed files with 183 additions and 174 deletions

View File

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

View File

@ -13,11 +13,11 @@ use super::method::MethodCallee;
use super::{FnCtxt, PlaceOp}; use super::{FnCtxt, PlaceOp};
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> { pub(crate) fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
Autoderef::new(self, self.param_env, self.body_id, span, base_ty) Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
} }
pub fn try_overloaded_deref( pub(crate) fn try_overloaded_deref(
&self, &self,
span: Span, span: Span,
base_ty: Ty<'tcx>, base_ty: Ty<'tcx>,
@ -26,11 +26,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Returns the adjustment steps. /// Returns the adjustment steps.
pub fn adjust_steps(&self, autoderef: &Autoderef<'a, 'tcx>) -> Vec<Adjustment<'tcx>> { pub(crate) fn adjust_steps(&self, autoderef: &Autoderef<'a, 'tcx>) -> Vec<Adjustment<'tcx>> {
self.register_infer_ok_obligations(self.adjust_steps_as_infer_ok(autoderef)) self.register_infer_ok_obligations(self.adjust_steps_as_infer_ok(autoderef))
} }
pub fn adjust_steps_as_infer_ok( pub(crate) fn adjust_steps_as_infer_ok(
&self, &self,
autoderef: &Autoderef<'a, 'tcx>, autoderef: &Autoderef<'a, 'tcx>,
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> { ) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {

View File

@ -29,7 +29,7 @@ use crate::errors;
/// Checks that it is legal to call methods of the trait corresponding /// Checks that it is legal to call methods of the trait corresponding
/// to `trait_id` (this only cares about the trait, not the specific /// to `trait_id` (this only cares about the trait, not the specific
/// method that is called). /// method that is called).
pub fn check_legal_trait_for_method_call( pub(crate) fn check_legal_trait_for_method_call(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
span: Span, span: Span,
receiver: Option<Span>, receiver: Option<Span>,
@ -62,7 +62,7 @@ enum CallStep<'tcx> {
} }
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_call( pub(crate) fn check_call(
&self, &self,
call_expr: &'tcx hir::Expr<'tcx>, call_expr: &'tcx hir::Expr<'tcx>,
callee_expr: &'tcx hir::Expr<'tcx>, callee_expr: &'tcx hir::Expr<'tcx>,
@ -940,7 +940,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DeferredCallResolution<'tcx> { pub(crate) struct DeferredCallResolution<'tcx> {
call_expr: &'tcx hir::Expr<'tcx>, call_expr: &'tcx hir::Expr<'tcx>,
callee_expr: &'tcx hir::Expr<'tcx>, callee_expr: &'tcx hir::Expr<'tcx>,
closure_ty: Ty<'tcx>, closure_ty: Ty<'tcx>,
@ -949,7 +949,7 @@ pub struct DeferredCallResolution<'tcx> {
} }
impl<'a, 'tcx> DeferredCallResolution<'tcx> { impl<'a, 'tcx> DeferredCallResolution<'tcx> {
pub fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) { pub(crate) fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
debug!("DeferredCallResolution::resolve() {:?}", self); debug!("DeferredCallResolution::resolve() {:?}", self);
// we should not be invoked until the closure kind has been // we should not be invoked until the closure kind has been

View File

@ -976,7 +976,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// adjusted type of the expression, if successful. /// adjusted type of the expression, if successful.
/// Adjustments are only recorded if the coercion succeeded. /// Adjustments are only recorded if the coercion succeeded.
/// The expressions *must not* have any preexisting adjustments. /// The expressions *must not* have any preexisting adjustments.
pub fn coerce( pub(crate) fn coerce(
&self, &self,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
expr_ty: Ty<'tcx>, expr_ty: Ty<'tcx>,
@ -1011,7 +1011,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// Returns false if the coercion creates any obligations that result in /// Returns false if the coercion creates any obligations that result in
/// errors. /// errors.
pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { pub(crate) fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool {
// FIXME(-Znext-solver): We need to structurally resolve both types here. // FIXME(-Znext-solver): We need to structurally resolve both types here.
let source = self.resolve_vars_with_obligations(expr_ty); let source = self.resolve_vars_with_obligations(expr_ty);
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target); debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
@ -1032,7 +1032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Given a type and a target type, this function will calculate and return /// Given a type and a target type, this function will calculate and return
/// how many dereference steps needed to achieve `expr_ty <: target`. If /// how many dereference steps needed to achieve `expr_ty <: target`. If
/// it's not possible, return `None`. /// it's not possible, return `None`.
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> { pub(crate) fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable); let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
// We don't ever need two-phase here since we throw out the result of the coercion // We don't ever need two-phase here since we throw out the result of the coercion
let coerce = Coerce::new(self, cause, AllowTwoPhase::No); let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
@ -1047,7 +1047,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// This function is for diagnostics only, since it does not register /// This function is for diagnostics only, since it does not register
/// trait or region sub-obligations. (presumably we could, but it's not /// trait or region sub-obligations. (presumably we could, but it's not
/// particularly important for diagnostics...) /// particularly important for diagnostics...)
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> { pub(crate) fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| { self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
self.infcx self.infcx
.type_implements_trait( .type_implements_trait(
@ -1341,7 +1341,7 @@ pub fn can_coerce<'tcx>(
/// } /// }
/// let final_ty = coerce.complete(fcx); /// let final_ty = coerce.complete(fcx);
/// ``` /// ```
pub struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> { pub(crate) struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> {
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,
final_ty: Option<Ty<'tcx>>, final_ty: Option<Ty<'tcx>>,
expressions: Expressions<'tcx, 'exprs, E>, expressions: Expressions<'tcx, 'exprs, E>,
@ -1350,7 +1350,7 @@ pub struct CoerceMany<'tcx, 'exprs, E: AsCoercionSite> {
/// The type of a `CoerceMany` that is storing up the expressions into /// The type of a `CoerceMany` that is storing up the expressions into
/// a buffer. We use this in `check/mod.rs` for things like `break`. /// a buffer. We use this in `check/mod.rs` for things like `break`.
pub type DynamicCoerceMany<'tcx> = CoerceMany<'tcx, 'tcx, &'tcx hir::Expr<'tcx>>; pub(crate) type DynamicCoerceMany<'tcx> = CoerceMany<'tcx, 'tcx, &'tcx hir::Expr<'tcx>>;
enum Expressions<'tcx, 'exprs, E: AsCoercionSite> { enum Expressions<'tcx, 'exprs, E: AsCoercionSite> {
Dynamic(Vec<&'tcx hir::Expr<'tcx>>), Dynamic(Vec<&'tcx hir::Expr<'tcx>>),
@ -1361,7 +1361,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// The usual case; collect the set of expressions dynamically. /// The usual case; collect the set of expressions dynamically.
/// If the full set of coercion sites is known before hand, /// If the full set of coercion sites is known before hand,
/// consider `with_coercion_sites()` instead to avoid allocation. /// consider `with_coercion_sites()` instead to avoid allocation.
pub fn new(expected_ty: Ty<'tcx>) -> Self { pub(crate) fn new(expected_ty: Ty<'tcx>) -> Self {
Self::make(expected_ty, Expressions::Dynamic(vec![])) Self::make(expected_ty, Expressions::Dynamic(vec![]))
} }
@ -1370,7 +1370,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// expected to pass each element in the slice to `coerce(...)` in /// expected to pass each element in the slice to `coerce(...)` in
/// order. This is used with arrays in particular to avoid /// order. This is used with arrays in particular to avoid
/// needlessly cloning the slice. /// needlessly cloning the slice.
pub fn with_coercion_sites(expected_ty: Ty<'tcx>, coercion_sites: &'exprs [E]) -> Self { pub(crate) fn with_coercion_sites(expected_ty: Ty<'tcx>, coercion_sites: &'exprs [E]) -> Self {
Self::make(expected_ty, Expressions::UpFront(coercion_sites)) Self::make(expected_ty, Expressions::UpFront(coercion_sites))
} }
@ -1386,7 +1386,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// Typically, this is used as the expected type when /// Typically, this is used as the expected type when
/// type-checking each of the alternative expressions whose types /// type-checking each of the alternative expressions whose types
/// we are trying to merge. /// we are trying to merge.
pub fn expected_ty(&self) -> Ty<'tcx> { pub(crate) fn expected_ty(&self) -> Ty<'tcx> {
self.expected_ty self.expected_ty
} }
@ -1394,7 +1394,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// at the LUB of the expressions we've seen so far (if any). This /// at the LUB of the expressions we've seen so far (if any). This
/// isn't *final* until you call `self.complete()`, which will return /// isn't *final* until you call `self.complete()`, which will return
/// the merged type. /// the merged type.
pub fn merged_ty(&self) -> Ty<'tcx> { pub(crate) fn merged_ty(&self) -> Ty<'tcx> {
self.final_ty.unwrap_or(self.expected_ty) self.final_ty.unwrap_or(self.expected_ty)
} }
@ -1403,7 +1403,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// could coerce from. This will record `expression`, and later /// could coerce from. This will record `expression`, and later
/// calls to `coerce` may come back and add adjustments and things /// calls to `coerce` may come back and add adjustments and things
/// if necessary. /// if necessary.
pub fn coerce<'a>( pub(crate) fn coerce<'a>(
&mut self, &mut self,
fcx: &FnCtxt<'a, 'tcx>, fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
@ -1425,7 +1425,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// The `augment_error` gives you a chance to extend the error /// The `augment_error` gives you a chance to extend the error
/// message, in case any results (e.g., we use this to suggest /// message, in case any results (e.g., we use this to suggest
/// removing a `;`). /// removing a `;`).
pub fn coerce_forced_unit<'a>( pub(crate) fn coerce_forced_unit<'a>(
&mut self, &mut self,
fcx: &FnCtxt<'a, 'tcx>, fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
@ -1920,7 +1920,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
} }
} }
pub fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> { pub(crate) fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> {
if let Some(final_ty) = self.final_ty { if let Some(final_ty) = self.final_ty {
final_ty final_ty
} else { } else {
@ -1934,7 +1934,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
/// Something that can be converted into an expression to which we can /// Something that can be converted into an expression to which we can
/// apply a coercion. /// apply a coercion.
pub trait AsCoercionSite { pub(crate) trait AsCoercionSite {
fn as_coercion_site(&self) -> &hir::Expr<'_>; fn as_coercion_site(&self) -> &hir::Expr<'_>;
} }

View File

@ -18,7 +18,7 @@ use super::method::probe;
use crate::FnCtxt; use crate::FnCtxt;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn emit_type_mismatch_suggestions( pub(crate) fn emit_type_mismatch_suggestions(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'tcx>, expr: &hir::Expr<'tcx>,
@ -70,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn emit_coerce_suggestions( pub(crate) fn emit_coerce_suggestions(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'tcx>, expr: &hir::Expr<'tcx>,
@ -165,13 +165,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Requires that the two types unify, and prints an error message if /// Requires that the two types unify, and prints an error message if
/// they don't. /// they don't.
pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) { pub(crate) fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
if let Err(e) = self.demand_suptype_diag(sp, expected, actual) { if let Err(e) = self.demand_suptype_diag(sp, expected, actual) {
e.emit(); e.emit();
} }
} }
pub fn demand_suptype_diag( pub(crate) fn demand_suptype_diag(
&'a self, &'a self,
sp: Span, sp: Span,
expected: Ty<'tcx>, expected: Ty<'tcx>,
@ -193,13 +193,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e)) .map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
} }
pub fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) { pub(crate) fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
if let Err(err) = self.demand_eqtype_diag(sp, expected, actual) { if let Err(err) = self.demand_eqtype_diag(sp, expected, actual) {
err.emit(); err.emit();
} }
} }
pub fn demand_eqtype_diag( pub(crate) fn demand_eqtype_diag(
&'a self, &'a self,
sp: Span, sp: Span,
expected: Ty<'tcx>, expected: Ty<'tcx>,
@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual) self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
} }
pub fn demand_eqtype_with_origin( pub(crate) fn demand_eqtype_with_origin(
&'a self, &'a self,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
@ -220,7 +220,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e)) .map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
} }
pub fn demand_coerce( pub(crate) fn demand_coerce(
&self, &self,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
checked_ty: Ty<'tcx>, checked_ty: Ty<'tcx>,
@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Notes the point at which a variable is constrained to some type incompatible /// Notes the point at which a variable is constrained to some type incompatible
/// with some expectation given by `source`. /// with some expectation given by `source`.
pub fn note_source_of_type_mismatch_constraint( pub(crate) fn note_source_of_type_mismatch_constraint(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
@ -558,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// When encountering a type error on the value of a `break`, try to point at the reason for the // When encountering a type error on the value of a `break`, try to point at the reason for the
// expected type. // expected type.
pub fn annotate_loop_expected_due_to_inference( pub(crate) fn annotate_loop_expected_due_to_inference(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
@ -964,7 +964,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
); );
} }
pub fn get_conversion_methods_for_diagnostic( pub(crate) fn get_conversion_methods_for_diagnostic(
&self, &self,
span: Span, span: Span,
expected: Ty<'tcx>, expected: Ty<'tcx>,
@ -1186,7 +1186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub enum TypeMismatchSource<'tcx> { pub(crate) enum TypeMismatchSource<'tcx> {
/// Expected the binding to have the given type, but it was found to have /// Expected the binding to have the given type, but it was found to have
/// a different type. Find out when that type first became incompatible. /// a different type. Find out when that type first became incompatible.
Ty(Ty<'tcx>), Ty(Ty<'tcx>),

View File

@ -8,7 +8,7 @@ use rustc_span::{Span, DUMMY_SP};
/// as diverging), with some manual adjustments for control-flow /// as diverging), with some manual adjustments for control-flow
/// primitives (approximating a CFG). /// primitives (approximating a CFG).
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Diverges { pub(crate) enum Diverges {
/// Potentially unknown, some cases converge, /// Potentially unknown, some cases converge,
/// others require a CFG to determine them. /// others require a CFG to determine them.
Maybe, Maybe,

View File

@ -17,7 +17,7 @@ use crate::fluent_generated as fluent;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_field_multiply_specified_in_initializer, code = E0062)] #[diag(hir_typeck_field_multiply_specified_in_initializer, code = E0062)]
pub struct FieldMultiplySpecifiedInInitializer { pub(crate) struct FieldMultiplySpecifiedInInitializer {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
@ -28,7 +28,7 @@ pub struct FieldMultiplySpecifiedInInitializer {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_return_stmt_outside_of_fn_body, code = E0572)] #[diag(hir_typeck_return_stmt_outside_of_fn_body, code = E0572)]
pub struct ReturnStmtOutsideOfFnBody { pub(crate) struct ReturnStmtOutsideOfFnBody {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[label(hir_typeck_encl_body_label)] #[label(hir_typeck_encl_body_label)]
@ -38,7 +38,7 @@ pub struct ReturnStmtOutsideOfFnBody {
pub statement_kind: ReturnLikeStatementKind, pub statement_kind: ReturnLikeStatementKind,
} }
pub enum ReturnLikeStatementKind { pub(crate) enum ReturnLikeStatementKind {
Return, Return,
Become, Become,
} }
@ -57,21 +57,21 @@ impl IntoDiagArg for ReturnLikeStatementKind {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_rustcall_incorrect_args)] #[diag(hir_typeck_rustcall_incorrect_args)]
pub struct RustCallIncorrectArgs { pub(crate) struct RustCallIncorrectArgs {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_yield_expr_outside_of_coroutine, code = E0627)] #[diag(hir_typeck_yield_expr_outside_of_coroutine, code = E0627)]
pub struct YieldExprOutsideOfCoroutine { pub(crate) struct YieldExprOutsideOfCoroutine {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_struct_expr_non_exhaustive, code = E0639)] #[diag(hir_typeck_struct_expr_non_exhaustive, code = E0639)]
pub struct StructExprNonExhaustive { pub(crate) struct StructExprNonExhaustive {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub what: &'static str, pub what: &'static str,
@ -79,21 +79,21 @@ pub struct StructExprNonExhaustive {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)] #[diag(hir_typeck_functional_record_update_on_non_struct, code = E0436)]
pub struct FunctionalRecordUpdateOnNonStruct { pub(crate) struct FunctionalRecordUpdateOnNonStruct {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_address_of_temporary_taken, code = E0745)] #[diag(hir_typeck_address_of_temporary_taken, code = E0745)]
pub struct AddressOfTemporaryTaken { pub(crate) struct AddressOfTemporaryTaken {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum AddReturnTypeSuggestion { pub(crate) enum AddReturnTypeSuggestion {
#[suggestion( #[suggestion(
hir_typeck_add_return_type_add, hir_typeck_add_return_type_add,
code = " -> {found}", code = " -> {found}",
@ -116,7 +116,7 @@ pub enum AddReturnTypeSuggestion {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum ExpectedReturnTypeLabel<'tcx> { pub(crate) enum ExpectedReturnTypeLabel<'tcx> {
#[label(hir_typeck_expected_default_return_type)] #[label(hir_typeck_expected_default_return_type)]
Unit { Unit {
#[primary_span] #[primary_span]
@ -132,7 +132,7 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_explicit_destructor, code = E0040)] #[diag(hir_typeck_explicit_destructor, code = E0040)]
pub struct ExplicitDestructorCall { pub(crate) struct ExplicitDestructorCall {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
@ -141,7 +141,7 @@ pub struct ExplicitDestructorCall {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum ExplicitDestructorCallSugg { pub(crate) enum ExplicitDestructorCallSugg {
#[suggestion(hir_typeck_suggestion, code = "drop", applicability = "maybe-incorrect")] #[suggestion(hir_typeck_suggestion, code = "drop", applicability = "maybe-incorrect")]
Empty(#[primary_span] Span), Empty(#[primary_span] Span),
#[multipart_suggestion(hir_typeck_suggestion, style = "short")] #[multipart_suggestion(hir_typeck_suggestion, style = "short")]
@ -155,7 +155,7 @@ pub enum ExplicitDestructorCallSugg {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_missing_parentheses_in_range, code = E0689)] #[diag(hir_typeck_missing_parentheses_in_range, code = E0689)]
pub struct MissingParenthesesInRange { pub(crate) struct MissingParenthesesInRange {
#[primary_span] #[primary_span]
#[label(hir_typeck_missing_parentheses_in_range)] #[label(hir_typeck_missing_parentheses_in_range)]
pub span: Span, pub span: Span,
@ -166,7 +166,7 @@ pub struct MissingParenthesesInRange {
} }
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
pub enum NeverTypeFallbackFlowingIntoUnsafe { pub(crate) enum NeverTypeFallbackFlowingIntoUnsafe {
#[help] #[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)] #[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
Call, Call,
@ -187,7 +187,7 @@ pub enum NeverTypeFallbackFlowingIntoUnsafe {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[help] #[help]
#[diag(hir_typeck_dependency_on_unit_never_type_fallback)] #[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
pub struct DependencyOnUnitNeverTypeFallback<'tcx> { pub(crate) struct DependencyOnUnitNeverTypeFallback<'tcx> {
#[note] #[note]
pub obligation_span: Span, pub obligation_span: Span,
pub obligation: ty::Predicate<'tcx>, pub obligation: ty::Predicate<'tcx>,
@ -199,7 +199,7 @@ pub struct DependencyOnUnitNeverTypeFallback<'tcx> {
style = "verbose", style = "verbose",
applicability = "maybe-incorrect" applicability = "maybe-incorrect"
)] )]
pub struct AddMissingParenthesesInRange { pub(crate) struct AddMissingParenthesesInRange {
pub func_name: String, pub func_name: String,
#[suggestion_part(code = "(")] #[suggestion_part(code = "(")]
pub left: Span, pub left: Span,
@ -207,7 +207,7 @@ pub struct AddMissingParenthesesInRange {
pub right: Span, pub right: Span,
} }
pub struct TypeMismatchFruTypo { pub(crate) struct TypeMismatchFruTypo {
/// Span of the LHS of the range /// Span of the LHS of the range
pub expr_span: Span, pub expr_span: Span,
/// Span of the `..RHS` part of the range /// Span of the `..RHS` part of the range
@ -246,7 +246,7 @@ impl Subdiagnostic for TypeMismatchFruTypo {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_lossy_provenance_int2ptr)] #[diag(hir_typeck_lossy_provenance_int2ptr)]
#[help] #[help]
pub struct LossyProvenanceInt2Ptr<'tcx> { pub(crate) struct LossyProvenanceInt2Ptr<'tcx> {
pub expr_ty: Ty<'tcx>, pub expr_ty: Ty<'tcx>,
pub cast_ty: Ty<'tcx>, pub cast_ty: Ty<'tcx>,
#[subdiagnostic] #[subdiagnostic]
@ -255,14 +255,14 @@ pub struct LossyProvenanceInt2Ptr<'tcx> {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_ptr_cast_add_auto_to_object)] #[diag(hir_typeck_ptr_cast_add_auto_to_object)]
pub struct PtrCastAddAutoToObject { pub(crate) struct PtrCastAddAutoToObject {
pub traits_len: usize, pub traits_len: usize,
pub traits: DiagSymbolList<String>, pub traits: DiagSymbolList<String>,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(hir_typeck_suggestion, applicability = "has-placeholders")] #[multipart_suggestion(hir_typeck_suggestion, applicability = "has-placeholders")]
pub struct LossyProvenanceInt2PtrSuggestion { pub(crate) struct LossyProvenanceInt2PtrSuggestion {
#[suggestion_part(code = "(...).with_addr(")] #[suggestion_part(code = "(...).with_addr(")]
pub lo: Span, pub lo: Span,
#[suggestion_part(code = ")")] #[suggestion_part(code = ")")]
@ -272,7 +272,7 @@ pub struct LossyProvenanceInt2PtrSuggestion {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_lossy_provenance_ptr2int)] #[diag(hir_typeck_lossy_provenance_ptr2int)]
#[help] #[help]
pub struct LossyProvenancePtr2Int<'tcx> { pub(crate) struct LossyProvenancePtr2Int<'tcx> {
pub expr_ty: Ty<'tcx>, pub expr_ty: Ty<'tcx>,
pub cast_ty: Ty<'tcx>, pub cast_ty: Ty<'tcx>,
#[subdiagnostic] #[subdiagnostic]
@ -280,7 +280,7 @@ pub struct LossyProvenancePtr2Int<'tcx> {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum LossyProvenancePtr2IntSuggestion<'tcx> { pub(crate) enum LossyProvenancePtr2IntSuggestion<'tcx> {
#[multipart_suggestion(hir_typeck_suggestion, applicability = "maybe-incorrect")] #[multipart_suggestion(hir_typeck_suggestion, applicability = "maybe-incorrect")]
NeedsParensCast { NeedsParensCast {
#[suggestion_part(code = "(")] #[suggestion_part(code = "(")]
@ -314,7 +314,7 @@ pub enum LossyProvenancePtr2IntSuggestion<'tcx> {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum HelpUseLatestEdition { pub(crate) enum HelpUseLatestEdition {
#[help(hir_typeck_help_set_edition_cargo)] #[help(hir_typeck_help_set_edition_cargo)]
#[note(hir_typeck_note_edition_guide)] #[note(hir_typeck_note_edition_guide)]
Cargo { edition: Edition }, Cargo { edition: Edition },
@ -324,7 +324,7 @@ pub enum HelpUseLatestEdition {
} }
impl HelpUseLatestEdition { impl HelpUseLatestEdition {
pub fn new() -> Self { pub(crate) fn new() -> Self {
let edition = LATEST_STABLE_EDITION; let edition = LATEST_STABLE_EDITION;
if rustc_session::utils::was_invoked_from_cargo() { if rustc_session::utils::was_invoked_from_cargo() {
Self::Cargo { edition } Self::Cargo { edition }
@ -336,7 +336,7 @@ impl HelpUseLatestEdition {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_invalid_callee, code = E0618)] #[diag(hir_typeck_invalid_callee, code = E0618)]
pub struct InvalidCallee { pub(crate) struct InvalidCallee {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub ty: String, pub ty: String,
@ -344,7 +344,7 @@ pub struct InvalidCallee {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_int_to_fat, code = E0606)] #[diag(hir_typeck_int_to_fat, code = E0606)]
pub struct IntToWide<'tcx> { pub(crate) struct IntToWide<'tcx> {
#[primary_span] #[primary_span]
#[label(hir_typeck_int_to_fat_label)] #[label(hir_typeck_int_to_fat_label)]
pub span: Span, pub span: Span,
@ -357,7 +357,7 @@ pub struct IntToWide<'tcx> {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum OptionResultRefMismatch { pub(crate) enum OptionResultRefMismatch {
#[suggestion( #[suggestion(
hir_typeck_option_result_copied, hir_typeck_option_result_copied,
code = ".copied()", code = ".copied()",
@ -396,7 +396,7 @@ pub enum OptionResultRefMismatch {
// }, // },
} }
pub struct RemoveSemiForCoerce { pub(crate) struct RemoveSemiForCoerce {
pub expr: Span, pub expr: Span,
pub ret: Span, pub ret: Span,
pub semi: Span, pub semi: Span,
@ -426,7 +426,7 @@ impl Subdiagnostic for RemoveSemiForCoerce {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_const_select_must_be_const)] #[diag(hir_typeck_const_select_must_be_const)]
#[help] #[help]
pub struct ConstSelectMustBeConst { pub(crate) struct ConstSelectMustBeConst {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
@ -435,7 +435,7 @@ pub struct ConstSelectMustBeConst {
#[diag(hir_typeck_const_select_must_be_fn)] #[diag(hir_typeck_const_select_must_be_fn)]
#[note] #[note]
#[help] #[help]
pub struct ConstSelectMustBeFn<'a> { pub(crate) struct ConstSelectMustBeFn<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub ty: Ty<'a>, pub ty: Ty<'a>,
@ -443,14 +443,14 @@ pub struct ConstSelectMustBeFn<'a> {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_union_pat_multiple_fields)] #[diag(hir_typeck_union_pat_multiple_fields)]
pub struct UnionPatMultipleFields { pub(crate) struct UnionPatMultipleFields {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_union_pat_dotdot)] #[diag(hir_typeck_union_pat_dotdot)]
pub struct UnionPatDotDot { pub(crate) struct UnionPatDotDot {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
@ -461,7 +461,7 @@ pub struct UnionPatDotDot {
applicability = "maybe-incorrect", applicability = "maybe-incorrect",
style = "verbose" style = "verbose"
)] )]
pub struct UseIsEmpty { pub(crate) struct UseIsEmpty {
#[suggestion_part(code = "!")] #[suggestion_part(code = "!")]
pub lo: Span, pub lo: Span,
#[suggestion_part(code = ".is_empty()")] #[suggestion_part(code = ".is_empty()")]
@ -471,13 +471,13 @@ pub struct UseIsEmpty {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_arg_mismatch_indeterminate)] #[diag(hir_typeck_arg_mismatch_indeterminate)]
pub struct ArgMismatchIndeterminate { pub(crate) struct ArgMismatchIndeterminate {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum SuggestBoxing { pub(crate) enum SuggestBoxing {
#[note(hir_typeck_suggest_boxing_note)] #[note(hir_typeck_suggest_boxing_note)]
#[multipart_suggestion( #[multipart_suggestion(
hir_typeck_suggest_boxing_when_appropriate, hir_typeck_suggest_boxing_when_appropriate,
@ -511,7 +511,7 @@ pub enum SuggestBoxing {
style = "verbose", style = "verbose",
code = "core::ptr::null_mut()" code = "core::ptr::null_mut()"
)] )]
pub struct SuggestPtrNullMut { pub(crate) struct SuggestPtrNullMut {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
@ -519,7 +519,7 @@ pub struct SuggestPtrNullMut {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_trivial_cast)] #[diag(hir_typeck_trivial_cast)]
#[help] #[help]
pub struct TrivialCast<'tcx> { pub(crate) struct TrivialCast<'tcx> {
pub numeric: bool, pub numeric: bool,
pub expr_ty: Ty<'tcx>, pub expr_ty: Ty<'tcx>,
pub cast_ty: Ty<'tcx>, pub cast_ty: Ty<'tcx>,
@ -527,7 +527,7 @@ pub struct TrivialCast<'tcx> {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_no_associated_item, code = E0599)] #[diag(hir_typeck_no_associated_item, code = E0599)]
pub struct NoAssociatedItem { pub(crate) struct NoAssociatedItem {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub item_kind: &'static str, pub item_kind: &'static str,
@ -539,7 +539,7 @@ pub struct NoAssociatedItem {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(hir_typeck_candidate_trait_note)] #[note(hir_typeck_candidate_trait_note)]
pub struct CandidateTraitNote { pub(crate) struct CandidateTraitNote {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub trait_name: String, pub trait_name: String,
@ -549,7 +549,7 @@ pub struct CandidateTraitNote {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_cannot_cast_to_bool, code = E0054)] #[diag(hir_typeck_cannot_cast_to_bool, code = E0054)]
pub struct CannotCastToBool<'tcx> { pub(crate) struct CannotCastToBool<'tcx> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub expr_ty: Ty<'tcx>, pub expr_ty: Ty<'tcx>,
@ -559,14 +559,14 @@ pub struct CannotCastToBool<'tcx> {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_cast_enum_drop)] #[diag(hir_typeck_cast_enum_drop)]
pub struct CastEnumDrop<'tcx> { pub(crate) struct CastEnumDrop<'tcx> {
pub expr_ty: Ty<'tcx>, pub expr_ty: Ty<'tcx>,
pub cast_ty: Ty<'tcx>, pub cast_ty: Ty<'tcx>,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_cast_unknown_pointer, code = E0641)] #[diag(hir_typeck_cast_unknown_pointer, code = E0641)]
pub struct CastUnknownPointer { pub(crate) struct CastUnknownPointer {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub to: bool, pub to: bool,
@ -574,7 +574,7 @@ pub struct CastUnknownPointer {
pub sub: CastUnknownPointerSub, pub sub: CastUnknownPointerSub,
} }
pub enum CastUnknownPointerSub { pub(crate) enum CastUnknownPointerSub {
To(Span), To(Span),
From(Span), From(Span),
} }
@ -601,7 +601,7 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum CannotCastToBoolHelp { pub(crate) enum CannotCastToBoolHelp {
#[suggestion( #[suggestion(
hir_typeck_suggestion, hir_typeck_suggestion,
applicability = "machine-applicable", applicability = "machine-applicable",
@ -615,7 +615,7 @@ pub enum CannotCastToBoolHelp {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_ctor_is_private, code = E0603)] #[diag(hir_typeck_ctor_is_private, code = E0603)]
pub struct CtorIsPrivate { pub(crate) struct CtorIsPrivate {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub def: String, pub def: String,
@ -623,7 +623,7 @@ pub struct CtorIsPrivate {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(hir_typeck_deref_is_empty)] #[note(hir_typeck_deref_is_empty)]
pub struct DerefImplsIsEmpty { pub(crate) struct DerefImplsIsEmpty {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub deref_ty: String, pub deref_ty: String,
@ -635,7 +635,7 @@ pub struct DerefImplsIsEmpty {
applicability = "machine-applicable", applicability = "machine-applicable",
style = "verbose" style = "verbose"
)] )]
pub struct SuggestConvertViaMethod<'tcx> { pub(crate) struct SuggestConvertViaMethod<'tcx> {
#[suggestion_part(code = "{sugg}")] #[suggestion_part(code = "{sugg}")]
pub span: Span, pub span: Span,
#[suggestion_part(code = "")] #[suggestion_part(code = "")]
@ -647,13 +647,13 @@ pub struct SuggestConvertViaMethod<'tcx> {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(hir_typeck_note_caller_chooses_ty_for_ty_param)] #[note(hir_typeck_note_caller_chooses_ty_for_ty_param)]
pub struct NoteCallerChoosesTyForTyParam<'tcx> { pub(crate) struct NoteCallerChoosesTyForTyParam<'tcx> {
pub ty_param_name: Symbol, pub ty_param_name: Symbol,
pub found_ty: Ty<'tcx>, pub found_ty: Ty<'tcx>,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum SuggestBoxingForReturnImplTrait { pub(crate) enum SuggestBoxingForReturnImplTrait {
#[multipart_suggestion(hir_typeck_rpit_change_return_type, applicability = "maybe-incorrect")] #[multipart_suggestion(hir_typeck_rpit_change_return_type, applicability = "maybe-incorrect")]
ChangeReturnType { ChangeReturnType {
#[suggestion_part(code = "Box<dyn")] #[suggestion_part(code = "Box<dyn")]
@ -672,7 +672,7 @@ pub enum SuggestBoxingForReturnImplTrait {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(hir_typeck_self_ctor_from_outer_item, code = E0401)] #[diag(hir_typeck_self_ctor_from_outer_item, code = E0401)]
pub struct SelfCtorFromOuterItem { pub(crate) struct SelfCtorFromOuterItem {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
#[label] #[label]
@ -683,7 +683,7 @@ pub struct SelfCtorFromOuterItem {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(hir_typeck_self_ctor_from_outer_item)] #[diag(hir_typeck_self_ctor_from_outer_item)]
pub struct SelfCtorFromOuterItemLint { pub(crate) struct SelfCtorFromOuterItemLint {
#[label] #[label]
pub impl_span: Span, pub impl_span: Span,
#[subdiagnostic] #[subdiagnostic]
@ -692,7 +692,7 @@ pub struct SelfCtorFromOuterItemLint {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion(hir_typeck_suggestion, code = "{name}", applicability = "machine-applicable")] #[suggestion(hir_typeck_suggestion, code = "{name}", applicability = "machine-applicable")]
pub struct ReplaceWithName { pub(crate) struct ReplaceWithName {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub name: String, pub name: String,

View File

@ -7,7 +7,7 @@ use super::FnCtxt;
/// When type-checking an expression, we propagate downward /// When type-checking an expression, we propagate downward
/// whatever type hint we are able in the form of an `Expectation`. /// whatever type hint we are able in the form of an `Expectation`.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Expectation<'tcx> { pub(crate) enum Expectation<'tcx> {
/// We know nothing about what type this expression should have. /// We know nothing about what type this expression should have.
NoExpectation, NoExpectation,

View File

@ -51,7 +51,7 @@ use crate::{
}; };
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_expr_has_type_or_error( pub(crate) fn check_expr_has_type_or_error(
&self, &self,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,
@ -977,7 +977,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Check if the expression that could not be assigned to was a typoed expression that /// Check if the expression that could not be assigned to was a typoed expression that
pub fn check_for_missing_semi(&self, expr: &'tcx hir::Expr<'tcx>, err: &mut Diag<'_>) -> bool { pub(crate) fn check_for_missing_semi(
&self,
expr: &'tcx hir::Expr<'tcx>,
err: &mut Diag<'_>,
) -> bool {
if let hir::ExprKind::Binary(binop, lhs, rhs) = expr.kind if let hir::ExprKind::Binary(binop, lhs, rhs) = expr.kind
&& let hir::BinOpKind::Mul = binop.node && let hir::BinOpKind::Mul = binop.node
&& self.tcx.sess.source_map().is_multiline(lhs.span.between(rhs.span)) && self.tcx.sess.source_map().is_multiline(lhs.span.between(rhs.span))

View File

@ -18,7 +18,7 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
use crate::{errors, FnCtxt, TypeckRootCtxt}; use crate::{errors, FnCtxt, TypeckRootCtxt};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum DivergingFallbackBehavior { pub(crate) enum DivergingFallbackBehavior {
/// Always fallback to `()` (aka "always spontaneous decay") /// Always fallback to `()` (aka "always spontaneous decay")
ToUnit, ToUnit,
/// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken. /// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken.

View File

@ -132,18 +132,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
deferred_call_resolutions.remove(&closure_def_id).unwrap_or_default() deferred_call_resolutions.remove(&closure_def_id).unwrap_or_default()
} }
pub fn tag(&self) -> String { fn tag(&self) -> String {
format!("{self:p}") format!("{self:p}")
} }
pub fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> { pub(crate) fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid)) span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid))
}) })
} }
#[inline] #[inline]
pub fn write_ty(&self, id: HirId, ty: Ty<'tcx>) { pub(crate) fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
let mut typeck = self.typeck_results.borrow_mut(); let mut typeck = self.typeck_results.borrow_mut();
let mut node_ty = typeck.node_types_mut(); let mut node_ty = typeck.node_types_mut();
@ -165,7 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn write_field_index( pub(crate) fn write_field_index(
&self, &self,
hir_id: HirId, hir_id: HirId,
index: FieldIdx, index: FieldIdx,
@ -198,7 +198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.write_args(hir_id, method.args); self.write_args(hir_id, method.args);
} }
pub fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) { fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
if !args.is_empty() { if !args.is_empty() {
debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag()); debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
@ -364,7 +364,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
} }
pub fn require_type_meets( pub(crate) fn require_type_meets(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
span: Span, span: Span,
@ -374,7 +374,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_bound(ty, def_id, traits::ObligationCause::new(span, self.body_id, code)); self.register_bound(ty, def_id, traits::ObligationCause::new(span, self.body_id, code));
} }
pub fn require_type_is_sized( pub(crate) fn require_type_is_sized(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
span: Span, span: Span,
@ -386,7 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn require_type_is_sized_deferred( pub(crate) fn require_type_is_sized_deferred(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
span: Span, span: Span,
@ -397,7 +397,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn require_type_has_static_alignment( pub(crate) fn require_type_has_static_alignment(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
span: Span, span: Span,
@ -426,7 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn register_bound( pub(crate) fn register_bound(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
def_id: DefId, def_id: DefId,
@ -443,7 +443,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> { pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
let ty = self.lowerer().lower_ty(hir_ty); let ty = self.lowerer().lower_ty(hir_ty);
self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None)); self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
LoweredTy::from_raw(self, hir_ty.span, ty) LoweredTy::from_raw(self, hir_ty.span, ty)
@ -474,7 +474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn lower_array_length(&self, length: &hir::ArrayLen<'tcx>) -> ty::Const<'tcx> { pub(crate) fn lower_array_length(&self, length: &hir::ArrayLen<'tcx>) -> ty::Const<'tcx> {
match length { match length {
hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span), hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span),
hir::ArrayLen::Body(const_arg) => { hir::ArrayLen::Body(const_arg) => {
@ -486,7 +486,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn lower_const_arg( pub(crate) fn lower_const_arg(
&self, &self,
const_arg: &'tcx hir::ConstArg<'tcx>, const_arg: &'tcx hir::ConstArg<'tcx>,
param_def_id: DefId, param_def_id: DefId,
@ -515,7 +515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
t.has_free_regions() || t.has_aliases() || t.has_infer_types() t.has_free_regions() || t.has_aliases() || t.has_infer_types()
} }
pub fn node_ty(&self, id: HirId) -> Ty<'tcx> { pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => t, Some(&t) => t,
None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e), None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
@ -529,7 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> { pub(crate) fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t), Some(&t) => Some(t),
None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)), None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
@ -538,7 +538,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Registers an obligation for checking later, during regionck, that `arg` is well-formed. /// Registers an obligation for checking later, during regionck, that `arg` is well-formed.
pub fn register_wf_obligation( pub(crate) fn register_wf_obligation(
&self, &self,
arg: ty::GenericArg<'tcx>, arg: ty::GenericArg<'tcx>,
span: Span, span: Span,
@ -555,7 +555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Registers obligations that all `args` are well-formed. /// Registers obligations that all `args` are well-formed.
pub fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, expr: &hir::Expr<'_>) { pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, expr: &hir::Expr<'_>) {
for arg in args.iter().filter(|arg| { for arg in args.iter().filter(|arg| {
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..)) matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
}) { }) {
@ -566,7 +566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// FIXME(arielb1): use this instead of field.ty everywhere // FIXME(arielb1): use this instead of field.ty everywhere
// Only for fields! Returns <none> for methods> // Only for fields! Returns <none> for methods>
// Indifferent to privacy flags // Indifferent to privacy flags
pub fn field_ty( pub(crate) fn field_ty(
&self, &self,
span: Span, span: Span,
field: &'tcx ty::FieldDef, field: &'tcx ty::FieldDef,
@ -897,7 +897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Given a `HirId`, return the `HirId` of the enclosing function, its `FnDecl`, and whether a /// Given a `HirId`, return the `HirId` of the enclosing function, its `FnDecl`, and whether a
/// suggestion can be made, `None` otherwise. /// suggestion can be made, `None` otherwise.
pub fn get_fn_decl( pub(crate) fn get_fn_decl(
&self, &self,
blk_id: HirId, blk_id: HirId,
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> { ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> {
@ -1534,7 +1534,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// If no resolution is possible, then an error is reported. /// If no resolution is possible, then an error is reported.
/// Numeric inference variables may be left unresolved. /// Numeric inference variables may be left unresolved.
pub fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> { pub(crate) fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
let ty = self.try_structurally_resolve_type(sp, ty); let ty = self.try_structurally_resolve_type(sp, ty);
if !ty.is_ty_var() { if !ty.is_ty_var() {

View File

@ -12,7 +12,7 @@ use rustc_trait_selection::traits;
use crate::FnCtxt; use crate::FnCtxt;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn adjust_fulfillment_error_for_expr_obligation( pub(crate) fn adjust_fulfillment_error_for_expr_obligation(
&self, &self,
error: &mut traits::FulfillmentError<'tcx>, error: &mut traits::FulfillmentError<'tcx>,
) -> bool { ) -> bool {
@ -483,7 +483,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
* *
* This function only updates the error span. * This function only updates the error span.
*/ */
pub fn blame_specific_expr_if_possible( pub(crate) fn blame_specific_expr_if_possible(
&self, &self,
error: &mut traits::FulfillmentError<'tcx>, error: &mut traits::FulfillmentError<'tcx>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,

View File

@ -17,7 +17,7 @@ rustc_index::newtype_index! {
} }
impl ExpectedIdx { impl ExpectedIdx {
pub fn to_provided_idx(self) -> ProvidedIdx { pub(crate) fn to_provided_idx(self) -> ProvidedIdx {
ProvidedIdx::from_usize(self.as_usize()) ProvidedIdx::from_usize(self.as_usize())
} }
} }

View File

@ -45,7 +45,7 @@ use crate::{
}; };
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub enum DivergingBlockBehavior { pub(crate) enum DivergingBlockBehavior {
/// This is the current stable behavior: /// This is the current stable behavior:
/// ///
/// ```rust /// ```rust
@ -1556,7 +1556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn check_struct_path( pub(crate) fn check_struct_path(
&self, &self,
qpath: &QPath<'tcx>, qpath: &QPath<'tcx>,
hir_id: HirId, hir_id: HirId,
@ -1622,7 +1622,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn check_decl_initializer( fn check_decl_initializer(
&self, &self,
hir_id: HirId, hir_id: HirId,
pat: &'tcx hir::Pat<'tcx>, pat: &'tcx hir::Pat<'tcx>,
@ -1700,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Type check a `let` statement. /// Type check a `let` statement.
pub fn check_decl_local(&self, local: &'tcx hir::LetStmt<'tcx>) { fn check_decl_local(&self, local: &'tcx hir::LetStmt<'tcx>) {
self.check_decl(local.into()); self.check_decl(local.into());
if local.pat.is_never_pattern() { if local.pat.is_never_pattern() {
self.diverges.set(Diverges::Always { self.diverges.set(Diverges::Always {
@ -1710,7 +1710,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>) { fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>) {
// Don't do all the complex logic below for `DeclItem`. // Don't do all the complex logic below for `DeclItem`.
match stmt.kind { match stmt.kind {
hir::StmtKind::Item(..) => return, hir::StmtKind::Item(..) => return,
@ -1745,7 +1745,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.diverges.set(self.diverges.get() | old_diverges); self.diverges.set(self.diverges.get() | old_diverges);
} }
pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) { pub(crate) fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) {
let unit = self.tcx.types.unit; let unit = self.tcx.types.unit;
let ty = self.check_block_with_expected(blk, ExpectHasType(unit)); let ty = self.check_block_with_expected(blk, ExpectHasType(unit));

View File

@ -117,7 +117,7 @@ pub(crate) struct FnCtxt<'a, 'tcx> {
} }
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn new( pub(crate) fn new(
root_ctxt: &'a TypeckRootCtxt<'tcx>, root_ctxt: &'a TypeckRootCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId, body_id: LocalDefId,
@ -148,15 +148,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.root_ctxt.infcx.dcx() self.root_ctxt.infcx.dcx()
} }
pub fn cause(&self, span: Span, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> { pub(crate) fn cause(
&self,
span: Span,
code: ObligationCauseCode<'tcx>,
) -> ObligationCause<'tcx> {
ObligationCause::new(span, self.body_id, code) ObligationCause::new(span, self.body_id, code)
} }
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> { pub(crate) fn misc(&self, span: Span) -> ObligationCause<'tcx> {
self.cause(span, ObligationCauseCode::Misc) self.cause(span, ObligationCauseCode::Misc)
} }
pub fn sess(&self) -> &Session { pub(crate) fn sess(&self) -> &Session {
self.tcx.sess self.tcx.sess
} }
@ -165,7 +169,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Use [`InferCtxtErrorExt::err_ctxt`] to start one without a `TypeckResults`. /// Use [`InferCtxtErrorExt::err_ctxt`] to start one without a `TypeckResults`.
/// ///
/// [`InferCtxtErrorExt::err_ctxt`]: rustc_trait_selection::error_reporting::InferCtxtErrorExt::err_ctxt /// [`InferCtxtErrorExt::err_ctxt`]: rustc_trait_selection::error_reporting::InferCtxtErrorExt::err_ctxt
pub fn err_ctxt(&'a self) -> TypeErrCtxt<'a, 'tcx> { pub(crate) fn err_ctxt(&'a self) -> TypeErrCtxt<'a, 'tcx> {
let mut sub_relations = SubRelations::default(); let mut sub_relations = SubRelations::default();
sub_relations.add_constraints( sub_relations.add_constraints(
self, self,
@ -365,7 +369,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
/// This is a bridge between the interface of HIR ty lowering, which outputs a raw /// This is a bridge between the interface of HIR ty lowering, which outputs a raw
/// `Ty`, and the API in this module, which expect `Ty` to be fully normalized. /// `Ty`, and the API in this module, which expect `Ty` to be fully normalized.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct LoweredTy<'tcx> { pub(crate) struct LoweredTy<'tcx> {
/// The unnormalized type provided by the user. /// The unnormalized type provided by the user.
pub raw: Ty<'tcx>, pub raw: Ty<'tcx>,
@ -374,7 +378,7 @@ pub struct LoweredTy<'tcx> {
} }
impl<'tcx> LoweredTy<'tcx> { impl<'tcx> LoweredTy<'tcx> {
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> { fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
// FIXME(-Znext-solver): We're still figuring out how to best handle // FIXME(-Znext-solver): We're still figuring out how to best handle
// normalization and this doesn't feel too great. We should look at this // normalization and this doesn't feel too great. We should look at this
// code again before stabilizing it. // code again before stabilizing it.

View File

@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// - Points out the method's return type as the reason for the expected type. /// - Points out the method's return type as the reason for the expected type.
/// - Possible missing semicolon. /// - Possible missing semicolon.
/// - Possible missing return type if the return type is the default, and not `fn main()`. /// - Possible missing return type if the return type is the default, and not `fn main()`.
pub fn suggest_mismatched_types_on_tail( pub(crate) fn suggest_mismatched_types_on_tail(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.err_ctxt().extract_callable_info(self.body_id, self.param_env, ty) self.err_ctxt().extract_callable_info(self.body_id, self.param_env, ty)
} }
pub fn suggest_two_fn_call( pub(crate) fn suggest_two_fn_call(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
lhs_expr: &'tcx hir::Expr<'tcx>, lhs_expr: &'tcx hir::Expr<'tcx>,
@ -251,7 +251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn suggest_remove_last_method_call( pub(crate) fn suggest_remove_last_method_call(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'tcx>, expr: &hir::Expr<'tcx>,
@ -280,7 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false false
} }
pub fn suggest_deref_ref_or_into( pub(crate) fn suggest_deref_ref_or_into(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'tcx>, expr: &hir::Expr<'tcx>,
@ -747,7 +747,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// If the expression is the expression of a closure without block (`|| expr`), a /// If the expression is the expression of a closure without block (`|| expr`), a
/// block is needed to be added too (`|| { expr; }`). This is denoted by `needs_block`. /// block is needed to be added too (`|| { expr; }`). This is denoted by `needs_block`.
pub fn suggest_missing_semicolon( pub(crate) fn suggest_missing_semicolon(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expression: &'tcx hir::Expr<'tcx>, expression: &'tcx hir::Expr<'tcx>,
@ -2077,7 +2077,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If the expr is a while or for loop and is the tail expr of its // If the expr is a while or for loop and is the tail expr of its
// enclosing body suggest returning a value right after it // enclosing body suggest returning a value right after it
pub fn suggest_returning_value_after_loop( pub(crate) fn suggest_returning_value_after_loop(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
expr: &hir::Expr<'tcx>, expr: &hir::Expr<'tcx>,

View File

@ -38,7 +38,7 @@ fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
} }
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) { pub(crate) fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
let tcx = self.tcx; let tcx = self.tcx;
let dl = &tcx.data_layout; let dl = &tcx.data_layout;
let span = tcx.hir().span(hir_id); let span = tcx.hir().span(hir_id);

View File

@ -8,6 +8,7 @@
#![feature(let_chains)] #![feature(let_chains)]
#![feature(never_type)] #![feature(never_type)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end // tidy-alphabetical-end
#[macro_use] #[macro_use]

View File

@ -42,13 +42,13 @@ impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ConfirmResult<'tcx> { pub(crate) struct ConfirmResult<'tcx> {
pub callee: MethodCallee<'tcx>, pub callee: MethodCallee<'tcx>,
pub illegal_sized_bound: Option<Span>, pub illegal_sized_bound: Option<Span>,
} }
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn confirm_method( pub(crate) fn confirm_method(
&self, &self,
span: Span, span: Span,
self_expr: &'tcx hir::Expr<'tcx>, self_expr: &'tcx hir::Expr<'tcx>,
@ -66,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
confirm_cx.confirm(unadjusted_self_ty, pick, segment) confirm_cx.confirm(unadjusted_self_ty, pick, segment)
} }
pub fn confirm_method_for_diagnostic( pub(crate) fn confirm_method_for_diagnostic(
&self, &self,
span: Span, span: Span,
self_expr: &'tcx hir::Expr<'tcx>, self_expr: &'tcx hir::Expr<'tcx>,

View File

@ -4,7 +4,7 @@
mod confirm; mod confirm;
mod prelude_edition_lints; mod prelude_edition_lints;
pub mod probe; pub(crate) mod probe;
mod suggest; mod suggest;
use rustc_errors::{Applicability, Diag, SubdiagMessage}; use rustc_errors::{Applicability, Diag, SubdiagMessage};
@ -24,15 +24,15 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_trait_selection::traits::{self, NormalizeExt}; use rustc_trait_selection::traits::{self, NormalizeExt};
use self::probe::{IsSuggestion, ProbeScope}; use self::probe::{IsSuggestion, ProbeScope};
pub use self::MethodError::*; pub(crate) use self::MethodError::*;
use crate::FnCtxt; use crate::FnCtxt;
pub fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
probe::provide(providers); probe::provide(providers);
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct MethodCallee<'tcx> { pub(crate) struct MethodCallee<'tcx> {
/// Impl method ID, for inherent methods, or trait method ID, otherwise. /// Impl method ID, for inherent methods, or trait method ID, otherwise.
pub def_id: DefId, pub def_id: DefId,
pub args: GenericArgsRef<'tcx>, pub args: GenericArgsRef<'tcx>,
@ -44,7 +44,7 @@ pub struct MethodCallee<'tcx> {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum MethodError<'tcx> { pub(crate) enum MethodError<'tcx> {
// Did not find an applicable method, but we did find various near-misses that may work. // Did not find an applicable method, but we did find various near-misses that may work.
NoMatch(NoMatchData<'tcx>), NoMatch(NoMatchData<'tcx>),
@ -70,7 +70,7 @@ pub enum MethodError<'tcx> {
// Contains a list of static methods that may apply, a list of unsatisfied trait predicates which // Contains a list of static methods that may apply, a list of unsatisfied trait predicates which
// could lead to matches if satisfied, and a list of not-in-scope traits which may work. // could lead to matches if satisfied, and a list of not-in-scope traits which may work.
#[derive(Debug)] #[derive(Debug)]
pub struct NoMatchData<'tcx> { pub(crate) struct NoMatchData<'tcx> {
pub static_candidates: Vec<CandidateSource>, pub static_candidates: Vec<CandidateSource>,
pub unsatisfied_predicates: pub unsatisfied_predicates:
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>, Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
@ -82,7 +82,7 @@ pub struct NoMatchData<'tcx> {
// A pared down enum describing just the places from which a method // A pared down enum describing just the places from which a method
// candidate can arise. Used for error reporting only. // candidate can arise. Used for error reporting only.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum CandidateSource { pub(crate) enum CandidateSource {
Impl(DefId), Impl(DefId),
Trait(DefId /* trait id */), Trait(DefId /* trait id */),
} }
@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(result.callee) Ok(result.callee)
} }
pub fn lookup_method_for_diagnostic( pub(crate) fn lookup_method_for_diagnostic(
&self, &self,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
segment: &hir::PathSegment<'tcx>, segment: &hir::PathSegment<'tcx>,
@ -296,7 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(pick) Ok(pick)
} }
pub fn lookup_probe_for_diagnostic( pub(crate) fn lookup_probe_for_diagnostic(
&self, &self,
method_name: Ident, method_name: Ident,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
@ -569,7 +569,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Finds item with name `item_name` defined in impl/trait `def_id` /// Finds item with name `item_name` defined in impl/trait `def_id`
/// and return it, or `None`, if no such item was defined there. /// and return it, or `None`, if no such item was defined there.
pub fn associated_value(&self, def_id: DefId, item_name: Ident) -> Option<ty::AssocItem> { fn associated_value(&self, def_id: DefId, item_name: Ident) -> Option<ty::AssocItem> {
self.tcx self.tcx
.associated_items(def_id) .associated_items(def_id)
.find_by_name_and_namespace(self.tcx, item_name, Namespace::ValueNS, def_id) .find_by_name_and_namespace(self.tcx, item_name, Namespace::ValueNS, def_id)

View File

@ -38,14 +38,14 @@ use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use self::CandidateKind::*; use self::CandidateKind::*;
pub use self::PickKind::*; pub(crate) use self::PickKind::*;
use super::{suggest, CandidateSource, MethodError, NoMatchData}; use super::{suggest, CandidateSource, MethodError, NoMatchData};
use crate::FnCtxt; use crate::FnCtxt;
/// Boolean flag used to indicate if this search is for a suggestion /// Boolean flag used to indicate if this search is for a suggestion
/// or not. If true, we can allow ambiguity and so forth. /// or not. If true, we can allow ambiguity and so forth.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct IsSuggestion(pub bool); pub(crate) struct IsSuggestion(pub bool);
pub(crate) struct ProbeContext<'a, 'tcx> { pub(crate) struct ProbeContext<'a, 'tcx> {
fcx: &'a FnCtxt<'a, 'tcx>, fcx: &'a FnCtxt<'a, 'tcx>,
@ -134,7 +134,7 @@ enum ProbeResult {
/// (at most) one of these. Either the receiver has type `T` and we convert it to `&T` (or with /// (at most) one of these. Either the receiver has type `T` and we convert it to `&T` (or with
/// `mut`), or it has type `*mut T` and we convert it to `*const T`. /// `mut`), or it has type `*mut T` and we convert it to `*const T`.
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
pub enum AutorefOrPtrAdjustment { pub(crate) enum AutorefOrPtrAdjustment {
/// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it. /// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it.
/// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing. /// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing.
Autoref { Autoref {
@ -158,7 +158,7 @@ impl AutorefOrPtrAdjustment {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Pick<'tcx> { pub(crate) struct Pick<'tcx> {
pub item: ty::AssocItem, pub item: ty::AssocItem,
pub kind: PickKind<'tcx>, pub kind: PickKind<'tcx>,
pub import_ids: SmallVec<[LocalDefId; 1]>, pub import_ids: SmallVec<[LocalDefId; 1]>,
@ -179,7 +179,7 @@ pub struct Pick<'tcx> {
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum PickKind<'tcx> { pub(crate) enum PickKind<'tcx> {
InherentImplPick, InherentImplPick,
ObjectPick, ObjectPick,
TraitPick, TraitPick,
@ -189,10 +189,10 @@ pub enum PickKind<'tcx> {
), ),
} }
pub type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>; pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum Mode { pub(crate) enum Mode {
// An expression of the form `receiver.method_name(...)`. // An expression of the form `receiver.method_name(...)`.
// Autoderefs are performed on `receiver`, lookup is done based on the // Autoderefs are performed on `receiver`, lookup is done based on the
// `self` argument of the method, and static methods aren't considered. // `self` argument of the method, and static methods aren't considered.
@ -204,7 +204,7 @@ pub enum Mode {
} }
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum ProbeScope { pub(crate) enum ProbeScope {
// Single candidate coming from pre-resolved delegation method. // Single candidate coming from pre-resolved delegation method.
Single(DefId), Single(DefId),
@ -507,7 +507,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
providers.method_autoderef_steps = method_autoderef_steps; providers.method_autoderef_steps = method_autoderef_steps;
} }
@ -1288,7 +1288,7 @@ impl<'tcx> Pick<'tcx> {
/// Checks whether two picks do not refer to the same trait item for the same `Self` type. /// Checks whether two picks do not refer to the same trait item for the same `Self` type.
/// Only useful for comparisons of picks in order to improve diagnostics. /// Only useful for comparisons of picks in order to improve diagnostics.
/// Do not use for type checking. /// Do not use for type checking.
pub fn differs_from(&self, other: &Self) -> bool { pub(crate) fn differs_from(&self, other: &Self) -> bool {
let Self { let Self {
item: item:
AssocItem { AssocItem {
@ -1312,7 +1312,7 @@ impl<'tcx> Pick<'tcx> {
} }
/// In case there were unstable name collisions, emit them as a lint. /// In case there were unstable name collisions, emit them as a lint.
pub fn maybe_emit_unstable_name_collision_hint( pub(crate) fn maybe_emit_unstable_name_collision_hint(
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
span: Span, span: Span,

View File

@ -415,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err err
} }
pub fn suggest_use_shadowed_binding_with_method( fn suggest_use_shadowed_binding_with_method(
&self, &self,
self_source: SelfSource<'tcx>, self_source: SelfSource<'tcx>,
method_name: Ident, method_name: Ident,
@ -4223,19 +4223,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum SelfSource<'a> { enum SelfSource<'a> {
QPath(&'a hir::Ty<'a>), QPath(&'a hir::Ty<'a>),
MethodCall(&'a hir::Expr<'a> /* rcvr */), MethodCall(&'a hir::Expr<'a> /* rcvr */),
} }
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
pub struct TraitInfo { pub(crate) struct TraitInfo {
pub def_id: DefId, pub def_id: DefId,
} }
/// Retrieves all traits in this crate and any dependent crates, /// Retrieves all traits in this crate and any dependent crates,
/// and wraps them into `TraitInfo` for custom sorting. /// and wraps them into `TraitInfo` for custom sorting.
pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> { pub(crate) fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
tcx.all_traits().map(|def_id| TraitInfo { def_id }).collect() tcx.all_traits().map(|def_id| TraitInfo { def_id }).collect()
} }

View File

@ -25,7 +25,7 @@ use crate::Expectation;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Checks a `a <op>= b` /// Checks a `a <op>= b`
pub fn check_binop_assign( pub(crate) fn check_binop_assign(
&self, &self,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
op: hir::BinOp, op: hir::BinOp,
@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Checks a potentially overloaded binary operator. /// Checks a potentially overloaded binary operator.
pub fn check_binop( pub(crate) fn check_binop(
&self, &self,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
op: hir::BinOp, op: hir::BinOp,
@ -770,7 +770,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn check_user_unop( pub(crate) fn check_user_unop(
&self, &self,
ex: &'tcx hir::Expr<'tcx>, ex: &'tcx hir::Expr<'tcx>,
operand_ty: Ty<'tcx>, operand_ty: Ty<'tcx>,

View File

@ -944,7 +944,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn check_dereferenceable( fn check_dereferenceable(
&self, &self,
span: Span, span: Span,
expected: Ty<'tcx>, expected: Ty<'tcx>,

View File

@ -246,7 +246,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// always know whether a place needs to be mutable or not in the first pass. /// always know whether a place needs to be mutable or not in the first pass.
/// This happens whether there is an implicit mutable reborrow, e.g. when the type /// This happens whether there is an implicit mutable reborrow, e.g. when the type
/// is used as the receiver of a method call. /// is used as the receiver of a method call.
pub fn convert_place_derefs_to_mutable(&self, expr: &hir::Expr<'_>) { pub(crate) fn convert_place_derefs_to_mutable(&self, expr: &hir::Expr<'_>) {
// Gather up expressions we want to munge. // Gather up expressions we want to munge.
let mut exprs = vec![expr]; let mut exprs = vec![expr];

View File

@ -65,7 +65,7 @@ fn record_rvalue_scope(
} }
} }
pub fn resolve_rvalue_scopes<'a, 'tcx>( pub(crate) fn resolve_rvalue_scopes<'a, 'tcx>(
fcx: &'a FnCtxt<'a, 'tcx>, fcx: &'a FnCtxt<'a, 'tcx>,
scope_tree: &'a ScopeTree, scope_tree: &'a ScopeTree,
def_id: DefId, def_id: DefId,

View File

@ -77,7 +77,7 @@ impl<'tcx> Deref for TypeckRootCtxt<'tcx> {
} }
impl<'tcx> TypeckRootCtxt<'tcx> { impl<'tcx> TypeckRootCtxt<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner; let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;
let infcx = tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(def_id).build(); let infcx = tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(def_id).build();
@ -124,7 +124,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
infer_ok.value infer_ok.value
} }
pub fn update_infer_var_info(&self, obligation: &PredicateObligation<'tcx>) { fn update_infer_var_info(&self, obligation: &PredicateObligation<'tcx>) {
let infer_var_info = &mut self.infer_var_info.borrow_mut(); let infer_var_info = &mut self.infer_var_info.borrow_mut();
// (*) binder skipped // (*) binder skipped

View File

@ -74,7 +74,7 @@ enum PlaceAncestryRelation {
type InferredCaptureInformation<'tcx> = Vec<(Place<'tcx>, ty::CaptureInfo)>; type InferredCaptureInformation<'tcx> = Vec<(Place<'tcx>, ty::CaptureInfo)>;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn closure_analyze(&self, body: &'tcx hir::Body<'tcx>) { pub(crate) fn closure_analyze(&self, body: &'tcx hir::Body<'tcx>) {
InferBorrowKindVisitor { fcx: self }.visit_body(body); InferBorrowKindVisitor { fcx: self }.visit_body(body);
// it's our job to process these. // it's our job to process these.

View File

@ -35,7 +35,7 @@ use crate::FnCtxt;
// resolve_type_vars_in_body, which creates a new TypeTables which // resolve_type_vars_in_body, which creates a new TypeTables which
// doesn't contain any inference types. // doesn't contain any inference types.
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn resolve_type_vars_in_body( pub(crate) fn resolve_type_vars_in_body(
&self, &self,
body: &'tcx hir::Body<'tcx>, body: &'tcx hir::Body<'tcx>,
) -> &'tcx ty::TypeckResults<'tcx> { ) -> &'tcx ty::TypeckResults<'tcx> {