diff options
| author | lcnr <rust@lcnr.de> | 2022-01-05 13:02:16 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2022-02-01 10:15:59 +0100 |
| commit | a1a30f7548bdb625f8f90c25258f8ab463cebe8c (patch) | |
| tree | 99c2f538217e5b632984902189e1eba204e407b2 /src | |
| parent | 25862ffc8d360b34dd8ec82a2f01750aaab976b7 (diff) | |
add a rustc::query_stability lint
Diffstat (limited to 'src')
4 files changed, 95 insertions, 0 deletions
diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.rs b/src/test/ui-fulldeps/internal-lints/query_stability.rs new file mode 100644 index 00000000000..560675b4486 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability.rs @@ -0,0 +1,24 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_private)] +#![deny(rustc::potential_query_instability)] + +extern crate rustc_data_structures; + +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; + +fn main() { + let mut x = FxHashMap::<u32, i32>::default(); + + for _ in x.drain() {} + //~^ ERROR using `drain` can result in unstable + + for _ in x.iter() {} + //~^ ERROR using `iter` + + for _ in Some(&mut x).unwrap().iter_mut() {} + //~^ ERROR using `iter_mut` + + for _ in x {} + //~^ ERROR using `into_iter` +} diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.stderr b/src/test/ui-fulldeps/internal-lints/query_stability.stderr new file mode 100644 index 00000000000..7e8b448f41a --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability.stderr @@ -0,0 +1,39 @@ +error: using `drain` can result in unstable query results + --> $DIR/query_stability.rs:13:16 + | +LL | for _ in x.drain() {} + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/query_stability.rs:4:9 + | +LL | #![deny(rustc::potential_query_instability)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `iter` can result in unstable query results + --> $DIR/query_stability.rs:16:16 + | +LL | for _ in x.iter() {} + | ^^^^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `iter_mut` can result in unstable query results + --> $DIR/query_stability.rs:19:36 + | +LL | for _ in Some(&mut x).unwrap().iter_mut() {} + | ^^^^^^^^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: using `into_iter` can result in unstable query results + --> $DIR/query_stability.rs:22:14 + | +LL | for _ in x {} + | ^ + | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale + +error: aborting due to 4 previous errors + diff --git a/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs new file mode 100644 index 00000000000..f478b73329e --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z unstable-options + +#![feature(rustc_attrs)] + +#[rustc_lint_query_instability] +//~^ ERROR attribute should be applied to a function +struct Foo; + +impl Foo { + #[rustc_lint_query_instability(a)] + //~^ ERROR malformed `rustc_lint_query_instability` + fn bar() {} +} + +fn main() {} diff --git a/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr new file mode 100644 index 00000000000..b5156f2ac59 --- /dev/null +++ b/src/test/ui-fulldeps/internal-lints/query_stability_incorrect.stderr @@ -0,0 +1,17 @@ +error: malformed `rustc_lint_query_instability` attribute input + --> $DIR/query_stability_incorrect.rs:10:5 + | +LL | #[rustc_lint_query_instability(a)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_query_instability]` + +error: attribute should be applied to a function + --> $DIR/query_stability_incorrect.rs:5:1 + | +LL | #[rustc_lint_query_instability] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct Foo; + | ----------- not a function + +error: aborting due to 2 previous errors + |
