mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
Fix [redundant_slicing
] when the slice is behind a mutable reference
Fixes #12751 changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference
This commit is contained in:
parent
b31bce4f5f
commit
58027e2657
@ -113,8 +113,11 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||
a.kind,
|
||||
Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. }))
|
||||
)
|
||||
}) {
|
||||
// The slice was used to make a temporary reference.
|
||||
}) || (matches!(
|
||||
cx.typeck_results().expr_ty(indexed).ref_mutability(),
|
||||
Some(Mutability::Mut)
|
||||
) && mutability == Mutability::Not)
|
||||
{
|
||||
(DEREF_BY_SLICING_LINT, "&*", "reborrow the original value instead")
|
||||
} else if deref_count != 0 {
|
||||
(DEREF_BY_SLICING_LINT, "", "dereference the original value instead")
|
||||
|
@ -25,4 +25,8 @@ fn main() {
|
||||
|
||||
let bytes: &[u8] = &[];
|
||||
let _ = (&*bytes).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice
|
||||
|
||||
// issue 12751
|
||||
let a = &mut [1, 2, 3][..];
|
||||
let _ = &*a;
|
||||
}
|
||||
|
@ -25,4 +25,8 @@ fn main() {
|
||||
|
||||
let bytes: &[u8] = &[];
|
||||
let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice
|
||||
|
||||
// issue 12751
|
||||
let a = &mut [1, 2, 3][..];
|
||||
let _ = &a[..];
|
||||
}
|
||||
|
@ -55,5 +55,11 @@ error: slicing when dereferencing would work
|
||||
LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice
|
||||
| ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: slicing when dereferencing would work
|
||||
--> tests/ui/deref_by_slicing.rs:31:13
|
||||
|
|
||||
LL | let _ = &a[..];
|
||||
| ^^^^^^ help: reborrow the original value instead: `&*a`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user