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

Wrong error message when attempting to use a trait method's result as array length #48701

Closed
gnzlbg opened this Issue Mar 3, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@gnzlbg
Copy link
Contributor

gnzlbg commented Mar 3, 2018

The following code came up on IRC. It cannot ever work, but the error message is completely wrong (playground):

pub trait Foo { fn foo() -> usize; }

struct Bar();
impl Foo for Bar { fn foo() -> usize { 3 } }

fn baz<F: Foo>() {
    let _x = [0_u32; <F as Foo>::foo()];
}

fn main() {
    baz::<Bar>();
}

outputs:

error[E0277]: the trait bound `F: Foo` is not satisfied
 --> src/main.rs:7:22
  |
7 |     let _x = [0_u32; <F as Foo>::foo()];
  |                      ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `F`
  |
  = help: consider adding a `where F: Foo` bound
  = note: required by `Foo::foo`

This error messages is 100% wrong: F does implement the trait Foo since the function signature does require it.

@gnzlbg gnzlbg changed the title Confusing error message when using trait method for array length Wrong error message when using trait method for array length Mar 3, 2018

@gnzlbg gnzlbg changed the title Wrong error message when using trait method for array length Wrong error message when attempting to use a trait method's result as array length Mar 3, 2018

@gnzlbg

This comment has been minimized.

Copy link
Contributor Author

gnzlbg commented Mar 8, 2018

Is this a duplicate of: #44168 ? That one uses an associated constant but they do look really similar otherwise.

@dtolnay

This comment has been minimized.

Copy link
Member

dtolnay commented Jun 9, 2018

Closing as a duplicate of #44168. The "trait bounds don't work in array length" aspect of this is the same issue.

@dtolnay dtolnay closed this Jun 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.