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

E0308 shows an incorrect suggestion if include_bytes! is used where &str is expected #51551

Closed
ghost opened this issue Jun 14, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 14, 2018

fn main() {
    let _: &str = include_bytes!("/etc/passwd");
}

playground link

error[E0308]: mismatched types
 --> bug.rs:2:19
  |
2 |     let _: &str = include_bytes!("bug.rs");
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^
  |                   |
  |                   expected str, found array of 58 elements
  |                   help: consider removing the leading `b`: `nclude_bytes!("bug.rs")`
  |
  = note: expected type `&str`
             found type `&'static [u8; 58]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

The compiler (correctly) complains about a type mismatch, but suggests something that isn't applicable, as there is no literal to remove the b from.

Suggestion: define a special case for the include_bytes! and include_str! macros. The compiler should suggest replacing the former with the latter.

Meta

Rustc version:

rustc 1.28.0-nightly (4a9c58c6b 2018-06-05)
binary: rustc
commit-hash: 4a9c58c6bd0e609538053a35685e206f66019820
commit-date: 2018-06-05
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0
@ghost ghost changed the title E0308 shows an incorrect suggestion if include_bytes! is used where a &str is expected E0308 shows an incorrect suggestion if include_bytes! is used where a &str is expected Jun 14, 2018
@ghost ghost changed the title E0308 shows an incorrect suggestion if include_bytes! is used where a &str is expected E0308 shows an incorrect suggestion if include_bytes! is used where &str is expected Jun 14, 2018
@kennytm
Copy link
Member

kennytm commented Jun 14, 2018

Duplicate of #48364.

@kennytm kennytm closed this as completed Jun 14, 2018
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

No branches or pull requests

1 participant