summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui-toml/absolute_paths
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /src/tools/clippy/tests/ui-toml/absolute_paths
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/absolute_paths')
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr28
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr70
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs97
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml2
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs11
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml1
6 files changed, 209 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr
new file mode 100644
index 000000000..a8900da4e
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr
@@ -0,0 +1,28 @@
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:40:5
+ |
+LL | std::f32::MAX;
+ | ^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::absolute-paths` implied by `-D warnings`
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:41:5
+ |
+LL | core::f32::MAX;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:42:5
+ |
+LL | ::core::f32::MAX;
+ | ^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:58:5
+ |
+LL | ::std::f32::MAX;
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr
new file mode 100644
index 000000000..41b70644b
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr
@@ -0,0 +1,70 @@
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:40:5
+ |
+LL | std::f32::MAX;
+ | ^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::absolute-paths` implied by `-D warnings`
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:41:5
+ |
+LL | core::f32::MAX;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:42:5
+ |
+LL | ::core::f32::MAX;
+ | ^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:43:5
+ |
+LL | crate::a::b::c::C;
+ | ^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:44:5
+ |
+LL | crate::a::b::c::d::e::f::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:45:5
+ |
+LL | crate::a::A;
+ | ^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:46:5
+ |
+LL | crate::a::b::B;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:47:5
+ |
+LL | crate::a::b::c::C::ZERO;
+ | ^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:48:5
+ |
+LL | helper::b::c::d::e::f();
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:49:5
+ |
+LL | ::helper::b::c::d::e::f();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:58:5
+ |
+LL | ::std::f32::MAX;
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 11 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs
new file mode 100644
index 000000000..d4c250a8f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs
@@ -0,0 +1,97 @@
+//@aux-build:../../ui/auxiliary/proc_macros.rs:proc-macro
+//@aux-build:helper.rs
+//@revisions: allow_crates disallow_crates
+//@[allow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates
+//@[disallow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/disallow_crates
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::absolute_paths)]
+#![feature(decl_macro)]
+
+extern crate helper;
+#[macro_use]
+extern crate proc_macros;
+
+pub mod a {
+ pub mod b {
+ pub mod c {
+ pub struct C;
+
+ impl C {
+ pub const ZERO: u32 = 0;
+ }
+
+ pub mod d {
+ pub mod e {
+ pub mod f {
+ pub struct F;
+ }
+ }
+ }
+ }
+
+ pub struct B;
+ }
+
+ pub struct A;
+}
+
+fn main() {
+ f32::max(1.0, 2.0);
+ std::f32::MAX;
+ core::f32::MAX;
+ ::core::f32::MAX;
+ crate::a::b::c::C;
+ crate::a::b::c::d::e::f::F;
+ crate::a::A;
+ crate::a::b::B;
+ crate::a::b::c::C::ZERO;
+ helper::b::c::d::e::f();
+ ::helper::b::c::d::e::f();
+ fn b() -> a::b::B {
+ todo!()
+ }
+ std::println!("a");
+ let x = 1;
+ std::ptr::addr_of!(x);
+ // Test we handle max segments with `PathRoot` properly; this has 4 segments but we should say it
+ // has 3
+ ::std::f32::MAX;
+ // Do not lint due to the above
+ ::helper::a();
+ // Do not lint
+ helper::a();
+ use crate::a::b::c::C;
+ use a::b;
+ use std::f32::MAX;
+ a::b::c::d::e::f::F;
+ b::c::C;
+ fn a() -> a::A {
+ todo!()
+ }
+ use a::b::c;
+
+ fn c() -> c::C {
+ todo!()
+ }
+ fn d() -> Result<(), ()> {
+ todo!()
+ }
+ external! {
+ crate::a::b::c::C::ZERO;
+ }
+ // For some reason, `path.span.from_expansion()` takes care of this for us
+ with_span! {
+ span
+ crate::a::b::c::C::ZERO;
+ }
+ macro_rules! local_crate {
+ () => {
+ crate::a::b::c::C::ZERO;
+ };
+ }
+ macro local_crate_2_0() {
+ crate::a::b::c::C::ZERO;
+ }
+ local_crate!();
+ local_crate_2_0!();
+}
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml b/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml
new file mode 100644
index 000000000..59a621e9d
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml
@@ -0,0 +1,2 @@
+absolute-paths-max-segments = 2
+absolute-paths-allowed-crates = ["crate", "helper"]
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs b/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs
new file mode 100644
index 000000000..8e2678f5f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs
@@ -0,0 +1,11 @@
+pub fn a() {}
+
+pub mod b {
+ pub mod c {
+ pub mod d {
+ pub mod e {
+ pub fn f() {}
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml b/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml
new file mode 100644
index 000000000..d44d648c6
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml
@@ -0,0 +1 @@
+absolute-paths-max-segments = 2