Skip to content

Suggestion of match_as_ref does not compile #4437

Closed
@ordovicia

Description

@ordovicia

Version: clippy 0.0.212 (e3cb40e 2019-06-25)

#[derive(Debug)]
struct E {
    source: Option<ParseIntError>,
}

impl Error for E {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        // Clippy emits `match_as_ref` warning on this `match`
        // and suggests using `Option::as_ref()`.
        match self.source {
            Some(ref s) => Some(s),
            None => None,
        }
    //  ^ help: try this: `self.source.as_ref()`
    
    // ... but using `as_ref()` causes E0308: mismatched types.
        
    //  self.source.as_ref()
//      ^^^^^^^^^^^^^^^^^^^^ expected trait std::error::Error, found struct `std::num::ParseIntError`
// 
// = note: expected type `std::option::Option<&(dyn std::error::Error + 'static)>`
//            found type `std::option::Option<&std::num::ParseIntError>`
    }
}

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions