os-rust/tests/ui/moves/moved-value-on-as-ref-arg.rs
dianne 546ba3d310 suggest_borrow_generic_arg: instantiate clauses properly
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.
2024-11-17 18:09:36 -08:00

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
}