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

Rename private function Adc::read to Adc::inner_read #695

Merged
merged 1 commit into from
Sep 27, 2023

Conversation

jannic
Copy link
Member

@jannic jannic commented Sep 26, 2023

The name conflicts with the public trait method OneShot::read. This isn't an issue with correct programs, as rustc just uses the visible function when called from other crates.

But if you forget importing OneShot, you get a confusing error message:

error[E0624]: method `read` is private
   --> rp2040-hal/examples/adc.rs:116:45
    |
116 |         let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap();
    |                                             ^^^^ private method
    |
   ::: /home/jan/rp2040/rp-rs/rp-hal/rp2040-hal/src/adc.rs:302:5
    |
302 |     fn read(&mut self, chan: u8) -> u16 {
    |     ----------------------------------- private method defined here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
15  + use cortex_m::prelude::_embedded_hal_adc_OneShot;
    |

Note that the referenced method in line 302 is not the one that should be called, and also has different parameters.

(This was noticed in rp-rs/rp-hal-boards#42)

The name conflicts with the public trait method OneShot::read.
This isn't an issue with correct programs, as rustc just uses the
visible function when called from other crates.

But if you forget importing OneShot, you get a confusing error message:

```
error[E0624]: method `read` is private
   --> rp2040-hal/examples/adc.rs:116:45
    |
116 |         let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap();
    |                                             ^^^^ private method
    |
   ::: /home/jan/rp2040/rp-rs/rp-hal/rp2040-hal/src/adc.rs:302:5
    |
302 |     fn read(&mut self, chan: u8) -> u16 {
    |     ----------------------------------- private method defined here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
15  + use cortex_m::prelude::_embedded_hal_adc_OneShot;
    |
```

Note that the referenced method in line 302 is not the one that should
be called, and also has different parameters.

(This was noticed in rp-rs/rp-hal-boards#42)
@jannic
Copy link
Member Author

jannic commented Sep 26, 2023

For comparison, with this change, the error message becomes:

error[E0599]: no method named `read` found for struct `Adc` in the current scope
   --> rp2040-hal/examples/adc.rs:116:45
    |
116 |         let temp_sens_adc_counts: u16 = adc.read(&mut temperature_sensor).unwrap();
    |                                             ^^^^ method not found in `Adc`
    |
   ::: /home/jan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-hal-0.2.7/src/adc.rs:97:8
    |
97  |     fn read(&mut self, pin: &mut Pin) -> nb::Result<Word, Self::Error>;
    |        ---- the method is available for `Adc` here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
15  + use cortex_m::prelude::_embedded_hal_adc_OneShot;
    |

@jannic jannic merged commit fcebdea into rp-rs:main Sep 27, 2023
8 checks passed
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 this pull request may close these issues.

2 participants