Rust: Inference regression in nightly affecting `Pin::set` and futures

Created on 26 Nov 2018  路  6Comments  路  Source: rust-lang/rust

futures-util-preview does not build on the current nightly because the compiler is unable to infer that a type is Sized. This is a regression in the latest nightly.

The line that errors is here.

Error message:

error[E0277]: the size for values of type `<&mut future::maybe_done::MaybeDone<Fut> as std::ops::Deref>::Target` cannot be known at compilation time
   --> futures-util/src/future/maybe_done.rs:110:9
    |
110 |         Pin::set(self, MaybeDone::Done(res));
    |         ^^^^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `std::marker::Sized` is not implemented for `<&mut future::maybe_done::MaybeDone<Fut> as std::ops::Deref>::Target`

Relevant commits: https://github.com/rust-lang/rust/compare/edaac35d6...6acbb5b65

cc rust-lang-nursery/futures-rs#1350

P-high T-compiler regression-from-stable-to-beta

Most helpful comment

Minimized example without Pin and external dependencies:

use std::ops::{Deref, DerefMut};

fn foo<P>(_value: <P as Deref>::Target)
where
    P: DerefMut,
    <P as Deref>::Target: Sized,
{}

fn main() {
    foo::<&mut u32>(2);
}

Playground.

All 6 comments

Minimized example without Pin and external dependencies:

use std::ops::{Deref, DerefMut};

fn foo<P>(_value: <P as Deref>::Target)
where
    P: DerefMut,
    <P as Deref>::Target: Sized,
{}

fn main() {
    foo::<&mut u32>(2);
}

Playground.

Possibly caused by https://github.com/rust-lang/rust/pull/56045

cc @qnighy

Enabling the unsized_locals feature fixes this, so this is being caused by the gate here.

Perhaps do I need some normalization before doing deferred Sizedness checking?

triage. This is now a stable-to-beta regression. P-high.

assigning to @nikomatsakis to either r+ PR #56282, come up with a new fix, or delegate those options to someone else.

Was this page helpful?
0 / 5 - 0 ratings