Remove LocalKind::Var.

This commit is contained in:
Camille GILLOT 2023-03-10 10:29:19 +00:00
parent d31386a52b
commit 50d0959a2f
7 changed files with 17 additions and 18 deletions

View file

@ -1985,16 +1985,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let (place_desc, note) = if let Some(place_desc) = opt_place_desc { let (place_desc, note) = if let Some(place_desc) = opt_place_desc {
let local_kind = if let Some(local) = borrow.borrowed_place.as_local() { let local_kind = if let Some(local) = borrow.borrowed_place.as_local() {
match self.body.local_kind(local) { match self.body.local_kind(local) {
LocalKind::ReturnPointer | LocalKind::Temp => { LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
bug!("temporary or return pointer with a name") "local variable "
} }
LocalKind::Var => "local variable ",
LocalKind::Arg LocalKind::Arg
if !self.upvars.is_empty() && local == ty::CAPTURE_STRUCT_LOCAL => if !self.upvars.is_empty() && local == ty::CAPTURE_STRUCT_LOCAL =>
{ {
"variable captured by `move` " "variable captured by `move` "
} }
LocalKind::Arg => "function parameter ", LocalKind::Arg => "function parameter ",
LocalKind::ReturnPointer | LocalKind::Temp => {
bug!("temporary or return pointer with a name")
}
} }
} else { } else {
"local data " "local data "
@ -2008,16 +2010,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap(); self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
let local = root_place.local; let local = root_place.local;
match self.body.local_kind(local) { match self.body.local_kind(local) {
LocalKind::ReturnPointer | LocalKind::Temp => {
("temporary value".to_string(), "temporary value created here".to_string())
}
LocalKind::Arg => ( LocalKind::Arg => (
"function parameter".to_string(), "function parameter".to_string(),
"function parameter borrowed here".to_string(), "function parameter borrowed here".to_string(),
), ),
LocalKind::Var => { LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
("local binding".to_string(), "local binding introduced here".to_string()) ("local binding".to_string(), "local binding introduced here".to_string())
} }
LocalKind::ReturnPointer | LocalKind::Temp => {
("temporary value".to_string(), "temporary value created here".to_string())
}
} }
}; };

View file

@ -1681,7 +1681,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// - maybe we should make that a warning. // - maybe we should make that a warning.
return; return;
} }
LocalKind::Var | LocalKind::Temp => {} LocalKind::Temp => {}
} }
// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls // When `unsized_fn_params` or `unsized_locals` is enabled, only function calls

View file

@ -704,7 +704,7 @@ pub mod ty {
fn importance(&self) -> DiagnosticImportance { fn importance(&self) -> DiagnosticImportance {
match self.0 { match self.0 {
mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary, mir::LocalKind::Temp => DiagnosticImportance::Secondary,
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => { mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
DiagnosticImportance::Primary DiagnosticImportance::Primary
} }

View file

@ -106,8 +106,9 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location); debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
// We're only interested in temporaries and the return place // We're only interested in temporaries and the return place
match self.ccx.body.local_kind(index) { match self.ccx.body.local_kind(index) {
LocalKind::Temp | LocalKind::ReturnPointer => {} LocalKind::Arg => return,
LocalKind::Arg | LocalKind::Var => return, LocalKind::Temp if self.ccx.body.local_decls[index].is_user_variable() => return,
LocalKind::ReturnPointer | LocalKind::Temp => {}
} }
// Ignore drops, if the temp gets promoted, // Ignore drops, if the temp gets promoted,

View file

@ -401,8 +401,6 @@ impl<'tcx> Body<'tcx> {
LocalKind::ReturnPointer LocalKind::ReturnPointer
} else if index < self.arg_count + 1 { } else if index < self.arg_count + 1 {
LocalKind::Arg LocalKind::Arg
} else if self.local_decls[local].is_user_variable() {
LocalKind::Var
} else { } else {
LocalKind::Temp LocalKind::Temp
} }
@ -668,9 +666,7 @@ impl Atom for Local {
/// Classifies locals into categories. See `Body::local_kind`. /// Classifies locals into categories. See `Body::local_kind`.
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)] #[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)]
pub enum LocalKind { pub enum LocalKind {
/// User-declared variable binding. /// User-declared variable binding or compiler-introduced temporary.
Var,
/// Compiler-introduced temporary.
Temp, Temp,
/// Function argument. /// Function argument.
Arg, Arg,

View file

@ -788,7 +788,7 @@ impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> {
fn is_local_required(local: Local, body: &Body<'_>) -> bool { fn is_local_required(local: Local, body: &Body<'_>) -> bool {
match body.local_kind(local) { match body.local_kind(local) {
LocalKind::Arg | LocalKind::ReturnPointer => true, LocalKind::Arg | LocalKind::ReturnPointer => true,
LocalKind::Var | LocalKind::Temp => false, LocalKind::Temp => false,
} }
} }

View file

@ -102,7 +102,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> {
mir::LocalKind::Arg => return None, mir::LocalKind::Arg => return None,
mir::LocalKind::ReturnPointer => bug!("Return place was assigned to itself?"), mir::LocalKind::ReturnPointer => bug!("Return place was assigned to itself?"),
mir::LocalKind::Var | mir::LocalKind::Temp => {} mir::LocalKind::Temp => {}
} }
// If multiple different locals are copied to the return place. We can't pick a // If multiple different locals are copied to the return place. We can't pick a