]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / tests / ui-fulldeps / internal-lints / rustc_pass_by_value_self.rs
1 // compile-flags: -Z unstable-options
2 // NOTE: This test doesn't actually require `fulldeps`
3 // so we could instead use it as a `ui` test.
4 //
5 // Considering that all other `internal-lints` are tested here
6 // this seems like the cleaner solution though.
7 #![feature(rustc_attrs)]
8 #![deny(rustc::pass_by_value)]
9 #![allow(unused)]
10
11 #[rustc_pass_by_value]
12 struct TyCtxt<'tcx> {
13     inner: &'tcx (),
14 }
15
16 impl<'tcx> TyCtxt<'tcx> {
17     fn by_value(self) {} // OK
18     fn by_ref(&self) {} //~ ERROR passing `TyCtxt<'tcx>` by reference
19 }
20
21 struct TyS<'tcx> {
22     inner: &'tcx (),
23 }
24
25 #[rustc_pass_by_value]
26 type Ty<'tcx> = &'tcx TyS<'tcx>;
27
28 impl<'tcx> TyS<'tcx> {
29     fn by_value(self: Ty<'tcx>) {}
30     fn by_ref(self: &Ty<'tcx>) {} //~ ERROR passing `Ty<'tcx>` by reference
31 }
32
33 #[rustc_pass_by_value]
34 struct Foo;
35
36 impl Foo {
37     fn with_ref(&self) {} //~ ERROR passing `Foo` by reference
38 }
39
40 #[rustc_pass_by_value]
41 struct WithParameters<T, const N: usize, M = u32> {
42     slice: [T; N],
43     m: M,
44 }
45
46 impl<T> WithParameters<T, 1> {
47     fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
48 }
49
50 impl<T> WithParameters<T, 1, u8> {
51     fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
52 }
53
54 fn main() {}