Skip to content

Commit c4fa1d2

Browse files
committed
stop treating trait objects from #[fundamental] traits as fundamental
Fixes rust-lang#56503.
1 parent 0a1b226 commit c4fa1d2

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/librustc/traits/coherence.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'tcx>, in_crate: InCrate)
393393
-> Vec<Ty<'tcx>> {
394394
if ty_is_local_constructor(ty, in_crate) {
395395
vec![]
396-
} else if fundamental_ty(tcx, ty) {
396+
} else if fundamental_ty(ty) {
397397
ty.walk_shallow()
398398
.flat_map(|t| uncovered_tys(tcx, t, in_crate))
399399
.collect()
@@ -411,14 +411,13 @@ fn is_possibly_remote_type(ty: Ty<'_>, _in_crate: InCrate) -> bool {
411411

412412
fn ty_is_local(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'_>, in_crate: InCrate) -> bool {
413413
ty_is_local_constructor(ty, in_crate) ||
414-
fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, in_crate))
414+
fundamental_ty(ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, in_crate))
415415
}
416416

417-
fn fundamental_ty(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'_>) -> bool {
417+
fn fundamental_ty(ty: Ty<'_>) -> bool {
418418
match ty.sty {
419419
ty::Ref(..) => true,
420420
ty::Adt(def, _) => def.is_fundamental(),
421-
ty::Dynamic(ref data, ..) => tcx.has_attr(data.principal().def_id(), "fundamental"),
422421
_ => false
423422
}
424423
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_type = "rlib"]
2+
#![feature(fundamental)]
3+
4+
pub trait Misc {}
5+
6+
#[fundamental]
7+
pub trait Fundamental<T> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Check that trait objects from #[fundamental] traits are not
2+
// treated as #[fundamental] types - the 2 meanings of #[fundamental]
3+
// are distinct.
4+
5+
// aux-build:coherence_fundamental_trait_lib.rs
6+
7+
extern crate coherence_fundamental_trait_lib;
8+
9+
use coherence_fundamental_trait_lib::{Fundamental, Misc};
10+
11+
pub struct Local;
12+
impl Misc for dyn Fundamental<Local> {}
13+
//~^ ERROR E0117
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2+
--> $DIR/coherence-fundamental-trait-objects.rs:12:1
3+
|
4+
LL | impl Misc for dyn Fundamental<Local> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6+
|
7+
= note: the impl does not reference any types defined in this crate
8+
= note: define and implement a trait or new type instead
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0117`.

0 commit comments

Comments
 (0)