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

This commit is contained in:
Michael Goulet 2025-01-11 19:22:02 +00:00
parent fb65a3ee57
commit 85c9ce6d79
22 changed files with 177 additions and 185 deletions

View file

@ -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());

View file

@ -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,

View file

@ -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())
}
}

View file

@ -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};
@ -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();
}
}
@ -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();
}
}
@ -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 {
@ -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 {
@ -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();
}
}

View file

@ -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");

View file

@ -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;
@ -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()
@ -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,

View file

@ -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};
@ -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();
}
}
}

View file

@ -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};
@ -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 {

View file

@ -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
}

View file

@ -16,14 +16,6 @@ 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
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`
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
|
@ -39,7 +31,31 @@ help: you might have meant to write a bound here
LL | ) -> impl Iterator<Item: SubAssign> {
| ~
error: aborting due to 3 previous errors
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> {
| +++
help: you might have meant to write a bound here
|
LL | ) -> impl Iterator<Item: SubAssign> {
| ~
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`.

View file

@ -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`.

View file

@ -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!()
}

View file

@ -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
|
@ -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`.

View file

@ -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
|
@ -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`.

View file

@ -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
|
@ -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

View file

@ -1,12 +1,3 @@
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/early_bound.rs:7:17
|
LL | fn test<'a: 'a>(n: bool) -> impl Sized + 'a {
| -- this generic parameter must be used with a generic lifetime parameter
...
LL | let _ = identity::<&'a ()>(test(false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: concrete type differs from previous defining opaque type use
--> $DIR/early_bound.rs:3:29
|
@ -19,6 +10,15 @@ note: previous use here
LL | let _ = identity::<&'a ()>(test(false));
| ^^^^^^^^^^^
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/early_bound.rs:7:17
|
LL | fn test<'a: 'a>(n: bool) -> impl Sized + 'a {
| -- this generic parameter must be used with a generic lifetime parameter
...
LL | let _ = identity::<&'a ()>(test(false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0792`.

View file

@ -6,14 +6,6 @@ LL | fn foo<T>() -> impl Sized {
LL | let _: () = foo::<u8>();
| ^^
error[E0792]: expected generic type parameter, found `u8`
--> $DIR/non-defining-use.rs:8:12
|
LL | fn bar<T>(val: T) -> impl Sized {
| - this generic parameter must be used with a generic type parameter
LL | let _: u8 = bar(0u8);
| ^^
error: concrete type differs from previous defining opaque type use
--> $DIR/non-defining-use.rs:8:17
|
@ -26,6 +18,14 @@ note: previous use here
LL | fn bar<T>(val: T) -> impl Sized {
| ^^^^^^^^^^
error[E0792]: expected generic type parameter, found `u8`
--> $DIR/non-defining-use.rs:8:12
|
LL | fn bar<T>(val: T) -> impl Sized {
| - this generic parameter must be used with a generic type parameter
LL | let _: u8 = bar(0u8);
| ^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0792`.

View file

@ -1,42 +1,3 @@
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | trait A: Sized {
| - in this trait
LL | fn f(a: A) -> A;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:10:13
|
LL | trait B {
| - in this trait
LL | fn f(b: B) -> B;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(b: Self) -> Self;
| ~~~~ ~~~~
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:16:20
|
LL | trait C {
| - in this trait
LL | fn f(&self, c: C) -> C;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(&self, c: Self) -> Self;
| ~~~~ ~~~~
error[E0782]: expected a type, found a trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
@ -118,6 +79,45 @@ help: `C` is dyn-incompatible, use `impl C` to return an opaque type, as long as
LL | fn f(&self, c: C) -> impl C;
| ++++
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13
|
LL | trait A: Sized {
| - in this trait
LL | fn f(a: A) -> A;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(a: Self) -> Self;
| ~~~~ ~~~~
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:10:13
|
LL | trait B {
| - in this trait
LL | fn f(b: B) -> B;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(b: Self) -> Self;
| ~~~~ ~~~~
error: associated item referring to unboxed trait object for its own trait
--> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:16:20
|
LL | trait C {
| - in this trait
LL | fn f(&self, c: C) -> C;
| ^ ^
|
help: you might have meant to use `Self` to refer to the implementing type
|
LL | fn f(&self, c: Self) -> Self;
| ~~~~ ~~~~
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0782`.

View file

@ -1,4 +1,6 @@
#[derive(Clone)] //~ expected a type, found a trait
#[derive(Clone)]
//~^ expected a type, found a trait
//~| expected a type, found a trait
struct Foo;
trait Foo {} //~ the name `Foo` is defined multiple times
fn main() {}

View file

@ -1,5 +1,5 @@
error[E0428]: the name `Foo` is defined multiple times
--> $DIR/issue-106072.rs:3:1
--> $DIR/issue-106072.rs:5:1
|
LL | struct Foo;
| ----------- previous definition of the type `Foo` here
@ -16,7 +16,16 @@ LL | #[derive(Clone)]
|
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
error[E0782]: expected a type, found a trait
--> $DIR/issue-106072.rs:1:10
|
LL | #[derive(Clone)]
| ^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0428, E0782.
For more information about an error, try `rustc --explain E0428`.

View file

@ -1,15 +1,3 @@
error[E0277]: the trait bound `i64: Foo<i64>` is not satisfied
--> $DIR/missing-for-type-in-impl.rs:19:19
|
LL | let x: i64 = <i64 as Foo<i64>>::id(10);
| ^^^ the trait `Foo<i64>` is not implemented for `i64`
|
help: this trait has no implementations, consider adding one
--> $DIR/missing-for-type-in-impl.rs:3:1
|
LL | trait Foo<T> {
| ^^^^^^^^^^^^
error[E0782]: expected a type, found a trait
--> $DIR/missing-for-type-in-impl.rs:8:6
|
@ -25,6 +13,18 @@ help: you might have intended to implement this trait for a given type
LL | impl Foo<i64> for /* Type */ {
| ++++++++++++++
error[E0277]: the trait bound `i64: Foo<i64>` is not satisfied
--> $DIR/missing-for-type-in-impl.rs:19:19
|
LL | let x: i64 = <i64 as Foo<i64>>::id(10);
| ^^^ the trait `Foo<i64>` is not implemented for `i64`
|
help: this trait has no implementations, consider adding one
--> $DIR/missing-for-type-in-impl.rs:3:1
|
LL | trait Foo<T> {
| ^^^^^^^^^^^^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0782.

View file

@ -1,3 +1,15 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/hkl_forbidden4.rs:12:1
|
LL | async fn operation(_: &mut ()) -> () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body of operation()}`
|
note: previous use here
--> $DIR/hkl_forbidden4.rs:14:5
|
LL | call(operation).await
| ^^^^^^^^^^^^^^^
error: item does not constrain `FutNothing::{opaque#0}`, but has it in its signature
--> $DIR/hkl_forbidden4.rs:18:10
|
@ -35,18 +47,6 @@ LL |
LL | call(operation).await
| ^^^^^^^^^^^^^^^
error: concrete type differs from previous defining opaque type use
--> $DIR/hkl_forbidden4.rs:12:1
|
LL | async fn operation(_: &mut ()) -> () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body of operation()}`
|
note: previous use here
--> $DIR/hkl_forbidden4.rs:14:5
|
LL | call(operation).await
| ^^^^^^^^^^^^^^^
error[E0792]: expected generic lifetime parameter, found `'any`
--> $DIR/hkl_forbidden4.rs:22:1
|