546ba3d310
Fixes issue 133118. This also modifies `tests/ui/moves/moved-value-on-as-ref-arg.rs` to have more useful bounds on the tests for suggestions to borrow `Borrow` and `BorrowMut` arguments. With its old tautological `T: BorrowMut<T>` bound, this fix would make it suggest a shared borrow for that argument.
37 lines
773 B
Rust
37 lines
773 B
Rust
//@ run-rustfix
|
|
#![allow(unused_mut)]
|
|
use std::borrow::{Borrow, BorrowMut};
|
|
use std::convert::{AsMut, AsRef};
|
|
struct Bar;
|
|
|
|
impl AsRef<Bar> for Bar {
|
|
fn as_ref(&self) -> &Bar {
|
|
self
|
|
}
|
|
}
|
|
|
|
impl AsMut<Bar> for Bar {
|
|
fn as_mut(&mut self) -> &mut Bar {
|
|
self
|
|
}
|
|
}
|
|
|
|
fn foo<T: AsRef<Bar>>(_: T) {}
|
|
fn qux<T: AsMut<Bar>>(_: T) {}
|
|
fn bat<T: Borrow<Bar>>(_: T) {}
|
|
fn baz<T: BorrowMut<Bar>>(_: T) {}
|
|
|
|
pub fn main() {
|
|
let bar = Bar;
|
|
foo(bar);
|
|
let _baa = bar; //~ ERROR use of moved value
|
|
let mut bar = Bar;
|
|
qux(bar);
|
|
let _baa = bar; //~ ERROR use of moved value
|
|
let bar = Bar;
|
|
bat(bar);
|
|
let _baa = bar; //~ ERROR use of moved value
|
|
let mut bar = Bar;
|
|
baz(bar);
|
|
let _baa = bar; //~ ERROR use of moved value
|
|
}
|