]> git.proxmox.com Git - rustc.git/blame - tests/ui/internal-lints/rustc_pass_by_value_self.rs
Update upstream source from tag 'upstream/1.70.0+dfsg1'
[rustc.git] / tests / ui / internal-lints / rustc_pass_by_value_self.rs
CommitLineData
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
12struct TyCtxt<'tcx> {
13 inner: &'tcx (),
14}
15
16impl<'tcx> TyCtxt<'tcx> {
17 fn by_value(self) {} // OK
18 fn by_ref(&self) {} //~ ERROR passing `TyCtxt<'tcx>` by reference
19}
20
1b1a35ee
XL
21struct TyS<'tcx> {
22 inner: &'tcx (),
23}
24
5099ac24 25#[rustc_pass_by_value]
1b1a35ee
XL
26type Ty<'tcx> = &'tcx TyS<'tcx>;
27
28impl<'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]
34struct Foo;
35
36impl Foo {
37 fn with_ref(&self) {} //~ ERROR passing `Foo` by reference
38}
39
40#[rustc_pass_by_value]
41struct WithParameters<T, const N: usize, M = u32> {
42 slice: [T; N],
43 m: M,
44}
45
46impl<T> WithParameters<T, 1> {
064997fb 47 fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
5099ac24
FG
48}
49
50impl<T> WithParameters<T, 1, u8> {
064997fb 51 fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
5099ac24
FG
52}
53
1b1a35ee 54fn main() {}