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 Trait: Send: upcasting from dyn Trait to dyn Send does not work #126313

Open
lcnr opened this issue Jun 12, 2024 · 1 comment · May be fixed by #126660
Open

trait Trait: Send: upcasting from dyn Trait to dyn Send does not work #126313

lcnr opened this issue Jun 12, 2024 · 1 comment · May be fixed by #126660
Labels
C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Jun 12, 2024

The following compiles:

#![feature(trait_upcasting)]
trait Super {}
trait Trait: Super {}
fn foo(x: &dyn Trait) -> &dyn Super { x }

while this does not:

#![feature(trait_upcasting)]
trait Super {}
trait Trait: Send {}
fn foo(x: &dyn Trait) -> &dyn Send { x }

cc @compiler-errors I thought we actually had a PR for that at some point 🤔 I think that's actually not the case though. It wasn't part of #119338

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 12, 2024
@lcnr lcnr changed the title cannot upcast from dyn TraitWithSendSuper to dyn Send trait Trait: Send: upcasting from dyn Trait to dyn Send does not work Jun 12, 2024
@lcnr lcnr added F-trait_upcasting `#![feature(trait_upcasting)]` T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jun 12, 2024
@compiler-errors
Copy link
Member

I had a separate PR to upcast dropping the principal but I think I never FCPd it because I was too lazy: #114679 (comment)

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jun 12, 2024
fix RELEASES: we do not support upcasting to auto traits

rust-lang#119338 does not actually support casts from `dyn Trait` to `dyn Auto`, only from `dyn Trait` to `dyn Trait   Auto`. The following test does not compile

```rust
trait Trait: Send {}
impl<T: Send> Trait for T {}

fn foo() {
    let x: &i32 = &1;
    let y = x as &dyn Trait as &dyn Send;
}
```
it actually also doesn't compile with `feature(trait_upcasting)`, opened rust-lang#126313 for that

r? `@Mark-Simulacrum` `@cuviper`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 12, 2024
Rollup merge of rust-lang#126314 - lcnr:fix-relnotes, r=pietroalbini

fix RELEASES: we do not support upcasting to auto traits

rust-lang#119338 does not actually support casts from `dyn Trait` to `dyn Auto`, only from `dyn Trait` to `dyn Trait   Auto`. The following test does not compile

```rust
trait Trait: Send {}
impl<T: Send> Trait for T {}

fn foo() {
    let x: &i32 = &1;
    let y = x as &dyn Trait as &dyn Send;
}
```
it actually also doesn't compile with `feature(trait_upcasting)`, opened rust-lang#126313 for that

r? `@Mark-Simulacrum` `@cuviper`
@saethlin saethlin added C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 13, 2024
@Jules-Bertholet Jules-Bertholet linked a pull request Jun 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants