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

Compiler refuses code, demanding bound that's provided #54973

Closed
thenewwazoo opened this issue Oct 10, 2018 · 2 comments
Closed

Compiler refuses code, demanding bound that's provided #54973

thenewwazoo opened this issue Oct 10, 2018 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@thenewwazoo
Copy link

thenewwazoo commented Oct 10, 2018

This is a more complex, but different, case as #54972.

When I try to compile:

use std::marker::PhantomData;

struct Pin;
struct Adc<MODE>(PhantomData<MODE>) where MODE: RunMode;

trait RunMode {}

trait Channel<ADC> {
    type ID;
    const CHANNEL: Self::ID;
}

impl<MODE> Channel<Adc<MODE>> for Pin where MODE: RunMode {
    type ID = u8;
    const CHANNEL: u8 = 0;
}

the compiler refuses it with the error:

error[E0277]: the size for values of type `MODE` cannot be known at compilation time
  --> src/lib.rs:17:5
   |
17 |     const CHANNEL: u8 = 0;
   |     ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `MODE`
   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-sized>
   = help: consider adding a `where MODE: std::marker::Sized` bound
   = note: required because of the requirements on the impl of `Channel<Adc<MODE>>` for `Pin`

error[E0277]: the trait bound `MODE: RunMode` is not satisfied
  --> src/lib.rs:17:5
   |
17 |     const CHANNEL: u8 = 0;
   |     ^^^^^^^^^^^^^^^^^^^^^^ the trait `RunMode` is not implemented for `MODE`
   |
   = help: consider adding a `where MODE: RunMode` bound
   = note: required because of the requirements on the impl of `Channel<Adc<MODE>>` for `Pin`

error: aborting due to 2 previous errors

Similarly to #54972, if I add MODE: ?Sized bounds to lines 4 and 15, the Sized (first) error goes away, but the RunMode (second) one does not.

@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. A-const-eval Area: Constant evaluation (MIR interpretation) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2019
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Oct 8, 2019
@estebank
Copy link
Contributor

estebank commented Oct 8, 2019

This seems to compile correctly now?

@estebank estebank removed D-confusing Diagnostics: Confusing error or lint that should be reworked. D-papercut Diagnostics: An error or lint that needs small tweaks. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Oct 8, 2019
@estebank
Copy link
Contributor

estebank commented Oct 8, 2019

Accepted since 1.35.

@estebank estebank closed this as completed Oct 8, 2019
bors bot added a commit to rust-embedded/embedded-hal that referenced this issue Apr 13, 2020
198: Add MSRV configuration to CI r=therealprof a=eldruin

The compatibility with the MSRV should be checked by the CI. At the moment that is Rust 1.35.0 due to [this issue](rust-lang/rust#54973).
The MSRV and its update process should probably also be documented in the README.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. 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

2 participants