From eb72e6764e30003fab1d46ecc22e4938b060aaed Mon Sep 17 00:00:00 2001 From: reddevilmidzy Date: Mon, 24 Nov 2025 16:06:15 +0900 Subject: [PATCH] Fix None handling for simplify_type in for_each_relevant_impl --- compiler/rustc_middle/src/ty/context.rs | 8 ++++---- .../traits/dispatch-from-dyn-blanket-impl.rs | 10 ++++++++++ .../dispatch-from-dyn-blanket-impl.stderr | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tests/ui/traits/dispatch-from-dyn-blanket-impl.rs create mode 100644 tests/ui/traits/dispatch-from-dyn-blanket-impl.stderr diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 876297d3e407..3092c6e76c03 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -589,13 +589,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | ty::Never | ty::Tuple(_) | ty::UnsafeBinder(_) => { - let simp = ty::fast_reject::simplify_type( + if let Some(simp) = ty::fast_reject::simplify_type( tcx, self_ty, ty::fast_reject::TreatParams::AsRigid, - ) - .unwrap(); - consider_impls_for_simplified_type(simp); + ) { + consider_impls_for_simplified_type(simp); + } } // HACK: For integer and float variables we have to manually look at all impls diff --git a/tests/ui/traits/dispatch-from-dyn-blanket-impl.rs b/tests/ui/traits/dispatch-from-dyn-blanket-impl.rs new file mode 100644 index 000000000000..4e0e7ca9793f --- /dev/null +++ b/tests/ui/traits/dispatch-from-dyn-blanket-impl.rs @@ -0,0 +1,10 @@ +// Test that blanket impl of DispatchFromDyn is rejected. +// regression test for issue + +#![feature(dispatch_from_dyn)] + +impl std::ops::DispatchFromDyn for T {} +//~^ ERROR type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +//~| ERROR the trait `DispatchFromDyn` may only be implemented for a coercion between structures + +fn main() {} diff --git a/tests/ui/traits/dispatch-from-dyn-blanket-impl.stderr b/tests/ui/traits/dispatch-from-dyn-blanket-impl.stderr new file mode 100644 index 000000000000..69f360817805 --- /dev/null +++ b/tests/ui/traits/dispatch-from-dyn-blanket-impl.stderr @@ -0,0 +1,19 @@ +error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/dispatch-from-dyn-blanket-impl.rs:6:6 + | +LL | impl std::ops::DispatchFromDyn for T {} + | ^ type parameter `T` must be used as the type parameter for some local type + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local + = note: only traits defined in the current crate can be implemented for a type parameter + +error[E0377]: the trait `DispatchFromDyn` may only be implemented for a coercion between structures + --> $DIR/dispatch-from-dyn-blanket-impl.rs:6:1 + | +LL | impl std::ops::DispatchFromDyn for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0210, E0377. +For more information about an error, try `rustc --explain E0210`.