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

regression: conflicting trait impls because Box<dyn Fn*> now implements Fn*. #59750

Closed
adrian17 opened this issue Apr 6, 2019 · 9 comments
Closed
Labels
A-closures Area: closures (`|args| { .. }`) P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@adrian17
Copy link

adrian17 commented Apr 6, 2019

Most likely related to #59500 ?

Simplified reproduction:

pub type FuncWrapper = Box<dyn Fn() + 'static>;

pub trait IntoFuncWrapper {
    fn into_func(self) -> FuncWrapper;
}

impl<F> IntoFuncWrapper for F where F: Fn() + 'static {
    fn into_func(self) -> FuncWrapper { Box::new(self) }
}

impl IntoFuncWrapper for FuncWrapper {
    fn into_func(self) -> FuncWrapper { self }
}

fn main() { }

Before: compiles on stable, beta, previous nightly
On latest nightly:

error[E0119]: conflicting implementations of trait `IntoFuncWrapper` for type `std::boxed::Box<(dyn std::ops::Fn() + 'static)>`:
  --> src/main.rs:11:1
   |
7  | impl<F> IntoFuncWrapper for F where F: Fn() + 'static {
   | ----------------------------------------------------- first implementation here
...
11 | impl IntoFuncWrapper for FuncWrapper {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<(dyn std::ops::Fn() + 'static)>`

error: aborting due to previous error

I do not know whether that was expected and should be fixed on my side, or is it an unintended breakage.

@jonas-schievink jonas-schievink added A-closures Area: closures (`|args| { .. }`) regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Apr 6, 2019
@Centril
Copy link
Contributor

Centril commented Apr 6, 2019

Minimized reproduction:

trait B {}

impl<C: FnOnce()> B for C {}

impl B for Box<dyn FnOnce()> {}

The issue here is that Box<dyn FnOnce()>: FnOnce() and so if you set C = Box<dyn FnOnce()> you have impl B for Box<dyn FnOnce()> {} twice => overlap.

@pnkfelix pnkfelix changed the title Latest nightly doesn't compile previously-legal code regression: conflicting trait impls because Box<dyn Fn*> now implements Fn*. Apr 11, 2019
@pnkfelix
Copy link
Member

Is this a T-libs issue or a T-compiler one?

Was this was expected fallout from another change?

Tagging as P-high for now, due its nature as a regression.

@pnkfelix pnkfelix added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. P-high High priority labels Apr 11, 2019
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Apr 11, 2019
@cramertj
Copy link
Member

This is an expected regression due to introducing a new implementation of a #[fundamental] trait (the Fn traits are all #[fundamental]). Adding an implementation of a #[fundamental] trait is a breaking change. However, the missing impls of Fn traits for Box are a long-standing issue that we've been wanting to resolve. The addition of these impls has significant practical and ecosystem impact, in that FnOnce is now object-safe.

If there are key ecosystem crates that relied upon these impls not existing, then we should hold off on the introduction of these impls and give them time to migrate. However, I believe that it is important that we achieve our long-standing goal of object-safe FnOnce and continue to prioritize landing these impls on stable.

cc @rust-lang/lang @rust-lang/libs to call attention to the introduction of new trait impls causing breakage.

@pnkfelix
Copy link
Member

so is the next step to attempt some sort of evaluation to figure out if there exist "key ecosystem crates" relying on the absence of these impls?

I assume our main method for doing this (beyond the crater runs that have already been done) is to just wait and see:

  • what other bugs get filed that look like this one, and
  • what comments are posted with indications of which particular crates were broken

right?

@Centril
Copy link
Contributor

Centril commented Apr 11, 2019

I assume our main method for doing this (beyond the crater runs that have already been done) is to just wait and see:

What you could do is to open a PR that is effectively a no-op and crater run that one. Otherwise we'll find out in the usual beta crater runs and stuff.

@pnkfelix
Copy link
Member

In any case I don't think there is anything actually actionable here on our side until we see evidence that this change broke "key ecosystem crates" in the wild.

With that in mind, I'm going to downgrade this to P-medium.

@pnkfelix
Copy link
Member

I assume our main method for doing this (beyond the crater runs that have already been done) is to just wait and see:

What you could do is to open a PR that is effectively a no-op and crater run that one. Otherwise we'll find out in the usual beta crater runs and stuff.

Ah true; I assumed there had already been crater runs, but I don't know why I thought that.

@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Apr 11, 2019
@pietroalbini pietroalbini added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels May 23, 2019
@jonas-schievink jonas-schievink added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels May 23, 2019
@jonas-schievink
Copy link
Contributor

This made its way to 1.35.0 now

@Centril
Copy link
Contributor

Centril commented May 23, 2019

Given that it went into stable and in the blog post, this is non-actionable and therefore I'm closing as wontfix.

@Centril Centril closed this as completed May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: closures (`|args| { .. }`) P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants