Skip to content

Commit 2c3a7d6

Browse files
committed
transmutability: only short-circuit is_transmutable for non-region infers
1 parent 2972b5e commit 2c3a7d6

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ where
663663
return Err(NoSolution);
664664
}
665665

666+
if goal.predicate.has_non_region_infer() {
667+
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
668+
}
669+
666670
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
667671
let assume = ecx.structurally_normalize_const(
668672
goal.param_env,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(transmutability)]
2+
trait OpaqueTrait {}
3+
4+
impl<T: std::mem::TransmuteFrom<(), ()>> OpaqueTrait for T {}
5+
//~^ ERROR: type provided when a constant was expected
6+
7+
impl<T> OpaqueTrait for &T where T: OpaqueTrait {}
8+
//~^ ERROR: conflicting implementations of trait `OpaqueTrait` for type `&_`
9+
10+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0747]: type provided when a constant was expected
2+
--> $DIR/transmutability-coherence.rs:4:37
3+
|
4+
LL | impl<T: std::mem::TransmuteFrom<(), ()>> OpaqueTrait for T {}
5+
| ^^
6+
7+
error[E0119]: conflicting implementations of trait `OpaqueTrait` for type `&_`
8+
--> $DIR/transmutability-coherence.rs:7:1
9+
|
10+
LL | impl<T: std::mem::TransmuteFrom<(), ()>> OpaqueTrait for T {}
11+
| ---------------------------------------------------------- first implementation here
12+
...
13+
LL | impl<T> OpaqueTrait for &T where T: OpaqueTrait {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0119, E0747.
19+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)