Skip to content

Use a dummy TypeckResults instead of Option<TypeckResults> when linting - #158000

Open
Jarcho wants to merge 2 commits into
rust-lang:mainfrom
Jarcho:ownerless_typeck
Open

Jarcho wants to merge 2 commits into
rust-lang:mainfrom
Jarcho:ownerless_typeck

Conversation

@Jarcho

@Jarcho Jarcho commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Based on #157928

This brings the typeck results when linting back to what it was before #73743. The first commit adds a dummy ownerless typeck results and uses that as the initial value for the lint pass. The second commit just removes the now useless typeck_results method.

The dummy table is added to the global context more for convenience. It can't be a static since the lifetime argument is invariant. It could be created just for the linting, but that would need to add an extra lifetime parameter to LateContext and a lot of places downstream of that which would be a huge pain.

@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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. labels Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Jun 17, 2026
@rustbot rustbot assigned nikomatsakis and unassigned folkertdev Jun 17, 2026
@Jarcho

Jarcho commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

The line the error is complaining about doesn't even exist anywhere. What is the miri test even building?

@rust-bors

This comment has been minimized.

@Jarcho
Jarcho force-pushed the ownerless_typeck branch from 27bc424 to 93e8014 Compare June 18, 2026 10:36
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Jarcho
Jarcho force-pushed the ownerless_typeck branch from 93e8014 to ad83973 Compare June 18, 2026 10:47
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@Jarcho
Jarcho force-pushed the ownerless_typeck branch from ad83973 to 831a118 Compare June 26, 2026 02:00
@rustbot

This comment has been minimized.

@Jarcho
Jarcho force-pushed the ownerless_typeck branch from 831a118 to 40277ed Compare July 6, 2026 10:01
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@Jarcho
Jarcho force-pushed the ownerless_typeck branch from 40277ed to a24e697 Compare July 16, 2026 14:55
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-bors

rust-bors Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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

@BoxyUwU

BoxyUwU commented Oct 8, 2026

Copy link
Copy Markdown
Member

r? types

@rustbot rustbot assigned jackh726 and unassigned nikomatsakis Oct 8, 2026
@jackh726

jackh726 commented Oct 9, 2026

Copy link
Copy Markdown
Member

Hmm. I see the appeal - but I don't like losing the type safety of having this be optional. I would sooner like to see us refactor TypeckResults into something that's "always available" and what is only "sometimes available" - or to move this to a place where we don't incidentally want it around for linting.

@oli-obk

oli-obk commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

TypeckResults can't really be split up meaningfully (or I'm misunderstanding what you want to do). There is nothing that is always available (or well, this PR already splits it into "always available: empty tables", "sometimes available: owner def id".

If we want to have more type safety but also fewer unwraps, we can split the lint contexts and traits into "lint contexts in body" and "lint context without body", but not sure that is worth it.

There is also another option where everything outside the body has an owner id of the crate root or sth. This will incidentally work for all the checks we have right now, but it may be too subtle. Though I struggle to see where it would ever cause us problems

@Jarcho

Jarcho commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I'm unclear what type safety you get from the option given that it's just unwrapped everywhere. Modelling the option as a degenerate value which just does the right thing (crash when accessing) when performing the check we already want (that we have the correct table) avoids unwrapping it while still keeping the same level of correctness we currently have. Unwrapping will crash earlier, but only marginally.

There is also another option where everything outside the body has an owner id of the crate root or sth. This will incidentally work for all the checks we have right now, but it may be too subtle. Though I struggle to see where it would ever cause us problems

Using an optional owner will outright crash every query with a mismatching owner. Given that it's always nonsense to query the non-body results this seems like the better outcome.

@jackh726

jackh726 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

If we want to have more type safety but also fewer unwraps, we can split the lint contexts and traits into "lint contexts in body" and "lint context without body", but not sure that is worth it.

This is where I was going, yeah.

Unwrapping will crash earlier, but only marginally.

Perhaps this is true, but perhaps not. I don't really think it's true that you can do nothing with a dummy typeck context with this PR (or, that there isn't a chance someone adds that in the future) - where you definitely cannot today. My worry is that somebody goes to use typeck results somewhere were they don't actually have typeck results and get "incorrect" data.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants