2023-07-17 08:19:29 +00:00
|
|
|
#![allow(unused, clippy::needless_lifetimes, clippy::needless_pass_by_ref_mut)]
|
2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::mut_from_ref)]
|
2017-02-10 18:39:03 +00:00
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn this_wont_hurt_a_bit(&self) -> &mut Foo {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-10 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Ouch {
|
|
|
|
fn ouch(x: &Foo) -> &mut Foo;
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2017-02-10 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Ouch for Foo {
|
|
|
|
fn ouch(x: &Foo) -> &mut Foo {
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-10 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fail(x: &u32) -> &mut u16 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-10 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 23:32:12 +00:00
|
|
|
fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-10 23:32:12 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 14:10:25 +00:00
|
|
|
fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-12 12:53:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 18:39:03 +00:00
|
|
|
// this is OK, because the result borrows y
|
|
|
|
fn works<'a>(x: &u32, y: &'a mut u32) -> &'a mut u32 {
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
2017-02-10 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this is also OK, because the result could borrow y
|
|
|
|
fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 {
|
2022-05-05 14:12:52 +00:00
|
|
|
unsafe { unimplemented!() }
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn also_broken(x: &u32) -> &mut u32 {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: mutable borrow from immutable input(s)
|
2022-05-05 14:12:52 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn without_unsafe(x: &u32) -> &mut u32 {
|
2017-02-10 18:39:03 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
//TODO
|
|
|
|
}
|