2021-02-28 18:24:46 +00:00
|
|
|
//@ compile-flags: -Z unstable-options
|
2020-09-21 18:28:52 +00:00
|
|
|
// NOTE: This test doesn't actually require `fulldeps`
|
2021-08-22 16:15:49 +00:00
|
|
|
// so we could instead use it as a `ui` test.
|
2020-09-21 18:28:52 +00:00
|
|
|
//
|
|
|
|
// Considering that all other `internal-lints` are tested here
|
|
|
|
// this seems like the cleaner solution though.
|
|
|
|
#![feature(rustc_attrs)]
|
2022-01-07 11:38:16 +00:00
|
|
|
#![deny(rustc::pass_by_value)]
|
2020-09-21 18:28:52 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
|
2022-01-07 11:38:16 +00:00
|
|
|
#[rustc_pass_by_value]
|
2020-09-21 18:28:52 +00:00
|
|
|
struct TyCtxt<'tcx> {
|
|
|
|
inner: &'tcx (),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TyCtxt<'tcx> {
|
|
|
|
fn by_value(self) {} // OK
|
|
|
|
fn by_ref(&self) {} //~ ERROR passing `TyCtxt<'tcx>` by reference
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TyS<'tcx> {
|
|
|
|
inner: &'tcx (),
|
|
|
|
}
|
|
|
|
|
2022-01-07 11:38:16 +00:00
|
|
|
#[rustc_pass_by_value]
|
2020-09-21 18:28:52 +00:00
|
|
|
type Ty<'tcx> = &'tcx TyS<'tcx>;
|
|
|
|
|
|
|
|
impl<'tcx> TyS<'tcx> {
|
|
|
|
fn by_value(self: Ty<'tcx>) {}
|
|
|
|
fn by_ref(self: &Ty<'tcx>) {} //~ ERROR passing `Ty<'tcx>` by reference
|
|
|
|
}
|
|
|
|
|
2022-01-11 09:28:13 +00:00
|
|
|
#[rustc_pass_by_value]
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn with_ref(&self) {} //~ ERROR passing `Foo` by reference
|
|
|
|
}
|
|
|
|
|
2022-01-11 19:59:06 +00:00
|
|
|
#[rustc_pass_by_value]
|
|
|
|
struct WithParameters<T, const N: usize, M = u32> {
|
|
|
|
slice: [T; N],
|
|
|
|
m: M,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> WithParameters<T, 1> {
|
2022-07-18 23:54:13 +00:00
|
|
|
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
|
2022-01-11 19:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> WithParameters<T, 1, u8> {
|
2022-07-18 23:54:13 +00:00
|
|
|
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
|
2022-01-11 19:59:06 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 18:28:52 +00:00
|
|
|
fn main() {}
|