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

privacy: error messages could do better at telling me why something is private #13641

Closed
pnkfelix opened this issue Apr 20, 2014 · 2 comments · Fixed by #13647
Closed

privacy: error messages could do better at telling me why something is private #13641

pnkfelix opened this issue Apr 20, 2014 · 2 comments · Fixed by #13647

Comments

@pnkfelix
Copy link
Member

Consider this code:

mod a {
    #[cfg(not(fixed))]
    struct Foo;
    #[cfg(fixed)]
    pub struct Foo;

    impl Foo {
        pub fn new() -> Foo {
            Foo
        }
    }
}

fn main() {
    let foo = a::Foo::new();

    println!("foo: {:?}", foo);
}

When I run rustc today:

% rustc --version
/Users/pnkfelix/opt/rust-dbg/bin/rustc 0.10-pre (d79fbba 2014-03-29 18:56:36 -0700)
host: x86_64-apple-darwin
% rustc /tmp/f.rs
/tmp/f.rs:15:15: 15:26 error: static method `new` is inaccessible
/tmp/f.rs:15     let foo = a::Foo::new();
                           ^~~~~~~~~~~
error: aborting due to previous error
% 

The reason that new is inaccessible, AFAICT, is because Foo is private. However, this is not really relayed in the error message; my first instinct is to look at the definition of new itself, which has been declared pub.

(I had thought there was a related bug filed somewhere about saying that if something is private due to an intermediate non-pub mod along a chain, we could do a better job of pointing the user at one or more of the non-pub mods that would need to be made pub. Obviously that's not perfect since an item may be accessible via more than one path, and so any such suggestion coukd be misleading. But I could not find that related bug. Anyway, the situation today is not ideal.)

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 20, 2014
This gives a better NOTE error message when a privacy error is encountered with
a static method. Previously no note was emitted (due to lack of support), but
now a note is emitted indicating that the struct/enum itself is private.

Closes rust-lang#13641
bors added a commit that referenced this issue Apr 20, 2014
This gives a better NOTE error message when a privacy error is encountered with
a static method. Previously no note was emitted (due to lack of support), but
now a note is emitted indicating that the struct/enum itself is private.

Closes #13641
@pnkfelix
Copy link
Member Author

I had thought there was a related bug filed somewhere about saying that if something is private due to an intermediate non-pub mod along a chain

I was probably thinking of #13422 when I wrote that. (There are probably many places where it is hard to tell what the source of non-pubness is...)

@alexcrichton
Copy link
Member

It's true that there's a bunch of cases, but I'd love to know about missing ones like this!

Manishearth pushed a commit to Manishearth/rust that referenced this issue Nov 23, 2022
…ring, r=Veykril

fix: format expression parsing edge-cases

- Handle positional arguments with formatting options (i.e. `{:b}`). Previously copied `:b` as an argument, producing broken code.

- Handle indexed positional arguments (`{0}`) ([reference](https://doc.rust-lang.org/std/fmt/#positional-parameters)). Previously copied over `0` as an argument.

Note: the assist also breaks when named arguments are used (`"{name}$0", name = 2 + 2` is converted to `"{}"$0, name`. I'm working on fix for that as well.
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 7, 2024
…ntri3

needless_continue: check labels consistency before warning

changelog: [`needless_continue`]: check labels before warning about `continue` as the last statement in a loop body

Fix rust-lang#13641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants