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

Fix fn main() -> impl Trait for non-Termination trait #50656

Merged
merged 2 commits into from
May 17, 2018

Conversation

leoyvens
Copy link
Contributor

Fixes #50595.

This bug currently affects stable. Why I think we can go for hard error:

  • It will in stable for at most one cycle and there is no legitimate reason to abuse it, nor any known uses in the wild.
  • It only affects bin crates (which have a main), so there is little practical difference between a hard error or a deny lint, both are a one line fix.

The fix was to just unshadow a variable. Thanks @nikomatsakis for the mentoring!

r? @nikomatsakis

Fixes rust-lang#50595.

This bug currently affects stable. Why I think we can go for hard error:

- It will in stable for at most one cycle and there is no legitimate
reason to abuse it, nor any known uses in the wild.

- It only affects `bin` crates (which have a `main`), so there is
little practical difference between a hard error or a deny lint, both
are a one line fix.

The fix was to just unshadow a variable. Thanks @nikomatsakis for the
mentoring!

r? @nikomatsakis
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2018
@cramertj cramertj added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 11, 2018
@kennytm kennytm added the relnotes Marks issues that should be documented in the release notes of the next release. label May 14, 2018
@nikomatsakis
Copy link
Contributor

r=me on the technical side. cc @rust-lang/core and @rust-lang/lang to inquire re: policy, but I think we should just land this. For those who haven't been following #50595, here is the background:

  • We stabilize the ability to use non-() returns types in main, but found shortly after the stable release that we now permit fn main() -> impl Debug -- or indeed any trait -- so long as the "hidden type" implements Terminate. You can rationalize this, but I think pretty clearly this behavior was not intentional nor particularly desired.
  • This PR fixes it and converts that into a hard error (fn main() -> impl Terminate does continue to work)

We can always convert to a lint or back out if it causes trouble, but it seems like it should be ok since we are acting very quickly and this is an obscure corner case.

@eddyb
Copy link
Member

eddyb commented May 14, 2018

@nikomatsakis But fn main() -> Result<(), impl Debug> would continue to work, right?

let ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
let revealed_ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
Copy link
Member

Choose a reason for hiding this comment

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

I think the original should be called declared_ret_ty and keep this one ret_ty. Since there is exactly one use of the original ret_ty and it's not even in this diff!

Copy link
Contributor Author

@leoyvens leoyvens May 14, 2018

Choose a reason for hiding this comment

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

Indeed the diff is confusing because the line that changes behavior isn't on the diff. What do you think of renaming both?

What I wonder is: which naming would've had a better chance of preventing the bug? I think the name revealed_ret_ty calls attention to private information being used.

Copy link
Member

Choose a reason for hiding this comment

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

I think the code that has to see the type "from the outside" being here is part of the problem - after all, this part of typeck is working on the body of the function being checked. cc @nikomatsakis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, what do you think of moving the check to the check_item_type pass, right here. I can try it in this PR, if we're not in a rush to land because of the point release.

@joshtriplett
Copy link
Member

joshtriplett commented May 14, 2018

This seems reasonable to me.

@eddyb Perhaps we should add a test for that?

@alexcrichton
Copy link
Member

@nikomatsakis this definitely isn't the first time we would "break" an API just after it was released, I think if we do a point release this is good to go

@nikomatsakis
Copy link
Contributor

@eddyb I believe that will work fine

@nikomatsakis
Copy link
Contributor

@bors r+ -- seems like consensus is to go forward

@bors
Copy link
Contributor

bors commented May 15, 2018

📌 Commit 587566e has been approved by nikomatsakis

@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 May 15, 2018
@nikomatsakis
Copy link
Contributor

@bors r- -- oh, well, were you going to rename variables @leodasvacas ?

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 15, 2018
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 15, 2018

📌 Commit 0582d02 has been approved by nikomatsakis

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 15, 2018
kennytm added a commit to kennytm/rust that referenced this pull request May 16, 2018
…ret, r=nikomatsakis

Fix `fn main() -> impl Trait` for non-`Termination` trait

Fixes rust-lang#50595.

This bug currently affects stable. Why I think we can go for hard error:
- It will in stable for at most one cycle and there is no legitimate reason to abuse it, nor any known uses in the wild.
- It only affects `bin` crates (which have a `main`), so there is little practical difference between a hard error or a deny lint, both are a one line fix.

The fix was to just unshadow a variable. Thanks @nikomatsakis for the mentoring!

r? @nikomatsakis
@Mark-Simulacrum
Copy link
Member

@bors p=1 (Needed for beta, stable backports)

bors added a commit that referenced this pull request May 17, 2018
Rollup of 17 pull requests

Successful merges:

 - #50170 (Implement From for more types on Cow)
 - #50638 (Don't unconditionally set CLOEXEC twice on every fd we open on Linux)
 - #50656 (Fix `fn main() -> impl Trait` for non-`Termination` trait)
 - #50669 (rustdoc: deprecate `#![doc(passes, plugins, no_default_passes)]`)
 - #50726 (read2: Use inner function instead of closure)
 - #50728 (Fix rustdoc panic with `impl Trait` in type parameters)
 - #50736 (env: remove unwrap in examples in favor of try op)
 - #50740 (Remove LazyBTreeMap.)
 - #50752 (Add missing error codes in libsyntax-ext asm)
 - #50779 (Make mutable_noalias and arg_align_attributes be tracked)
 - #50787 (Fix run-make wasm tests)
 - #50788 (Fix an ICE when casting a nonexistent const)
 - #50789 (Ensure libraries built in stage0 have unique metadata)
 - #50793 (tidy: Add a check for empty UI test files)
 - #50797 (fix a typo in signed-integer::from_str_radix())
 - #50808 (Stabilize num::NonZeroU*)
 - #50809 (GitHub: Stop treating Cargo.lock as a generated file.)

Failed merges:
@bors bors merged commit 0582d02 into rust-lang:master May 17, 2018
@alexcrichton alexcrichton added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels May 21, 2018
bors added a commit that referenced this pull request May 21, 2018
[beta] Process backports

Merged in master and accepted:

* #50758: Stabilise inclusive_range_methods
* #50656: Fix `fn main() -> impl Trait` for non-`Termination` trait

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: 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.

impl Trait is allowed in the return type of main
10 participants