Repository navigation
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Description
Code
I tried this code:
#![allow(unused)]
#[derive(Clone)] // nothing substantial changes if this is replaced with a manual impl Clone for Test
struct Hello {
a: std::borrow::Cow<'static, [Self]>,
}
fn main(){}I expected to see this happen: On 1.78 and below, this fails to compile with several E0277s (trait bound not satisfied)
full error message
error[E0277]: the trait bound `[Hello]: ToOwned` is not satisfied in `Hello`
--> src/main.rs:4:32
|
4 | a: std::borrow::Cow<'static, [Self]>,
| ^^^^^^ within `Hello`, the trait `ToOwned` is not implemented for `[Hello]`, which is required by `Hello: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Hello`
--> src/main.rs:3:8
|
3 | struct Hello {
| ^^^^^
= note: slice and array elements must have `Sized` type
error[E0277]: the trait bound `[Hello]: ToOwned` is not satisfied in `Hello`
--> src/main.rs:2:10
|
2 | #[derive(Clone)]
| ^^^^^ within `Hello`, the trait `ToOwned` is not implemented for `[Hello]`, which is required by `Hello: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Hello`
--> src/main.rs:3:8
|
3 | struct Hello {
| ^^^^^
note: required by a bound in `Clone`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/clone.rs:147:1
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `[Hello]: ToOwned` is not satisfied in `Hello`
--> src/main.rs:2:10
|
2 | #[derive(Clone)]
| ^^^^^ within `Hello`, the trait `ToOwned` is not implemented for `[Hello]`, which is required by `Hello: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Hello`
--> src/main.rs:3:8
|
3 | struct Hello {
| ^^^^^
= note: the return type of a function must have a statically known size
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `[Hello]: ToOwned` is not satisfied in `Cow<'_, [Hello]>`
--> src/main.rs:4:3
|
2 | #[derive(Clone)]
| ----- in this derive macro expansion
3 | struct Hello {
4 | a: std::borrow::Cow<'static, [Self]>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `Cow<'_, [Hello]>`, the trait `ToOwned` is not implemented for `[Hello]`, which is required by `Cow<'_, [Hello]>: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Cow<'_, [Hello]>`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/borrow.rs:180:10
note: required by a bound in `clone`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/clone.rs:160:5
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `bisectee` (bin "bisectee") due to 4 previous errorsInstead, this happened: On Rust 1.79 and above, it compiles without error
Version it didn't work on
It most recently didn't work on: Rust 1.78.0
Version with anti-regression
rustc --version --verbose:
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
Bisection:
searched nightlies: from nightly-2024-03-16 to nightly-2024-04-28
regressed nightly: nightly-2024-03-20
searched commit range: 3c85e56...a7e4de1
regressed commit: 196ff44
bisected with cargo-bisect-rustc v0.6.9
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc --start=1.78.0 --end=1.79.0 --regress success --preserve cc @lukas-code The description of #122493 says "This should not make more or less code compile, but it can change error output in some rare cases."
Probably nothing to do but add a test to make sure this keeps compiling in the future?
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Activity
theemathas commentedon Aug 25, 2024
The code you show has
Selfbut the error has[Self]. Is this intentional?workingjubilee commentedon Aug 25, 2024
Fixed. The gression did indeed happen for
[Self]:https://rust.godbolt.org/z/4TY7a54Ps
Regression test for rust-lang#129541
compiler-errors commentedon Aug 25, 2024
So I expect this code to compile, especially given that
Cow<'_, [T]>isSized, so this struct is coinductivelySized. There's a slight "risk" w/ this code compiling wrt the way we handle coinduction the solver, but I'll leave that to @lcnr to judge.It would be interesting to know what specifically about #122493 caused this to compile, though I haven't looked at all about it.
WaffleLapkin commentedon Aug 25, 2024
I think this is more about
Clonerather thanSized-ness by itself. (forSizedthere is an example which compiled since forever,Cow<[T]>doesn't require coinduction to beSized-- it contains a&[T](trivially sized) and<[T] as ToOwned>::Owned(which has an implicit: Sizedbound)).What I think happened is that
#[derive(Clone)]expansion requiresCow<'static, [Self]>: Clonewhich requiresCow<'static, [Self]>: Sizedwhich, before #122493, requiredwf(Cow<'static, [Self]>)which requires[Self]: ToOwnedwhich requiresSelf: Clonewhich requiresCow<'static, [Self]>: Clonemaking a cycle.I think some details in my explanation are wrong (particularly the last step?), because I'm not familiar enough with type checking in rustc; but. I do think that "not requiring
wf(Enum)when evaluatingEnum: Sized" makes it so we don't evaluate bounds which lead to a cycle.lukas-code commentedon Aug 25, 2024
This was properly fixed in #122791, which also landed in 1.78.0.
That PR also allows this similar code to compile, which still fails after #122493:
This happens, because normalizing
<Hello as ToOwned>::Ownedin this example involves a cycle during candidate selection, which is no longer an error after #122791:The Code in the OP compiles with just #122493, because that PR changed
Cow<T>: Sizedto always hold and not require checking<T as ToOwned>::Owned: Sizedand therefore avoid the cycle.marmeladema commentedon Aug 25, 2024
I think this has solved #100347
apiraino commentedon Aug 26, 2024
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
39 remaining items
Unrolled build for rust-lang#129542
lcnr commentedon Sep 21, 2024
please also add the 3 tests from #129541 (comment)
Enselic commentedon Nov 25, 2024
@lcnr I think you link to the wrong comment? I think you mean "tests from issues referenced from #129541 (comment)" ?
lcnr commentedon Nov 25, 2024
no, to close this issue I would like to also want the following tests from my FCP proposal to get added as regression tests:
Enselic commentedon Nov 25, 2024
PR that adds those tests: #133467
I'm a bit confused though because one of them still fails. If I did something wrong it's hopefully easy for you to point out what I should change.
lcnr commentedon Nov 25, 2024
I want to merge the failing test to also catch when its behavior changes, even if it goes from pass to fail. I want to make sure we realize that we accidentally stabilized something before it hits stable 😁
Rollup merge of rust-lang#133467 - Enselic:recurse-tests, r=lcnr
Rollup merge of rust-lang#133467 - Enselic:recurse-tests, r=lcnr
Unrolled build for rust-lang#133467
Rollup merge of rust-lang#133488 - Enselic:recurse-2, r=BoxyUwU
Rollup merge of rust-lang#133488 - Enselic:recurse-2, r=BoxyUwU
Unrolled build for rust-lang#133488