about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGeorg Semmler <georg_semmler_05@web.de>2019-09-17 14:40:36 +0200
committerGeorg Semmler <georg_semmler_05@web.de>2019-09-17 14:40:36 +0200
commit3f004a1bc44859857f05a9f692a578124b3f3e01 (patch)
tree5acc439ceaeb6d16fc618bb3d980b92d7bac9b72 /src
parente69d1b67b6603e0635c553eff693a0606d282d75 (diff)
downloadrust-3f004a1bc44859857f05a9f692a578124b3f3e01.tar.gz
rust-3f004a1bc44859857f05a9f692a578124b3f3e01.zip
Fix re-rebalance coherence implementation for fundamental types
Fixes #64412
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/coherence.rs10
-rw-r--r--src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs5
-rw-r--r--src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr19
3 files changed, 30 insertions, 4 deletions
diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs
index b6f0addd771..bc6bcb1f76f 100644
--- a/src/librustc/traits/coherence.rs
+++ b/src/librustc/traits/coherence.rs
@@ -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);
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
index db671cb9bca..54425b6d708 100644
--- a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs
@@ -2,7 +2,6 @@
 
 // compile-flags:--crate-name=test
 // aux-build:coherence_lib.rs
-// check-pass
 
 extern crate coherence_lib as lib;
 use lib::*;
@@ -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() {}
diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr
new file mode 100644
index 00000000000..7859665a7bb
--- /dev/null
+++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr
@@ -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`.