2019-04-24 21:23:44 +00:00
|
|
|
//@ compile-flags: -Z unstable-options
|
|
|
|
|
2022-01-10 08:54:42 +00:00
|
|
|
#![feature(rustc_attrs)]
|
2019-04-24 21:23:44 +00:00
|
|
|
#![feature(rustc_private)]
|
2022-01-07 11:38:16 +00:00
|
|
|
#![deny(rustc::pass_by_value)]
|
2019-04-24 21:23:44 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
|
2020-03-29 16:08:01 +00:00
|
|
|
extern crate rustc_middle;
|
2019-04-24 21:23:44 +00:00
|
|
|
|
2020-03-29 16:08:01 +00:00
|
|
|
use rustc_middle::ty::{Ty, TyCtxt};
|
2019-04-24 21:23:44 +00:00
|
|
|
|
|
|
|
fn ty_by_ref(
|
|
|
|
ty_val: Ty<'_>,
|
|
|
|
ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
ty_ctxt_val: TyCtxt<'_>,
|
|
|
|
ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn ty_multi_ref(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
|
2019-04-24 21:23:44 +00:00
|
|
|
//~^ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
//~^^ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
|
|
|
|
trait T {
|
|
|
|
fn ty_by_ref_in_trait(
|
|
|
|
ty_val: Ty<'_>,
|
|
|
|
ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
ty_ctxt_val: TyCtxt<'_>,
|
|
|
|
ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
);
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>);
|
2019-04-24 21:23:44 +00:00
|
|
|
//~^ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
//~^^ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl T for Foo {
|
|
|
|
fn ty_by_ref_in_trait(
|
|
|
|
ty_val: Ty<'_>,
|
|
|
|
ty_ref: &Ty<'_>,
|
2019-06-13 21:48:52 +00:00
|
|
|
ty_ctxt_val: TyCtxt<'_>,
|
|
|
|
ty_ctxt_ref: &TyCtxt<'_>,
|
2019-04-24 21:23:44 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
|
2019-04-24 21:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn ty_by_ref_assoc(
|
|
|
|
ty_val: Ty<'_>,
|
|
|
|
ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
ty_ctxt_val: TyCtxt<'_>,
|
|
|
|
ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
|
2019-04-24 21:23:44 +00:00
|
|
|
//~^ ERROR passing `Ty<'_>` by reference
|
2019-06-13 21:48:52 +00:00
|
|
|
//~^^ ERROR passing `TyCtxt<'_>` by reference
|
2019-04-24 21:23:44 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 08:54:42 +00:00
|
|
|
#[rustc_pass_by_value]
|
|
|
|
enum CustomEnum {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CustomEnum {
|
|
|
|
fn test(
|
|
|
|
value: CustomEnum,
|
|
|
|
reference: &CustomEnum, //~ ERROR passing `CustomEnum` by reference
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rustc_pass_by_value]
|
|
|
|
struct CustomStruct {
|
|
|
|
s: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rustc_pass_by_value]
|
|
|
|
type CustomAlias<'a> = &'a CustomStruct; //~ ERROR passing `CustomStruct` by reference
|
|
|
|
|
|
|
|
impl CustomStruct {
|
|
|
|
fn test(
|
|
|
|
value: CustomStruct,
|
|
|
|
reference: &CustomStruct, //~ ERROR passing `CustomStruct` by reference
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_alias(
|
|
|
|
value: CustomAlias,
|
2022-06-04 20:50:19 +00:00
|
|
|
reference: &CustomAlias, //~ ERROR passing `CustomAlias<'_>` by reference
|
2022-01-10 08:54:42 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-11 21:28:04 +00:00
|
|
|
fn test<'a>(
|
2022-01-11 19:59:06 +00:00
|
|
|
value: WithParameters<T, 1>,
|
2022-01-11 21:28:04 +00:00
|
|
|
reference: &'a WithParameters<T, 1>, //~ ERROR passing `WithParameters<T, 1>` by reference
|
2022-01-11 19:59:06 +00:00
|
|
|
reference_with_m: &WithParameters<T, 1, u32>, //~ ERROR passing `WithParameters<T, 1, u32>` by reference
|
2022-01-11 21:28:04 +00:00
|
|
|
) -> &'a WithParameters<T, 1> {
|
|
|
|
//~^ ERROR passing `WithParameters<T, 1>` by reference
|
|
|
|
reference as &WithParameters<_, 1> //~ ERROR passing `WithParameters<_, 1>` by reference
|
2022-01-11 19:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 21:23:44 +00:00
|
|
|
fn main() {}
|