]>
Commit | Line | Data |
---|---|---|
17df50a5 | 1 | // compile-flags: -Z unstable-options |
1b1a35ee | 2 | // NOTE: This test doesn't actually require `fulldeps` |
94222f64 | 3 | // so we could instead use it as a `ui` test. |
1b1a35ee XL |
4 | // |
5 | // Considering that all other `internal-lints` are tested here | |
6 | // this seems like the cleaner solution though. | |
7 | #![feature(rustc_attrs)] | |
5099ac24 | 8 | #![deny(rustc::pass_by_value)] |
1b1a35ee XL |
9 | #![allow(unused)] |
10 | ||
5099ac24 | 11 | #[rustc_pass_by_value] |
1b1a35ee XL |
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 | ||
1b1a35ee XL |
21 | struct TyS<'tcx> { |
22 | inner: &'tcx (), | |
23 | } | |
24 | ||
5099ac24 | 25 | #[rustc_pass_by_value] |
1b1a35ee XL |
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 | ||
5099ac24 FG |
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> { | |
064997fb | 47 | fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference |
5099ac24 FG |
48 | } |
49 | ||
50 | impl<T> WithParameters<T, 1, u8> { | |
064997fb | 51 | fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference |
5099ac24 FG |
52 | } |
53 | ||
1b1a35ee | 54 | fn main() {} |