From 59df6010d5a27b5394af679a75cdb169ae82ce23 Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Mon, 5 Oct 2026 05:27:31 +0000 Subject: [PATCH] Add a test for suboptimal diagnostics --- ...lowing-opaque-incorrectly-unconstrained.rs | 22 +++++++++++++++++++ ...ng-opaque-incorrectly-unconstrained.stderr | 18 +++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.rs create mode 100644 tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.stderr diff --git a/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.rs b/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.rs new file mode 100644 index 00000000000..0c12528f22f --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.rs @@ -0,0 +1,22 @@ +//@ compile-flags: -Znext-solver + +// FIXME: The diagnostics here are suboptimal. +// See . + +#![feature(type_alias_impl_trait)] +//~^^^^^^ ERROR: overflow evaluating the requirement `X == _` + +// TAIT with self-referencing bounds +type X = impl std::ops::Add; + +struct Foo; + +impl Foo { + #[define_opaque(X)] + pub fn new() -> X { + //~^ ERROR: item does not constrain `X::{opaque#0}` + 0i32 + } +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.stderr b/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.stderr new file mode 100644 index 00000000000..9445f07778d --- /dev/null +++ b/tests/ui/traits/next-solver/diagnostics/overflowing-opaque-incorrectly-unconstrained.stderr @@ -0,0 +1,18 @@ +error: item does not constrain `X::{opaque#0}` + --> $DIR/overflowing-opaque-incorrectly-unconstrained.rs:16:12 + | +LL | pub fn new() -> X { + | ^^^ + | + = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]` +note: this opaque type is supposed to be constrained + --> $DIR/overflowing-opaque-incorrectly-unconstrained.rs:10:10 + | +LL | type X = impl std::ops::Add; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0275]: overflow evaluating the requirement `X == _` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`.