Closed
Description
Given the following code:
use std::fs::read_to_string;
fn main() {
let input: String = read_to_string ("file.txt").unwrap() ;
let good_lines: Vec<_> = input: String
.lines(): Lines
.filter(|l |capital_letter (l)): impl Iterator<Itm = &str>
.collect();
error: casts cannot be followed by a method call
[--> src/main.rs:4:30
](https://play.rust-lang.org/#) |
4 | let good_lines: Vec<_> = input: String
| ^^^^^^^^^^^^^
|
help: try surrounding the expression in parentheses
|
4 | let good_lines: Vec<_> = (input: String)
| + +
error: casts cannot be followed by a method call
[--> src/main.rs:4:30
](https://play.rust-lang.org/#) |
4 | let good_lines: Vec<_> = input: String
| ______________________________^
5 | | .lines(): Lines
| |_______________________^
|
help: try surrounding the expression in parentheses
|
4 ~ let good_lines: Vec<_> = (input: String
5 ~ .lines(): Lines)
|
error: casts cannot be followed by a method call
[--> src/main.rs:4:30
](https://play.rust-lang.org/#) |
4 | let good_lines: Vec<_> = input: String
| ______________________________^
5 | | .lines(): Lines
6 | | .filter(|l|capital_letter (l)): impl Iterator<Itm = &str>
| |_________________________________________________________________^
|
help: try surrounding the expression in parentheses
|
4 ~ let good_lines: Vec<_> = (input: String
5 | .lines(): Lines
6 ~ .filter(|l|capital_letter (l)): impl Iterator<Itm = &str>)
|
It should (instead?/also?) suggest removing the type ascription, as it is more likely what the end user wanted. Particularly in stable compilers.
Taken from https://users.rust-lang.org/t/cannot-compile-my-code/72894
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Too much output caused by a single piece of incorrect code.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.`#![feature(type_ascription)]`Relevant to the compiler team, which will review and decide on the PR/issue.