-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
expected (), found usize, while really this is the other way around #51767
Comments
The Sometimes we get more info, sometimes not: fn foo() -> i32 {
let s = "bar".chars().count();
s
} ... clearly blames fn foo() -> i32 {
let s: i32 = "bar".chars().count();
s
} ... blames the rhs with "expected It would be very helpful if
A similar example to OP's code would be #![feature(const_fn)]
const fn foo() -> i32 {
1
}
fn main() {
[(); { foo() } ];
} The error is
Asides from the unrelated "expected
|
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
May I suggest this issue is re-opened, even if it will stay open for a while. @estebank is doing the Lord's Work on compiler error messages and the recent changes are very welcome. Yet I think the fundamental problem of For the programmer, the whole point about the error is to figure out what went wrong in those lines of reasoning; the contradicting result ( These are just my two cents, yet I may advertise to re-open this issue and maybe get the compiler's reasoning explained when |
@lukaslueg Thanks for the kind words. I believe that this would fall under the umbrella of #61067: pointing at where the requirement is coming from. Sadly, the way we do type resolution currently means that we lose the chain of decisions that cause the current expected type to be expected. In order to improve diagnostics now (as opposed to wildly refactoring how type resolution is performed) we've been adding specific local analysis for local type errors (return type checking, for example). I believe that we can get 90% there with these kind of checks, like #61066 and #61067. It is preferable to have more, smaller, targeted tickets that can be hyper focused and tackle-able by new contributors as opposed to large open ended tracking issues, particularly around diagnostics. Because of this I feel this ticket in particular could be closed. This, of course, unless I am missing some part of the original ticket that wasn't covered by #63337. |
When playing around in the playground, I found an error message that was kind of strange for the situation:
The error message is as follow:
playground link: https://play.rust-lang.org/?gist=c6caaee68d6886fce7e3f0af324f5338&version=nightly&mode=debug
The error message would make more sense if described as
Expected usize, found ()
, or just not permitloop {}
constructs at all at the place of the length of an array.The text was updated successfully, but these errors were encountered: