Skip to content

Concatenating bytestrings fails; rustc suggests non-existent bconcat!() #52710

Closed
@jsgf

Description

@jsgf

concat!() doesn't work on bytestrings (why?). When trying it, it fails with:

1 | const FOO: &[u8] = concat!("foo", "bar");
  |                    ^^^^^^^^^^^^^^^^^^^^^
  |                    |
  |                    expected slice, found str
  |                    help: consider adding a leading `b`: `bconcat!("foo", "bar")`
  |
  = note: expected type `&'static [u8]`
             found type `&'static str`

bconcat!() sounds interesting, but it isn't documented, and the compiler doesn't accept it:

error: cannot find macro `bconcat!` in this scope
 --> src/main.rs:1:20
  |
1 | const FOO: &[u8] = bconcat!("foo", "bar");
  |                    ^^^^^^^ help: you could try the macro: `concat`

I think the real fix here is that bconcat!() should exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions