Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnr

Tweaks in and around `rustc_middle`

A bunch of tiny improvements I found while working on bigger things.

r? ```@lcnr```
This commit is contained in:
Matthias Krüger 2025-02-21 12:45:25 +01:00 committed by GitHub
commit 1f6c75e682
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 59 additions and 91 deletions

View file

@ -226,7 +226,7 @@ fn emit_polonius_mir<'tcx>(
regioncx, regioncx,
closure_region_requirements, closure_region_requirements,
borrow_set, borrow_set,
pass_where.clone(), pass_where,
out, out,
)?; )?;

View file

@ -28,7 +28,6 @@ use rustc_middle::bug;
use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues}; use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues};
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::traits::select; use rustc_middle::traits::select;
pub use rustc_middle::ty::IntVarValue;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{ use rustc_middle::ty::fold::{
BoundVarReplacerDelegate, TypeFoldable, TypeFolder, TypeSuperFoldable, fold_regions, BoundVarReplacerDelegate, TypeFoldable, TypeFolder, TypeSuperFoldable, fold_regions,

View file

@ -30,7 +30,6 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
use tracing::{debug, trace}; use tracing::{debug, trace};
pub use self::query::*; pub use self::query::*;
use self::visit::TyContext;
use crate::mir::interpret::{AllocRange, Scalar}; use crate::mir::interpret::{AllocRange, Scalar};
use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths}; use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
@ -108,7 +107,7 @@ impl MirPhase {
} }
} }
/// Parses an `MirPhase` from a pair of strings. Panics if this isn't possible for any reason. /// Parses a `MirPhase` from a pair of strings. Panics if this isn't possible for any reason.
pub fn parse(dialect: String, phase: Option<String>) -> Self { pub fn parse(dialect: String, phase: Option<String>) -> Self {
match &*dialect.to_ascii_lowercase() { match &*dialect.to_ascii_lowercase() {
"built" => { "built" => {
@ -532,17 +531,6 @@ impl<'tcx> Body<'tcx> {
} }
} }
pub fn span_for_ty_context(&self, ty_context: TyContext) -> Span {
match ty_context {
TyContext::UserTy(span) => span,
TyContext::ReturnTy(source_info)
| TyContext::LocalDecl { source_info, .. }
| TyContext::YieldTy(source_info)
| TyContext::ResumeTy(source_info) => source_info.span,
TyContext::Location(loc) => self.source_info(loc).span,
}
}
/// Returns the return type; it always return first element from `local_decls` array. /// Returns the return type; it always return first element from `local_decls` array.
#[inline] #[inline]
pub fn return_ty(&self) -> Ty<'tcx> { pub fn return_ty(&self) -> Ty<'tcx> {
@ -784,7 +772,7 @@ impl<T> ClearCrossCrate<T> {
} }
} }
pub fn assert_crate_local(self) -> T { pub fn unwrap_crate_local(self) -> T {
match self { match self {
ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"), ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"),
ClearCrossCrate::Set(v) => v, ClearCrossCrate::Set(v) => v,
@ -941,7 +929,7 @@ mod binding_form_impl {
/// involved in borrow_check errors, e.g., explanations of where the /// involved in borrow_check errors, e.g., explanations of where the
/// temporaries come from, when their destructors are run, and/or how /// temporaries come from, when their destructors are run, and/or how
/// one might revise the code to satisfy the borrow checker's rules. /// one might revise the code to satisfy the borrow checker's rules.
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub struct BlockTailInfo { pub struct BlockTailInfo {
/// If `true`, then the value resulting from evaluating this tail /// If `true`, then the value resulting from evaluating this tail
/// expression is ignored by the block's expression context. /// expression is ignored by the block's expression context.
@ -965,7 +953,6 @@ pub struct LocalDecl<'tcx> {
/// Temporaries and the return place are always mutable. /// Temporaries and the return place are always mutable.
pub mutability: Mutability, pub mutability: Mutability,
// FIXME(matthewjasper) Don't store in this in `Body`
pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>, pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,
/// The type of this local. /// The type of this local.
@ -975,7 +962,6 @@ pub struct LocalDecl<'tcx> {
/// e.g., via `let x: T`, then we carry that type here. The MIR /// e.g., via `let x: T`, then we carry that type here. The MIR
/// borrow checker needs this information since it can affect /// borrow checker needs this information since it can affect
/// region inference. /// region inference.
// FIXME(matthewjasper) Don't store in this in `Body`
pub user_ty: Option<Box<UserTypeProjections>>, pub user_ty: Option<Box<UserTypeProjections>>,
/// The *syntactic* (i.e., not visibility) source scope the local is defined /// The *syntactic* (i.e., not visibility) source scope the local is defined
@ -1083,7 +1069,6 @@ pub enum LocalInfo<'tcx> {
AggregateTemp, AggregateTemp,
/// A temporary created for evaluation of some subexpression of some block's tail expression /// A temporary created for evaluation of some subexpression of some block's tail expression
/// (with no intervening statement context). /// (with no intervening statement context).
// FIXME(matthewjasper) Don't store in this in `Body`
BlockTailTemp(BlockTailInfo), BlockTailTemp(BlockTailInfo),
/// A temporary created during evaluating `if` predicate, possibly for pattern matching for `let`s, /// A temporary created during evaluating `if` predicate, possibly for pattern matching for `let`s,
/// and subject to Edition 2024 temporary lifetime rules /// and subject to Edition 2024 temporary lifetime rules
@ -1098,7 +1083,7 @@ pub enum LocalInfo<'tcx> {
impl<'tcx> LocalDecl<'tcx> { impl<'tcx> LocalDecl<'tcx> {
pub fn local_info(&self) -> &LocalInfo<'tcx> { pub fn local_info(&self) -> &LocalInfo<'tcx> {
self.local_info.as_ref().assert_crate_local() self.local_info.as_ref().unwrap_crate_local()
} }
/// Returns `true` only if local is a binding that can itself be /// Returns `true` only if local is a binding that can itself be

View file

@ -22,7 +22,7 @@ pub(crate) const ALIGN: usize = 40;
/// An indication of where we are in the control flow graph. Used for printing /// An indication of where we are in the control flow graph. Used for printing
/// extra information in `dump_mir` /// extra information in `dump_mir`
#[derive(Clone)] #[derive(Clone, Copy)]
pub enum PassWhere { pub enum PassWhere {
/// We have not started dumping the control flow graph, but we are about to. /// We have not started dumping the control flow graph, but we are about to.
BeforeCFG, BeforeCFG,

View file

@ -86,7 +86,7 @@ impl SwitchTargets {
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise()) self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
} }
/// Adds a new target to the switch. But You cannot add an already present value. /// Adds a new target to the switch. Panics if you add an already present value.
#[inline] #[inline]
pub fn add_target(&mut self, value: u128, bb: BasicBlock) { pub fn add_target(&mut self, value: u128, bb: BasicBlock) {
let value = Pu128(value); let value = Pu128(value);

View file

@ -51,7 +51,7 @@ pub struct ObligationCause<'tcx> {
/// information. /// information.
pub body_id: LocalDefId, pub body_id: LocalDefId,
code: InternedObligationCauseCode<'tcx>, code: ObligationCauseCodeHandle<'tcx>,
} }
// This custom hash function speeds up hashing for `Obligation` deduplication // This custom hash function speeds up hashing for `Obligation` deduplication
@ -97,7 +97,7 @@ impl<'tcx> ObligationCause<'tcx> {
pub fn map_code( pub fn map_code(
&mut self, &mut self,
f: impl FnOnce(InternedObligationCauseCode<'tcx>) -> ObligationCauseCode<'tcx>, f: impl FnOnce(ObligationCauseCodeHandle<'tcx>) -> ObligationCauseCode<'tcx>,
) { ) {
self.code = f(std::mem::take(&mut self.code)).into(); self.code = f(std::mem::take(&mut self.code)).into();
} }
@ -152,15 +152,16 @@ pub struct UnifyReceiverContext<'tcx> {
pub args: GenericArgsRef<'tcx>, pub args: GenericArgsRef<'tcx>,
} }
/// A compact form of `ObligationCauseCode`.
#[derive(Clone, PartialEq, Eq, Default, HashStable)] #[derive(Clone, PartialEq, Eq, Default, HashStable)]
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)] #[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
pub struct InternedObligationCauseCode<'tcx> { pub struct ObligationCauseCodeHandle<'tcx> {
/// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of /// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of
/// the time). `Some` otherwise. /// the time). `Some` otherwise.
code: Option<Arc<ObligationCauseCode<'tcx>>>, code: Option<Arc<ObligationCauseCode<'tcx>>>,
} }
impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> { impl<'tcx> std::fmt::Debug for ObligationCauseCodeHandle<'tcx> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let cause: &ObligationCauseCode<'_> = self; let cause: &ObligationCauseCode<'_> = self;
cause.fmt(f) cause.fmt(f)
@ -169,14 +170,14 @@ impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> {
impl<'tcx> ObligationCauseCode<'tcx> { impl<'tcx> ObligationCauseCode<'tcx> {
#[inline(always)] #[inline(always)]
fn into(self) -> InternedObligationCauseCode<'tcx> { fn into(self) -> ObligationCauseCodeHandle<'tcx> {
InternedObligationCauseCode { ObligationCauseCodeHandle {
code: if let ObligationCauseCode::Misc = self { None } else { Some(Arc::new(self)) }, code: if let ObligationCauseCode::Misc = self { None } else { Some(Arc::new(self)) },
} }
} }
} }
impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> { impl<'tcx> std::ops::Deref for ObligationCauseCodeHandle<'tcx> {
type Target = ObligationCauseCode<'tcx>; type Target = ObligationCauseCode<'tcx>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -305,7 +306,7 @@ pub enum ObligationCauseCode<'tcx> {
/// The node of the function call. /// The node of the function call.
call_hir_id: HirId, call_hir_id: HirId,
/// The obligation introduced by this argument. /// The obligation introduced by this argument.
parent_code: InternedObligationCauseCode<'tcx>, parent_code: ObligationCauseCodeHandle<'tcx>,
}, },
/// Error derived when checking an impl item is compatible with /// Error derived when checking an impl item is compatible with
@ -390,7 +391,8 @@ pub enum ObligationCauseCode<'tcx> {
/// `WellFormed(None)`. /// `WellFormed(None)`.
WellFormed(Option<WellFormedLoc>), WellFormed(Option<WellFormedLoc>),
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against. /// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching
/// against.
MatchImpl(ObligationCause<'tcx>, DefId), MatchImpl(ObligationCause<'tcx>, DefId),
BinOp { BinOp {
@ -413,7 +415,7 @@ pub enum ObligationCauseCode<'tcx> {
ConstParam(Ty<'tcx>), ConstParam(Ty<'tcx>),
/// Obligations emitted during the normalization of a weak type alias. /// Obligations emitted during the normalization of a weak type alias.
TypeAlias(InternedObligationCauseCode<'tcx>, Span, DefId), TypeAlias(ObligationCauseCodeHandle<'tcx>, Span, DefId),
} }
/// Whether a value can be extracted into a const. /// Whether a value can be extracted into a const.
@ -514,12 +516,6 @@ impl<'tcx> ObligationCauseCode<'tcx> {
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
rustc_data_structures::static_assert_size!(ObligationCauseCode<'_>, 48); rustc_data_structures::static_assert_size!(ObligationCauseCode<'_>, 48);
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum StatementAsExpression {
CorrectType,
NeedsBoxing,
}
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeVisitable, TypeFoldable)] #[derive(TypeVisitable, TypeFoldable)]
pub struct MatchExpressionArmCause<'tcx> { pub struct MatchExpressionArmCause<'tcx> {
@ -584,7 +580,7 @@ pub struct DerivedCause<'tcx> {
pub parent_trait_pred: ty::PolyTraitPredicate<'tcx>, pub parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
/// The parent trait had this cause. /// The parent trait had this cause.
pub parent_code: InternedObligationCauseCode<'tcx>, pub parent_code: ObligationCauseCodeHandle<'tcx>,
} }
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
@ -592,9 +588,9 @@ pub struct DerivedCause<'tcx> {
pub struct ImplDerivedCause<'tcx> { pub struct ImplDerivedCause<'tcx> {
pub derived: DerivedCause<'tcx>, pub derived: DerivedCause<'tcx>,
/// The `DefId` of the `impl` that gave rise to the `derived` obligation. /// The `DefId` of the `impl` that gave rise to the `derived` obligation.
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl, /// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle /// impl, then this will be the `DefId` of that trait alias. Care should therefore be taken to
/// that exceptional case where appropriate. /// handle that exceptional case where appropriate.
pub impl_or_alias_def_id: DefId, pub impl_or_alias_def_id: DefId,
/// The index of the derived predicate in the parent impl's predicates. /// The index of the derived predicate in the parent impl's predicates.
pub impl_def_predicate_index: Option<usize>, pub impl_def_predicate_index: Option<usize>,
@ -611,7 +607,7 @@ pub struct DerivedHostCause<'tcx> {
pub parent_host_pred: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>, pub parent_host_pred: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
/// The parent trait had this cause. /// The parent trait had this cause.
pub parent_code: InternedObligationCauseCode<'tcx>, pub parent_code: ObligationCauseCodeHandle<'tcx>,
} }
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]

View file

@ -75,12 +75,6 @@ pub type CanonicalPredicateGoal<'tcx> =
pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> = pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> =
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>; CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>;
pub type CanonicalTypeOpEqGoal<'tcx> =
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Eq<'tcx>>>;
pub type CanonicalTypeOpSubtypeGoal<'tcx> =
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Subtype<'tcx>>>;
pub type CanonicalTypeOpProvePredicateGoal<'tcx> = pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ProvePredicate<'tcx>>>; CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ProvePredicate<'tcx>>>;

View file

@ -331,8 +331,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let expr = &this.thir[expr_id]; let expr = &this.thir[expr_id];
let tail_result_is_ignored = let tail_result_is_ignored =
destination_ty.is_unit() || this.block_context.currently_ignores_tail_results(); destination_ty.is_unit() || this.block_context.currently_ignores_tail_results();
this.block_context this.block_context.push(BlockFrame::TailExpr {
.push(BlockFrame::TailExpr { tail_result_is_ignored, span: expr.span }); info: BlockTailInfo { tail_result_is_ignored, span: expr.span },
});
block = this.expr_into_dest(destination, block, expr_id).into_block(); block = this.expr_into_dest(destination, block, expr_id).into_block();
let popped = this.block_context.pop(); let popped = this.block_context.pop();

View file

@ -142,7 +142,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Overwrite temp local info if we have something more interesting to record. // Overwrite temp local info if we have something more interesting to record.
if !matches!(local_info, LocalInfo::Boring) { if !matches!(local_info, LocalInfo::Boring) {
let decl_info = let decl_info =
this.local_decls[operand].local_info.as_mut().assert_crate_local(); this.local_decls[operand].local_info.as_mut().unwrap_crate_local();
if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info { if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info {
**decl_info = local_info; **decl_info = local_info;
} }

View file

@ -85,7 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
_ => LocalInfo::Boring, _ => LocalInfo::Boring,
}; };
**local_decl.local_info.as_mut().assert_crate_local() = local_info; **local_decl.local_info.as_mut().unwrap_crate_local() = local_info;
this.local_decls.push(local_decl) this.local_decls.push(local_decl)
}; };
debug!(?temp); debug!(?temp);

View file

@ -164,8 +164,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
} }
this.block_context.push(BlockFrame::TailExpr { this.block_context.push(BlockFrame::TailExpr {
tail_result_is_ignored: true, info: BlockTailInfo { tail_result_is_ignored: true, span: expr.span },
span: expr.span,
}); });
Some(expr.span) Some(expr.span)
} else { } else {

View file

@ -722,7 +722,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let LocalInfo::User(BindingForm::Var(VarBindingForm { if let LocalInfo::User(BindingForm::Var(VarBindingForm {
opt_match_place: Some((ref mut match_place, _)), opt_match_place: Some((ref mut match_place, _)),
.. ..
})) = **self.local_decls[local].local_info.as_mut().assert_crate_local() })) = **self.local_decls[local].local_info.as_mut().unwrap_crate_local()
{ {
*match_place = Some(place); *match_place = Some(place);
} else { } else {

View file

@ -112,16 +112,7 @@ enum BlockFrame {
/// Evaluation is currently within the tail expression of a block. /// Evaluation is currently within the tail expression of a block.
/// ///
/// Example: `{ STMT_1; STMT_2; EXPR }` /// Example: `{ STMT_1; STMT_2; EXPR }`
TailExpr { TailExpr { info: BlockTailInfo },
/// If true, then the surrounding context of the block ignores
/// the result of evaluating the block's tail expression.
///
/// Example: `let _ = { STMT_1; EXPR };`
tail_result_is_ignored: bool,
/// `Span` of the tail expression.
span: Span,
},
/// Generic mark meaning that the block occurred as a subexpression /// Generic mark meaning that the block occurred as a subexpression
/// where the result might be used. /// where the result might be used.
@ -277,9 +268,7 @@ impl BlockContext {
match bf { match bf {
BlockFrame::SubExpr => continue, BlockFrame::SubExpr => continue,
BlockFrame::Statement { .. } => break, BlockFrame::Statement { .. } => break,
&BlockFrame::TailExpr { tail_result_is_ignored, span } => { &BlockFrame::TailExpr { info } => return Some(info),
return Some(BlockTailInfo { tail_result_is_ignored, span });
}
} }
} }
@ -302,9 +291,9 @@ impl BlockContext {
// otherwise: use accumulated is_ignored state. // otherwise: use accumulated is_ignored state.
Some( Some(
BlockFrame::TailExpr { tail_result_is_ignored: ignored, .. } BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: ign, .. } }
| BlockFrame::Statement { ignores_expr_result: ignored }, | BlockFrame::Statement { ignores_expr_result: ign },
) => *ignored, ) => *ign,
} }
} }
} }
@ -967,7 +956,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} => { } => {
self.local_decls[local].mutability = mutability; self.local_decls[local].mutability = mutability;
self.local_decls[local].source_info.scope = self.source_scope; self.local_decls[local].source_info.scope = self.source_scope;
**self.local_decls[local].local_info.as_mut().assert_crate_local() = **self.local_decls[local].local_info.as_mut().unwrap_crate_local() =
if let Some(kind) = param.self_kind { if let Some(kind) = param.self_kind {
LocalInfo::User(BindingForm::ImplicitSelf(kind)) LocalInfo::User(BindingForm::ImplicitSelf(kind))
} else { } else {
@ -1032,7 +1021,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let parent_id = self.source_scopes[original_source_scope] let parent_id = self.source_scopes[original_source_scope]
.local_data .local_data
.as_ref() .as_ref()
.assert_crate_local() .unwrap_crate_local()
.lint_root; .lint_root;
self.maybe_new_source_scope(pattern_span, arg_hir_id, parent_id); self.maybe_new_source_scope(pattern_span, arg_hir_id, parent_id);
} }

View file

@ -604,7 +604,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let source_scope = self.source_scope; let source_scope = self.source_scope;
if let LintLevel::Explicit(current_hir_id) = lint_level { if let LintLevel::Explicit(current_hir_id) = lint_level {
let parent_id = let parent_id =
self.source_scopes[source_scope].local_data.as_ref().assert_crate_local().lint_root; self.source_scopes[source_scope].local_data.as_ref().unwrap_crate_local().lint_root;
self.maybe_new_source_scope(region_scope.1.span, current_hir_id, parent_id); self.maybe_new_source_scope(region_scope.1.span, current_hir_id, parent_id);
} }
self.push_scope(region_scope); self.push_scope(region_scope);
@ -992,7 +992,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
lint_root: if let LintLevel::Explicit(lint_root) = lint_level { lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
lint_root lint_root
} else { } else {
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root self.source_scopes[parent].local_data.as_ref().unwrap_crate_local().lint_root
}, },
}; };
self.source_scopes.push(SourceScopeData { self.source_scopes.push(SourceScopeData {

View file

@ -79,7 +79,7 @@ impl<'tcx> ConstMutationChecker<'_, 'tcx> {
let lint_root = self.body.source_scopes[source_info.scope] let lint_root = self.body.source_scopes[source_info.scope]
.local_data .local_data
.as_ref() .as_ref()
.assert_crate_local() .unwrap_crate_local()
.lint_root; .lint_root;
Some((lint_root, source_info.span, self.tcx.def_span(const_item))) Some((lint_root, source_info.span, self.tcx.def_span(const_item)))

View file

@ -945,7 +945,7 @@ fn compute_layout<'tcx>(
let decl = &body.local_decls[local]; let decl = &body.local_decls[local];
debug!(?decl); debug!(?decl);
// Do not `assert_crate_local` here, as post-borrowck cleanup may have already cleared // Do not `unwrap_crate_local` here, as post-borrowck cleanup may have already cleared
// the information. This is alright, since `ignore_for_traits` is only relevant when // the information. This is alright, since `ignore_for_traits` is only relevant when
// this code runs on pre-cleanup MIR, and `ignore_for_traits = false` is the safer // this code runs on pre-cleanup MIR, and `ignore_for_traits = false` is the safer
// default. // default.

View file

@ -85,7 +85,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
let lint_root = body.source_scopes[terminator.source_info.scope] let lint_root = body.source_scopes[terminator.source_info.scope]
.local_data .local_data
.as_ref() .as_ref()
.assert_crate_local() .unwrap_crate_local()
.lint_root; .lint_root;
let span = terminator.source_info.span; let span = terminator.source_info.span;

View file

@ -154,7 +154,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
let lint_root = self.body.source_scopes[source_info.scope] let lint_root = self.body.source_scopes[source_info.scope]
.local_data .local_data
.as_ref() .as_ref()
.assert_crate_local() .unwrap_crate_local()
.lint_root; .lint_root;
// FIXME: use existing printing routines to print the function signature // FIXME: use existing printing routines to print the function signature
let fn_sig = self.tcx.fn_sig(fn_id).instantiate(self.tcx, fn_args); let fn_sig = self.tcx.fn_sig(fn_id).instantiate(self.tcx, fn_args);

View file

@ -158,7 +158,7 @@ impl<'tcx> MirPatch<'tcx> {
let index = self.next_local; let index = self.next_local;
self.next_local += 1; self.next_local += 1;
let mut new_decl = LocalDecl::new(ty, span); let mut new_decl = LocalDecl::new(ty, span);
**new_decl.local_info.as_mut().assert_crate_local() = local_info; **new_decl.local_info.as_mut().unwrap_crate_local() = local_info;
self.new_locals.push(new_decl); self.new_locals.push(new_decl);
Local::new(index) Local::new(index)
} }

View file

@ -10,7 +10,6 @@ use rustc_hir::def::Res;
use rustc_hir::{MatchSource, Node}; use rustc_hir::{MatchSource, Node};
use rustc_middle::traits::{ use rustc_middle::traits::{
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
StatementAsExpression,
}; };
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
@ -26,8 +25,14 @@ use crate::errors::{
SuggestTuplePatternMany, SuggestTuplePatternOne, TypeErrorAdditionalDiags, SuggestTuplePatternMany, SuggestTuplePatternOne, TypeErrorAdditionalDiags,
}; };
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
enum StatementAsExpression {
CorrectType,
NeedsBoxing,
}
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum SuggestAsRefKind { enum SuggestAsRefKind {
Option, Option,
Result, Result,
} }
@ -382,7 +387,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
pub fn suggest_function_pointers_impl( pub(crate) fn suggest_function_pointers_impl(
&self, &self,
span: Option<Span>, span: Option<Span>,
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>, exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
@ -518,7 +523,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
pub fn should_suggest_as_ref_kind( fn should_suggest_as_ref_kind(
&self, &self,
expected: Ty<'tcx>, expected: Ty<'tcx>,
found: Ty<'tcx>, found: Ty<'tcx>,
@ -588,8 +593,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) -> Option<TypeErrorAdditionalDiags> { ) -> Option<TypeErrorAdditionalDiags> {
/// Find the if expression with given span /// Find the if expression with given span
struct IfVisitor { struct IfVisitor {
pub found_if: bool, found_if: bool,
pub err_span: Span, err_span: Span,
} }
impl<'v> Visitor<'v> for IfVisitor { impl<'v> Visitor<'v> for IfVisitor {
@ -736,7 +741,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'tcx> TypeErrCtxt<'_, 'tcx> {
/// Be helpful when the user wrote `{... expr; }` and taking the `;` off /// Be helpful when the user wrote `{... expr; }` and taking the `;` off
/// is enough to fix the error. /// is enough to fix the error.
pub fn could_remove_semicolon( fn could_remove_semicolon(
&self, &self,
blk: &'tcx hir::Block<'tcx>, blk: &'tcx hir::Block<'tcx>,
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,
@ -816,7 +821,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
/// Suggest returning a local binding with a compatible type if the block /// Suggest returning a local binding with a compatible type if the block
/// has no return expression. /// has no return expression.
pub fn consider_returning_binding_diag( fn consider_returning_binding_diag(
&self, &self,
blk: &'tcx hir::Block<'tcx>, blk: &'tcx hir::Block<'tcx>,
expected_ty: Ty<'tcx>, expected_ty: Ty<'tcx>,

View file

@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
let node = mir.source_scopes[scope] let node = mir.source_scopes[scope]
.local_data .local_data
.as_ref() .as_ref()
.assert_crate_local() .unwrap_crate_local()
.lint_root; .lint_root;
if let Some(snip) = span.get_source_text(cx) if let Some(snip) = span.get_source_text(cx)