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

"Found value name used as type" #7607

Closed
bytwise opened this issue Jul 5, 2013 · 3 comments · Fixed by #17321
Closed

"Found value name used as type" #7607

bytwise opened this issue Jul 5, 2013 · 3 comments · Fixed by #17321
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@bytwise
Copy link
Contributor

bytwise commented Jul 5, 2013

Trying to compile:

struct Foo {
    x: int
}

impl Fo {
    fn foo() {}
}

fn main() {}

gives the unhelpful error:

main.rs:5:5: 5:7 error: found value name used as a type: def_mod({crate: 0, node: 13})
main:rs:5 impl Fo {
               ^~

A better error message would be:

error: use of undeclared type name `Fo`

Even better would be, if it could recognize the typo:

error: use of undeclared type name `Fo`. Did you mean `Foo`?
@nikomatsakis
Copy link
Contributor

The problem is not just a matter of an error message. I encountered the same error with this example:

pub mod a {
    pub struct Foo { a: uint }
}

pub mod b {
    use a::Foo;
    impl Foo { // ERROR: found value name used as type
        fn bar(&self) { }
    }
}

pub fn main() { }

Somehow the impl seems to "override" imported struct names? Or at least interact badly with them. Rewriting to impl a::Foo works.

@nikomatsakis
Copy link
Contributor

Adjusting title.

@domluna
Copy link

domluna commented Aug 9, 2013

I'm also getting the error in this context:

enum Shape {
    Circle { center: Point, radius: float },
    Rectangle { top_left: Point, bottom_right: Point }
}

impl Circle {
    fn area(&self) -> float {
        self.radius * self.radius * float::consts::pi
    }
}

I get "error: found value name used as type", so I'm thinking that because Circle is defined inside Shape it doesn't recognize Circle is actually type, due to closure I'm guessing.

One way to get around this in my particular case is defining the types outside of the Shape enum.

struct Circle { center: Point, radius: float }
struct Rectangle { top_left: Point, bottom_right: Point }

enum Shape {
    Circle,
    Rectangle
}

impl Circle {
    fn area(&self) -> float {
        self.radius * self.radius * float::consts::pi
    }
}

apoelstra added a commit to apoelstra/rust that referenced this issue Sep 28, 2014
bors added a commit that referenced this issue Sep 29, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 8, 2021
`mut_range_bound` check for immediate break after mutation

closes rust-lang#7532

`mut_range_bound` ignores mutation on range bounds that is placed immediately before break. Still warns if the break is not always reachable.

changelog: [`mut_range_bound`] ignore range bound mutations before immediate break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants