Skip to content

Commit

Permalink
Unrolled build for rust-lang#135378
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#135378 - compiler-errors:unnecessary-stashing, r=chenyukang

Remove a bunch of diagnostic stashing that doesn't do anything

rust-lang#121669 removed a bunch of conditional diagnostic stashing/canceling, but left around the `steal` calls which just emitted the error eagerly instead of canceling the diagnostic. I think that these no-op `steal` calls don't do much and are confusing to encounter, so let's remove them.

The net effect is:
1. We emit more duplicated errors, since stashing has the side effect of duplicating diagnostics. This is not a big deal, since outside of `-Zdeduplicate-diagnostics=no`, the errors are already being deduplicated by the compiler.
2. It changes the order of diagnostics, since we're no longer stashing and then later stealing the errors. I don't think this matters much for the changes that the UI test suite manifests, and it makes these errors less order dependent.
  • Loading branch information
rust-timer authored Jan 12, 2025
2 parents c0f6a1c + 85c9ce6 commit 36f8b45
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 181 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let (Ok(e) | Err(e)) = prev
.build_mismatch_error(
&OpaqueHiddenType { ty, span: concrete_type.span },
opaque_type_key.def_id,
infcx.tcx,
)
.map(|d| d.emit());
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,7 @@ pub enum StashKey {
/// FRU syntax
MaybeFruTypo,
CallAssocMethod,
TraitMissingMethod,
AssociatedTypeSuggestion,
OpaqueHiddenTypeMismatch,
MaybeForgetReturn,
/// Query cycle detected, stashing in favor of a better error.
Cycle,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ fn sanity_check_found_hidden_type<'tcx>(
} else {
let span = tcx.def_span(key.def_id);
let other = ty::OpaqueHiddenType { ty: hidden_ty, span };
Err(ty.build_mismatch_error(&other, key.def_id, tcx)?.emit())
Err(ty.build_mismatch_error(&other, tcx)?.emit())
}
}

