-
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
Warning about non-local impl-definition in derive-macro output #131643
Comments
cc @Urgau as you know about EDIT: I'm dumb and was looking at different issue pages. |
Hmm, I wonder if this is a duplicate of #131474 ? The problem is still present in the latest nightly, but maybe the fix for the above issue is not yet in nightly? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Yeah, I think this whole bug report is a duplicate. Unless the fix from #131498 for some reason doesn't work in this particular case? How can I determine if I have the fix or not? |
Let me double check the commits |
I'm using |
I'll double-check the logic in the lint, I think this might not be the exact same thing yeah |
I tried rebuilding rustc from source, using latest 'master' (commit ef4e825), and the problem exists on this version as well. |
My basic understanding is that unlike #131474 struct Test;
const _: () = {
const _: () = {
impl Default for Test {
fn default() -> Test {
Test
}
}
};
}; the example in this issue const _: () = {
const _: () = {
impl Callable for Dummy {}
};
pub trait Callable {}
struct Dummy;
}; is different: the #131474 example produces a non-local definition inside nested anon consts for a outermost-level type rust/compiler/rustc_lint/src/non_local_def.rs Lines 141 to 170 in ecf2d1f
|
Remark: this would be fixed by #131660 once that is beta-backported. |
…ouxu Also use outermost const-anon for impl items in `non_local_defs` lint This PR update the logic for the impl paths (items) in the `non_local_definitions` lint to also consider const-anon in case the impl definition is wrapped inside const-anon it-self wrapped into a const-anon where the items are. r? `@jieyouxu` *(since you interacted on the issue)* Fixes *(after beta-backport)* rust-lang#131643
Rollup merge of rust-lang#131660 - Urgau:non_local_def-131643, r=jieyouxu Also use outermost const-anon for impl items in `non_local_defs` lint This PR update the logic for the impl paths (items) in the `non_local_definitions` lint to also consider const-anon in case the impl definition is wrapped inside const-anon it-self wrapped into a const-anon where the items are. r? `@jieyouxu` *(since you interacted on the issue)* Fixes *(after beta-backport)* rust-lang#131643
Also adding that yes, the original issue I mentioned in #131474 is still triggering because part of it is inside a proc macro. I thought it was because the nightly hadn't yet included the change but I checked and confirmed this myself. |
# Objective Another clippy-lint fix: the goal is so that `ci lints` actually displays the problems that a contributor caused, and not a bunch of existing stuff in the repo. (when run on nightly) ## Solution This fixes all but the `clippy::needless_lifetimes` lint, which will result in substantially more fixes and be in other PR(s). I also explicitly allow `non_local_definitions` since it is [not working correctly, but will be fixed](rust-lang/rust#131643). A few things were manually fixed: for example, some places had an explicitly defined `div_ceil` function that was used, which is no longer needed since this function is stable on unsigned integers. Also, empty lines in doc comments were handled individually. ## Testing I ran `cargo clippy --workspace --all-targets --all-features --fix --allow-staged` with the `clippy::needless_lifetimes` lint marked as `allow` in `Cargo.toml` to avoid fixing that too. It now passes with all but the listed lint.
To clarify, do you mean the fix for #131474 wasn't sufficient? Could you check if that's still a problem once #131660 is available in nightly, and if so open a new issue (or reopen if it's the same code pattern)? |
Yup, that's the plan: I just wanted to clarify that yes, the issue isn't fully resolved yet. |
### What Pin the version of nightly in builds and CI, and make a few minor changes. ### Why The version is pinned because there's a bug in the next version of nightly that we can't work around. The bug is: - rust-lang/rust#131643 The other minor changes that are to prepare for updating to the next nightly and were required by it when using it. ### Known limitations N/A
#131660 was beta backported, this issue is no longer reproducible, closing as fixed if there are more issue(s), please open a new issue |
After updating to
The macro is generated by: |
The original problem also persists in 'savefile'. However, I've added Here is a new minimal reproducer: mod some_module {
const _: () = {
const _: () = {
impl Callable for Dummy {}
};
pub trait Callable {}
struct Dummy;
};
} It's reproducible in nightly on the playground: |
Code
I tried this code:
I expected to see this happen: The code should compile without errors or warnings.
Instead, this happened: There is a warning: "warning: non-local
impl
definition,impl
blocks should be written at the same level as their item".This might seem very convoluted. It is a minimization of code generated by the savefile-derive crate when it is generating implementations of AbiExportable for traits returning boxed Fn-trait objects. It generates helper-types for these, and then effectively recurses, generating impls for these helpers types. That's why we get two levels of the
const _: () = {...}
-trick. This trick is used by crates like savefile and serde, but I suppose serde doesn't end up recursing and is probably not affected by this issue.Version it worked on
It works in stable rust 1.81, and also in
rustc 1.83.0-nightly (52fd99839 2024-10-10)
.Version with regression
It does not work in
rustc 1.83.0-nightly (1bc403daa 2024-10-11)
.@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: