summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui-toml/nonstandard_macro_braces
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/nonstandard_macro_braces')
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs18
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/clippy.toml6
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs60
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr94
4 files changed, 178 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs
new file mode 100644
index 000000000..6452189a4
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs
@@ -0,0 +1,18 @@
+// compile-flags: --emit=link
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(DeriveSomething)]
+pub fn derive(_: TokenStream) -> TokenStream {
+ "fn _f() -> Vec<u8> { vec![] }".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn foo_bar(_: TokenStream) -> TokenStream {
+ "fn issue_7422() { eprintln!(); }".parse().unwrap()
+}
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/clippy.toml b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/clippy.toml
new file mode 100644
index 000000000..bced8948a
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/clippy.toml
@@ -0,0 +1,6 @@
+standard-macro-braces = [
+ { name = "quote", brace = "{" },
+ { name = "quote::quote", brace = "{" },
+ { name = "eprint", brace = "[" },
+ { name = "type_pos", brace = "[" },
+]
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
new file mode 100644
index 000000000..5b4adc868
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
@@ -0,0 +1,60 @@
+// aux-build:proc_macro_derive.rs
+
+#![warn(clippy::nonstandard_macro_braces)]
+
+extern crate proc_macro_derive;
+extern crate quote;
+
+use quote::quote;
+
+#[derive(proc_macro_derive::DeriveSomething)]
+pub struct S;
+
+proc_macro_derive::foo_bar!();
+
+#[rustfmt::skip]
+macro_rules! test {
+ () => {
+ vec!{0, 0, 0}
+ };
+}
+
+#[rustfmt::skip]
+macro_rules! test2 {
+ ($($arg:tt)*) => {
+ format_args!($($arg)*)
+ };
+}
+
+macro_rules! type_pos {
+ ($what:ty) => {
+ Vec<$what>
+ };
+}
+
+macro_rules! printlnfoo {
+ ($thing:expr) => {
+ println!("{}", $thing)
+ };
+}
+
+#[rustfmt::skip]
+fn main() {
+ let _ = vec! {1, 2, 3};
+ let _ = format!["ugh {} stop being such a good compiler", "hello"];
+ let _ = quote!(let x = 1;);
+ let _ = quote::quote!(match match match);
+ let _ = test!(); // trigger when macro def is inside our own crate
+ let _ = vec![1,2,3];
+
+ let _ = quote::quote! {true || false};
+ let _ = vec! [0 ,0 ,0];
+ let _ = format!("fds{}fds", 10);
+ let _ = test2!["{}{}{}", 1, 2, 3];
+
+ let _: type_pos!(usize) = vec![];
+
+ eprint!("test if user config overrides defaults");
+
+ printlnfoo!["test if printlnfoo is triggered by println"];
+}
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr
new file mode 100644
index 000000000..039b23b1b
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr
@@ -0,0 +1,94 @@
+error: use of irregular braces for `vec!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:43:13
+ |
+LL | let _ = vec! {1, 2, 3};
+ | ^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings`
+help: consider writing `vec![1, 2, 3]`
+ --> $DIR/conf_nonstandard_macro_braces.rs:43:13
+ |
+LL | let _ = vec! {1, 2, 3};
+ | ^^^^^^^^^^^^^^
+
+error: use of irregular braces for `format!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:44:13
+ |
+LL | let _ = format!["ugh {} stop being such a good compiler", "hello"];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider writing `format!("ugh () stop being such a good compiler", "hello")`
+ --> $DIR/conf_nonstandard_macro_braces.rs:44:13
+ |
+LL | let _ = format!["ugh {} stop being such a good compiler", "hello"];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: use of irregular braces for `quote!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:45:13
+ |
+LL | let _ = quote!(let x = 1;);
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: consider writing `quote! {let x = 1;}`
+ --> $DIR/conf_nonstandard_macro_braces.rs:45:13
+ |
+LL | let _ = quote!(let x = 1;);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: use of irregular braces for `quote::quote!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:46:13
+ |
+LL | let _ = quote::quote!(match match match);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider writing `quote::quote! {match match match}`
+ --> $DIR/conf_nonstandard_macro_braces.rs:46:13
+ |
+LL | let _ = quote::quote!(match match match);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: use of irregular braces for `vec!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:18:9
+ |
+LL | vec!{0, 0, 0}
+ | ^^^^^^^^^^^^^
+...
+LL | let _ = test!(); // trigger when macro def is inside our own crate
+ | ------- in this macro invocation
+ |
+help: consider writing `vec![0, 0, 0]`
+ --> $DIR/conf_nonstandard_macro_braces.rs:18:9
+ |
+LL | vec!{0, 0, 0}
+ | ^^^^^^^^^^^^^
+...
+LL | let _ = test!(); // trigger when macro def is inside our own crate
+ | ------- in this macro invocation
+ = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: use of irregular braces for `type_pos!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:55:12
+ |
+LL | let _: type_pos!(usize) = vec![];
+ | ^^^^^^^^^^^^^^^^
+ |
+help: consider writing `type_pos![usize]`
+ --> $DIR/conf_nonstandard_macro_braces.rs:55:12
+ |
+LL | let _: type_pos!(usize) = vec![];
+ | ^^^^^^^^^^^^^^^^
+
+error: use of irregular braces for `eprint!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:57:5
+ |
+LL | eprint!("test if user config overrides defaults");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider writing `eprint!["test if user config overrides defaults"]`
+ --> $DIR/conf_nonstandard_macro_braces.rs:57:5
+ |
+LL | eprint!("test if user config overrides defaults");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 7 previous errors
+