-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
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
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 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. |
@nikomatsakis But |
src/librustc_typeck/check/mod.rs
Outdated
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))); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
This seems reasonable to me. @eddyb Perhaps we should add a test for that? |
@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 |
@eddyb I believe that will work fine |
@bors r+ -- seems like consensus is to go forward |
📌 Commit 587566e has been approved by |
@bors r- -- oh, well, were you going to rename variables @leodasvacas ? |
@bors r+ |
📌 Commit 0582d02 has been approved by |
…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
@bors p=1 (Needed for beta, stable backports) |
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:
[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
Fixes #50595.
This bug currently affects stable. Why I think we can go for hard error:
bin
crates (which have amain
), 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