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

Recursive type with Cow, 'static and slice triggers "overflow evaluating the requirement" #47032

Closed
m-ou-se opened this issue Dec 27, 2017 · 8 comments
Labels
C-bug Category: This is a bug. P-medium Medium 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

@m-ou-se
Copy link
Member

m-ou-se commented Dec 27, 2017

The following compiles with rustc 1.7.0 and earlier, but not in 1.8.0 and later:

use std::borrow::Cow;

#[derive(Clone)]
pub struct Node {
	// ...
	pub children_a: &'static [Node], // Works
	pub children_b: Vec<Node>, // Works
	pub children_c: Cow<'static, [Node]> // Doesn't compile
}

The errors:

error[E0275]: overflow evaluating the requirement `<[Node] as std::borrow::ToOwned>::Owned`
 --> src/lib.rs:6:2
  |
6 |     pub children_a: &'static [Node],
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: required because it appears within the type `Node`
  = note: required because of the requirements on the impl of `std::borrow::ToOwned` for `[Node]`
  = note: required because it appears within the type `Node`
  = note: slice and array elements must have `Sized` type

Since it compiles fine with the first two members (reference to slice, and Vec), I'd expect a Cow of a slice to also work. Is this a regression, or is this supposed to not compile?

@sgrif
Copy link
Contributor

sgrif commented Jan 3, 2018

This is related to #34260

@pietroalbini pietroalbini added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. C-bug Category: This is a bug. labels Jan 30, 2018
@nikomatsakis
Copy link
Contributor

triage: P-medium

@sgrif and I are working on this a bit =)

@jesskfullwood
Copy link

Is there a workaround for this? It has me completely stumped

@bkchr
Copy link
Contributor

bkchr commented Feb 28, 2019

@nikomatsakis any update on this?

@Licenser
Copy link

Same, ran into this too and unsure how to resolve this. It seems it's a regression from 2016?

@kyleedwardsny
Copy link

I believe I found a workaround until this is fixed. The trick is to put the Cow inside a dummy struct:

#[derive(Clone)]
pub struct DummyHolder<T> {
    pub data: T,
}

#[derive(Clone)]
pub struct Node {
    pub children: DummyHolder<Cow<'static, [Node]>>,
}

@kyleedwardsny
Copy link

I just made an interesting discovery. The following does not compile:

#[derive(Clone)]
pub struct DummyHolder<T: ?Sized> { // <-- Triggers the error
    pub data: T,
}

#[derive(Clone)]
pub struct Node {
    pub children: DummyHolder<Cow<'static, [Node]>>,
}

So it seems that enforcing a Sized constraint somewhere in the loop makes this example compile (Cow allows the borrowed type to be ?Sized.)

@Enselic
Copy link
Member

Enselic commented Nov 26, 2024

Triage: This began to compile in 1.79 and was retroactively stabilized via FCP. See #129541 for details.

Regression test added via https://github.com/rust-lang/rust/pull/133473/files which I bet is equivalent to the code in this issue.

Closing as duplicate of #100347 although it should probably be the other way around since this issue is much older.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-medium Medium 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