Skip to content

Commit 8f988bd

Browse files
committed
Coherence should allow fundamental types to impl traits
1 parent f466f52 commit 8f988bd

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/librustc/traits/coherence.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,21 @@ 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-
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()
381+
fn uncover_fundamental_ty<'a>(
382+
tcx: TyCtxt<'_>,
383+
ty: Ty<'a>,
384+
in_crate: InCrate,
385+
) -> Vec<Ty<'a>> {
386+
if fundamental_ty(ty) && !ty_is_local(tcx, ty, in_crate) {
387+
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate)).collect()
384388
} else {
385389
vec![ty]
386390
}
387391
}
388392

389-
for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
393+
for input_ty in
394+
trait_ref.input_types().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
395+
{
390396
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
391397
if ty_is_local(tcx, input_ty, in_crate) {
392398
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(fundamental)]
2+
#![feature(re_rebalance_coherence)]
3+
4+
// compile-flags:--crate-name=test
5+
// aux-build:coherence_lib.rs
6+
// check-pass
7+
8+
extern crate coherence_lib as lib;
9+
use lib::*;
10+
11+
#[fundamental]
12+
struct Local;
13+
14+
impl Remote for Local {}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(fundamental)]
2+
#![feature(re_rebalance_coherence)]
3+
4+
// compile-flags:--crate-name=test
5+
// aux-build:coherence_lib.rs
6+
// check-pass
7+
8+
extern crate coherence_lib as lib;
9+
use lib::*;
10+
11+
#[fundamental]
12+
struct MyBox<T>(T);
13+
14+
impl<T> Remote for MyBox<T> {}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)