Skip to content
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

Rework non_local_definitions lint to only use a syntactic heuristic #127117

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Jun 29, 2024

This PR reworks the non_local_definitions lint to only use a syntactic heuristic, i.e. not use a type-system logic for whenever an impl is local or not.

Instead the new logic wanted by T-lang in #126768 (comment), which is to consider every paths in Self and Trait and to no longer use the type-system inference trick.

@rustbot labels +L-non_local_definitions
Fixes #126768

@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. L-non_local_definitions Lint: non_local_definitions labels Jun 29, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 30, 2024

r? @WaffleLapkin since you reviewed the original PR

@rustbot rustbot assigned WaffleLapkin and unassigned BoxyUwU Jun 30, 2024
Copy link
Contributor

@traviscross traviscross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked over the tests; looks right to me.

tests/ui/lint/non-local-defs/generics.rs Show resolved Hide resolved
Copy link
Contributor

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just typo nits

compiler/rustc_lint/src/non_local_def.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/non_local_def.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jul 9, 2024

☔ The latest upstream changes (presumably #127493) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to review this. T-lang's proposal looks to me like "let's make the lint incorrect". And I don't see why the lint is useful, if it's incorrect...

@workingjubilee
Copy link
Contributor

r? lang

@rustbot rustbot added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jul 11, 2024
@rustbot rustbot assigned scottmcm and unassigned WaffleLapkin Jul 11, 2024
@workingjubilee
Copy link
Contributor

workingjubilee commented Jul 11, 2024

cc @rust-lang/lang also posted a followup comment in #126768 (comment)

@traviscross
Copy link
Contributor

traviscross commented Jul 11, 2024

Replied with further context and background over in #126768 (comment).

r? @workingjubilee

@rustbot rustbot assigned workingjubilee and unassigned scottmcm Jul 11, 2024
@workingjubilee
Copy link
Contributor

💭 ...if I asked for lang to review this, and then TC nominated me, does that mean I'm on lang? Is this my punishment for ribbing T-lang one too many times? Am I now the target of my own japes? ...oh no, I'm barely even awake at 9, how am I going to make a meeting at 8?

@traviscross
Copy link
Contributor

Maybe all of that? /s.... but no, seriously that was me just handing back off after answering the lang questions. Looking again, though, I mean to hand it back to compiler, so...

r? compiler

@michaelwoerister
Copy link
Member

r? diagnostics

@rustbot rustbot assigned oli-obk and unassigned michaelwoerister Jul 16, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jul 19, 2024

I've tried to review this every day of the past 3 days and each time finished with a bit more knowledge but mostly feeling unhappy with my understanding of it and the exact things we want to lint. I don't think I can reasonably review this without just removing it entirely, and writing it from scratch and hoping I come up with a close enough final result.

That said, the diff makes sense and looks like it does what T-lang wants, I'm just not confident in the full behaviour of this lint now, the cases it's missing and the cases it's not missing.

I'm not sure my feelings should be blocking it, but I also don't want to pass on the hot potato for long enough until someone feels like it's not important to understand it fully.

@Urgau
Copy link
Member Author

Urgau commented Jul 19, 2024

and the exact things we want to lint

My understanding is that the lint should fire for what TC calls "sneaky inner impl".

What I understand from this is that the lint should warn on impl defs where syntactically none of "part" (idk the right word) of the Self and Trait types refer to something at the same nesting as the impl def it-self.

In particular it should not take into account the perfect type-system definition since T-lang doesn't "feel" like impls that would lint because of the 1-impl rule are "sneaky".

I think one could say that an impl def is sneaky if is hidden (that is nested inside other items) and that none of the syntactic part1 of the Self and Trait types refer to something at the same nesting as the impl definition it-self.

I think it's also clear from unanimous decision from T-lang that they were not looking at a perfect non local impl defs detection, which the above rule is nowhere near.

@traviscross could you confirm or deny what I just said.

Footnotes

  1. in the compiler those are {ast,hir}::Path, idk if we have a word or acronym at the syntax level

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 19, 2024

I can review this if you want, I only reassigned because I figured waffle might want to review this since it was on the original PR 🤷‍♀️

@workingjubilee
Copy link
Contributor

Let's go!

r? @BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned oli-obk Jul 19, 2024
@traviscross
Copy link
Contributor

traviscross commented Jul 20, 2024

@Urgau: That sounds right to me, but I'd probably point more normatively to my earlier comments if there were any questions here. And I think @BoxyUwU has a handle on this in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-non_local_definitions Lint: non_local_definitions S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

non_local_definitions lint fires for impl Trait for NonLocalType<SomeLocalType>, probably shouldn't
10 participants