Skip to content

Commit 3f004a1

Browse files
committed
Fix re-rebalance coherence implementation for fundamental types
Fixes #64412
1 parent e69d1b6 commit 3f004a1

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/librustc/traits/coherence.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
378378
// Let Ti be the first such type.
379379
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
380380
//
381-
for input_ty in trait_ref.input_types() {
381+
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
382+
if fundamental_ty(ty) {
383+
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
384+
} else {
385+
vec![ty]
386+
}
387+
}
388+
389+
for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
382390
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
383391
if ty_is_local(tcx, input_ty, in_crate) {
384392
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);

src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

76
extern crate coherence_lib as lib;
87
use lib::*;
@@ -11,11 +10,11 @@ use std::rc::Rc;
1110
struct Local;
1211

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

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

2120
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:12:1
3+
|
4+
LL | impl<T> Remote1<Local> for Box<T> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:16:1
11+
|
12+
LL | impl<T> Remote1<Local> for &T {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.

0 commit comments

Comments
 (0)