Skip to content

Fix linker error by resolving regions for main return type obligations#151377

Open
xonx4l wants to merge 6 commits intorust-lang:mainfrom
xonx4l:main_termination
Open

Fix linker error by resolving regions for main return type obligations#151377
xonx4l wants to merge 6 commits intorust-lang:mainfrom
xonx4l:main_termination

Conversation

@xonx4l
Copy link
Copy Markdown
Contributor

@xonx4l xonx4l commented Jan 19, 2026

This PR fix linker error by resolving regions for main return type obligations as discussed in #148421

Added a final check . Now the compiler double-checks the lifetimes for main right away. If they don't work it stops and gives the user a clean compiler error instead of a linker crash.

@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 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 19, 2026

r? @fee1-dead

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

}

let region_errors =
infcx.resolve_regions(main_diagnostics_def_id, param_env, tcx.mk_type_list(&[]));
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.

One thing I'm slightly unsure about is the diagnostic span main_diagnostics_def_id as this points to the function as a whole.

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 DefId is the context in which we're emitting the errors, so it should be the DefId of the whole body. This is correct. Please use ty::List::empty() instead of mk_type_list

Also, can you change this function to return Result<(), ErrorGuaranteed> and instead of using error = true just return Err(guar).

We shouldn't emit region errors if there are fulfillment errors

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.

@lcnr sorry I was a bit busy . I have made the the changes you asked for . Thanks!

@rust-log-analyzer

This comment has been minimized.

@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 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 22, 2026

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

@rust-log-analyzer

This comment has been minimized.

@xonx4l
Copy link
Copy Markdown
Contributor Author

xonx4l commented Feb 7, 2026

@rustbot ready

@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 Feb 7, 2026
@fee1-dead
Copy link
Copy Markdown
Member

Overall looks correct, but for signoff:

r? lcnr

@rustbot rustbot assigned lcnr and unassigned fee1-dead Feb 17, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@xonx4l
Copy link
Copy Markdown
Contributor Author

xonx4l commented Feb 23, 2026

@rustbot ready


if error {
return;
return Ok(());
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.

?

we should return Err(ErrorGuaranteed) here

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 am sorry I got a bit busy and it just slipped out of my focus . Updated to enforce Err(ErrorGuaranteed). Thanks !

.is_err()
{
return;
return Ok(());
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.

and here

@rust-bors

This comment has been minimized.

@xonx4l xonx4l force-pushed the main_termination branch from 48c7506 to ce665cd Compare March 24, 2026 04:57
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 24, 2026

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-log-analyzer

This comment has been minimized.

.and(items.par_opaques(|item| tcx.ensure_result().check_well_formed(item)));
super::entry::check_for_entry_fn(tcx);

super::entry::check_for_entry_fn(tcx)?;
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.

why not part of the and 🤔

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 kept it separate to make sure error is propagated.

@@ -0,0 +1,15 @@
// check-fail
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.

check-fail isn't necessary.

Can you add a comment for what this is testing (and link to the issue in the file (and not necessarily in the test name))

Copy link
Copy Markdown
Contributor Author

@xonx4l xonx4l Mar 26, 2026

Choose a reason for hiding this comment

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

Okay will add.

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

5 participants