rust/compiler/rustc_passes/src
Jana Dönszelmann 63c5a84b74
Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk
Add runtime check to avoid overwrite arg in `Diag`

## Origin PR description
At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it.

For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error
```
arg `instance`already exists.
```

This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure:

1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~
2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~

## Final Decision

After trying and discussing, we made a final decision.

For `#[derive(Subdiagnostic)]`, This PR made two changes:

1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`.
2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25 22:14:55 +02:00
..
liveness compiler: Use size_of from the prelude instead of imported 2025-03-07 13:37:04 -08: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 Rollup merge of #142825 - jdonszelmann:track-caller, r=oli-obk 2025-06-24 19:45:32 -07:00
check_export.rs apply clippy::or_fun_call 2025-06-17 13:59:53 +03:00
dead.rs Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02: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 Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
hir_id_validator.rs Adjust Map's to_string functionality. 2025-03-12 08:30:03 +11:00
input_stats.rs Tweak -Zinput-stats and -Zmeta-stats output. 2025-06-24 13:07:14 +10: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 Cleanup CodegenFnAttrFlags 2025-05-24 20:31:37 +02:00
stability.rs Tracking the old name of renamed unstable library attribute 2025-06-12 19:24:11 +08: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