Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #121859

Merged
merged 28 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
75da582
Fix incorrect suggestion for uninitialize binding in destructuring pa…
clubby789 Feb 4, 2024
748c615
make unused_imports less assertive in test modules
Suya1671 Feb 25, 2024
a9907b1
remove Mutex::unlock
HTGAzureX1212 Feb 28, 2024
4996194
Improve error messages for generics with default parameters
veera-sivarajan Feb 21, 2024
3ba50b3
Avoid code duplication
veera-sivarajan Feb 23, 2024
cc13f82
Update item order in test
veera-sivarajan Feb 23, 2024
a7832b1
Make the success arms of `if lhs || rhs` meet up in a separate block
Zalathar Feb 28, 2024
f11713b
Error on stray .stderr/.stdout files for (un-)revisioned tests
jieyouxu Feb 22, 2024
19ee457
Remove stray stdout/stderr files
jieyouxu Feb 22, 2024
721c741
Remove unnecessary `Level::` qualifiers.
nnethercote Feb 29, 2024
7e64163
CFI: Remove unused `typeid_for_fnsig`
rcvalle Feb 29, 2024
44f0043
Handle stashing of delayed bugs.
nnethercote Feb 29, 2024
2064c19
Remove unused fluent messages
mu001999 Mar 1, 2024
beac5b1
Fix typo in comment
gurry Mar 1, 2024
f6d2607
Make `ZeroablePrimitive` trait unsafe.
reitermarkus Mar 1, 2024
0700ec0
normalizes-to: handle negative impls
lcnr Mar 1, 2024
80549a8
Rollup merge of #120646 - clubby789:uninit-destructuring-sugg, r=mich…
matthiaskrgr Mar 1, 2024
f23c6dd
Rollup merge of #121416 - veera-sivarajan:bugfix-120785, r=nnethercote
matthiaskrgr Mar 1, 2024
dcde08f
Rollup merge of #121475 - jieyouxu:tidy-stderr-check, r=the8472,compi…
matthiaskrgr Mar 1, 2024
58825b4
Rollup merge of #121580 - Suyashtnt:issue-121502-fix, r=michaelwoerister
matthiaskrgr Mar 1, 2024
90ca049
Rollup merge of #121736 - HTGAzureX1212:HTGAzureX1212/remove-mutex-un…
matthiaskrgr Mar 1, 2024
1a4c93e
Rollup merge of #121784 - Zalathar:if-or-converge, r=Nadrieril
matthiaskrgr Mar 1, 2024
b5ef517
Rollup merge of #121818 - rcvalle:rust-cfi-remove-unused-typeid-for-f…
matthiaskrgr Mar 1, 2024
47a491d
Rollup merge of #121819 - nnethercote:fix-121812, r=oli-obk
matthiaskrgr Mar 1, 2024
01b58bd
Rollup merge of #121828 - mu001999:clean, r=Nilstrieb
matthiaskrgr Mar 1, 2024
96e3777
Rollup merge of #121831 - gurry:fix-typo, r=oli-obk
matthiaskrgr Mar 1, 2024
68dd5e6
Rollup merge of #121850 - reitermarkus:generic-nonzero-unsafe-trait, …
matthiaskrgr Mar 1, 2024
ff22925
Rollup merge of #121853 - lcnr:normalizes_to-polarity, r=compiler-errors
matthiaskrgr Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle stashing of delayed bugs.
By just emitting them immediately, because it does happen in practice,
when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the
callsite. This commit changes things so it's handled within
`stash_diagnostic` instead, because #121812 identified a second case,
and it's possible there are more.

Fixes #121812.
  • Loading branch information
nnethercote committed Feb 29, 2024
commit 44f0043e82fb2d3156434797f2e638cb61b07ce9
36 changes: 25 additions & 11 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,33 +712,47 @@ impl DiagCtxt {
/// Stashes a diagnostic for possible later improvement in a different,
/// later stage of the compiler. Possible actions depend on the diagnostic
/// level:
/// - Level::Bug, Level:Fatal: not allowed, will trigger a panic.
/// - Level::Error: immediately counted as an error that has occurred, because it
/// is guaranteed to be emitted eventually. Can be later accessed with the
/// provided `span` and `key` through
/// [`DiagCtxt::try_steal_modify_and_emit_err`] or
/// [`DiagCtxt::try_steal_replace_and_emit_err`]. These do not allow
/// cancellation or downgrading of the error. Returns
/// `Some(ErrorGuaranteed)`.
/// - Level::DelayedBug: this does happen occasionally with errors that are
/// downgraded to delayed bugs. It is not stashed, but immediately
/// emitted as a delayed bug. This is because stashing it would cause it
/// to be counted by `err_count` which we don't want. It doesn't matter
/// that we cannot steal and improve it later, because it's not a
/// user-facing error. Returns `Some(ErrorGuaranteed)` as is normal for
/// delayed bugs.
/// - Level::Warning and lower (i.e. !is_error()): can be accessed with the
/// provided `span` and `key` through [`DiagCtxt::steal_non_err()`]. This
/// allows cancelling and downgrading of the diagnostic. Returns `None`.
/// - Others: not allowed, will trigger a panic.
pub fn stash_diagnostic(
&self,
span: Span,
key: StashKey,
diag: DiagInner,
) -> Option<ErrorGuaranteed> {
let guar = if diag.level() == Level::Error {
// This `unchecked_error_guaranteed` is valid. It is where the
// `ErrorGuaranteed` for stashed errors originates. See
// `DiagCtxtInner::drop`.
#[allow(deprecated)]
Some(ErrorGuaranteed::unchecked_error_guaranteed())
} else if !diag.is_error() {
None
} else {
self.span_bug(span, format!("invalid level in `stash_diagnostic`: {}", diag.level));
let guar = match diag.level {
Bug | Fatal => {
self.span_bug(
span,
format!("invalid level in `stash_diagnostic`: {:?}", diag.level),
);
}
Error => {
// This `unchecked_error_guaranteed` is valid. It is where the
// `ErrorGuaranteed` for stashed errors originates. See
// `DiagCtxtInner::drop`.
#[allow(deprecated)]
Some(ErrorGuaranteed::unchecked_error_guaranteed())
}
DelayedBug => return self.inner.borrow_mut().emit_diagnostic(diag),
ForceWarning(_) | Warning | Note | OnceNote | Help | OnceHelp | FailureNote | Allow
| Expect(_) => None,
};

// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
Expand Down
12 changes: 2 additions & 10 deletions compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_ast::TraitObjectSyntax;
use rustc_errors::{codes::*, Diag, EmissionGuarantee, Level, StashKey};
use rustc_errors::{codes::*, Diag, EmissionGuarantee, StashKey};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
Expand Down Expand Up @@ -237,15 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
// check if the impl trait that we are considering is a impl of a local trait
self.maybe_lint_blanket_trait_impl(self_ty, &mut diag);
match diag.level() {
Level::Error => {
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
}
Level::DelayedBug => {
diag.emit();
}
_ => unreachable!(),
}
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
} else {
let msg = "trait objects without an explicit `dyn` are deprecated";
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/typeck/invalid-stashed-level-issue-121812.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
union U {
a: u16,
b: [u8; 3],
}

fn main() {
_ = U { b: [()] }; //~ ERROR mismatched types
}
9 changes: 9 additions & 0 deletions tests/ui/typeck/invalid-stashed-level-issue-121812.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0308]: mismatched types
--> $DIR/invalid-stashed-level-issue-121812.rs:7:17
|
LL | _ = U { b: [()] };
| ^^ expected `u8`, found `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading