Skip to content

Fix trait method resolution on an adjusted never type#156047

Merged
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
JonathanBrouwer:never-ty-method
Jul 15, 2026
Merged

Fix trait method resolution on an adjusted never type#156047
rust-bors[bot] merged 6 commits into
rust-lang:mainfrom
JonathanBrouwer:never-ty-method

Conversation

@JonathanBrouwer

@JonathanBrouwer JonathanBrouwer commented May 1, 2026

Copy link
Copy Markdown
Contributor

@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. labels May 1, 2026
@rustbot

rustbot commented May 1, 2026

Copy link
Copy Markdown
Collaborator

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

@JonathanBrouwer JonathanBrouwer May 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that this PR allows more code to compile on stable, for example see this test.

View changes since the review

@JonathanBrouwer JonathanBrouwer May 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this is a problem we could delay the problem by putting this change behind the never_type feature gate

Comment thread compiler/rustc_hir_typeck/src/method/probe.rs Outdated

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this a reasonable change, I would expect us to emit a FCW here, I don't want to support this permanently or more importantly, this may overlap with other kinds of inference fallback in the future, so we generally don't want users to rely on this

View changes since this review

@WaffleLapkin WaffleLapkin added the F-never_type `#![feature(never_type)]` label May 1, 2026
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-types Relevant to the types team, which will review and decide on the PR/issue. labels May 1, 2026
@JonathanBrouwer

JonathanBrouwer commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

This PR is now based on #156048, still need to add the FCW lint, I'll do that later.
@rustbot author

Is "Trait method call on adjusted never type" the correct terminology? I'm not super familiar with the type system yet

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 2, 2026
@rustbot

rustbot commented May 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 2, 2026
@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread compiler/rustc_lint_defs/src/builtin.rs Outdated
Comment thread compiler/rustc_lint_defs/src/builtin.rs
@JonathanBrouwer

JonathanBrouwer commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

I rebased on #156079 and #156048 so the diff is nicely small now

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 3, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
Rollup of 6 pull requests

Successful merges:

 - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets)
 - #156047 (Fix trait method resolution on an adjusted never type)
 - #159061 (Skip trivial cast lint for trait object upcasts)
 - #159241 (Update books)
 - #159248 (compiler: Remove `-Zmutable-noalias`)
 - #159250 (Rename `errors.rs` file to `diagnostics.rs` (13/N))
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 14, 2026
…=lcnr,wafflelapkin

Fix trait method resolution on an adjusted never type

Fixes rust-lang#143349

r? @WaffleLapkin
cc @lcnr
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
Rollup of 6 pull requests

Successful merges:

 - #159039 (resolve: fix effective visibilities for items in ambiguous glob sets)
 - #156047 (Fix trait method resolution on an adjusted never type)
 - #158981 (Fix where-bound suggestion with legacy const generics)
 - #159061 (Skip trivial cast lint for trait object upcasts)
 - #159248 (compiler: Remove `-Zmutable-noalias`)
 - #159250 (Rename `errors.rs` file to `diagnostics.rs` (13/N))
@ehuss ehuss mentioned this pull request Jul 14, 2026
@jhpratt

jhpratt commented Jul 14, 2026

Copy link
Copy Markdown
Member

@bors r- #159260 (comment)

Simple typo

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 14, 2026
@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159262), which was unapproved.

View changes since this unapproval

Comment thread compiler/rustc_lint_defs/src/builtin.rs Outdated
///
/// ### Example
///
/// ```rust,ignore (does not compile on stage1 until bootstrap, change this to no_run after bootstrap is updated, writing CURRENT_RUSTC_VERSION hoping this is noticed in the diff)

@ehuss ehuss Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't quite the correct way to do this for a new lint. I think it requires some combination of #[cfg_attr(bootstrap, doc = "```rust")] lines. See https://github.com/rust-lang/rust/pull/155521/changes#diff-c39514e6f2a747139246fae90b0fca9c3485b104d3a0a04aea11361918d2434fR20-R23 for an example.

