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

!Sized return type error panics with 'no errors encountered even though delay_span_bug issued' #80207

Closed
QuineDot opened this issue Dec 19, 2020 · 7 comments
Labels
A-DSTs Area: Dynamically-sized types (DSTs) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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.

Comments

@QuineDot
Copy link

Code

use std::ops::BitOr;

pub trait IntWrapper {
    type InternalStorage;
}

impl<T> BitOr for dyn IntWrapper<InternalStorage = T>
where
    Self: Sized,
    T: BitOr + BitOr<Output = T>,
{
    type Output = Self;
    fn bitor(self, _other: Self) -> Self {
        todo!()
    }
}

Meta

Via the playground on all of stable, beta, and nightly.

note: rustc 1.48.0 (7eac88a 2020-11-16) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib
note: some of the compiler flags provided by cargo are hidden

Error output

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: `!Sized` return type
  --> src/lib.rs:13:37
   |
13 |     fn bitor(self, _other: Self) -> Self {
   |                                     ^^^^
   |
   = note: delayed at compiler/rustc_typeck/src/check/check.rs:154:18

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:961:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

Credit

Discovered by rectang as reported on the user forum.

@QuineDot QuineDot added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 19, 2020
@rectang
Copy link

rectang commented Dec 19, 2020

A further reduction clarifies that the bug has nothing to do with std::ops::BitOr.

pub trait Foo {
    fn do_stuff() -> Self;
}

pub trait Bar {
    type Output;
}

impl<T> Foo for dyn Bar<Output = T>
where
    Self: Sized,
{
    fn do_stuff() -> Self {
        todo!()
    }
}

@SNCPlay42
Copy link
Contributor

This code compiled successfully in 1.44 and earlier. The delay_span_bug it's hitting was added in #70998 (here).

@rustbot label regression-from-stable-to-stable A-dst

@rustbot rustbot added A-DSTs Area: Dynamically-sized types (DSTs) regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 20, 2020
@camelid
Copy link
Member

camelid commented Dec 20, 2020

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@camelid camelid added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 21, 2020
@osa1
Copy link
Contributor

osa1 commented Jan 27, 2021

The delay_span_bug in this ICE is this one:

// FIXME: We need to verify that the return type is `Sized` after the return expression has
// been evaluated so that we have types available for all the nodes being returned, but that
// requires the coerced evaluated type to be stored. Moving `check_return_expr` before this
// causes unsized errors caused by the `declared_ret_ty` to point at the return expression,
// while keeping the current ordering we will ignore the tail expression's type because we
// don't know it yet. We can't do `check_expr_kind` while keeping `check_return_expr`
// because we will trigger "unreachable expression" lints unconditionally.
// Because of all of this, we perform a crude check to know whether the simplest `!Sized`
// case that a newcomer might make, returning a bare trait, and in that case we populate
// the tail expression's type so that the suggestion will be correct, but ignore all other
// possible cases.
fcx.check_expr(&body.value);
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
tcx.sess.delay_span_bug(decl.output.span(), "`!Sized` return type");

It was added in e536257.

I think the problem with this program is that we have Self: Sized but the self is actually dyn <trait> which is not Sized, right? So we don't expect to compile it, we should just reject it with a good error message?

Pinging @estebank as he is the author of the commit above.

@estebank
Copy link
Contributor

It would be nice if we could come up with more repro cases that don't involve Self. It'd be easy to fix only this one case but I'm struggling to see what other cases could trigger this.

@estebank
Copy link
Contributor

As mentioned in the pr fixing this, the delay_span_bug was incorrect. It should have never been added.

m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 3, 2021
Remove incorrect `delay_span_bug`

The following code is supposed to compile

```rust
use std::ops::BitOr;

pub trait IntWrapper {
    type InternalStorage;
}

impl<T> BitOr for dyn IntWrapper<InternalStorage = T>
where
    Self: Sized,
    T: BitOr + BitOr<Output = T>,
{
    type Output = Self;
    fn bitor(self, _other: Self) -> Self {
        todo!()
    }
}
```

Before this change it would ICE. In rust-lang#70998 the removed logic was added
to provide better suggestions, and the `delay_span_bug` guard was added
to  protect against a potential logic error when returning traits. As it
happens, there are cases, like the one above, where traits can indeed be
returned, so valid code was being rejected.

Fix (but not close) rust-lang#80207.
@bors bors closed this as completed in ede0a71 Feb 3, 2021
@estebank
Copy link
Contributor

estebank commented Feb 3, 2021

Reopening for the backport.

@estebank estebank reopened this Feb 3, 2021
ehuss pushed a commit to ehuss/rust that referenced this issue Feb 5, 2021
Remove incorrect `delay_span_bug`

The following code is supposed to compile

```rust
use std::ops::BitOr;

pub trait IntWrapper {
    type InternalStorage;
}

impl<T> BitOr for dyn IntWrapper<InternalStorage = T>
where
    Self: Sized,
    T: BitOr + BitOr<Output = T>,
{
    type Output = Self;
    fn bitor(self, _other: Self) -> Self {
        todo!()
    }
}
```

Before this change it would ICE. In rust-lang#70998 the removed logic was added
to provide better suggestions, and the `delay_span_bug` guard was added
to  protect against a potential logic error when returning traits. As it
happens, there are cases, like the one above, where traits can indeed be
returned, so valid code was being rejected.

Fix (but not close) rust-lang#80207.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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.
Projects
None yet
Development

No branches or pull requests

8 participants