Skip to content

absolute path names are not correct for crates not in root namespace #1920

Closed

Description

@nikomatsakis

Right now, if you get the absolute path of an item using the ty::item_path() function, and that item is an external crate x, you always get a path like x::foo::bar where foo::bar is the path to the item within the crate x. This is usually right but not always, because it is possible that the crate x is not linked into the root namespace.

For example, you might have:

mod local_mod {
    use x;
    ...
}

in which case the right path would be local_mod::x::foo::bar.

To fix this, we ought to store some valid path to the crate along with the crate metadata (preferably a shortest path [there could be more than one shortest path]). We can then prepend this path. The function csearch.rs:get_item_path() would be the primary one to change.

Activity

  1. catamorphism commented on Mar 8, 2012

    @catamorphism
    Contributor

    assigning this to @nikomatsakis since you seem to be the author of the relevant code :-)

  2. emberian commented on Jul 1, 2013

    @emberian
    Contributor

    @nikomatsakis can you clarify this, possibly with a broken test case? I don't quite understand the description.

  3. thestinger commented on Aug 19, 2013

    @thestinger
    Contributor

    Triage bump.

  4. emberian commented on Mar 18, 2014

    @emberian
    Contributor

    Visiting for triage. Presumably still an issue.

  5. steveklabnik commented on Jan 20, 2015

    @steveklabnik
    Contributor

    @nikomatsakis , I share @cmr's lack of understanding of what the issue actually is here. And it's been a loooong time. So, without some code to reproduce, I'm giving this a close.

  6. emberian commented on Jan 20, 2015

    @emberian
    Contributor

    I get this now, seeing if I can repro.

  7. emberian commented on Jan 20, 2015

    @emberian
    Contributor

    Repro:

    mod foo {
        extern crate core;
    }
    
    fn assert_clone<T>() where T : Clone { }
    
    fn main() {
        assert_clone::<foo::core::atomic::AtomicBool>();
    }
    
    csguest@itl:~$ rustc foo.rs
    foo.rs:8:2: 8:47 error: the trait `core::clone::Clone` is not implemented for the type `core::atomic::AtomicBool`
    foo.rs:8    assert_clone::<foo::core::atomic::AtomicBool>();
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  8. emberian commented on Jan 20, 2015

    @emberian
    Contributor

    (note that there is a fixme in the code, as suggested by the issue description)

  9. steveklabnik commented on Jan 20, 2015

    @steveklabnik
    Contributor

    👍 ❤️

  10. nikomatsakis commented on Feb 2, 2015

    @nikomatsakis
    ContributorAuthor

    Another related issue here is that we have no way to take into account re-exports -- see the reference to core, for example, and not std.

  11. nikomatsakis commented on Feb 2, 2015

    @nikomatsakis
    ContributorAuthor

    (Handling re-exports may require some sort of annotations though.)

  12. nikomatsakis commented on Feb 2, 2015

    @nikomatsakis
    ContributorAuthor

    ps I remember filing this bug and can hardly believe it's still a thing. ;)

  13. 2 remaining items

  14. nikomatsakis commented on Oct 4, 2015

    @nikomatsakis
    ContributorAuthor

    Hmm. There was an effort to fix this. Not sure why it is not handling that test case.I will investigate.

  15. mitaa commented on Oct 5, 2015

    @mitaa
    Contributor

    There is a compile-fail test for this case, so this should work, though this change is not in stable rust yet.

  16. jonas-schievink commented on Oct 29, 2015

    @jonas-schievink
    Contributor

    But it looks correct?

    <anon>:8:5: 8:56 error: the trait `foo::core::clone::Clone` is not implemented for the type `foo::core::sync::atomic::AtomicBool` [E0277]
    <anon>:8     assert_clone::<foo::core::sync::atomic::AtomicBool>();
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    The nightly is fine, stable isn't, so this looks fixed.

  17. nikomatsakis commented on Oct 29, 2015

    @nikomatsakis
    ContributorAuthor

    Closing as fixed, thanks!

  18. added 4 commits that reference this issue on Sep 17, 2025
  19. added a commit that references this issue on Aug 21, 2026
    ae6305b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-frontendArea: Compiler frontend (errors, parsing and HIR)E-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