rust/compiler/rustc_resolve/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
..
late Fix PathSource lifetimes. 2025-06-16 10:33:00 +10:00
rustdoc source_span_for_markdown_range: fix utf8 violation 2025-05-31 14:51:16 -05:00
build_reduced_graph.rs resolve: Tweak private_macro_use lint to be compatible with upcoming macro prelude changes 2025-06-03 00:09:54 +03:00
check_unused.rs deduplicate more walk_* methods in AST visit 2025-06-06 04:59:26 +00:00
def_collector.rs remove equivalent new method on context 2025-06-20 07:50:11 +02:00
diagnostics.rs Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg 2025-06-25 21:07:16 +08:00
effective_visibilities.rs Reorder ast::ItemKind::{Struct,Enum,Union} fields. 2025-05-28 15:48:45 +10:00
errors.rs Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg 2025-06-25 21:07:16 +08:00
ident.rs Detect when attribute is provided by missing derive macro 2025-06-12 21:28:49 +00:00
imports.rs Emit a single error when importing a path with _ 2025-06-24 16:21:26 +00:00
late.rs Auto merge of #142706 - fee1-dead-contrib:push-zsznlqyrzsqo, r=oli-obk 2025-06-22 14:03:44 +00:00
lib.rs Auto merge of #134841 - estebank:serde-attr-4, r=wesleywiser 2025-06-13 22:59:24 +00:00
macros.rs Auto merge of #134841 - estebank:serde-attr-4, r=wesleywiser 2025-06-13 22:59:24 +00:00
rustdoc.rs Add AttributeExt::doc_resolution_scope 2025-06-21 11:09:12 -07:00