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

Don't ICE if TAIT-defining fn contains a closure with _ in return type #119975

Conversation

lukas-code
Copy link
Member

The delay_span_bug got added in 0e82aae to reduce the amount of errors emitted for functions that have _ in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types can be inferred.

Fixes #119916.

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@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 Jan 14, 2024
}
// Function items with `_` in their return type already emit an error, skip any
// "non-defining use" errors for them.
if let Some(hir_sig) = self.tcx.hir_node_by_def_id(item_def_id).fn_sig()
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to manually match on node kind, and only look for Node::Item/Node::TraitItem/Node::ImplItem/Node::ForeignItem?

The difference between when Node::fn_sig and Node::fn_decl return Some(_) is extremely subtle. It took me quite some time to even realize that's what changed in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

For Node::ForeignItem this isn't necessary because we already skip them here:

// No need to call `check`, as we do not run borrowck on foreign items.

I've added a test to ensure that is the case and we don't emit any extra errors for them.

Without Node::ForeignItem, the manual match is now just Node::fn_sig manually inlined and I don't think that's a lot better. The real problem here is the ambigous naming of FnSig vs FnDecl, where FnSig = FnDecl + FnHeader and FnHeader = effects (const/aync/unsafe) + call abi.

Copy link
Member

Choose a reason for hiding this comment

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

What about renaming it to fn_item_sig or fn_sig_of_item or something? Something that distinguishes that it's grabbing just the signature of an item.

Copy link
Member Author

Choose a reason for hiding this comment

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

For fn_item_sig I'd expect it to also include foreign function items, which fn_sig does not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the comment regarding fn_sig vs fn_decl and added a debug_assert! to hopefully make it more clear what's happening here.

And I'd rather not bikeshed a new name for fn_sig in this PR, so with that,
@rustbot review

For the record, here is the manual match version, which is literally just inlined fn_sig: 79b8fa5

Copy link
Member

Choose a reason for hiding this comment

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

I prefer the manual match version, but whatever

@compiler-errors
Copy link
Member

@rustbot author

r=me after that tho

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2024
@lukas-code lukas-code force-pushed the inferring-return-types-and-opaque-types-do-mix-sometimes branch from 3fccae4 to 669f847 Compare January 15, 2024 00:26
@lukas-code lukas-code force-pushed the inferring-return-types-and-opaque-types-do-mix-sometimes branch from 669f847 to 22833c1 Compare January 16, 2024 15:38
@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 Jan 16, 2024
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 17, 2024

📌 Commit 22833c1 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2024
@compiler-errors
Copy link
Member

@bors rollup

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jan 17, 2024
…and-opaque-types-do-mix-sometimes, r=compiler-errors

Don't ICE if TAIT-defining fn contains a closure with `_` in return type

The `delay_span_bug` got added in rust-lang@0e82aae to reduce the amount of errors emitted for functions that have `_` in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types *can* be inferred.

Fixes rust-lang#119916.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2024
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#115291 (Save liveness results for DestinationPropagation)
 - rust-lang#119651 (proc_macro: Add Literal::c_string constructor)
 - rust-lang#119855 (Enable Static Builds for FreeBSD)
 - rust-lang#119955 (Modify GenericArg and Term structs to use strict provenance rules)
 - rust-lang#119975 (Don't ICE if TAIT-defining fn contains a closure with `_` in return type)
 - rust-lang#119984 (Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.)
 - rust-lang#120001 (Consistently unset RUSTC_BOOTSTRAP when compiling bootstrap)
 - rust-lang#120020 (Gracefully handle missing typeck information if typeck errored)
 - rust-lang#120032 (Fix `rustc_abi` build on stable)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 17, 2024
…and-opaque-types-do-mix-sometimes, r=compiler-errors

Don't ICE if TAIT-defining fn contains a closure with `_` in return type

The `delay_span_bug` got added in rust-lang@0e82aae to reduce the amount of errors emitted for functions that have `_` in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types *can* be inferred.

Fixes rust-lang#119916.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2024
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#115291 (Save liveness results for DestinationPropagation)
 - rust-lang#119855 (Enable Static Builds for FreeBSD)
 - rust-lang#119975 (Don't ICE if TAIT-defining fn contains a closure with `_` in return type)
 - rust-lang#119984 (Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.)
 - rust-lang#120001 (Consistently unset RUSTC_BOOTSTRAP when compiling bootstrap)
 - rust-lang#120020 (Gracefully handle missing typeck information if typeck errored)
 - rust-lang#120031 (Construct closure type eagerly)
 - rust-lang#120032 (Fix `rustc_abi` build on stable)
 - rust-lang#120039 (pat_analysis: Don't rely on contiguous `VariantId`s outside of rustc)
 - rust-lang#120044 (Fix typo in comments (in_place_collect))
 - rust-lang#120056 (Use FnOnceOutput instead of FnOnce where expected)

r? `@ghost`
`@rustbot` modify labels: rollup
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jan 17, 2024
…and-opaque-types-do-mix-sometimes, r=compiler-errors

Don't ICE if TAIT-defining fn contains a closure with `_` in return type

The `delay_span_bug` got added in rust-lang@0e82aae to reduce the amount of errors emitted for functions that have `_` in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types *can* be inferred.

Fixes rust-lang#119916.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#115291 (Save liveness results for DestinationPropagation)
 - rust-lang#119855 (Enable Static Builds for FreeBSD)
 - rust-lang#119975 (Don't ICE if TAIT-defining fn contains a closure with `_` in return type)
 - rust-lang#120001 (Consistently unset RUSTC_BOOTSTRAP when compiling bootstrap)
 - rust-lang#120020 (Gracefully handle missing typeck information if typeck errored)
 - rust-lang#120031 (Construct closure type eagerly)
 - rust-lang#120032 (Fix `rustc_abi` build on stable)
 - rust-lang#120039 (pat_analysis: Don't rely on contiguous `VariantId`s outside of rustc)
 - rust-lang#120044 (Fix typo in comments (in_place_collect))
 - rust-lang#120056 (Use FnOnceOutput instead of FnOnce where expected)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#115291 (Save liveness results for DestinationPropagation)
 - rust-lang#119855 (Enable Static Builds for FreeBSD)
 - rust-lang#119975 (Don't ICE if TAIT-defining fn contains a closure with `_` in return type)
 - rust-lang#120001 (Consistently unset RUSTC_BOOTSTRAP when compiling bootstrap)
 - rust-lang#120020 (Gracefully handle missing typeck information if typeck errored)
 - rust-lang#120031 (Construct closure type eagerly)
 - rust-lang#120032 (Fix `rustc_abi` build on stable)
 - rust-lang#120039 (pat_analysis: Don't rely on contiguous `VariantId`s outside of rustc)
 - rust-lang#120044 (Fix typo in comments (in_place_collect))
 - rust-lang#120056 (Use FnOnceOutput instead of FnOnce where expected)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 22f1913 into rust-lang:master Jan 18, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 18, 2024
@lukas-code lukas-code deleted the inferring-return-types-and-opaque-types-do-mix-sometimes branch January 18, 2024 07:19
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
Rollup merge of rust-lang#119975 - lukas-code:inferring-return-types-and-opaque-types-do-mix-sometimes, r=compiler-errors

Don't ICE if TAIT-defining fn contains a closure with `_` in return type

The `delay_span_bug` got added in rust-lang@0e82aae to reduce the amount of errors emitted for functions that have `_` in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types *can* be inferred.

Fixes rust-lang#119916.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nightly-20240112 regression: ICE: delayed span bug: inferring return types and opaque types do not mix well
5 participants