diff options
| author | bors <bors@rust-lang.org> | 2019-04-28 20:42:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-28 20:42:09 +0000 |
| commit | 272000c94edda10d3ccd7042d2b9914c2c974f29 (patch) | |
| tree | 00f63ea8e174115dc61b1b102f05ab940dd88778 /src/test | |
| parent | bdfdbcd44d457b2ac6d0cea4fb71739d3166cb98 (diff) | |
| parent | 2e5f0b3c49875e8cf1ee1bad2a74c2a81dcc7f78 (diff) | |
| download | rust-272000c94edda10d3ccd7042d2b9914c2c974f29.tar.gz rust-272000c94edda10d3ccd7042d2b9914c2c974f29.zip | |
Auto merge of #60317 - flip1995:internal_lints, r=oli-obk
Internal lints: usage_of_qualified_ty & ty_pass_by_reference Closes #59952 Implements internal lints: - `USAGE_OF_QUALIFIED_TY` - `TY_PASS_BY_REFERENCE` r? @oli-obk
Diffstat (limited to 'src/test')
5 files changed, 200 insertions, 1 deletions
diff --git a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs new file mode 100644 index 00000000000..075ce8b1a1c --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.rs @@ -0,0 +1,64 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(ty_pass_by_reference)] +#![allow(unused)] + +extern crate rustc; + +use rustc::ty::{Ty, TyCtxt}; + +fn ty_by_ref( + ty_val: Ty<'_>, + ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference + ty_ctxt_val: TyCtxt<'_, '_, '_>, + ty_ctxt_ref: &TyCtxt<'_, '_, '_>, //~ ERROR passing `TyCtxt<'_, '_, '_>` by reference +) { +} + +fn ty_multi_ref(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} +//~^ ERROR passing `Ty<'_>` by reference +//~^^ ERROR passing `TyCtxt<'_, '_, '_>` by reference + +trait T { + fn ty_by_ref_in_trait( + ty_val: Ty<'_>, + ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference + ty_ctxt_val: TyCtxt<'_, '_, '_>, + ty_ctxt_ref: &TyCtxt<'_, '_, '_>, //~ ERROR passing `TyCtxt<'_, '_, '_>` by reference + ); + + fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>); + //~^ ERROR passing `Ty<'_>` by reference + //~^^ ERROR passing `TyCtxt<'_, '_, '_>` by reference +} + +struct Foo; + +impl T for Foo { + fn ty_by_ref_in_trait( + ty_val: Ty<'_>, + ty_ref: &Ty<'_>, + ty_ctxt_val: TyCtxt<'_, '_, '_>, + ty_ctxt_ref: &TyCtxt<'_, '_, '_>, + ) { + } + + fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} +} + +impl Foo { + fn ty_by_ref_assoc( + ty_val: Ty<'_>, + ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference + ty_ctxt_val: TyCtxt<'_, '_, '_>, + ty_ctxt_ref: &TyCtxt<'_, '_, '_>, //~ ERROR passing `TyCtxt<'_, '_, '_>` by reference + ) { + } + + fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} + //~^ ERROR passing `Ty<'_>` by reference + //~^^ ERROR passing `TyCtxt<'_, '_, '_>` by reference +} + +fn main() {} diff --git a/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr new file mode 100644 index 00000000000..f3e630f3be2 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/pass_ty_by_ref.stderr @@ -0,0 +1,80 @@ +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:13:13 + | +LL | ty_ref: &Ty<'_>, + | ^^^^^^^ help: try passing by value: `Ty<'_>` + | +note: lint level defined here + --> $DIR/pass_ty_by_ref.rs:4:9 + | +LL | #![deny(ty_pass_by_reference)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:15:18 + | +LL | ty_ctxt_ref: &TyCtxt<'_, '_, '_>, + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:19:28 + | +LL | fn ty_multi_ref(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} + | ^^^^^^^ help: try passing by value: `Ty<'_>` + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:19:55 + | +LL | fn ty_multi_ref(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:26:17 + | +LL | ty_ref: &Ty<'_>, + | ^^^^^^^ help: try passing by value: `Ty<'_>` + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:28:22 + | +LL | ty_ctxt_ref: &TyCtxt<'_, '_, '_>, + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:31:41 + | +LL | fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>); + | ^^^^^^^ help: try passing by value: `Ty<'_>` + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:31:68 + | +LL | fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>); + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:53:17 + | +LL | ty_ref: &Ty<'_>, + | ^^^^^^^ help: try passing by value: `Ty<'_>` + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:55:22 + | +LL | ty_ctxt_ref: &TyCtxt<'_, '_, '_>, + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: passing `Ty<'_>` by reference + --> $DIR/pass_ty_by_ref.rs:59:38 + | +LL | fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} + | ^^^^^^^ help: try passing by value: `Ty<'_>` + +error: passing `TyCtxt<'_, '_, '_>` by reference + --> $DIR/pass_ty_by_ref.rs:59:65 + | +LL | fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_, '_, '_>) {} + | ^^^^^^^^^^^^^^^^^^^ help: try passing by value: `TyCtxt<'_, '_, '_>` + +error: aborting due to 12 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs new file mode 100644 index 00000000000..5e10697ec66 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs @@ -0,0 +1,35 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(usage_of_qualified_ty)] +#![allow(unused)] + +extern crate rustc; + +use rustc::ty::{self, Ty, TyCtxt}; + +macro_rules! qualified_macro { + ($a:ident) => { + fn ty_in_macro( + ty_q: ty::Ty<'_>, + ty: Ty<'_>, + ty_ctxt_q: ty::TyCtxt<'_, '_, '_>, + ty_ctxt: TyCtxt<'_, '_, '_>, + ) { + println!("{}", stringify!($a)); + } + }; +} + +fn ty_qualified( + ty_q: ty::Ty<'_>, //~ ERROR usage of qualified `ty::Ty<'_>` + ty: Ty<'_>, + ty_ctxt_q: ty::TyCtxt<'_, '_, '_>, //~ ERROR usage of qualified `ty::TyCtxt<'_, '_, '_>` + ty_ctxt: TyCtxt<'_, '_, '_>, +) { +} + + +fn main() { + qualified_macro!(a); +} diff --git a/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr new file mode 100644 index 00000000000..31d776cd9e0 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.stderr @@ -0,0 +1,20 @@ +error: usage of qualified `ty::Ty<'_>` + --> $DIR/qualified_ty_ty_ctxt.rs:25:11 + | +LL | ty_q: ty::Ty<'_>, + | ^^^^^^^^^^ help: try using it unqualified: `Ty<'_>` + | +note: lint level defined here + --> $DIR/qualified_ty_ty_ctxt.rs:4:9 + | +LL | #![deny(usage_of_qualified_ty)] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: usage of qualified `ty::TyCtxt<'_, '_, '_>` + --> $DIR/qualified_ty_ty_ctxt.rs:27:16 + | +LL | ty_ctxt_q: ty::TyCtxt<'_, '_, '_>, + | ^^^^^^^^^^^^^^^^^^^^^^ help: try using it unqualified: `TyCtxt<'_, '_, '_>` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr index 4e94af12453..10229a331c2 100644 --- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -190,7 +190,7 @@ error: usage of `ty::TyKind` LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} | ^^^^^^^^^^ | - = help: try using `ty::Ty` instead + = help: try using `Ty` instead error: aborting due to 31 previous errors |
