rust/compiler
Matthias Krüger 2f1ac412ec
Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk
Fix `ErrorGuaranteed` unsoundness with stash/steal.

When you stash an error, the error count is incremented. You can then use the non-zero error count to get an `ErrorGuaranteed`. You can then steal the error, which decrements the error count. You can then cancel the error.

Example code:
```
fn unsound(dcx: &DiagCtxt) -> ErrorGuaranteed {
    let sp = rustc_span::DUMMY_SP;
    let k = rustc_errors::StashKey::Cycle;
    dcx.struct_err("bogus").stash(sp, k);           // increment error count on stash
    let guar = dcx.has_errors().unwrap();           // ErrorGuaranteed from error count > 0
    let err = dcx.steal_diagnostic(sp, k).unwrap(); // decrement error count on steal
    err.cancel();                                   // cancel error
    guar                                            // ErrorGuaranteed with no error emitted!
}
```

This commit fixes the problem in the simplest way: by not counting stashed errors in `DiagCtxt::{err_count,has_errors}`.

However, just doing this without any other changes leads to over 40 ui test failures. Mostly because of uninteresting extra errors (many saying "type annotations needed" when type inference fails), and in a few cases, due to delayed bugs causing ICEs when no normal errors are printed.

To fix these, this commit adds `DiagCtxt::stashed_err_count`, and uses it in three places alongside `DiagCtxt::{has_errors,err_count}`. It's dodgy to rely on it, because unlike `DiagCtxt::err_count` it can go up and down. But it's needed to preserve existing behaviour, and at least the three places that need it are now obvious.

r? oli-obk
2024-02-09 14:41:52 +01:00
..
rustc
rustc_abi Fix rustc_abi build on stable 2024-01-16 21:15:31 +01:00
rustc_arena Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_ast Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_ast_lowering Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_ast_passes Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_ast_pretty Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_attr Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #120704 - amandasystems:silly-region-name-rewrite, r=compiler-errors 2024-02-09 14:41:50 +01:00
rustc_builtin_macros Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_codegen_cranelift Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_codegen_gcc Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_codegen_llvm Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_codegen_ssa Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_const_eval Rollup merge of #120817 - compiler-errors:more-mir-errors, r=oli-obk 2024-02-09 14:41:51 +01:00
rustc_data_structures Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_driver
rustc_driver_impl Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_error_codes Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_error_messages Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_errors Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk 2024-02-09 14:41:52 +01:00
rustc_expand Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_feature Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_fluent_macro Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_fs_util Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_graphviz Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_hir Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_hir_analysis Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_hir_pretty Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_hir_typeck Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk 2024-02-09 14:41:52 +01:00
rustc_incremental Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_index Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_index_macros Restrict access to the private field of newtype indexes 2024-01-19 15:38:47 +00:00
rustc_infer Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk 2024-02-09 14:41:52 +01:00
rustc_interface Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk 2024-02-09 14:41:52 +01:00
rustc_lexer Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_lint Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_lint_defs Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_llvm Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_log Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_macros Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_metadata Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_middle Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_mir_build Rollup merge of #120817 - compiler-errors:more-mir-errors, r=oli-obk 2024-02-09 14:41:51 +01:00
rustc_mir_dataflow Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_mir_transform Rollup merge of #120817 - compiler-errors:more-mir-errors, r=oli-obk 2024-02-09 14:41:51 +01:00
rustc_monomorphize Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_next_trait_solver Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
rustc_parse Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_parse_format Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_passes Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_pattern_analysis Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_privacy Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_query_impl Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_query_system Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_resolve Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_serialize Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_session Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_smir Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
rustc_span Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_symbol_mangling Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_target Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_trait_selection Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_traits Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_transmute Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
rustc_ty_utils Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
rustc_type_ir Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco 2024-02-09 14:41:50 +01:00
stable_mir Remove the abi_amdgpu_kernel feature 2024-01-30 15:46:40 +00:00