Skip to content

Bogus error when creating for an impl for a nonexistent type #8767

Closed

Description

@jdm
impl B {
}

fn main() {
}
/tmp/foopy.rs:1:5: 1:6 error: found value name used as a type: def_mod({crate: 0, node: 3})
/tmp/foopy.rs:1 impl B {
                     ^

Activity

  1. owaspjocur commented on Nov 5, 2013

    @owaspjocur

    Could this be fixed by "::unwrap" in the file (src/test/compile-fail/trait-or-new-type-instead.rs)

    // error-pattern: found value name used as a type
    impl Option::unwrap {
    pub fn foo(&self) {

    }

    fn main() { }
    screen shot 2013-11-05 at 11 22 35 am

  2. jdm commented on Nov 5, 2013

    @jdm
    ContributorAuthor

    @owaspjocur I don't understand your question, and that's not valid syntax. You can only create an impl for a type in the same module.

  3. owaspjocur commented on Nov 5, 2013

    @owaspjocur

    definitely I'm confused :-P. Im trying to determine how to fix this issue.Has been a while I didnt work with C like language(last 5 years have been working with C# and Java) ;-)
    If I create my own file (as you did writing the foopy.rs) and implement the same code, I get the issue. Rust is a compiler, so Im assuming that a compiler file should be fixed in order to avoid the user implement namespace overlapping imports. Is my assumption correct about this problem?

  4. jdm commented on Nov 5, 2013

    @jdm
    ContributorAuthor

    Yes, your assumption is correct. The goal is to provide an error message that makes sense when a program tries to create an impl for a type that is not in scope (ie. does not exist).

  5. owaspjocur commented on Nov 6, 2013

    @owaspjocur

    The code I provided is a Rust compiler file (which i changed), not a new one. Im trying to understand where in the code can I implement this fix

  6. jdm commented on Nov 6, 2013

    @jdm
    ContributorAuthor

    Find the place that generates the error message, and follow the code backwards until it's clear where you could modify it to produce a better error message for this case.

  7. owaspjocur commented on Nov 6, 2013

    @owaspjocur

    Someone gave me a good tip on how to debug Rust http://michaelwoerister.github.io/2013/09/27/what-you-call-the-present.html. I will try this. The terminal is quite archaic ;-P

  8. huonw commented on Nov 6, 2013

    @huonw
    Contributor

    @owaspjocur I think @jdm's point was essentially "grep for the error message, and look at the code there", using a full debugger to find out where it is is probably still quite hard at the moment.

    In any case, running git grep "found name value used as type" turns up this code here. So it looks like one could just expand the _ pattern to cover more cases.

  9. owaspjocur commented on Nov 7, 2013

    @owaspjocur

    @huonw I used Eclipse as explained by Michael and did a search and found that file. Now correct me if I'm wrong but the it seems that there is no
    "match a_def {" (startting at line 444)
    for the impl type.

    I'm going to attempt to add a case and test

  10. owaspjocur commented on Nov 13, 2013

    @owaspjocur

    @jdm in ast.rs there is an enumeration, I dont see one for 'impl' (such as DefTrait for example)
    line 226.
    Isn't suppose to be one?

  11. jdm commented on Nov 13, 2013

    @jdm
    ContributorAuthor

    No, because the name we are creating an impl for is not itself an impl; the compiler seems to think that it is a module instead. Figuring out why this is the case would be a good start.

  12. owaspjocur commented on Nov 14, 2013

    @owaspjocur

    @jdm seems like astriranna solved the issue by adding:
    ast::DefMod(_) =>

          tcx.sess.span_fatal(ast_ty.span,
    
                              format!("found module name used as a type: {:?}", a_def));
          }
    
  13. owaspjocur commented on Nov 14, 2013

    @owaspjocur

    I just tested but this does not work for 'impl' (still get the same error message)

  14. jdm commented on Nov 14, 2013

    @jdm
    ContributorAuthor

    Yes, that is not a solution, just a slightly clearer (but still incorrect) error message.

  15. added a commit that references this issue on Nov 24, 2013
  16. added a commit that references this issue on Sep 29, 2014
    b9478ee
  17. added a commit that references this issue on May 5, 2022
  18. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions