1
Fork 0

Rename ClearCrossCrate::assert_crate_local.

As `unwrap_crate_local`, because it follows exactly the standard form of
an `unwrap` function.
This commit is contained in:
Nicholas Nethercote 2025-02-13 14:00:39 +11:00
parent 2f695dc64e
commit 5d2d11fd5d
12 changed files with 15 additions and 15 deletions

View file

@ -780,7 +780,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,
@ -1094,7 +1094,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

@ -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

@ -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

@ -967,7 +967,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 +1032,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

@ -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)