Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
lcnr opened this issue Jun 12, 2024 · 1 comment · Fixed by #131857
Closed

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

lcnr opened this issue Jun 12, 2024 · 1 comment · Fixed by #131857
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
@bors bors closed this as completed in 13b3984 Oct 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 18, 2024
Rollup merge of rust-lang#131857 - WaffleLapkin:dyn-drop-principal-3, r=compiler-errors

Allow dropping dyn principal

Revival of rust-lang#126660, which was a revival of rust-lang#114679. Fixes rust-lang#126313.

Allows dropping principal when coercing trait objects, e.g. `dyn Debug + Send` -> `dyn Send`.

cc `@compiler-errors` `@Jules-Bertholet`
r? `@lcnr`
# for free to join this conversation on GitHub. Already have an account? # 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
4 participants