-
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
Tracking issue for future-incompatibility lint elided_lifetimes_in_associated_constant
#115010
Comments
I'm old enough to remember when clippy used to nag me to change |
Is it possible to loosen the implicit lifetime to |
@tgross35: that's behavior that @rust-lang/lang needs to stabilize separately. I'll nominate this issue to see if opinions have changed since #38831, but this lint is specifically aimed at making sure people are not relying on behavior that was never formally stabilized. Question for T-lang: What should we do here?
|
On the latest lifetime we're getting the following warning in the server macro: warning: `&` without an explicit lifetime name cannot be used here --> src/login.rs:19:1 | 19 | #[server(Login, "/api")] | ^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: this warning originates in the attribute macro `server` (in Nightly builds, run with -Z macro-backtrace for more info)
The clippy warn-by-default lint |
@repi: The rust/src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs Lines 104 to 108 in b2515fa
Can you share code where you encountered a conflict between this future-compat warning and the clippy lint? |
dug a bit deeper and I was wrong, this clippy lint indeed doesn't trigger on associated consts. sorry. was able to resolve all of our lint warnings on this without |
Lang team consensus is that we should go with (A.) above:
Since this was inadvertently stabilized and a separate RFC would need to be authored if it's desired to make elision work in associated consts. See notes here: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Triage.20meeting.202023-08-29/near/388257641 |
Heads up: This lint as currently written accepts code that is not accepted in Rust 1.72 (nor 1.63). From 1.64 to current stable, anonymous lifetimes were allowed, but they weren't specifically Under the change which accompanied this lint, elided lifetimes are no longer independent, they are specifically Example (Rust 1.63 fails; Rust 1.72 fails; nightly succeeds): struct S;
impl S {
const C: &&str = &"";
} Perhaps this will be considered fine since the lint is supposedly going to be The change also means that contravariant cases that worked from 1.64-1.72 fail on nightly: struct Contra<'a>(PhantomData<fn(&'a str)>);
struct S;
impl S {
const C: Contra<'_> = Contra(PhantomData);
}
fn f<'a>() {
let _: Contra<'a> = S::C;
} But probably that's not ecosystem-breaking like the covariant case is. More examples that probably add nothingThe last three examples in this section (before " This example fails on 1.63 due to the use core::marker::PhantomData;
trait Single<'a>: 'a + Send + Sync {}
struct L<'l, 'm>(&'l str, &'m str);
impl<'a, 'b> L<'a, 'b> {
const ECS: PhantomData<Box<dyn Single<'_>>> = PhantomData;
const SCS: PhantomData<Box<dyn Single<'static>>> = PhantomData;
const S_ECS: PhantomData<Box<dyn Single<'static> + 'static>> = Self::ECS;
const S_SCS: PhantomData<Box<dyn Single<'static> + 'static>> = Self::SCS;
} This example fails on 1.63 due to the use core::marker::PhantomData;
trait Double<'a, 'b>: 'a + 'b + Send + Sync {}
struct L<'l, 'm>(&'l str, &'m str);
impl<'a, 'b> L<'a, 'b> {
const EBCD: PhantomData<Box<dyn Double<'a, '_>>> = PhantomData;
} This example fails on 1.63 due to the use of use core::marker::PhantomData;
trait Single<'a>: 'a + Send + Sync {}
struct R<'l, 'm, 'r>(&'l str, &'m str, &'r ());
impl<'a, 'b, 'r> R<'a, 'b, 'r> where 'a: 'r, 'b: 'r {
const ECS: PhantomData<&dyn Single<'_>> = PhantomData;
const RECS: PhantomData<&'r dyn Single<'_>> = PhantomData;
} |
…rough, r=cjgillot Fall through when resolving elided assoc const lifetimes `@QuineDot` makes a good point in rust-lang#115010 (comment) that we probably should not accept *more* code due to rust-lang#115011 even though that code will eventually become a forbid-warning in a few versions (rust-lang#115010 (comment)). Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
…rough, r=cjgillot Fall through when resolving elided assoc const lifetimes ``@QuineDot`` makes a good point in rust-lang#115010 (comment) that we probably should not accept *more* code due to rust-lang#115011 even though that code will eventually become a forbid-warning in a few versions (rust-lang#115010 (comment)). Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
…ugh, r=cjgillot Fall through when resolving elided assoc const lifetimes `@QuineDot` makes a good point in rust-lang#115010 (comment) that we probably should not accept *more* code due to rust-lang#115011 even though that code will eventually become a forbid-warning in a few versions (rust-lang#115010 (comment)). Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
# Objective Fix some nightly warnings found by running `cargo +nightly clippy` ## Solution Fix the following warnings: - [x] [elided_lifetimes_in_associated_constant](rust-lang/rust#115010) 2219861 - [x] [unwrap_or_default](https://rust-lang.github.io/rust-clippy/master/index.html#/unwrap_or_default) 32e21c7 - [x] [needless_pass_by_ref_mut](https://rust-lang.github.io/rust-clippy/master/index.html#/needless_pass_by_ref_mut) c85d6d4 There is no breaking change, some internal `bevy_ecs` code no longer uses a few mutable references but I don't think it should cause any regression or be performance sensitive, but there might be some ECS magic I'm unaware of that could break because of those changes
…gillot Fall through when resolving elided assoc const lifetimes `@QuineDot` makes a good point in rust-lang/rust#115010 (comment) that we probably should not accept *more* code due to #115011 even though that code will eventually become a forbid-warning in a few versions (rust-lang/rust#115010 (comment)). Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
This is a new warning in an upcoming version of Rust: ``` warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! note: for more information, see issue #115010 <rust-lang/rust#115010> ```
Apologies if I miss something obvious here, I've only been using Rust for a few years and haven't touched its internals, but why can this... struct Foo;
impl Foo {
const STR: &str = "hello, world";
} ... not be desugared into this? struct Foo;
impl Foo {
const STR: &'static str = "hello, world";
} Is this some limitation of the compiler, or is this a backwards-incompatible change? If it's backwards-incompatible, isn't it better to change this behavior in a Rust edition? I find it strange that const fields can have non- |
@holly-hacker the problem is that this is loosening bounds from the current behavior, which needs to go through the review process since it is part of a bigger picture. The notes where this was discussed are here: https://hackmd.io/4br69DHGRy2EIm-JY5dTgw#%E2%80%9CTracking-Issue-for-ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT-future-compat-lint%E2%80%9D-rust115010, I think that the RFC linked there illustrate some of the potential issues. It seems like generally everyone is in agreement that the current behavior is not expected, it's just not yet clear how to make expected and actual behavior align. It might be possible to special-case something for the common cases - but those discussions and decisions will take time (I just opened some discussion on Zulip about this)
Lints can be added outside of edition boundaries since they can always be disabled (editions are usually things that aren't configurable) |
This was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! See https://github.com/ rust-lang/rust/issues/115010.
This CL adds an explicit 'static lifetime to the a few constant to unblock the toolchain roll. For more information on this lint, see rust-lang/rust#115010. Test: fx build host_x64/gen/src/developer/ffx/config/lib.clippy Bug: 132466 Change-Id: I0c894b28b9ebfd50257d4811d0993186cba9a23d Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/906953 Reviewed-by: Marie Janssen <jamuraa@google.com> Fuchsia-Auto-Submit: Mitchell Kember <mkember@google.com> Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com> Reviewed-by: Tyler Mandry <tmandry@google.com> Reviewed-by: David Koloski <dkoloski@google.com>
``` warning: `&` without an explicit lifetime name cannot be used here --> src/fdo/dbus.rs:29:21 | 29 | pub const PATH: &str = "/org/freedesktop/DBus"; | ^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default help: use the `'static` lifetime | 29 | pub const PATH: &'static str = "/org/freedesktop/DBus"; | +++++++ ```
Fixes "warning: `&` without an explicit lifetime name cannot be used here". This warning will become a hard error in "the future". For more information, see issue #115010 <rust-lang/rust#115010> Closes: #162 Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit suppresses the following warning reported by rustc version 1.75. warning: `&` without an explicit lifetime name cannot be used here ... = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default help: use the `'static` lifetime Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit suppresses the following warning reported by rustc version 1.75. warning: `&` without an explicit lifetime name cannot be used here ... = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default help: use the `'static` lifetime Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit suppresses the following warning reported by rustc version 1.75. warning: `&` without an explicit lifetime name cannot be used here ... = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default help: use the `'static` lifetime Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit suppresses the following warning reported by rustc version 1.75. warning: `&` without an explicit lifetime name cannot be used here ... = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #115010 <rust-lang/rust#115010> = note: `#[warn(elided_lifetimes_in_associated_constant)]` on by default help: use the `'static` lifetime Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This PR removes unneeded `'static` lifetimes on `&str`s stored in `const` declarations. This addresses some Clippy lints about [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#/redundant_static_lifetimes). In item-level `const` declarations we can rely on lifetime elision and use the default `'static` lifetime. Note that associated constants still require an explicit `'static` lifetime, as explained in rust-lang/rust#115010. Release Notes: - N/A
This produces as warning that will become a hard-error in the future. See also: rust-lang/rust#115010 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT
future-compat lintelided_lifetimes_in_associated_constant
This is a tracking issue for the
elided_lifetimes_in_associated_constant
future-incompatibility lint.The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our breaking change policy guidelines.
What
The
elided_lifetimes_in_associated_constant
lint detects elided lifetimes that became erroneously allowed in associated constants after #97313.They current desugar to fresh early-bound lifetimes on the parent impl, like:
This is in contrast to the way that elided lifetimes are treated in item-level consts (where elided lifetimes are resolved to
'static
), and this behavior was also never formally decided -- static-in-const lifetime rules do not apply to associated consts (rust-lang/rfcs#1623 (comment), #38831 (comment)).Why
It was never decided what to do with elided lifetimes in consts, and it is not clear that the current behavior is optimal here. This is to stop the leaking by making sure existing elided lifetimes are fixed back to using
'static
as they were required to before version 1.64, and that new usages of elided lifetimes in consts are not introduced.How to fix
Replace the elided lifetimes with
'static
(or manually introduce or reference another lifetime):Tracking
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT
) #115011elided_lifetimes_in_associated_constant
to deny #124211The text was updated successfully, but these errors were encountered: