Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upimpl Trait is allowed in the return type of main #50595
Comments
This comment has been minimized.
This comment has been minimized.
|
It's a bit late to change this. Does it cause any problem? AFAICT it just gives you a weird way to declare |
This comment has been minimized.
This comment has been minimized.
|
It doesn't give any new capability, I guess |
This comment has been minimized.
This comment has been minimized.
pietroalbini
added
I-nominated
T-compiler
labels
May 10, 2018
This comment has been minimized.
This comment has been minimized.
earthengine
commented
May 10, 2018
|
Why this is an issue? |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Yea, it seems you can use any trait:
trait Goo {}
impl Goo for () {}
fn main() -> impl Goo {}Works on beta and nightly. So it'll probably work on this weeks stable You can't do anything stupid with this feature. The checks see right through the impl Trait to the real type (http://play.rust-lang.org/?gist=243499b4b1e837bc41905ac814bb9a4b&version=nightly&mode=debug). I'd say adding a regression test that ensures that this corner case essentially ignores the anonymization of impl Trait is fine. We can add a deny by default lint that tells you that while this works, it's not pretty. |
This comment has been minimized.
This comment has been minimized.
|
This seems fine to me and unless we care enough to stop the stable release we're not going to change this. cc @rust-lang/lang though. |
This comment has been minimized.
This comment has been minimized.
|
Hmm, I feel like we should just fix this. I doubt there are a lot of people taking advantage of it. I can put up some mentoring instructions. We can do a warning period if needed. |
This comment has been minimized.
This comment has been minimized.
|
Fwiw I tried fixing by doing this and got ICEs and stack oveflows which I couldn't debug so I gave up. |
This comment has been minimized.
This comment has been minimized.
Hmm, I don't understand the stack overflows, but I think I would expect that patch to have no effect. The cause of the bug is that we are "instantiating" the impl Trait, here: rust/src/librustc_typeck/check/mod.rs Line 1041 in 57dc984 In the process, we shadow the "original" Later on, when we add the obligation that rust/src/librustc_typeck/check/mod.rs Line 1135 in 57dc984 If we used the original (currently shadowed) (That said, it wouldn't be the end of the world if we just let this go, I suppose.) |
This comment has been minimized.
This comment has been minimized.
|
As far as I understand we don't want to block 1.26 stable on this, right? In that case I think we should go with a lint instead of an hard error, since both of the features will be stabilized |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I probably borked the state of my clone or something. Thanks for the explanation, makes perfect sense, will make a patch. |
leodasvacas commentedMay 10, 2018
we’re stabilizing the combination of features that allows you to put
impl Traitin the return type of main as infn main() -> impl Copy {}. Amusing but unintended so it’s better to forbid this for now.