Skip to content

fix(infer): stop skipping Empty lifetime checks - #161935

Open
im-lunex wants to merge 2 commits into
rust-lang:mainfrom
im-lunex:fix_#161864
Open

im-lunex wants to merge 2 commits into
rust-lang:mainfrom
im-lunex:fix_#161864

Conversation

@im-lunex

@im-lunex im-lunex commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

stop skipping the check in lexical_region_resolve/mod.rs and actually validate Empty lifetimes..

follow-up - make note_and_explain.rs handle ReVar and ReErased so it prints a normal error message instead of exploding.. - (added ui-test and .stderr)

fixes: #161864

r? @lcnr

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 28, 2026
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
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 75 candidates
  • Random selection from 20 candidates

@rustbot rustbot assigned lcnr and unassigned mu001999 Aug 28, 2026
@lcnr

lcnr commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This doesn't feel 100% sufficient and don't have the capacity to fully dive into this myself rn, started a zulip thread about it https://rust-lang.zulipchat.com/#narrow/channel/618216-t-types.2Fcall-for-participation/topic/yeet.20.27empty.20in.20region.20handling/with/621318591

ty::ReVar(_) => (alt_span, "revar", region.to_string()),

ty::ReBound(..) => {
bug!("unexpected region for DescriptionCtx: {:?}", region);

@adwinwhite adwinwhite Sep 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.

any idea why we have ReVar/ReErases now? I kinda lost track of this.

View changes since the review

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.

added separate handling for ReVar and ReErased because they represent different kinds of regions... so thought differentiating those would be better...

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.

So nothing blows up if we don't change them? Better keep them as is then. We want them to fail loud.

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.

This actually the upstream panics when it gets a ReErased region... so keeping it for now

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.

what code triggers the panic? some ui test?

@adwinwhite adwinwhite Sep 20, 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.

Oh, this is annoying. It has never been actually called before because it's a fallback for try_report_nice_region_error. And the diagnostics type must outlive [reerased] is confusing.

Would you like to investigate why try_report_trait_placeholder_mismatch doesn't work and try to make it work so that this fallback doesn't get triggered? The error kind we handle here is RegionResolutionError::UpperBoundUniverseConflict if I'm not mistaken.

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.

Yeah I think the blocker is that RelateParamBound doesn't carry the TypeTrace/ValuePairs data that try_report_trait_placeholder_mismatch needs.. it's (Span, Ty, Option) a completely different shape. we can't just add a match arm..

That's a separate, larger task with its own design and review. [This issue is truly annoying while working on this we just encountered 3 more]

@adwinwhite adwinwhite Sep 28, 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.

I guess we have to create a new diagnostics on our own then. Are you interested in doing that? 😃
It probably amounts to adding a new method try_report_placeholder_leak in fn try_report(), which would handle RegionResolutionError::UpperBoundUniverseConflict and emit a custom error.
The wording is likely similiar to TypeError::RegionsPlaceholderMismatch, plus regions' spans.

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.

yeah i will give it a try..

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.

Thanks! Feel free to ask if anything's unclear.

@adwinwhite adwinwhite 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.

Thanks for working on this!

@rustbot author

View changes since this review

ty::ReVar(_) => (alt_span, "revar", region.to_string()),

ty::ReBound(..) => {
bug!("unexpected region for DescriptionCtx: {:?}", region);

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.

So nothing blows up if we don't change them? Better keep them as is then. We want them to fail loud.

@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 Sep 16, 2026
@rustbot

rustbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

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

@im-lunex
im-lunex requested a review from adwinwhite September 16, 2026 09:21
Comment on lines +1 to +4
// Regression test for https://github.com/rust-lang/rust/issues/161864
//@ revisions: current next
//[next] compile-flags: -Znext-solver=coherence
//@ compile-flags: -Znext-solver

@adwinwhite adwinwhite Sep 17, 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.

Suggested change
// Regression test for https://github.com/rust-lang/rust/issues/161864
//@ revisions: current next
//[next] compile-flags: -Znext-solver=coherence
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
// Regression test for https://github.com/rust-lang/rust/issues/161864
// We used to allow placeholders to outlive `'empty` in any universe,
// which can be exploited to extend lifetimes.
// `'empty` is a misleading name because the region can cover function body
// for the callee.

View changes since the review

@adwinwhite

Copy link
Copy Markdown
Contributor

r? me so I don't forget about this.

@rustbot rustbot assigned adwinwhite and unassigned lcnr Sep 21, 2026
@im-lunex

This comment was marked as duplicate.

@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Requested reviewer is already assigned to this pull request.

Please choose another assignee.

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

instantiating impl generic args with 'empty is unsound

5 participants