Expand Down
21 changes: 7 additions & 14 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_errors::StashKey;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor};
Expand Down Expand Up @@ -45,7 +44,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
if !hidden.ty.references_error() {
for concrete_type in locator.typeck_types {
if concrete_type.ty != tcx.erase_regions(hidden.ty) {
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, def_id, tcx) {
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, tcx) {
d.emit();
}
}
Expand Down Expand Up @@ -121,7 +120,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
if !hidden.ty.references_error() {
for concrete_type in locator.typeck_types {
if concrete_type.ty != tcx.erase_regions(hidden.ty) {
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, def_id, tcx) {
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, tcx) {
d.emit();
}
}
Expand Down Expand Up @@ -285,9 +284,8 @@ impl TaitConstraintLocator<'_> {
debug!(?concrete_type, "found constraint");
if let Some(prev) = &mut self.found {
if concrete_type.ty != prev.ty {
let (Ok(guar) | Err(guar)) = prev
.build_mismatch_error(&concrete_type, self.def_id, self.tcx)
.map(|d| d.emit());
let (Ok(guar) | Err(guar)) =
prev.build_mismatch_error(&concrete_type, self.tcx).map(|d| d.emit());
prev.ty = Ty::new_error(self.tcx, guar);
}
} else {
Expand Down Expand Up @@ -361,11 +359,8 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
);
if let Some(prev) = &mut hir_opaque_ty {
if concrete_type.ty != prev.ty {
if let Ok(d) = prev.build_mismatch_error(&concrete_type, def_id, tcx) {
d.stash(
tcx.def_span(opaque_type_key.def_id),
StashKey::OpaqueHiddenTypeMismatch,
);
if let Ok(d) = prev.build_mismatch_error(&concrete_type, tcx) {
d.emit();
}
}
} else {
Expand Down Expand Up @@ -435,9 +430,7 @@ impl RpitConstraintChecker<'_> {
debug!(?concrete_type, "found constraint");

if concrete_type.ty != self.found.ty {
if let Ok(d) =
self.found.build_mismatch_error(&concrete_type, self.def_id, self.tcx)
{
if let Ok(d) = self.found.build_mismatch_error(&concrete_type, self.tcx) {
d.emit();
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
s1.append(s2);
sugg.cancel();
}
diag.stash(self_ty.span, StashKey::TraitMissingMethod)
Some(diag.emit())
} else {
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, |lint| {
lint.primary_message("trait objects without an explicit `dyn` are deprecated");
Expand Down
24 changes: 1 addition & 23 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::slice;

use rustc_abi::FieldIdx;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey};
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
Expand Down Expand Up @@ -806,17 +806,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let item_name = item_segment.ident;
let result = self
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
.map(|r| {
// lint bare trait if the method is found in the trait
if span.edition().at_least_rust_2021() {
self.dcx().try_steal_modify_and_emit_err(
qself.span,
StashKey::TraitMissingMethod,
|_err| {},
);
}
r
})
.or_else(|error| {
let guar = self
.dcx()
Expand All @@ -840,17 +829,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

// Emit the diagnostic for bare traits. (We used to cancel for slightly better
// error messages, but cancelling stashed diagnostics is no longer allowed because
// it causes problems when tracking whether errors have actually occurred.)
if span.edition().at_least_rust_2021() {
self.dcx().try_steal_modify_and_emit_err(
qself.span,
StashKey::TraitMissingMethod,
|_err| {},
);
}

if item_name.name != kw::Empty {
self.report_method_error(
hir_id,
Expand Down
13 changes: 3 additions & 10 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::mem;

use rustc_data_structures::unord::ExtendUnord;
use rustc_errors::{ErrorGuaranteed, StashKey};
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::intravisit::{self, Visitor};
Expand Down Expand Up @@ -582,15 +582,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
&& last_opaque_ty.ty != hidden_type.ty
{
assert!(!self.fcx.next_trait_solver());
if let Ok(d) = hidden_type.build_mismatch_error(
&last_opaque_ty,
opaque_type_key.def_id,
self.tcx(),
) {
d.stash(
self.tcx().def_span(opaque_type_key.def_id),
StashKey::OpaqueHiddenTypeMismatch,
);
if let Ok(d) = hidden_type.build_mismatch_error(&last_opaque_ty, self.tcx()) {
d.emit();
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
use rustc_errors::{Diag, ErrorGuaranteed};
use rustc_hir::LangItem;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
Expand Down Expand Up @@ -782,18 +782,8 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
pub fn build_mismatch_error(
&self,
other: &Self,
opaque_def_id: LocalDefId,
tcx: TyCtxt<'tcx>,
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
// We used to cancel here for slightly better error messages, but
// cancelling stashed diagnostics is no longer allowed because it
// causes problems when tracking whether errors have actually
// occurred.
tcx.sess.dcx().try_steal_modify_and_emit_err(
tcx.def_span(opaque_def_id),
StashKey::OpaqueHiddenTypeMismatch,
|_err| {},
);
(self.ty, other.ty).error_reported()?;
// Found different concrete types for the opaque type.
let sub_diag = if self.span == other.span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn f<T>(
}],
) -> impl Iterator<Item = SubAssign> {
//~^ ERROR expected a type, found a trait
//~| ERROR expected a type, found a trait
//~| ERROR `()` is not an iterator
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,28 @@ help: you might be missing a type parameter
LL | fn f<T, F>(
| +++

error[E0277]: `()` is not an iterator
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6
error[E0782]: expected a type, found a trait
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
| ^^^^^^^^^
|
= help: the trait `Iterator` is not implemented for `()`
help: you can add the `dyn` keyword if you want a trait object
|
LL | ) -> impl Iterator<Item = dyn SubAssign> {
| +++
help: you might have meant to write a bound here
|
LL | ) -> impl Iterator<Item: SubAssign> {
| ~

error[E0782]: expected a type, found a trait
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: you can add the `dyn` keyword if you want a trait object
|
LL | ) -> impl Iterator<Item = dyn SubAssign> {
Expand All @@ -39,7 +47,15 @@ help: you might have meant to write a bound here
LL | ) -> impl Iterator<Item: SubAssign> {
| ~

error: aborting due to 3 previous errors
error[E0277]: `()` is not an iterator
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0277, E0412, E0782.
For more information about an error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ help: you can add the `dyn` keyword if you want a trait object
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++

error: aborting due to 1 previous error
error[E0782]: expected a type, found a trait
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:24
|
LL | fn ice() -> impl AsRef<Fn(&())> {
| ^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: you can add the `dyn` keyword if you want a trait object
|
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0782`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
fn ice() -> impl AsRef<Fn(&())> {
//[edition2015]~^ ERROR: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied [E0277]
//[edition2021]~^^ ERROR: expected a type, found a trait [E0782]
//[edition2021]~| ERROR: expected a type, found a trait [E0782]
todo!()
}

Expand Down
18 changes: 9 additions & 9 deletions tests/ui/impl-trait/issue-99073-2.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
error[E0792]: expected generic type parameter, found `i32`
--> $DIR/issue-99073-2.rs:9:22
|
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
| - this generic parameter must be used with a generic type parameter
LL | let f = || {
LL | let i: u32 = test::<i32>(-1, false);
| ^^^^^^^^^^^^^^^^^^^^^^

error: concrete type differs from previous defining opaque type use
--> $DIR/issue-99073-2.rs:9:22
|
Expand All @@ -19,6 +10,15 @@ note: previous use here
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
| ^^^^^^^^^^^^

error[E0792]: expected generic type parameter, found `i32`
--> $DIR/issue-99073-2.rs:9:22
|
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
| - this generic parameter must be used with a generic type parameter
LL | let f = || {
LL | let i: u32 = test::<i32>(-1, false);
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0792`.
16 changes: 8 additions & 8 deletions tests/ui/impl-trait/issue-99073.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
error[E0792]: expected generic type parameter, found `&F`
--> $DIR/issue-99073.rs:6:11
|
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
| - this generic parameter must be used with a generic type parameter
LL | move || f(fix(&f))
| ^^^^^^^^^^

error: concrete type differs from previous defining opaque type use
--> $DIR/issue-99073.rs:6:13
|
Expand All @@ -18,6 +10,14 @@ note: previous use here
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
| ^^^^^^^^^

error[E0792]: expected generic type parameter, found `&F`
--> $DIR/issue-99073.rs:6:11
|
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
| - this generic parameter must be used with a generic type parameter
LL | move || f(fix(&f))
| ^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0792`.
24 changes: 12 additions & 12 deletions tests/ui/impl-trait/multiple-defining-usages-in-body.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
warning: function cannot return without recursing
--> $DIR/multiple-defining-usages-in-body.rs:4:1
|
LL | fn foo<T: Trait, U: Trait>() -> impl Trait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
LL |
LL | let a: T = foo::<T, U>();
| ------------- recursive call site
|
= help: a `loop` may express intention better if this is on purpose
= note: `#[warn(unconditional_recursion)]` on by default

error: concrete type differs from previous defining opaque type use
--> $DIR/multiple-defining-usages-in-body.rs:8:16
|
Expand All @@ -22,5 +10,17 @@ note: previous use here
LL | let a: T = foo::<T, U>();
| ^^^^^^^^^^^^^

warning: function cannot return without recursing
--> $DIR/multiple-defining-usages-in-body.rs:4:1
|
LL | fn foo<T: Trait, U: Trait>() -> impl Trait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
LL |
LL | let a: T = foo::<T, U>();
| ------------- recursive call site
|
= help: a `loop` may express intention better if this is on purpose
= note: `#[warn(unconditional_recursion)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

Loading

0 comments on commit 36f8b45

Please sign in to comment.