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

Confusing error when using CoercePointee #134846

Open
RalfJung opened this issue Dec 28, 2024 · 2 comments · May be fixed by #136796
Open

Confusing error when using CoercePointee #134846

RalfJung opened this issue Dec 28, 2024 · 2 comments · May be fixed by #136796
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

Code

#![feature(derive_coerce_pointee)]
use std::marker::CoercePointee;
use std::rc::Rc;

#[repr(transparent)]
#[derive(CoercePointee)]
struct RcWithId<T: ?Sized> {
    inner: Rc<(i32, Box<T>)>,
}

Current output

error[E0277]: the trait bound `Box<T>: Unsize<Box<__S>>` is not satisfied
 --> src/main.rs:6:10
  |
6 | #[derive(CoercePointee)]
  |          ^^^^^^^^^^^^^ the trait `Unsize<Box<__S>>` is not implemented for `Box<T>`
  |
  = note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
  = note: required for `Rc<(i32, Box<T>)>` to implement `DispatchFromDyn<Rc<(i32, Box<__S>)>>`
  = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Box<T>: Unsize<Box<__S>>` is not satisfied
 --> src/main.rs:6:10
  |
6 | #[derive(CoercePointee)]
  |          ^^^^^^^^^^^^^ the trait `Unsize<Box<__S>>` is not implemented for `Box<T>`
  |
  = note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
  = note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)

Desired output

Something that does not mention internal things like `Unsize` or `__S`

Rationale and extra context

No response

Other cases

Rust Version

current nightly

Anything else?

No response

@RalfJung RalfJung added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation labels Dec 28, 2024
@Darksonn
Copy link
Contributor

I just learned of this issue.

Thoughts @dingxiangfei2009? Could we utilize the traits from #136107 to emit better errors?

@dingxiangfei2009
Copy link
Contributor

@Darksonn honestly I was pondering about this problem yesterday but I wasn't aware of this ticket that was filed.

The check can definitely be performed with the new trait. The next step I will need to look into, is to devise a method to suppress the errors when checks with CoercePointee have failed.

Or I suspect the better way could be, when the coherence check for DispatchFromDyn and CoerceUnsize is initiated, the check would attempt to determine if a CoercePointee is indeed to be derived on the target and present the error with the correct wording intended for CoercePointee accordingly. I will start with this approach first.

@dingxiangfei2009 dingxiangfei2009 linked a pull request Feb 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants