-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Incorrectly typed for
expression when into_iter expression diverges.
#78240
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
Comments
Also, for the hat trick: fn test_while() -> ! {
while { panic!(); false } {}
} is incorrectly typed. I'll defer an additional bug since it's similar enough to the |
I don't think this is a bug. |
Here's my reasoning: This code for _ in { panic!(); 0.. } {} is equivalent to let range: RangeFrom<i32> = { panic!(); 0.. };
for _ in range {} . The type of And the same reasoning for |
I have mixed feelings about this. I think this should work if and only if the following works: fn foo() -> ! {
return panic!();
()
} which currently does not work. This is because types must still be valid, even in unreachable code. However, |
@varkor Do you want to move this discussion to #t-lang on Zulip or to some kind of T-lang proposal? |
It was always my understanding that |
Hmm, that does seem confusing. I still don't think for _ in { panic!(); 0.. } {} should be typed as let x: ! = panic!();
let x: ! = { panic!() };
let x: () = { panic!(); };
let x: () = { panic!(); () }; |
I see where you're coming from, but unless you want to treat function bodies as different than other blocks, you will break every program like this: fn rand() -> u32 {
return 4;
} This is why I propose that all of the expressions you gave should be |
My suspicion is as you say, @adlerd: that people often write |
The special case is described here: rust/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs Lines 598 to 613 in d415fae
|
I tried this code:
I expected to see this happen: This should compile successfully. Moreover, the
for
expression should be assignable to any type and this should work for any function return type. In short, thefor
expression should be typed at!
not()
. As a general rule,for _ in b { c }
should be typed like{ b; () }
, not()
.Instead, this happened:
Version: playground, nightly 2020-10-18
See also #77156
The text was updated successfully, but these errors were encountered: