From e075586d4fd428374a788eecc391e23ec4a17b46 Mon Sep 17 00:00:00 2001 From: cynecx Date: Mon, 7 Feb 2022 01:21:23 +0100 Subject: add tests and fix comments --- .../ui/feature-gates/feature-gate-used_with_arg.rs | 7 +++++++ .../feature-gates/feature-gate-used_with_arg.stderr | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/ui/feature-gates/feature-gate-used_with_arg.rs create mode 100644 src/test/ui/feature-gates/feature-gate-used_with_arg.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/feature-gates/feature-gate-used_with_arg.rs b/src/test/ui/feature-gates/feature-gate-used_with_arg.rs new file mode 100644 index 00000000000..1c8f01bdef1 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-used_with_arg.rs @@ -0,0 +1,7 @@ +#[used(linker)] //~ ERROR `#[used(linker)]` is currently unstable +static mut USED_LINKER: [usize; 1] = [0]; + +#[used(compiler)] //~ ERROR `#[used(compiler)]` is currently unstable +static mut USED_COMPILER: [usize; 1] = [0]; + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr b/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr new file mode 100644 index 00000000000..aaf4ceaf795 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr @@ -0,0 +1,19 @@ +error[E0658]: `#[used(linker)]` is currently unstable + --> $DIR/feature-gate-used_with_arg.rs:1:1 + | +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ + | + = help: add `#![feature(used_with_arg)]` to the crate attributes to enable + +error[E0658]: `#[used(compiler)]` is currently unstable + --> $DIR/feature-gate-used_with_arg.rs:4:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(used_with_arg)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. -- cgit 1.4.1-3-g733a5 From 438826fd1a9a119d00992ede948cdd479431ecbb Mon Sep 17 00:00:00 2001 From: cynecx Date: Tue, 8 Feb 2022 23:51:17 +0100 Subject: add more tests and make used(linker/compiler) mutually exclusive --- compiler/rustc_passes/src/check_attr.rs | 34 +++++++++++++++++++++++++++++++++ compiler/rustc_typeck/src/collect.rs | 1 + src/test/codegen/used_with_arg.rs | 6 ++---- src/test/ui/used_with_arg.rs | 19 ++++++++++++++++++ src/test/ui/used_with_arg.stderr | 18 +++++++++++++++++ src/test/ui/used_with_multi_args.rs | 6 ++++++ src/test/ui/used_with_multi_args.stderr | 8 ++++++++ 7 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/used_with_arg.rs create mode 100644 src/test/ui/used_with_arg.stderr create mode 100644 src/test/ui/used_with_multi_args.rs create mode 100644 src/test/ui/used_with_multi_args.stderr (limited to 'src/test/ui') diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ca511f7b814..479a08e43c0 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1741,12 +1741,46 @@ impl CheckAttrVisitor<'_> { } fn check_used(&self, attrs: &[Attribute], target: Target) { + let mut used_linker_span = None; + let mut used_compiler_span = None; for attr in attrs { if attr.has_name(sym::used) && target != Target::Static { self.tcx .sess .span_err(attr.span, "attribute must be applied to a `static` variable"); } + let inner = attr.meta_item_list(); + match inner.as_deref() { + Some([item]) if item.has_name(sym::linker) => { + if used_linker_span.is_none() { + used_linker_span = Some(attr.span); + } + } + Some([item]) if item.has_name(sym::compiler) => { + if used_compiler_span.is_none() { + used_compiler_span = Some(attr.span); + } + } + Some(_) => { + // This error case is handled in rustc_typeck::collect. + } + None => { + // Default case (compiler) when arg isn't defined. + if used_compiler_span.is_none() { + used_compiler_span = Some(attr.span); + } + } + } + } + if let (Some(linker_span), Some(compiler_span)) = (used_linker_span, used_compiler_span) { + let spans = vec![linker_span, compiler_span]; + self.tcx + .sess + .struct_span_err( + spans, + "`used(compiler)` and `used(linker)` can't be used together", + ) + .emit(); } } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 4a3c477021c..2a280ff97e9 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1,3 +1,4 @@ +// ignore-tidy-filelength //! "Collection" is the process of determining the type and other external //! details of each item in Rust. Collection is specifically concerned //! with *inter-procedural* things -- for example, for a function diff --git a/src/test/codegen/used_with_arg.rs b/src/test/codegen/used_with_arg.rs index cd759b167c0..5bff50a40d4 100644 --- a/src/test/codegen/used_with_arg.rs +++ b/src/test/codegen/used_with_arg.rs @@ -1,12 +1,10 @@ -// compile-flags: -O - #![crate_type = "lib"] #![feature(used_with_arg)] -// CHECK: @llvm.used = appending global [1 x i8*] +// CHECK: @llvm.used = appending global [1 x i8*]{{.*}}USED_LINKER #[used(linker)] static mut USED_LINKER: [usize; 1] = [0]; -// CHECK-NEXT: @llvm.compiler.used = appending global [1 x i8*] +// CHECK-NEXT: @llvm.compiler.used = appending global [1 x i8*]{{.*}}USED_COMPILER #[used(compiler)] static mut USED_COMPILER: [usize; 1] = [0]; diff --git a/src/test/ui/used_with_arg.rs b/src/test/ui/used_with_arg.rs new file mode 100644 index 00000000000..ad80ff53f0e --- /dev/null +++ b/src/test/ui/used_with_arg.rs @@ -0,0 +1,19 @@ +#![feature(used_with_arg)] + +#[used(linker)] +static mut USED_LINKER: [usize; 1] = [0]; + +#[used(compiler)] +static mut USED_COMPILER: [usize; 1] = [0]; + +#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together +#[used(linker)] +static mut USED_COMPILER_LINKER2: [usize; 1] = [0]; + +#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together +#[used(linker)] +#[used(compiler)] +#[used(linker)] +static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; + +fn main() {} diff --git a/src/test/ui/used_with_arg.stderr b/src/test/ui/used_with_arg.stderr new file mode 100644 index 00000000000..440e5c4a5a0 --- /dev/null +++ b/src/test/ui/used_with_arg.stderr @@ -0,0 +1,18 @@ +error: `used(compiler)` and `used(linker)` can't be used together + --> $DIR/used_with_arg.rs:9:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ + +error: `used(compiler)` and `used(linker)` can't be used together + --> $DIR/used_with_arg.rs:13:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/used_with_multi_args.rs b/src/test/ui/used_with_multi_args.rs new file mode 100644 index 00000000000..2e17fcfd7a4 --- /dev/null +++ b/src/test/ui/used_with_multi_args.rs @@ -0,0 +1,6 @@ +#![feature(used_with_arg)] + +#[used(compiler, linker)] //~ expected `used`, `used(compiler)` or `used(linker)` +static mut USED_COMPILER_LINKER: [usize; 1] = [0]; + +fn main() {} diff --git a/src/test/ui/used_with_multi_args.stderr b/src/test/ui/used_with_multi_args.stderr new file mode 100644 index 00000000000..c93aafcfc7c --- /dev/null +++ b/src/test/ui/used_with_multi_args.stderr @@ -0,0 +1,8 @@ +error: expected `used`, `used(compiler)` or `used(linker)` + --> $DIR/used_with_multi_args.rs:3:1 + | +LL | #[used(compiler, linker)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 933963e10ae8837965f44b7e9748ff135f6c57a5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 9 Feb 2022 10:59:33 +0100 Subject: Add tracking issue --- compiler/rustc_feature/src/active.rs | 2 +- src/test/ui/feature-gates/feature-gate-used_with_arg.stderr | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/test/ui') diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 0908e9d1ef9..c652e54ffe7 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -534,7 +534,7 @@ declare_features! ( /// NOTE: A limited form of `union U { ... }` was accepted in 1.19.0. (active, untagged_unions, "1.13.0", Some(55149), None), /// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute. - (active, used_with_arg, "1.60.0", Some(00000), None), + (active, used_with_arg, "1.60.0", Some(93798), None), /// Allows `extern "wasm" fn` (active, wasm_abi, "1.53.0", Some(83788), None), // !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! diff --git a/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr b/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr index aaf4ceaf795..d115bf4e365 100644 --- a/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr +++ b/src/test/ui/feature-gates/feature-gate-used_with_arg.stderr @@ -4,6 +4,7 @@ error[E0658]: `#[used(linker)]` is currently unstable LL | #[used(linker)] | ^^^^^^^^^^^^^^^ | + = note: see issue #93798 for more information = help: add `#![feature(used_with_arg)]` to the crate attributes to enable error[E0658]: `#[used(compiler)]` is currently unstable @@ -12,6 +13,7 @@ error[E0658]: `#[used(compiler)]` is currently unstable LL | #[used(compiler)] | ^^^^^^^^^^^^^^^^^ | + = note: see issue #93798 for more information = help: add `#![feature(used_with_arg)]` to the crate attributes to enable error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5 From 170593313a6ac2206107ec52a0d3bb9cc873a97c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 9 Feb 2022 11:00:39 +0100 Subject: Move tests into attributes directory to pacify tidy --- src/test/ui/attributes/used_with_arg.rs | 19 +++++++++++++++++++ src/test/ui/attributes/used_with_arg.stderr | 18 ++++++++++++++++++ src/test/ui/attributes/used_with_multi_args.rs | 6 ++++++ src/test/ui/attributes/used_with_multi_args.stderr | 8 ++++++++ src/test/ui/used_with_arg.rs | 19 ------------------- src/test/ui/used_with_arg.stderr | 18 ------------------ src/test/ui/used_with_multi_args.rs | 6 ------ src/test/ui/used_with_multi_args.stderr | 8 -------- 8 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/test/ui/attributes/used_with_arg.rs create mode 100644 src/test/ui/attributes/used_with_arg.stderr create mode 100644 src/test/ui/attributes/used_with_multi_args.rs create mode 100644 src/test/ui/attributes/used_with_multi_args.stderr delete mode 100644 src/test/ui/used_with_arg.rs delete mode 100644 src/test/ui/used_with_arg.stderr delete mode 100644 src/test/ui/used_with_multi_args.rs delete mode 100644 src/test/ui/used_with_multi_args.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/attributes/used_with_arg.rs b/src/test/ui/attributes/used_with_arg.rs new file mode 100644 index 00000000000..ad80ff53f0e --- /dev/null +++ b/src/test/ui/attributes/used_with_arg.rs @@ -0,0 +1,19 @@ +#![feature(used_with_arg)] + +#[used(linker)] +static mut USED_LINKER: [usize; 1] = [0]; + +#[used(compiler)] +static mut USED_COMPILER: [usize; 1] = [0]; + +#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together +#[used(linker)] +static mut USED_COMPILER_LINKER2: [usize; 1] = [0]; + +#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together +#[used(linker)] +#[used(compiler)] +#[used(linker)] +static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; + +fn main() {} diff --git a/src/test/ui/attributes/used_with_arg.stderr b/src/test/ui/attributes/used_with_arg.stderr new file mode 100644 index 00000000000..440e5c4a5a0 --- /dev/null +++ b/src/test/ui/attributes/used_with_arg.stderr @@ -0,0 +1,18 @@ +error: `used(compiler)` and `used(linker)` can't be used together + --> $DIR/used_with_arg.rs:9:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ + +error: `used(compiler)` and `used(linker)` can't be used together + --> $DIR/used_with_arg.rs:13:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/attributes/used_with_multi_args.rs b/src/test/ui/attributes/used_with_multi_args.rs new file mode 100644 index 00000000000..2e17fcfd7a4 --- /dev/null +++ b/src/test/ui/attributes/used_with_multi_args.rs @@ -0,0 +1,6 @@ +#![feature(used_with_arg)] + +#[used(compiler, linker)] //~ expected `used`, `used(compiler)` or `used(linker)` +static mut USED_COMPILER_LINKER: [usize; 1] = [0]; + +fn main() {} diff --git a/src/test/ui/attributes/used_with_multi_args.stderr b/src/test/ui/attributes/used_with_multi_args.stderr new file mode 100644 index 00000000000..c93aafcfc7c --- /dev/null +++ b/src/test/ui/attributes/used_with_multi_args.stderr @@ -0,0 +1,8 @@ +error: expected `used`, `used(compiler)` or `used(linker)` + --> $DIR/used_with_multi_args.rs:3:1 + | +LL | #[used(compiler, linker)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/used_with_arg.rs b/src/test/ui/used_with_arg.rs deleted file mode 100644 index ad80ff53f0e..00000000000 --- a/src/test/ui/used_with_arg.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(used_with_arg)] - -#[used(linker)] -static mut USED_LINKER: [usize; 1] = [0]; - -#[used(compiler)] -static mut USED_COMPILER: [usize; 1] = [0]; - -#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together -#[used(linker)] -static mut USED_COMPILER_LINKER2: [usize; 1] = [0]; - -#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together -#[used(linker)] -#[used(compiler)] -#[used(linker)] -static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; - -fn main() {} diff --git a/src/test/ui/used_with_arg.stderr b/src/test/ui/used_with_arg.stderr deleted file mode 100644 index 440e5c4a5a0..00000000000 --- a/src/test/ui/used_with_arg.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: `used(compiler)` and `used(linker)` can't be used together - --> $DIR/used_with_arg.rs:9:1 - | -LL | #[used(compiler)] - | ^^^^^^^^^^^^^^^^^ -LL | #[used(linker)] - | ^^^^^^^^^^^^^^^ - -error: `used(compiler)` and `used(linker)` can't be used together - --> $DIR/used_with_arg.rs:13:1 - | -LL | #[used(compiler)] - | ^^^^^^^^^^^^^^^^^ -LL | #[used(linker)] - | ^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/used_with_multi_args.rs b/src/test/ui/used_with_multi_args.rs deleted file mode 100644 index 2e17fcfd7a4..00000000000 --- a/src/test/ui/used_with_multi_args.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![feature(used_with_arg)] - -#[used(compiler, linker)] //~ expected `used`, `used(compiler)` or `used(linker)` -static mut USED_COMPILER_LINKER: [usize; 1] = [0]; - -fn main() {} diff --git a/src/test/ui/used_with_multi_args.stderr b/src/test/ui/used_with_multi_args.stderr deleted file mode 100644 index c93aafcfc7c..00000000000 --- a/src/test/ui/used_with_multi_args.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected `used`, `used(compiler)` or `used(linker)` - --> $DIR/used_with_multi_args.rs:3:1 - | -LL | #[used(compiler, linker)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - -- cgit 1.4.1-3-g733a5