-
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
False positives for the new non_local_definitions
lint
#121746
Comments
See #121621 But TLDR, not a false positive. |
Except that the non local |
Ok, let me clarify this issue again. I believe the emitted message is at least highly misleading for the following reasons:
It talks about
This part of the error message is factually wrong. The problem here is not that the derive comes from an older edition or that it needs to be updated. In fact it already uses the "suggested" anonymous constant pattern. The issue here (if it exists at all) is that the derive is used in a "local" scope. So that's a usage issue, instead of an issue with that derive. By wording this error message that way you essentially blame the developers of the derive crate instead of helping users to point out the actual issue with their code. At very least the lint should detect that and skip these lines if the anonymous constant pattern is there in the generated code. As a more general note: As this is testing code for proc macro related functionality: How would the corresponding rust team expect that code to be written in a future edition of rust? I believe that this pattern is quite common for crates that offer derives (or similar macros), as it allows to easily define these items in scope of the actual test. The lint proposes to move that to a more global scope, which will make it much harder to write these tests as you now need to consider naming collisions and you move code away from the actual test. |
As noted this has nothing to do with coherence. I tried making that clear by adding the definition of "non-local impl" in the diagnostic output.
Except that it affects code outside that "limited scope", that's the issue!
This note was requested by T-lang and comes from the Crater run were we discovered that more than around 90% of the warnings could be fixed by just updating the dependency. Regarding "This part of the error message is factually wrong.", I would like to mention that the note is saying "may" and "try", in the hope that macro author already fixed the problematic code.
I don't understand this part. This lint doesn't test "proc macro related functionality", it checks |
As written above: It would likely be clearer of you would just not use the terms
Expect that's not relevant for code in a
Well in that case the compiler can (and does) know that this cannot help as the code in question:
Therefore there is no need to generate that hint all. The only effect that this hint will have is that users go to the issue tracker of the affected derive crate and fill issues there that their code needs to be updated, which puts more work on the maintainers of that crate. (Rant: Given that this is an edition related change, I shouldn't be surprised by that, given how all last two editions broke diesel. It seems to be easier for the rust project to just let the ecosystem deal with these kind of breaking change.)
This lint warns against a commonly used testing pattern for crates that rely on proc macros. So essentially breaks that workflow. So please advice how that workflow can be fixed. |
The issue can still be triggered in pub trait Trait: Sized {
fn method(self) {}
}
#[test]
fn one_test() {
struct Thing;
impl Trait for &Thing {}
}
#[test]
fn second_test() {
Trait::method(&{ todo!() });
// this is a bit silly, but you could imagine `Thing: Default`,
// or some other way to actually construct `Thing`
} For the rest, I will let T-lang respond. |
Maybe I miss something but it feels wrong to disallow this particular pattern just because it can be reused in some edge case. The lint currently targets all places where some impl is provided that could potentially be used in that way. It would be much better to instead link those places where these impls are actually misused, as that would greatly reduce the impact of that lint. Or can you explain what's wrong with this pattern as long as you don't use the impl outside of the scope of that function? (Or even what's wrong with it when using it outside of the current function, I mean there are more than enough other ways to define voldemort types, so why disallow this only particular one?) |
From the RFC PR:
|
I'm well aware of that RFC. I raised my criticisms there before the RFC was accepted. I do net remember getting a response to my criticism back then, nor does it feel like any of that was incorporated into the design. Anyway as you are trying to push this forward without replying to consents let me word my question differently: Given the code linked in the issue, what would be the official endorsed way to write this specific test such that it fulfilled the proposed goals of the linked RFC. |
That would obviously work, but it will explicitly contraindicate the stated goal of the RFC as it requires moving away the relevant code from the test case. That in turn will require exactly that cross referencing that the RFC calls out as bad. Also to write that down explicitly: That's no critic at your implementation of the lint, it's more about the underlying semantic change that doesn't seem to be fully understand in terms of impact to the ecosystem. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
Implement T-types suggested logic for perfect non-local impl detection This implement [T-types suggested logic](rust-lang/rust#121621 (comment)) for perfect non-local impl detection: > for each impl, instantiate all local types with inference vars and then assemble candidates for that goal, if there are more than 1 (non-private impls), it does not leak This extension to the current logic is meant to address issues reported in rust-lang/rust#121621. This PR also re-enables the lint `non_local_definitions` to warn-by-default. Implementation was discussed in this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/Implementing.20new.20non-local.20impl.20defs.20logic). Fixes rust-lang/rust#121621 Fixes rust-lang/rust#121746 r? `@lcnr` *(feel free to re-roll)*
@apiraino It was discussed at the same time as #121621: #121621 (comment) (I think we just forgot to remove the nomination here) |
Code
I tried this code: https://github.com/diesel-rs/diesel/blob/33ddddcd44d64368c4e8edb630e3f281e4a1a77d/diesel/src/sqlite/connection/mod.rs#L931
This is reproducible with
cargo +nightly check -p diesel -F sqlite --all-targets
I expected to see this happen: No warning or at least no warning that tells me that this is an issue with the derive itself. (It's just that the derive is used in a function for scoping reasons).
Instead, this happened: I see the following warning:
Version it worked on
It most recently worked on: 1.77.0-beta.5
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-beta-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: