Skip to content

Suggest removal of type ascription in stable #95014

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

Closed
estebank opened this issue Mar 16, 2022 · 1 comment · Fixed by #95104
Closed

Suggest removal of type ascription in stable #95014

estebank opened this issue Mar 16, 2022 · 1 comment · Fixed by #95104
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-type_ascription `#![feature(type_ascription)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Mar 16, 2022

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();

The current output is:

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

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-type_ascription `#![feature(type_ascription)]` labels Mar 16, 2022
@compiler-errors
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. F-type_ascription `#![feature(type_ascription)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants