• E
    Specify when type parameter shadows primitive type · 68e8624d
    Esteban Küber 提交于
    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 #35030
    68e8624d
lib.rs 26.8 KB