1
Fork 0

Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=estebank

Count stashed errors again

Stashed diagnostics are such a pain. Their "might be emitted, might not" semantics messes with lots of things.

#120828 and #121206 made some big changes to how they work, improving some things, but still leaving some problems, as seen by the issues caused by #121206. This PR aims to fix all of them by restricting them in a way that eliminates the "might be emitted, might not" semantics while still allowing 98% of their benefit. Details in the individual commit logs.

r? `@oli-obk`
This commit is contained in:
Guillaume Gomez 2024-02-29 17:08:38 +01:00 committed by GitHub
commit a5945b5d8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 476 additions and 343 deletions

View file

@ -2520,14 +2520,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
if attr.style == AttrStyle::Inner {
for attr_to_check in ATTRS_TO_CHECK {
if attr.has_name(*attr_to_check) {
if let AttrKind::Normal(ref p) = attr.kind
&& let Some(diag) = tcx.dcx().steal_diagnostic(
p.item.path.span,
StashKey::UndeterminedMacroResolution,
)
{
diag.cancel();
}
let item = tcx
.hir()
.items()
@ -2537,7 +2529,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
span: item.ident.span,
kind: item.kind.descr(),
});
tcx.dcx().emit_err(errors::InvalidAttrAtCrateLevel {
let err = tcx.dcx().create_err(errors::InvalidAttrAtCrateLevel {
span: attr.span,
sugg_span: tcx
.sess
@ -2553,6 +2545,16 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
name: *attr_to_check,
item,
});
if let AttrKind::Normal(ref p) = attr.kind {
tcx.dcx().try_steal_replace_and_emit_err(
p.item.path.span,
StashKey::UndeterminedMacroResolution,
err,
);
} else {
err.emit();
}
}
}
}