-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
struct MyStruct {
foo: String
}
fn ok() -> MyStruct {
MyStruct {
foo: std::env::temp_dir().join("something").to_str().unwrap().to_string()
}
}
fn bad_refactor() -> MyStruct {
let foo: std::env::temp_dir().join("something").to_str().unwrap().to_string();
MyStruct {
foo
}
}Current output
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
--> src/main.rs:14:34
|
12 | let foo: std::env::temp_dir().join("something").to_str().unwrap().to_string();
| ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`Desired output
error: did you mean `=` instead of `:`?
--> src/main.rs:14:34
|
12 | let foo: std::env::temp_dir().join("something").to_str().unwrap().to_string();
| ^ did you mean `=` instead of `:`?
OR
error: expected type, found function `expresion`
--> src/main.rs:14:34
|
12 | let foo: std::env::temp_dir().join("something").to_str().unwrap().to_string();
| --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
| |
| help: use `=` if you meant to assignRationale and extra context
I was just been asked about this in not too much complicated code, and we was both thinking, why join does not work, if there needs to be some use ... to bring it to the scope.
When I tried to write the simplified example I got much better error. (help: use `=` if you meant to assign)
Other cases
fn ok2() -> MyStruct {
MyStruct {
foo: some_fn()
}
}
fn bad_refactor2() -> MyStruct {
let foo: some_fn();
MyStruct {
foo
}
}
fn some_fn() -> String {
"".into()
}
// produces:
error[E0573]: expected type, found function `some_fn`
--> src/main.rs:25:14
|
25 | let foo: some_fn();
| --^^^^^^^^^ not a type
| |
| help: use `=` if you meant to assignAnything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.