Skip to content

Commit f82875e

Browse files
authoredFeb 16, 2024
Rollup merge of rust-lang#121181 - oli-obk:normalize_with_conflicting_impls, r=cjgillot
Fix an ICE in the recursion lint fixes rust-lang#121170 I looked into it, and there is no good path towards tainting mir_build (where the ICE happens), but using `try_normalize` in a lint seems generally better anyway
2 parents 0c92146 + db4ba49 commit f82875e

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed
 

‎compiler/rustc_mir_build/src/lints.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ impl<'tcx> TerminatorClassifier<'tcx> for CallRecursion<'tcx> {
137137

138138
let func_ty = func.ty(body, tcx);
139139
if let ty::FnDef(callee, args) = *func_ty.kind() {
140-
let normalized_args = tcx.normalize_erasing_regions(param_env, args);
140+
let Ok(normalized_args) = tcx.try_normalize_erasing_regions(param_env, args) else {
141+
return false;
142+
};
141143
let (callee, call_args) = if let Ok(Some(instance)) =
142144
Instance::resolve(tcx, param_env, callee, normalized_args)
143145
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
fn problematic_function<Space>(material_surface_element: ())
2+
where
3+
DefaultAllocator: FiniteElementAllocator<(), Space>,
4+
{
5+
let _: Point2<f64> = material_surface_element.map_reference_coords().into();
6+
}
7+
8+
impl<N, R> Allocator<N, R> for DefaultAllocator
9+
where
10+
R::Value: DimName, //~ ERROR: `Value` not found for `R`
11+
{
12+
type Buffer = ();
13+
}
14+
impl<N> Allocator<N, ()> for DefaultAllocator {}
15+
//~^ ERROR: conflicting implementations
16+
impl DimName for () {}
17+
impl DimName for u32 {}
18+
impl<N, D: DimName> From<VectorN<N, D>> for Point<N, D> {
19+
fn from(_: VectorN<N, D>) -> Self {
20+
todo!()
21+
}
22+
}
23+
24+
impl FiniteElement<u32> for () {}
25+
26+
type VectorN<N, D> = Matrix<<DefaultAllocator as Allocator<N, D>>::Buffer>;
27+
28+
type Point2<N> = Point<N, u32>;
29+
30+
struct DefaultAllocator;
31+
struct Matrix<S>(S);
32+
struct Point<N, D>(N, D);
33+
34+
trait Allocator<Scalar, R> {
35+
type Buffer;
36+
}
37+
trait DimName {}
38+
trait FiniteElementAllocator<GeometryDim, NodalDim>:
39+
Allocator<f64, ()> + Allocator<f64, NodalDim>
40+
{
41+
}
42+
43+
trait FiniteElement<GeometryDim> {
44+
fn map_reference_coords(&self) -> VectorN<f64, GeometryDim> {
45+
todo!()
46+
}
47+
}
48+
49+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0220]: associated type `Value` not found for `R`
2+
--> $DIR/normalize-conflicting-impls.rs:10:8
3+
|
4+
LL | R::Value: DimName,
5+
| ^^^^^ associated type `Value` not found
6+
7+
error[E0119]: conflicting implementations of trait `Allocator<_, ()>` for type `DefaultAllocator`
8+
--> $DIR/normalize-conflicting-impls.rs:14:1
9+
|
10+
LL | / impl<N, R> Allocator<N, R> for DefaultAllocator
11+
LL | | where
12+
LL | | R::Value: DimName,
13+
| |______________________- first implementation here
14+
...
15+
LL | impl<N> Allocator<N, ()> for DefaultAllocator {}
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `DefaultAllocator`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0119, E0220.
21+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)