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

Watch out for modules privacy when proposing traits to associate with an item #95080

Open
catenacyber opened this issue Mar 18, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-visibility Area: Visibility / privacy D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@catenacyber
Copy link

catenacyber commented Mar 18, 2022

Working on suricata OISF/suricata#7150

The current output is:

error[E0599]: no associated item named `MAX` found for type parameter `T` in the current scope
   --> src/detect.rs:109:18
    |
109 |         x < <T>::MAX
    |                  ^^^ associated item not found in `T`
    |
    = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `MAX`, perhaps you need to restrict type parameter `T` with one of them:
    |
104 | fn detect_parse_uint_start_greater<T: lexical_core::util::num::Float + std::str::FromStr>(i: &str) -> IResult<&str, DetectUintData<T>> {
    |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104 | fn detect_parse_uint_start_greater<T: lexical_core::util::num::Integer + std::str::FromStr>(i: &str) -> IResult<&str, DetectUintData<T>> {

This proposal looks interesting but when It tried it, I was disappointed :

error[E0603]: module `util` is private --> src/detect.rs:41:51 | 41 | fn detect_parse_uint_start_equal<T: lexical_core::util::num::Integer>(i: &str) -> IResult<&str, DetectUintData<T>> { | ^^^^ private module | note: the module `util` is defined here --> /Users/catena/.cargo/registry/src/gitpro.ttaallkk.top-1ecc6299db9ec823/lexical-core-0.7.6/src/lib.rs:189:1


<!-- The following is not always necessary. -->
Ideally the output should look like:

"the following traits define an item MAX, you could restrict the type parameter, but it is private so you can't"?

@catenacyber catenacyber added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2022
@estebank estebank added A-resolve Area: Name resolution A-visibility Area: Visibility / privacy A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Mar 18, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jun 2, 2022

This shows the same issue, without any dependencies other than std:

fn main() {
    struct A;
    A.is_minus_one();
}
error[E0599]: no method named `is_minus_one` found for struct `A` in the current scope
 --> src/main.rs:3:7
  |
2 |     struct A;
  |     --------- method `is_minus_one` not found for this
3 |     A.is_minus_one();
  |       ^^^^^^^^^^^^ method not found in `A`
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `is_minus_one`, perhaps you need to implement it:
          candidate #1: `std::sys::unix::IsMinusOne`

std::sys::unix::IsMinusOne is an internal implementation detail of std. It's declared as pub trait IsMinusOne, but it's not publicly accessible, since std::sys isn't public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-visibility Area: Visibility / privacy D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants
@m-ou-se @estebank @catenacyber and others