-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
nightly-2021-12-02 to nightly-2021-12-03 regression (PR #91354): auto-deref on Cow
does not seem to work anymore in all circumstances
#91489
Comments
Would be nice if we can have a minimal test case for this, so we can reintroduce @fee1-dead changes again being sure that this won't be an issue again. |
Yeah I tried but I don't see the difference between my (incomplete) testcase above and the real code that fails :) |
Reduced: (playground) use std::borrow::Borrow;
use std::borrow::Cow;
pub struct VariantType {}
pub struct VariantTy {}
impl Borrow<VariantTy> for VariantType {
fn borrow(&self) -> &VariantTy {
unimplemented!()
}
}
impl ToOwned for VariantTy {
type Owned = VariantType;
fn to_owned(&self) -> VariantType {
unimplemented!()
}
}
impl VariantTy {
pub fn as_str(&self) -> () {}
}
static _TYP: () = {
let _ = || {
Cow::Borrowed(&VariantTy {}).as_str();
};
}; The existence of fn foo(x: Cow<'_, VariantTy>) {
x.as_str();
} It will error iff |
@SNCPlay42 do you want to send a PR with that test case? cc me and I can merge it. Would need to sit on top of this #91491 but it will be on master soon. |
Revert "Auto merge of rust-lang#91354 - fee1-dead:const_env, r=spastorino" This reverts commit 18bb8c6, reversing changes made to d9baa36. Reverts rust-lang#91354 in order to address rust-lang#91489. We would need to place this changes in a more granular way and would also be nice to address the small perf regression that was also introduced. r? `@oli-obk` cc `@fee1-dead`
I would imagine this error is because of caching still. Because the only const impl in the standard library with a EDIT: doesn't seem to be at all related to caching, I think this is a general problem with closures in consts and how they interact with |
FYI the closure is only there to make this work on stable (and because the original crate had it), this version has the same problem: #![feature(const_deref)]
#![feature(const_trait_impl)]
use std::borrow::Borrow;
use std::borrow::Cow;
pub struct VariantType {}
pub struct VariantTy {}
impl Borrow<VariantTy> for VariantType {
fn borrow(&self) -> &VariantTy {
unimplemented!()
}
}
impl ToOwned for VariantTy {
type Owned = VariantType;
fn to_owned(&self) -> VariantType {
unimplemented!()
}
}
impl VariantTy {
pub const fn as_str(&self) -> () {}
}
static _TYP: () = {
Cow::Borrowed(&VariantTy {}).as_str();
}; |
That is expected to not work because the #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
where
B::Owned: ~const Borrow<B>, Your code is in a const context, and the trait bounds are actually unsatisfied. It actually works if you change |
It's odd that it compiles on yesterday's nightly then (per godbolt) - I guess On the current nightly it errors with the same |
umm, how do I explain this 😅 We have a cache for whether trait bounds satisfy for a given type for performance, but a bug causes the compiler to treat a closure's body inside const contexts as const specifically for solving whether trait bounds satisfy (rustc_trait_selection). I think adding a call before the usage in EDIT: except it does because |
Actually, the closure in const is a bug introduced by the PR that caused the regression. |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high |
@rustbot assign @fee1-dead |
Eliminate ConstnessAnd again Closes rust-lang#91489. Closes rust-lang#89432. Reverts rust-lang#91491. Reverts rust-lang#89450. r? `@spastorino`
(probably hit by rust-lang/rust#91489)
Eliminate ConstnessAnd again Closes rust-lang#91489. Closes rust-lang#89432. Reverts rust-lang#91491. Reverts rust-lang#89450. r? `@spastorino`
Code
See https://github.com/gtk-rs/gtk-rs-core/blob/master/glib-macros/tests/test.rs#L290
This fails with the latest nightly with (run
cargo test
inside theglib-macros
directory).Simplified code from
gtk-rs
/glib
which works without problems for some reason so I'm not entirely sure what causes it:Version it worked on
It most recently worked on: 2021-12-02
Version with regression
rustc --version --verbose
:(note that this is actually the one from today, 2021-12-03, but there's an off-by-one in the version information)
Running
cargo bisect-rustc
yields:Which would be this PR: #91354 (CC @fee1-dead).
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: