Skip to content

Implements RFC 1937: ? in main - #46479

Merged
bors merged 25 commits into
rust-lang:masterfrom
bkchr:termination_trait
Dec 27, 2017
Merged

Implements RFC 1937: ? in main#46479
bors merged 25 commits into
rust-lang:masterfrom
bkchr:termination_trait

Conversation

@bkchr

@bkchrbkchr commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

This is the first part of the RFC 1937 that supports new
Termination trait in the rust main function.

Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help!

The support for doctest and #[test] is still missing, bu as @nikomatsakis said, smaller pull requests are better :)

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

Comment threadsrc/libstd/termination.rs Outdated

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.

Consider having only this impl in the first commit, since some of the others are more controversial in the details.

(Tests of the feature can add their own impls for their own types.)

Comment threadsrc/librustc_trans/lib.rs Outdated

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.

Reminder to undo this at some point.

@kennytmkennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 4, 2017
Comment threadsrc/librustc/middle/lang_items.rs Outdated

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.

is this line expected?

@bkchrbkchrDec 4, 2017

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, that is expected. There are multiple empty lines (scroll a little bit up in the file).

@shepmaster

Copy link
Copy Markdown
Member

Feels unlikely that @arielb1 will have much time to review this before the end of the year, so let's reassign to...

r? @estebank

@rust-highfiverust-highfive assigned estebank and unassigned arielb1Dec 9, 2017
Comment threadsrc/librustc_trans/partitioning.rs Outdated

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.

use self.tcx().lang_items().start_fn == Some(def_id) to avoid spurious errors on small tests.

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.

(To elaborate, I believe @arielb1's goal here is to avoid requiring the start lang item to be present if you are trying to write a tiny test targeting e.g. a #![no_std] library, where the start lang item would not otherwise be needed. I agree this makes sense.)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, already done that! :)

Comment threadsrc/librustc_trans/base.rs Outdated

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.

Because user-defined start is supposed to be non-generic, passing a substs to it could cause problems, so please don't.

@bkchrbkchrDec 21, 2017

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

You are right, but user-defined start is handled in the else branch.

Comment threadsrc/librustc_typeck/check/mod.rs Outdated

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.

You'll need to add a feature gate to avoid this being insta-stable for types other than ().

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.

That should also "fix" the compile-fail tests. Or you could just fix them for real and add #![feature(termination_trait)] to them.

Comment threadsrc/libstd/termination.rs Outdated

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.

You might want a

#[rustc_on_unimplemented("`main` can only return types that implement {Termination}, not `{Self}`")]

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 did you make this change? Seems like purely churn.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

That was done by @nikomatsakis to fix the tests.

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.

In particular, the new definition of start based around Termination winds up pulling in a lot of code related to panics and unwinds, causing the output of -Zprint-type-sizes to have a lot of unrelated gunk in it.

@arielb1

arielb1 commented Dec 9, 2017

Copy link
Copy Markdown
Contributor

@shepmaster

I would rather r? @nikomatsakis if I don't finish this.

However, I think this is basically good to go, except:

  1. this needs a feature-gate to avoid being insta-stable
  2. I would like a run-fail (or run-make) test to see that if you return an integer other than 0 from main, this actually causes a failure.

@shepmaster

Copy link
Copy Markdown
Member

@arielb1 sounds good; just didn't want to put too much on your plate! ❤️

r? @arielb1

@rust-highfiverust-highfive assigned arielb1 and unassigned estebankDec 9, 2017
@arielb1arielb1 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 Dec 13, 2017
@bkchrbkchr mentioned this pull request Dec 17, 2017
12 tasks
@bors

bors commented Dec 19, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #45525) made this pull request unmergeable. Please resolve the merge conflicts.

Comment threadsrc/librustc_typeck/check/mod.rs Outdated

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.

nit: replace this with

ifletSome(term_id) = fcx.tcx.lang_items().termination().is_some(){

And then you won't need to require it within.

Comment threadsrc/librustc_typeck/check/mod.rs Outdated

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.

nit: use if let Some(term_id) = fcx.tcx.lang_items().termination(), then you won't need to require it later

@arielb1

Copy link
Copy Markdown
Contributor

@bkchr

This still needs a feature gate, also it would bee nice if you fix the nit.

Comment threadsrc/libstd/rt.rs Outdated

sys::init();

process::exit(unsafe {

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.

From our discussion on gitter, this is the cause of the problem in wasm (usage of process::exit which is an abort on wasm).

Let's change this to propagate the error code outwards I think?

alexcrichtonand others added 2 commits December 26, 2017 14:26
This'll avoid exporting a symbol from binaries unnecessarily and should help the
linker clean things up if it can.
@arielb1

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 26, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 5a4298b has been approved by arielb1

@bors

bors commented Dec 26, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 5a4298b with merge 60fb575...

bors added a commit that referenced this pull request Dec 26, 2017
Implements RFC 1937: `?` in `main`
This is the first part of the RFC 1937 that supports new
`Termination` trait in the rust `main` function.
Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help!
The support for doctest and `#[test]` is still missing, bu as @nikomatsakis said, smaller pull requests are better :)
@bkchr

Copy link
Copy Markdown
ContributorAuthor

Can someone approve?

@killercup

Copy link
Copy Markdown
Contributor

@bors r=arielb1

@bors

bors commented Dec 27, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 09f94be has been approved by arielb1

@kennytmkennytm 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 Dec 27, 2017
@bors

bors commented Dec 27, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 09f94be with merge bfbb1f5...

bors added a commit that referenced this pull request Dec 27, 2017
Implements RFC 1937: `?` in `main`
This is the first part of the RFC 1937 that supports new
`Termination` trait in the rust `main` function.
Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help!
The support for doctest and `#[test]` is still missing, bu as @nikomatsakis said, smaller pull requests are better :)
@bors

bors commented Dec 27, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing bfbb1f5 to master...

@bors
bors merged commit 09f94be into rust-lang:masterDec 27, 2017
@bkchr

Copy link
Copy Markdown
ContributorAuthor

Finally! :)

sgrif added a commit to sgrif/rust that referenced this pull request Jan 31, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
sgrif added a commit to sgrif/rust that referenced this pull request Feb 6, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
sgrif added a commit to sgrif/rust that referenced this pull request Mar 1, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12 participants

@bkchr@rust-highfive@shepmaster@arielb1@bors@estebank@nikomatsakis@alexcrichton@kennytm@killercup@steveklabnik@scottmcm