Skip to content

Receiver when Self = () should have a Scalar ABI, found ScalarPair ... #56806

@sunchao

Description

@sunchao

I was trying this code:

use std::any::Any;

pub trait Foo {
  fn to_any(self: Box<Foo>) -> Box<Any>;
}

pub fn main() {
  println!("GOOD");
}

I know, this doesn't make much sense, but I was expecting a proper error message. Instead, I got:

error[E0307]: invalid `self` type: std::boxed::Box<(dyn Foo + 'static)>
 --> src/bin/test.rs:4:19
  |
4 |   fn to_any(self: Box<Foo>) -> Box<Any>;
  |                   ^^^^^^^^
  |
  = note: type must be `Self` or a type that dereferences to it
  = help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`

error: internal compiler error: src/librustc/traits/object_safety.rs:353: Receiver when Self = () should have a Scalar ABI, found ScalarPair(Scalar { value: Pointer, valid_range: 1..=18446744073709551615 }, Scalar { value: Pointer, valid_range: 1..=18446744073709551615 })

thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:600:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0307`.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.32.0-nightly (f4a421ee3 2018-12-13) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions