Skip to content
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

Be more specific when type parameter shadows primitive type #36338

Merged
merged 1 commit into from
Sep 16, 2016

Commits on Sep 16, 2016

  1. Specify when type parameter shadows primitive type

    When a type parameter shadows a primitive type, the error message
    was non obvious. For example, given the file `file.rs`:
    
    ```rust
    trait Parser<T> {
        fn parse(text: &str) -> Option<T>;
    }
    
    impl<bool> Parser<bool> for bool {
        fn parse(text: &str) -> Option<bool> {
            Some(true)
        }
    }
    
    fn main() {
        println!("{}", bool::parse("ok").unwrap_or(false));
    }
    ```
    
    The output was:
    
    ```bash
    % rustc file.rs
    error[E0308]: mismatched types
     --> file.rs:7:14
      |
    7 |         Some(true)
      |              ^^^^ expected type parameter, found bool
      |
      = note: expected type `bool`
      = note:    found type `bool`
    
    error: aborting due to previous error
    ```
    
    We now show extra information about the type:
    
    ```bash
    % rustc file.rs
    error[E0308]: mismatched types
     --> file.rs:7:14
      |
    7 |         Some(true)
      |              ^^^^ expected type parameter, found bool
      |
      = note: expected type `bool` (type parameter)
      = note:    found type `bool` (bool)
    
    error: aborting due to previous error
    ```
    
    Fixes rust-lang#35030
    estebank committed Sep 16, 2016
    Configuration menu
    Copy the full SHA
    68e8624 View commit details
    Browse the repository at this point in the history