-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
regression 1.51: lifetime may not live long enough with &impl Error
#81460
Comments
Regressed yesterday (!): searched nightlies: from nightly-2020-12-01 to nightly-2021-01-28 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-apple-darwin cargo bisect-rustc --regress=error --start=2020-12-01 --preserve I suspect #75180. cc @KodrAus @m-ou-se @rustbot label: -E-needs-bisection +T-libs |
&impl Error
From that PR:
Given that someone ran into this so quickly (the day after it was merged), should that decision be reconsidered? |
Assigning |
I find it startling that breaking existing code that isn't wrong could be considered acceptable. |
Nominating for T-libs discussion and removing T-compiler label (I don't think this issue has a compiler component). @rustbot label: +I-nominated -T-compiler |
If we never considered a change that could break not-wrong existing code acceptable, we would, for example, never be able to add a new method to a trait, or add an implementation of a trait to an existing type. |
related: eyre-rs/stable-eyre#4 |
We discussed this in the library team meeting again just now, and agreed that this breakage still seems acceptable. Closing this issue for now. If this turns out to cause any significant breakage in the ecosystem, feel free to re-open. |
It's unfortunate that we no longer get that auto-deref for free that lops off the fn walk_source_chain(error: &impl Error) {
for e in iter::successors(error.source(), |&e| e.source()) {
println!("{}", e);
}
} Or alternatively by accepting a fn walk_source_chain(error: &(dyn Error + 'static)) {
for e in error.chain() {
println!("{}", e);
}
} To make trait ChainExt: Error {
fn chain(&self) -> Chain
where
Self: Sized + 'static,
{
<dyn Error + 'static>::chain(self)
}
}
impl<E: Error> ChainExt for E {}
fn _assert_object_safe(_: &dyn ChainExt) {
}
fn walk_source_chain(error: &(impl Error + 'static)) {
for e in error.chain() {
println!("{}", e);
}
} which wouldn't clash with this: fn walk_source_chain(error: &(dyn Error + 'static)) {
for e in error.chain() {
println!("{}", e);
}
} but would with this: fn dyn_walk_source_chain<'a>(error: &'a &'a (dyn Error + 'static)) {
for e in error.chain() { // <-- would now fail to assert that `&'a (dyn Error + 'static)` is `'static`
println!("{}", e);
}
} That's basically the same cause as above. |
This compiles on stable and beta, but not nightly (1.51):
Error with nightly-2021-01-27:
Changing the closure parameter pattern to match
&e
fixes the borrow checker error in nightly.Originally posted by @mzabaluev in #80949 (comment)
The text was updated successfully, but these errors were encountered: