From db4ba498d9ffd584f9fd5483acd0c996c3379d8e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 16 Feb 2024 09:29:39 +0000 Subject: [PATCH] Fix an ICE in the recursion lint --- compiler/rustc_mir_build/src/lints.rs | 4 +- .../ui/traits/normalize-conflicting-impls.rs | 49 +++++++++++++++++++ .../traits/normalize-conflicting-impls.stderr | 21 ++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/ui/traits/normalize-conflicting-impls.rs create mode 100644 tests/ui/traits/normalize-conflicting-impls.stderr diff --git a/compiler/rustc_mir_build/src/lints.rs b/compiler/rustc_mir_build/src/lints.rs index 508936be29d..3f2b7c482a6 100644 --- a/compiler/rustc_mir_build/src/lints.rs +++ b/compiler/rustc_mir_build/src/lints.rs @@ -137,7 +137,9 @@ fn is_recursive_terminator( let func_ty = func.ty(body, tcx); if let ty::FnDef(callee, args) = *func_ty.kind() { - let normalized_args = tcx.normalize_erasing_regions(param_env, args); + let Ok(normalized_args) = tcx.try_normalize_erasing_regions(param_env, args) else { + return false; + }; let (callee, call_args) = if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, callee, normalized_args) { diff --git a/tests/ui/traits/normalize-conflicting-impls.rs b/tests/ui/traits/normalize-conflicting-impls.rs new file mode 100644 index 00000000000..454b2fd0153 --- /dev/null +++ b/tests/ui/traits/normalize-conflicting-impls.rs @@ -0,0 +1,49 @@ +fn problematic_function(material_surface_element: ()) +where + DefaultAllocator: FiniteElementAllocator<(), Space>, +{ + let _: Point2 = material_surface_element.map_reference_coords().into(); +} + +impl Allocator for DefaultAllocator +where + R::Value: DimName, //~ ERROR: `Value` not found for `R` +{ + type Buffer = (); +} +impl Allocator for DefaultAllocator {} +//~^ ERROR: conflicting implementations +impl DimName for () {} +impl DimName for u32 {} +impl From> for Point { + fn from(_: VectorN) -> Self { + todo!() + } +} + +impl FiniteElement for () {} + +type VectorN = Matrix<>::Buffer>; + +type Point2 = Point; + +struct DefaultAllocator; +struct Matrix(S); +struct Point(N, D); + +trait Allocator { + type Buffer; +} +trait DimName {} +trait FiniteElementAllocator: + Allocator + Allocator +{ +} + +trait FiniteElement { + fn map_reference_coords(&self) -> VectorN { + todo!() + } +} + +fn main() {} diff --git a/tests/ui/traits/normalize-conflicting-impls.stderr b/tests/ui/traits/normalize-conflicting-impls.stderr new file mode 100644 index 00000000000..9a66fe00c3f --- /dev/null +++ b/tests/ui/traits/normalize-conflicting-impls.stderr @@ -0,0 +1,21 @@ +error[E0220]: associated type `Value` not found for `R` + --> $DIR/normalize-conflicting-impls.rs:10:8 + | +LL | R::Value: DimName, + | ^^^^^ associated type `Value` not found + +error[E0119]: conflicting implementations of trait `Allocator<_, ()>` for type `DefaultAllocator` + --> $DIR/normalize-conflicting-impls.rs:14:1 + | +LL | / impl Allocator for DefaultAllocator +LL | | where +LL | | R::Value: DimName, + | |______________________- first implementation here +... +LL | impl Allocator for DefaultAllocator {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `DefaultAllocator` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0119, E0220. +For more information about an error, try `rustc --explain E0119`.