Skip to content

Commit e485b19

Browse files
Don't drop Upcast candidate in intercrate mode
1 parent 6f3df08 commit e485b19

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+6
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
921921
param_env: ty::ParamEnv<'tcx>,
922922
cause: &ObligationCause<'tcx>,
923923
) -> Option<ty::PolyExistentialTraitRef<'tcx>> {
924+
// Don't drop any candidates in intercrate mode, as it's incomplete.
925+
// (Not that it matters, since `Unsize` is not a stable trait.)
926+
if self.infcx.intercrate {
927+
return None;
928+
}
929+
924930
let tcx = self.tcx();
925931
if tcx.features().trait_upcasting {
926932
return None;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(unsize)]
2+
3+
use std::marker::Unsize;
4+
use std::ops::Deref;
5+
6+
trait Foo: Bar {}
7+
trait Bar {}
8+
9+
impl<T> Bar for T where dyn Foo: Unsize<dyn Bar> {}
10+
impl Bar for () {}
11+
//~^ ERROR conflicting implementations of trait `Bar` for type `()`
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0119]: conflicting implementations of trait `Bar` for type `()`
2+
--> $DIR/dont-drop-upcast-candidate.rs:10:1
3+
|
4+
LL | impl<T> Bar for T where dyn Foo: Unsize<dyn Bar> {}
5+
| ------------------------------------------------ first implementation here
6+
LL | impl Bar for () {}
7+
| ^^^^^^^^^^^^^^^ conflicting implementation for `()`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)