Skip to content

Commit

Permalink
Fix re-rebalance coherence implementation for fundamental types
Browse files Browse the repository at this point in the history
Fixes #64412
  • Loading branch information
weiznich committed Sep 17, 2019
1 parent e69d1b6 commit 3f004a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
// Let Ti be the first such type.
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
//
for input_ty in trait_ref.input_types() {
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
if fundamental_ty(ty) {
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
} else {
vec![ty]
}
}

for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
if ty_is_local(tcx, input_ty, in_crate) {
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
Expand All @@ -11,11 +10,11 @@ use std::rc::Rc;
struct Local;

impl<T> Remote1<Local> for Box<T> {
// FIXME(#64412) -- this is expected to error
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<T> Remote1<Local> for &T {
// FIXME(#64412) -- this is expected to error
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:12:1
|
LL | impl<T> Remote1<Local> for Box<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:16:1
|
LL | impl<T> Remote1<Local> for &T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.

0 comments on commit 3f004a1

Please sign in to comment.