]> git.lizzy.rs Git - rust.git/blob - src/test/ui/illegal-sized-bound/mutability-mismatch.rs
Rollup merge of #105843 - compiler-errors:sugg-const, r=lcnr
[rust.git] / src / test / ui / illegal-sized-bound / mutability-mismatch.rs
1 struct MutType;
2
3 pub trait MutTrait {
4     fn function(&mut self)
5     where
6         Self: Sized;
7     //~^ this has a `Sized` requirement
8 }
9
10 impl MutTrait for MutType {
11     fn function(&mut self) {}
12 }
13
14 struct Type;
15
16 pub trait Trait {
17     fn function(&self)
18     where
19         Self: Sized;
20     //~^ this has a `Sized` requirement
21 }
22
23 impl Trait for Type {
24     fn function(&self) {}
25 }
26
27 fn main() {
28     (&MutType as &dyn MutTrait).function();
29     //~^ ERROR the `function` method cannot be invoked on a trait object
30     //~| NOTE you need `&mut dyn MutTrait` instead of `&dyn MutTrait`
31     (&mut Type as &mut dyn Trait).function();
32     //~^ ERROR the `function` method cannot be invoked on a trait object
33     //~| NOTE you need `&dyn Trait` instead of `&mut dyn Trait`
34 }