rust/compiler/rustc_passes/src
bors b1d2f2c64c Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk
Split up the `unknown_or_malformed_diagnostic_attributes` lint

This splits up the lint into the following lint group:
- `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler
- `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for
- `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid
- `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
- this pr doesn't create it, but future lints for things like deprecations can also go here.

This PR does not start emitting lints in places that previously did not.

## Motivation

I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does

I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.

At this time, there are two options to silence these lints:

-  `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
- write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
    ```rust
    #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
    struct Foo;
    ```
    or conditionally `allow`  the lint:
    ```rust
   // lib.rs
   #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]
   ```

I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:
```rust
    #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
    #[diagnostic::new_attr_in_rust_99(thing = ..)]`
    struct Foo;
2025-07-13 01:11:56 +00:00
..
liveness use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
abi_test.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
check_attr.rs Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk 2025-07-13 01:11:56 +00:00
check_export.rs Port #[export_stable] to the new attribute system 2025-07-07 14:33:20 +03:00
dead.rs setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
debugger_visualizer.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
diagnostic_items.rs Implement lint against direct uses of rustc_type_ir in compiler crates 2025-06-18 16:01:41 +02:00
entry.rs use slice::contains where applicable 2025-03-28 12:21:21 +00:00
errors.rs Remove repr(align) code 2025-07-06 16:56:39 -04:00
hir_id_validator.rs Adjust Map's to_string functionality. 2025-03-12 08:30:03 +11:00
input_stats.rs compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
lang_items.rs deduplicate more walk_* methods in AST visit 2025-06-06 04:59:26 +00:00
layout_test.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
lib.rs Remove check_mod_loops query and run the checks per-body instead 2025-06-10 08:41:23 +00:00
lib_features.rs Tracking the old name of renamed unstable library attribute 2025-06-12 19:24:11 +08:00
liveness.rs Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
reachable.rs Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
stability.rs compiler: rename {ast,hir}::BareFn* to FnPtr* 2025-07-06 15:03:08 -07:00
upvars.rs Move methods from Map to TyCtxt, part 2. 2025-02-18 10:17:44 +11:00
weak_lang_items.rs Initial support for dynamically linked crates 2025-05-04 22:03:15 +03:00