Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trait objects of a fundamental trait are treated as fundamental types #56503

Closed
arielb1 opened this issue Dec 4, 2018 · 3 comments
Closed

trait objects of a fundamental trait are treated as fundamental types #56503

arielb1 opened this issue Dec 4, 2018 · 3 comments
Labels
A-trait-system Area: Trait system T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Dec 4, 2018

I don't think this is intentional, at least it is not documented in the RFCs 1023 or 2451:

STR

Crate a (compile with should_not_have_an_effect):

#![feature(fundamental)]

pub trait Abc {}

#[cfg_attr(should_not_have_an_effect, fundamental)]
pub trait Foo<T> {}

Crate b:

extern crate a;

pub struct Bar;
impl a::Abc for a::Foo<Bar> {}

Expected Result

The cfg_attr does not have an effect - the code gives this error:

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
 --> b.rs:4:1
  |
4 | impl a::Abc for a::Foo<Bar> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
  |
  = note: the impl does not reference any types defined in this crate
  = note: define and implement a trait or new type instead

error: aborting due to previous error

Actual result

With --cfg should_not_have_an_effect, the code compiles

Stability consequences

This can't be observed in stable code right now - the only stable #[fundamental] traits are Sized (which doesn't have type parameters) and the Fn traits (which can only be implemented for tuples, and these are never fundamental). However, if we did stabilize a "normal" #[fundamental] trait with type parameters, this would be visible on stable.

@arielb1 arielb1 added A-trait-system Area: Trait system I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 4, 2018
@arielb1
Copy link
Contributor Author

arielb1 commented Dec 4, 2018

This should either be fixed (#[fundamental] trait objects don't act as #[fundamental] types) or documented in the RFCs.

@nikomatsakis
Copy link
Contributor

Discussed in the @rust-lang/lang meeting. We decided that for now we should just make #[fundamental] trait objects not act as #[fundamental] types.

@arielb1 arielb1 added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Dec 14, 2018
@arielb1
Copy link
Contributor Author

arielb1 commented Dec 14, 2018

No warning period needed because this is a nightly feature? I think I'll E-mentor this or not, this looks too simple.

@arielb1 arielb1 removed the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Dec 14, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Dec 20, 2018
…matsakis

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
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Dec 21, 2018
…matsakis

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
Centril added a commit to Centril/rust that referenced this issue Dec 22, 2018
…matsakis

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
bors added a commit that referenced this issue Dec 22, 2018
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 #56503.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants