Skip to content

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Sep 4, 2025

fix #146191

I've tried moving the "is this an identity use" check to fn clone_and_resolve_opaque_types and this would allow the following code to compile as it now ignores Opaque<'!a> = Opaque<'!a> while they previously resulted in errors

type Inner<'a> = impl Sized;
#[define_opaque(Inner)]
fn outer_impl() -> impl for<'a> Fn(&'a ()) -> Inner<'a> {
|x| x //~ ERROR expected generic lifetime parameter, found `'a`
}

The closure signature gets inferred to for<'a> fn(&'a ()) -> Inner<'a>. The closure then has a defining use Inner<'a_latbound> = &'a_latebound () while the parent function has a non-defining Inner<'!a> = Inner<'!a>. By eagerly discarding identity uses we don't error on the non-defining use in the parent.

r? @BoxyUwU

@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 Sep 4, 2025
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the fix-non-defining-uses branch from 9a8d6e8 to 8cab2b3 Compare September 5, 2025 09:10
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr force-pushed the fix-non-defining-uses branch from 8cab2b3 to 381b326 Compare September 6, 2025 14:06
@lcnr
Copy link
Contributor Author

lcnr commented Sep 6, 2025

@bors r=BoxyUwU rollup

@bors
Copy link
Collaborator

bors commented Sep 6, 2025

📌 Commit 381b326 has been approved by BoxyUwU

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 Sep 6, 2025
bors added a commit that referenced this pull request Sep 6, 2025
Rollup of 5 pull requests

Successful merges:

 - #139524 (Add socket extensions for cygwin)
 - #145940 (single buffer for exponent fmt of integers)
 - #146206 (identity uses are ok, even if there are no defining uses)
 - #146272 (Update comment for `-Werror` on LLVM builds)
 - #146280 (Make `LetChainsPolicy` public for rustfmt usage)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d3d5c7f into rust-lang:master Sep 7, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Sep 7, 2025
rust-timer added a commit that referenced this pull request Sep 7, 2025
Rollup merge of #146206 - lcnr:fix-non-defining-uses, r=BoxyUwU

identity uses are ok, even if there are no defining uses

fix #146191

I've tried moving the "is this an identity use" check to `fn clone_and_resolve_opaque_types` and this would allow the following code to compile as it now ignores `Opaque<'!a> = Opaque<'!a>` while they previously resulted in errors https://github.com/rust-lang/rust/blob/71289c378d0a406a4f537fe4001282d19362931f/tests/ui/type-alias-impl-trait/hkl_forbidden.rs#L42-L46

The closure signature gets inferred to `for<'a> fn(&'a ()) -> Inner<'a>`. The closure then has a defining use `Inner<'a_latbound> = &'a_latebound ()` while the parent function has a non-defining `Inner<'!a> = Inner<'!a>`. By eagerly discarding identity uses we don't error on the non-defining use in the parent.

r? `@BoxyUwU`
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Sep 8, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#139524 (Add socket extensions for cygwin)
 - rust-lang/rust#145940 (single buffer for exponent fmt of integers)
 - rust-lang/rust#146206 (identity uses are ok, even if there are no defining uses)
 - rust-lang/rust#146272 (Update comment for `-Werror` on LLVM builds)
 - rust-lang/rust#146280 (Make `LetChainsPolicy` public for rustfmt usage)

r? `@ghost`
`@rustbot` modify labels: rollup
@lcnr lcnr deleted the fix-non-defining-uses branch September 8, 2025 08:45
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.

ICE: non-defining use in defining scope

5 participants