diff options
| author | Jana Dönszelmann <jonathan@donsz.nl> | 2025-06-25 22:14:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-25 22:14:55 +0200 |
| commit | 63c5a84b74091970026e9ff023ff4ba1fe01db44 (patch) | |
| tree | 2306cadb95c5bdce46d49d2246ef55753eba4c58 /compiler/rustc_passes/src/errors.rs | |
| parent | 131a2e47fbc107a7649c18ba46a751a43e72c5cf (diff) | |
| parent | d2d17c60bd62c03b91f6ded31b34da90addf2fc0 (diff) | |
| download | rust-63c5a84b74091970026e9ff023ff4ba1fe01db44.tar.gz rust-63c5a84b74091970026e9ff023ff4ba1fe01db44.zip | |
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.
Diffstat (limited to 'compiler/rustc_passes/src/errors.rs')
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index c933647165c..d9ec167aae3 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1516,7 +1516,7 @@ pub(crate) struct EnumVariantSameName<'tcx> { #[primary_span] pub variant_span: Span, pub dead_name: Symbol, - pub descr: &'tcx str, + pub dead_descr: &'tcx str, } #[derive(Subdiagnostic)] @@ -1714,6 +1714,7 @@ impl Subdiagnostic for UnusedVariableStringInterp { #[derive(LintDiagnostic)] #[diag(passes_unused_variable_try_ignore)] pub(crate) struct UnusedVarTryIgnore { + pub name: String, #[subdiagnostic] pub sugg: UnusedVarTryIgnoreSugg, } |
