Skip to content

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

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

Closed
nikomatsakis opened this issue Mar 3, 2012 · 19 comments
Closed
Assignees
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@nikomatsakis
Copy link
Contributor

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.

@ghost ghost assigned nikomatsakis Mar 8, 2012
@catamorphism
Copy link
Contributor

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

@emberian
Copy link
Member

emberian commented Jul 1, 2013

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

@thestinger
Copy link
Contributor

Triage bump.

@emberian
Copy link
Member

Visiting for triage. Presumably still an issue.

@steveklabnik
Copy link
Member

@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.

@emberian
Copy link
Member

I get this now, seeing if I can repro.

@emberian emberian reopened this Jan 20, 2015
@emberian
Copy link
Member

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>();
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@emberian
Copy link
Member

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

@steveklabnik
Copy link
Member

👍 ❤️

@nikomatsakis
Copy link
Contributor Author

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.

@nikomatsakis
Copy link
Contributor Author

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

@nikomatsakis
Copy link
Contributor Author

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

bors added a commit that referenced this issue Aug 5, 2015
This changes the current behaviour for two cases (that I know of)
```rust
mod foo {
    extern crate bar;
}
// `bar::` changes to `foo::bar::`
```

```rust
extern crate bar as quux;
// `bar::` changes to `quux::`
```
For example:
```rust
mod foo {
    extern crate core;
}

fn assert_clone<T>() where T : Clone { }

fn main() {
    assert_clone::<foo::core::atomic::AtomicBool>();
    // error: the trait `core::clone::Clone` is not implemented for the type `core::atomic::AtomicBool` [E0277]
    // changes to
    // error: the trait `foo::core::clone::Clone` is not implemented for the type `foo::core::atomic::AtomicBool` [E0277]
}
```

Notably the following test case broke:
```rust
 #[bench]
 fn bar(x: isize) { }
 //~^ ERROR mismatched types
 //~| expected `fn(&mut test::Bencher)`
 // changed to
 //~| expected `fn(&mut __test::test::Bencher)`
```
If a crate is linked multiple times the path with the least segments is stored.
Partially addresses #1920. (this doesn't solve the issue raised about re-exports)

r? @nikomatsakis
@carols10cents
Copy link
Member

(Hi, I'm trying to help make E-easy issues more accessible to newcomers 😸)

Yup, the failing test case above is still reproducible, although I no longer see a fixme anywhere near csearch.rs:get_item_path().

I'm not at all clear on what would need to be changed about get_item_path to make the test case pass though, especially with all the short variable names... @nikomatsakis could you clarify a bit, with kind of an outline of what needs to be changed? Or is this issue not really E-easy?

@nikomatsakis
Copy link
Contributor Author

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

@mitaa
Copy link
Contributor

mitaa commented Oct 5, 2015

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

@ghost
Copy link

ghost commented Oct 29, 2015

Updated test case:

mod foo {
    extern crate core;
}

fn assert_clone<T>() where T : Clone { }

fn main() {
    assert_clone::<foo::core::sync::atomic::AtomicBool>();
}

Still reproducible on the current nightly (2015-10-27)

@jonas-schievink
Copy link
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.

@nikomatsakis
Copy link
Contributor Author

Closing as fixed, thanks!

@ghost
Copy link

ghost commented Oct 29, 2015

@jonas-schievink oops sorry, you're right, this is fixed.

celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

8 participants