Skip to content

pub use path then use path silently cancels the reexport #14386

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
tomjakubowski opened this issue May 23, 2014 · 2 comments
Closed

pub use path then use path silently cancels the reexport #14386

tomjakubowski opened this issue May 23, 2014 · 2 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@tomjakubowski
Copy link
Contributor

mod foo {
    pub use self::bar::X;
    #[cfg(bug)]
    use self::bar::X;

    mod bar {
        pub struct X;
    }
}
fn main() {
    let _ = foo::X;
}

Just rustc 14386.rs compiles fine, but rustc --cfg bug 14386.rs fails with:

14386.rs:11:13: 11:19 error: unresolved name `foo::X`.
14386.rs:11     let _ = foo::X;
                        ^~~~~~
error: aborting due to previous error

Original report:

Re-using a re-exported item confuses the visible_private_types lint
pub use sub::Foo;
use sub::Foo;

mod sub {
    pub struct Foo;
}

pub fn blah() -> Foo {
    Foo
}

gives a warning:

private type in exported type signature, #[warn(visible_private_types)] on by default (rust)

Removing the use sub::Foo; line resolves this warning.

@tomjakubowski tomjakubowski changed the title Re-using a re-exporting item makes its visibility private again Re-using a re-exported item makes its visibility private again May 23, 2014
@tomjakubowski tomjakubowski changed the title Re-using a re-exported item makes its visibility private again Re-using a re-exported item confuses the visible_private_types lint May 23, 2014
@huonw
Copy link
Member

huonw commented Jun 16, 2014

The fundamental bug here seems to be: use can "shadow"/overrule a reexport, that is, the pub use causes Foo to be reexported, but the second use cancels that. (Updated bug.)

@huonw huonw changed the title Re-using a re-exported item confuses the visible_private_types lint pub use path then use path silently cancels the reexport Jun 16, 2014
@tomjakubowski
Copy link
Contributor Author

This now has a much nicer error message:

foo.rs:4:9: 4:21 error: a value named `X` has already been imported in this module
foo.rs:4     use self::bar::X;
                 ^~~~~~~~~~~~
foo.rs:4:9: 4:21 error: a type named `X` has already been imported in this module
foo.rs:4     use self::bar::X;
                 ^~~~~~~~~~~~
error: aborting due to 2 previous errors

(although double-printing the error, once for a value and once for a type, seems wrong)

I think it can be closed, but might need a test.

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 20, 2014
@bors bors closed this as completed in 1fd491c Dec 30, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Simple fix for make::impl_trait

This is my first PR in this project. I made this PR because I needed this function to work properly for the main PR I am working on  (rust-lang#14386). This is a small amendment to what it was before. We still need to improve this in order for it to fully comply with its syntactic definition as  stated [here](https://doc.rust-lang.org/reference/items/implementations.html).
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 17, 2023
feature : assist delegate impl

This PR ( fixes rust-lang#14386 ) introduces a new IDE assist that generates a trait impl for a struct that delegates a field. This is a draft because the current `ide_db::path_transform::PathTransform` produces some unwanted results when it deals with extern crates, an example of which I attach as a GIF.

GIFs :
1. A general case
![14386-functional](https://github.com/rust-lang/rust-analyzer/assets/20956650/22114959-caa6-45ec-a154-b4b2f458f6b1)

2. A case where `ide_db::path_transform::PathTransform` fails to correctly resolve a property ( take `Allocator` as an example ) to its full path, thus causing an error to occur. ( Not to even mention that resolving this causes another error `use of unstable library feature 'allocator_api'` to occur
![14386-erroneous](https://github.com/rust-lang/rust-analyzer/assets/20956650/922ca715-594e-4168-a579-7c5c006f93aa)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

3 participants