Skip to content

Commit 36f8b45

Browse files
authored
Unrolled build for rust-lang#135378
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.
2 parents c0f6a1c + 85c9ce6 commit 36f8b45

22 files changed

+173
-181
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
152152
let (Ok(e) | Err(e)) = prev
153153
.build_mismatch_error(
154154
&OpaqueHiddenType { ty, span: concrete_type.span },
155-
opaque_type_key.def_id,
156155
infcx.tcx,
157156
)
158157
.map(|d| d.emit());

compiler/rustc_errors/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,7 @@ pub enum StashKey {
566566
/// FRU syntax
567567
MaybeFruTypo,
568568
CallAssocMethod,
569-
TraitMissingMethod,
570569
AssociatedTypeSuggestion,
571-
OpaqueHiddenTypeMismatch,
572570
MaybeForgetReturn,
573571
/// Query cycle detected, stashing in favor of a better error.
574572
Cycle,

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ fn sanity_check_found_hidden_type<'tcx>(
575575
} else {
576576
let span = tcx.def_span(key.def_id);
577577
let other = ty::OpaqueHiddenType { ty: hidden_ty, span };
578-
Err(ty.build_mismatch_error(&other, key.def_id, tcx)?.emit())
578+
Err(ty.build_mismatch_error(&other, tcx)?.emit())
579579
}
580580
}
581581

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::StashKey;
21
use rustc_hir::def::DefKind;
32
use rustc_hir::def_id::LocalDefId;
43
use rustc_hir::intravisit::{self, Visitor};
@@ -45,7 +44,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
4544
if !hidden.ty.references_error() {
4645
for concrete_type in locator.typeck_types {
4746
if concrete_type.ty != tcx.erase_regions(hidden.ty) {
48-
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, def_id, tcx) {
47+
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, tcx) {
4948
d.emit();
5049
}
5150
}
@@ -121,7 +120,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
121120
if !hidden.ty.references_error() {
122121
for concrete_type in locator.typeck_types {
123122
if concrete_type.ty != tcx.erase_regions(hidden.ty) {
124-
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, def_id, tcx) {
123+
if let Ok(d) = hidden.build_mismatch_error(&concrete_type, tcx) {
125124
d.emit();
126125
}
127126
}
@@ -285,9 +284,8 @@ impl TaitConstraintLocator<'_> {
285284
debug!(?concrete_type, "found constraint");
286285
if let Some(prev) = &mut self.found {
287286
if concrete_type.ty != prev.ty {
288-
let (Ok(guar) | Err(guar)) = prev
289-
.build_mismatch_error(&concrete_type, self.def_id, self.tcx)
290-
.map(|d| d.emit());
287+
let (Ok(guar) | Err(guar)) =
288+
prev.build_mismatch_error(&concrete_type, self.tcx).map(|d| d.emit());
291289
prev.ty = Ty::new_error(self.tcx, guar);
292290
}
293291
} else {
@@ -361,11 +359,8 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
361359
);
362360
if let Some(prev) = &mut hir_opaque_ty {
363361
if concrete_type.ty != prev.ty {
364-
if let Ok(d) = prev.build_mismatch_error(&concrete_type, def_id, tcx) {
365-
d.stash(
366-
tcx.def_span(opaque_type_key.def_id),
367-
StashKey::OpaqueHiddenTypeMismatch,
368-
);
362+
if let Ok(d) = prev.build_mismatch_error(&concrete_type, tcx) {
363+
d.emit();
369364
}
370365
}
371366
} else {
@@ -435,9 +430,7 @@ impl RpitConstraintChecker<'_> {
435430
debug!(?concrete_type, "found constraint");
436431

437432
if concrete_type.ty != self.found.ty {
438-
if let Ok(d) =
439-
self.found.build_mismatch_error(&concrete_type, self.def_id, self.tcx)
440-
{
433+
if let Ok(d) = self.found.build_mismatch_error(&concrete_type, self.tcx) {
441434
d.emit();
442435
}
443436
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
9696
s1.append(s2);
9797
sugg.cancel();
9898
}
99-
diag.stash(self_ty.span, StashKey::TraitMissingMethod)
99+
Some(diag.emit())
100100
} else {
101101
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, |lint| {
102102
lint.primary_message("trait objects without an explicit `dyn` are deprecated");

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::slice;
33

44
use rustc_abi::FieldIdx;
55
use rustc_data_structures::fx::FxHashSet;
6-
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey};
6+
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
77
use rustc_hir::def::{CtorOf, DefKind, Res};
88
use rustc_hir::def_id::DefId;
99
use rustc_hir::intravisit::Visitor;
@@ -806,17 +806,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
806806
let item_name = item_segment.ident;
807807
let result = self
808808
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
809-
.map(|r| {
810-
// lint bare trait if the method is found in the trait
811-
if span.edition().at_least_rust_2021() {
812-
self.dcx().try_steal_modify_and_emit_err(
813-
qself.span,
814-
StashKey::TraitMissingMethod,
815-
|_err| {},
816-
);
817-
}
818-
r
819-
})
820809
.or_else(|error| {
821810
let guar = self
822811
.dcx()
@@ -840,17 +829,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
840829
);
841830
}
842831

843-
// Emit the diagnostic for bare traits. (We used to cancel for slightly better
844-
// error messages, but cancelling stashed diagnostics is no longer allowed because
845-
// it causes problems when tracking whether errors have actually occurred.)
846-
if span.edition().at_least_rust_2021() {
847-
self.dcx().try_steal_modify_and_emit_err(
848-
qself.span,
849-
StashKey::TraitMissingMethod,
850-
|_err| {},
851-
);
852-
}
853-
854832
if item_name.name != kw::Empty {
855833
self.report_method_error(
856834
hir_id,

compiler/rustc_hir_typeck/src/writeback.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::mem;
66

77
use rustc_data_structures::unord::ExtendUnord;
8-
use rustc_errors::{ErrorGuaranteed, StashKey};
8+
use rustc_errors::ErrorGuaranteed;
99
use rustc_hir as hir;
1010
use rustc_hir::HirId;
1111
use rustc_hir::intravisit::{self, Visitor};
@@ -582,15 +582,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
582582
&& last_opaque_ty.ty != hidden_type.ty
583583
{
584584
assert!(!self.fcx.next_trait_solver());
585-
if let Ok(d) = hidden_type.build_mismatch_error(
586-
&last_opaque_ty,
587-
opaque_type_key.def_id,
588-
self.tcx(),
589-
) {
590-
d.stash(
591-
self.tcx().def_span(opaque_type_key.def_id),
592-
StashKey::OpaqueHiddenTypeMismatch,
593-
);
585+
if let Ok(d) = hidden_type.build_mismatch_error(&last_opaque_ty, self.tcx()) {
586+
d.emit();
594587
}
595588
}
596589
}

compiler/rustc_middle/src/ty/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3232
use rustc_data_structures::intern::Interned;
3333
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3434
use rustc_data_structures::steal::Steal;
35-
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
35+
use rustc_errors::{Diag, ErrorGuaranteed};
3636
use rustc_hir::LangItem;
3737
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
3838
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
@@ -782,18 +782,8 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
782782
pub fn build_mismatch_error(
783783
&self,
784784
other: &Self,
785-
opaque_def_id: LocalDefId,
786785
tcx: TyCtxt<'tcx>,
787786
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
788-
// We used to cancel here for slightly better error messages, but
789-
// cancelling stashed diagnostics is no longer allowed because it
790-
// causes problems when tracking whether errors have actually
791-
// occurred.
792-
tcx.sess.dcx().try_steal_modify_and_emit_err(
793-
tcx.def_span(opaque_def_id),
794-
StashKey::OpaqueHiddenTypeMismatch,
795-
|_err| {},
796-
);
797787
(self.ty, other.ty).error_reported()?;
798788
// Found different concrete types for the opaque type.
799789
let sub_diag = if self.span == other.span {

tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn f<T>(
1515
}],
1616
) -> impl Iterator<Item = SubAssign> {
1717
//~^ ERROR expected a type, found a trait
18+
//~| ERROR expected a type, found a trait
1819
//~| ERROR `()` is not an iterator
1920
}
2021

tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr

+21-5
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ help: you might be missing a type parameter
1616
LL | fn f<T, F>(
1717
| +++
1818

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

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

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

4460
Some errors have detailed explanations: E0277, E0412, E0782.
4561
For more information about an error, try `rustc --explain E0277`.

tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ help: you can add the `dyn` keyword if you want a trait object
99
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
1010
| +++
1111

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

1426
For more information about this error, try `rustc --explain E0782`.

tests/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
fn ice() -> impl AsRef<Fn(&())> {
77
//[edition2015]~^ ERROR: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied [E0277]
88
//[edition2021]~^^ ERROR: expected a type, found a trait [E0782]
9+
//[edition2021]~| ERROR: expected a type, found a trait [E0782]
910
todo!()
1011
}
1112

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0792]: expected generic type parameter, found `i32`
2-
--> $DIR/issue-99073-2.rs:9:22
3-
|
4-
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
5-
| - this generic parameter must be used with a generic type parameter
6-
LL | let f = || {
7-
LL | let i: u32 = test::<i32>(-1, false);
8-
| ^^^^^^^^^^^^^^^^^^^^^^
9-
101
error: concrete type differs from previous defining opaque type use
112
--> $DIR/issue-99073-2.rs:9:22
123
|
@@ -19,6 +10,15 @@ note: previous use here
1910
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
2011
| ^^^^^^^^^^^^
2112

13+
error[E0792]: expected generic type parameter, found `i32`
14+
--> $DIR/issue-99073-2.rs:9:22
15+
|
16+
LL | fn test<T: Display>(t: T, recurse: bool) -> impl Display {
17+
| - this generic parameter must be used with a generic type parameter
18+
LL | let f = || {
19+
LL | let i: u32 = test::<i32>(-1, false);
20+
| ^^^^^^^^^^^^^^^^^^^^^^
21+
2222
error: aborting due to 2 previous errors
2323

2424
For more information about this error, try `rustc --explain E0792`.
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error[E0792]: expected generic type parameter, found `&F`
2-
--> $DIR/issue-99073.rs:6:11
3-
|
4-
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
5-
| - this generic parameter must be used with a generic type parameter
6-
LL | move || f(fix(&f))
7-
| ^^^^^^^^^^
8-
91
error: concrete type differs from previous defining opaque type use
102
--> $DIR/issue-99073.rs:6:13
113
|
@@ -18,6 +10,14 @@ note: previous use here
1810
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
1911
| ^^^^^^^^^
2012

13+
error[E0792]: expected generic type parameter, found `&F`
14+
--> $DIR/issue-99073.rs:6:11
15+
|
16+
LL | fn fix<F: Fn(G), G: Fn()>(f: F) -> impl Fn() {
17+
| - this generic parameter must be used with a generic type parameter
18+
LL | move || f(fix(&f))
19+
| ^^^^^^^^^^
20+
2121
error: aborting due to 2 previous errors
2222

2323
For more information about this error, try `rustc --explain E0792`.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
warning: function cannot return without recursing
2-
--> $DIR/multiple-defining-usages-in-body.rs:4:1
3-
|
4-
LL | fn foo<T: Trait, U: Trait>() -> impl Trait {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
6-
LL |
7-
LL | let a: T = foo::<T, U>();
8-
| ------------- recursive call site
9-
|
10-
= help: a `loop` may express intention better if this is on purpose
11-
= note: `#[warn(unconditional_recursion)]` on by default
12-
131
error: concrete type differs from previous defining opaque type use
142
--> $DIR/multiple-defining-usages-in-body.rs:8:16
153
|
@@ -22,5 +10,17 @@ note: previous use here
2210
LL | let a: T = foo::<T, U>();
2311
| ^^^^^^^^^^^^^
2412

13+
warning: function cannot return without recursing
14+
--> $DIR/multiple-defining-usages-in-body.rs:4:1
15+
|
16+
LL | fn foo<T: Trait, U: Trait>() -> impl Trait {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
18+
LL |
19+
LL | let a: T = foo::<T, U>();
20+
| ------------- recursive call site
21+
|
22+
= help: a `loop` may express intention better if this is on purpose
23+
= note: `#[warn(unconditional_recursion)]` on by default
24+
2525
error: aborting due to 1 previous error; 1 warning emitted
2626

0 commit comments

Comments
 (0)