(I don't love that the tests are run this way.)

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I don't love that the tests are run this way.)

Do you mean that we still run ignore'ed tests? How does that happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't even know you can cfg_attr doc comments, awesome! Will fix it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried looking for this on the rustc dev guide but couldn't find it, I'll also add a section for it :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ignore tests aren't run. The error message explains what is happening:

The documentation generator cannot generate the example output when the example is ignored.
Manually include the sample output below the example. For example:

It's the {{produces}} part that doesn't work with ignore (since there's no way for it to generate the output).

However, using ignore in this situation isn't the right thing. ignore should only be used in cases where it is impossible to exercise the lint with our current harness.

The reason you can't just have a normal rust example here is because there is a CI job that tries to run doctests with an older rustc. Personally I don't think that is worth trying to support that, but I understand it's not simple.

It's also just a bad interaction of using doc-comments for this purpose. The code examples are only intended to run with the lint-docs tool. I don't remember, but I don't think I ever intended them to run via doctests. I feel like something changed along the line, because this used to not be a problem.

One idea to try to work around this is to stop using doc-comments for this documentation. They cause several problems (like showing up in search engines). Perhaps either change them to regular comments, or move them to separate files (like the E code files).

@ehuss

ehuss commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Simple typo

That's not the case here. There's no typo for the widnows thing. That error message is showing an example of a lint that deals with a typo. It is unrelated here, as the issue is that it should be using cfg_attr.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor Author

@bors try jobs=x86_64-gnu-llvm-22-3

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
Fix trait method resolution on an adjusted never type


try-job: x86_64-gnu-llvm-22-3
@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b84fe77 (b84fe77d754fd3febfc50e255f344a678189db2e)
Base parent: da80ed0 (da80ed0708a09dc096c184345d6eb42cbcd50a1e)

@JonathanBrouwer

Copy link
Copy Markdown
Contributor Author

@bors r=lcnr,wafflelapkin

@rust-bors

rust-bors Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 62c7143 has been approved by lcnr,wafflelapkin

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 14, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #156047 (Fix trait method resolution on an adjusted never type)
 - #157824 (Comptime inherent impls)
 - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`)
 - #158723 (Support EII on Windows MSVC)
 - #158993 (rerun in original typing mode if we meet any opaques in post analysis)
 - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.)
 - #159183 (Introduce InstanceKind::LlvmIntrinsic)
 - #159251 (Bump rustc-perf submodule)
 - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing)
 - #159155 (unstable book: Document `diagnostic_on_unknown` feature)
 - #159235 (Add regression test for #95719)
 - #159243 (inline Once wait and wait_force)
 - #159255 (Replace shortened type with `_` instead of `...` as placeholder)
 - #159259 (Add regression test for #144033)
 - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable)
 - #159269 (disable range-len-try-from.rs on s390x)
 - #159272 (slice: make swap delegate to swap_unchecked)
 - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`)
 - #159275 (remove obsolete comment)
 - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants)
 - #159283 (Remove obsolete verbose flag from deref/ref suggestions)
 - #159290 (rustc-dev-guide subtree update)
rust-bors Bot pushed a commit that referenced this pull request Jul 15, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #156047 (Fix trait method resolution on an adjusted never type)
 - #157824 (Comptime inherent impls)
 - #158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`)
 - #158723 (Support EII on Windows MSVC)
 - #158993 (rerun in original typing mode if we meet any opaques in post analysis)
 - #159160 (Make `HasTokens` a sub-trait of `HasAttrs`.)
 - #159183 (Introduce InstanceKind::LlvmIntrinsic)
 - #159251 (Bump rustc-perf submodule)
 - #155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing)
 - #159155 (unstable book: Document `diagnostic_on_unknown` feature)
 - #159235 (Add regression test for #95719)
 - #159243 (inline Once wait and wait_force)
 - #159255 (Replace shortened type with `_` instead of `...` as placeholder)
 - #159259 (Add regression test for #144033)
 - #159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable)
 - #159269 (disable range-len-try-from.rs on s390x)
 - #159272 (slice: make swap delegate to swap_unchecked)
 - #159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`)
 - #159275 (remove obsolete comment)
 - #159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants)
 - #159283 (Remove obsolete verbose flag from deref/ref suggestions)
 - #159290 (rustc-dev-guide subtree update)
@rust-bors rust-bors Bot merged commit 820ae3c into rust-lang:main Jul 15, 2026
14 checks passed
rust-timer added a commit that referenced this pull request Jul 15, 2026
Rollup merge of #156047 - JonathanBrouwer:never-ty-method, r=lcnr,wafflelapkin

Fix trait method resolution on an adjusted never type

Fixes #143349

r? @WaffleLapkin
cc @lcnr
@rustbot rustbot added this to the 1.99.0 milestone Jul 15, 2026
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jul 15, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - rust-lang/rust#156047 (Fix trait method resolution on an adjusted never type)
 - rust-lang/rust#157824 (Comptime inherent impls)
 - rust-lang/rust#158235 (Store `DefId` instead of `EiiDecl` in `EiiImplResolution::Known`)
 - rust-lang/rust#158723 (Support EII on Windows MSVC)
 - rust-lang/rust#158993 (rerun in original typing mode if we meet any opaques in post analysis)
 - rust-lang/rust#159160 (Make `HasTokens` a sub-trait of `HasAttrs`.)
 - rust-lang/rust#159183 (Introduce InstanceKind::LlvmIntrinsic)
 - rust-lang/rust#159251 (Bump rustc-perf submodule)
 - rust-lang/rust#155013 (Suggest the `[const] Destruct` bound for type parameters in const functions when missing)
 - rust-lang/rust#159155 (unstable book: Document `diagnostic_on_unknown` feature)
 - rust-lang/rust#159235 (Add regression test for rust-lang/rust#95719)
 - rust-lang/rust#159243 (inline Once wait and wait_force)
 - rust-lang/rust#159255 (Replace shortened type with `_` instead of `...` as placeholder)
 - rust-lang/rust#159259 (Add regression test for rust-lang/rust#144033)
 - rust-lang/rust#159265 (bootstrap: skip intrinsic-test when rustfmt is unavailable)
 - rust-lang/rust#159269 (disable range-len-try-from.rs on s390x)
 - rust-lang/rust#159272 (slice: make swap delegate to swap_unchecked)
 - rust-lang/rust#159274 (bootstrap: Rename `std_crates_for_run_make` to `std_crates_for_make_run`)
 - rust-lang/rust#159275 (remove obsolete comment)
 - rust-lang/rust#159277 (Construct `tokens` for attrs made by `mk_attr_word` and other variants)
 - rust-lang/rust#159283 (Remove obsolete verbose flag from deref/ref suggestions)
 - rust-lang/rust#159290 (rustc-dev-guide subtree update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. F-never_type `#![feature(never_type)]` finished-final-comment-period The final comment period is finished for this PR / Issue. I-types-nominated Nominated for discussion during a types team meeting. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler 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.

Inconsistent method lookup on never type