Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable does not need to be mutable warning #54621

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ impl BorrowKind {
pub fn allows_two_phase_borrow(&self) -> bool {
match *self {
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => false,
BorrowKind::Mut { allow_two_phase_borrow } => allow_two_phase_borrow,
BorrowKind::Mut {
allow_two_phase_borrow,
} => allow_two_phase_borrow,
}
}
}
Expand Down Expand Up @@ -596,7 +598,7 @@ pub enum ImplicitSelfKind {
MutRef,
/// Represents when a function does not have a self argument or
/// when a function has a `self: X` argument.
None
None,
}

CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
Expand Down Expand Up @@ -820,8 +822,7 @@ impl<'tcx> LocalDecl<'tcx> {
pat_span: _,
}))) => true,

Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(ImplicitSelfKind::Imm)))
=> true,
Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(ImplicitSelfKind::Imm))) => true,

_ => false,
}
Expand Down Expand Up @@ -873,12 +874,7 @@ impl<'tcx> LocalDecl<'tcx> {
}

#[inline]
fn new_local(
ty: Ty<'tcx>,
mutability: Mutability,
internal: bool,
span: Span,
) -> Self {
fn new_local(ty: Ty<'tcx>, mutability: Mutability, internal: bool, span: Span) -> Self {
LocalDecl {
mutability,
ty,
Expand Down Expand Up @@ -1603,13 +1599,15 @@ impl<'tcx> TerminatorKind<'tcx> {
Scalar::Bits {
bits: u,
size: size.bytes() as u8,
}.into(),
}
.into(),
),
ty: switch_ty,
};
fmt_const_val(&mut s, &c).unwrap();
s.into()
}).chain(iter::once("otherwise".into()))
})
.chain(iter::once("otherwise".into()))
.collect()
}
Call {
Expand Down Expand Up @@ -1843,9 +1841,11 @@ impl<'tcx> Debug for Statement<'tcx> {
ref outputs,
ref inputs,
} => write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs),
AscribeUserType(ref place, ref variance, ref c_ty) => {
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
}
AscribeUserType(ref place, ref variance, ref c_ty) => write!(
fmt,
"AscribeUserType({:?}, {:?}, {:?})",
place, variance, c_ty
),
Nop => write!(fmt, "nop"),
}
}
Expand Down Expand Up @@ -1970,14 +1970,24 @@ impl<'tcx> Place<'tcx> {
/// Find the innermost `Local` from this `Place`.
pub fn local(&self) -> Option<Local> {
match self {
Place::Local(local) |
Place::Projection(box Projection {
Place::Local(local)
| Place::Projection(box Projection {
base: Place::Local(local),
elem: ProjectionElem::Deref,
}) => Some(*local),
_ => None,
}
}

/// Returns the local variable at the "base" of this place, if any. e.g., for a place like
/// a.b.c, returns Some(a). For a place based in a static or constant, returns None.
pub fn base_local(&self) -> Option<Local> {
nikomatsakis marked this conversation as resolved.
Show resolved Hide resolved
match self {
Place::Projection(box Projection { base, .. }) => base.base_local(),
Place::Local(local) => Some(*local),
Place::Static(..) | Place::Promoted(..) => None,
}
}
}

impl<'tcx> Debug for Place<'tcx> {
Expand Down Expand Up @@ -2691,7 +2701,9 @@ pub struct ClosureOutlivesRequirement<'tcx> {
/// order of the category, thereby influencing diagnostic output.
///
/// See also [rustc_mir::borrow_check::nll::constraints]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(
Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable,
)]
pub enum ConstraintCategory {
Return,
TypeAnnotation,
Expand Down
Loading