Skip to content

Spurious error reported after name not found in scope #58712

Closed
@joshlf

Description

@joshlf

I have the following code:

impl<H> AddrVec<H, DeviceId> {
    pub fn device(&self) -> DeviceId {
        self.tail()
    }
}

I forgot to use DeviceId, so it wasn't in scope. rustc gave me the following errors:

error[E0412]: cannot find type `DeviceId` in this scope
   --> src/address.rs:343:20
    |
343 | impl<H> AddrVec<H, DeviceId> {
    |                    ^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
    |
5   | use crate::device::DeviceId;
    |

error[E0412]: cannot find type `DeviceId` in this scope
   --> src/address.rs:344:29
    |
344 |     pub fn device(&self) -> DeviceId {
    |                             ^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
    |
5   | use crate::device::DeviceId;
    |

error[E0307]: invalid method receiver type: &address::AddrVec<H, [type error]>
   --> src/address.rs:344:19
    |
344 |     pub fn device(&self) -> DeviceId {
    |                   ^^^^^
    |
    = note: type must be `Self` or a type that dereferences to it
    = help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`

Maybe this is the intended behavior, but it seems odd to report an invalid method receiver type error simply because the type's name was unknown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions