rust/compiler/rustc_builtin_macros/src
Matthias Krüger 659382fa47
Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank
Add more info and suggestions to use of #[test] on invalid items

This pr changes the diagnostics for using `#[test]` on an item that can't be used as a test to explain that the attribute has no meaningful effect on non-functions and suggests the use of `#[cfg(test)]` for conditional compilation instead.

Example change:
```rs
#[test]
mod test {}
```
previously output
```
error: only functions may be used as tests
 --> src/lib.rs:2:1
  |
2 | mod test {}
  | ^^^^^^^^^^^
  ```
  now outputs
  ```
error: the `#[test]` attribute may only be used on a non-associated function
  --> $DIR/test-on-not-fn.rs:3:1
     |
LL | #[test]
     | ^^^^^^^
LL | mod test {}
     | ----------- expected a non-associated function, found a module
     |
     = note: the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
help: replace with conditional compilation to make the item only exist when tests are being run
     |
LL | #[cfg(test)]
     | ~~~~~~~~~~~~
   ```
2022-02-18 16:23:29 +01:00
..
deriving Rollup merge of #92366 - jhpratt:derive-default-enum, r=Mark-Simulacrum 2022-02-16 18:59:27 +01:00
format_foreign update tests 2021-12-31 12:51:27 -05:00
asm.rs Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
assert.rs Fix invalid special casing of the unreachable! macro 2022-01-31 17:09:31 +01:00
cfg_accessible.rs expand: Tell built-in macros whether we are currently in forced expansion mode 2020-11-19 19:25:20 +03:00
cfg_eval.rs Add a lint for duplicated attributes. 2021-12-15 23:43:13 +01:00
cfg.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
cmdline_attrs.rs Unconditionally capture tokens for attributes. 2020-10-21 18:57:29 -04:00
compile_error.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
concat_bytes.rs Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
concat_idents.rs Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
concat.rs Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
derive.rs Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
edition_panic.rs Fix invalid special casing of the unreachable! macro 2022-01-31 17:09:31 +01:00
env.rs Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
format_foreign.rs [rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape 2021-12-31 12:42:15 -05:00
format.rs Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
global_allocator.rs Point at type when a static #[global_allocator] doesn't impl GlobalAlloc 2021-12-15 01:40:08 +00:00
lib.rs Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
log_syntax.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
proc_macro_harness.rs Deny mixing bin crate type with lib crate types 2022-01-15 14:48:00 +01:00
source_util.rs Compute a better lint_node_id during expansion 2021-07-17 23:03:56 -05:00
standard_library_imports.rs Remove the alt_std_name option 2022-02-11 20:28:38 +01:00
test_harness.rs expand: Turn ast::Crate into a first class expansion target 2021-11-28 15:48:55 +08:00
test.rs Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank 2022-02-18 16:23:29 +01:00
trace_macros.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
util.rs Add a lint for duplicated attributes. 2021-12-15 23:43:13 +01:00