Skip to content

Compiler suggests wrong import collections::borrow instead of std::borrow #26635

Closed
@colin-kiegel

Description

@colin-kiegel

Example

type T = u32;

pub fn main() {
    let boxed : Option<Box<T>> = Some(Box::new(5));

    let reference : Option<&T> = match boxed {
        Some(ref x) => Some(x.borrow()),
        None => None
    };
}

results in:

<anon>:7:31: 7:39 error: no method named `borrow` found for type `&Box<u32>` in the current scope
<anon>:7         Some(ref x) => Some(x.borrow()),
                                       ^~~~~~~~
<anon>:7:31: 7:39 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
<anon>:7:31: 7:39 help: candidate #1: use `collections::borrow::Borrow`
error: aborting due to previous error
playpen: application terminated with error code 101
Compilation failed.

it would be correct if it suggested to use std::borrow::Borrow

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions