Skip to content

Commit b882acb

Browse files
Rollup merge of rust-lang#56862 - arielb1:fundamentally-clean, r=nikomatsakis
stop treating trait objects from #[fundamental] traits as fundamental This is a [breaking-change] to code that exploits this functionality (which should be limited to code using `#![feature(fundamental)]`. Fixes rust-lang#56503. r? @nikomatsakis
2 parents 00a388c + c4fa1d2 commit b882acb

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
@@ -397,7 +397,7 @@ fn uncovered_tys<'tcx>(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'tcx>, in_crate: InCrate)
397397
-> Vec<Ty<'tcx>> {
398398
if ty_is_local_constructor(ty, in_crate) {
399399
vec![]
400-
} else if fundamental_ty(tcx, ty) {
400+
} else if fundamental_ty(ty) {
401401
ty.walk_shallow()
402402
.flat_map(|t| uncovered_tys(tcx, t, in_crate))
403403
.collect()
@@ -415,14 +415,13 @@ fn is_possibly_remote_type(ty: Ty<'_>, _in_crate: InCrate) -> bool {
415415

416416
fn ty_is_local(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'_>, in_crate: InCrate) -> bool {
417417
ty_is_local_constructor(ty, in_crate) ||
418-
fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, in_crate))
418+
fundamental_ty(ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, in_crate))
419419
}
420420

421-
fn fundamental_ty(tcx: TyCtxt<'_, '_, '_>, ty: Ty<'_>) -> bool {
421+
fn fundamental_ty(ty: Ty<'_>) -> bool {
422422
match ty.sty {
423423
ty::Ref(..) => true,
424424
ty::Adt(def, _) => def.is_fundamental(),
425-
ty::Dynamic(ref data, ..) => tcx.has_attr(data.principal().def_id(), "fundamental"),
426425
_ => false
427426
}
428427
}
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)