Skip to content

const* suggestions won't compile, and no suggestion for *const #136602

Open
@Rudxain

Description

@Rudxain

Code

const C: [u8; 1] = [0];
pub const P: const* u8 = &C as _;

Current output

Compiling tmp v0.1.0 (/home/rudxain/tmp)
error: expected `mut` or `const` keyword in raw pointer type
 --> src/lib.rs:2:19
  |
2 | pub const P: const* u8 = &C as _;
  |                   ^
  |
help: add `mut` or `const` here
  |
2 | pub const P: const*mut  u8 = &C as _;
  |                    +++
2 | pub const P: const*const  u8 = &C as _;
  |                    +++++

error: expected a trait, found type
 --> src/lib.rs:2:19
  |
2 | pub const P: const* u8 = &C as _;
  |                   ^^^^
  |
help: consider removing the indirection
  |
2 - pub const P: const* u8 = &C as _;
2 + pub const P: constu8 = &C as _;
  |

error: const trait bounds are not allowed in trait object types
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^^^^^

error[E0404]: expected trait, found builtin type `u8`
 --> src/lib.rs:2:21
  |
2 | pub const P: const* u8 = &C as _;
  |                     ^^ not a trait

error[E0658]: const trait impls are experimental
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^
  |
  = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information

error[E0782]: expected a type, found a trait
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
2 | pub const P: dyn const* u8 = &C as _;
  |              +++

Desired output

Compiling tmp v0.1.0 (/home/rudxain/tmp)
error: raw pointer type must have a star before the mutability keyword
 --> src/lib.rs:2:19
  |
2 | pub const P: const* u8 = &C as _;
  |                   ^
  |
help: move it to the other side
  |
2 | pub const P: const* u8 = &C as _;
  |                   -
2 | pub const P: *const u8 = &C as _;
  |              +

error: expected `mut` or `const` keyword in raw pointer type
 --> src/lib.rs:2:19
  |
2 | pub const P: const* u8 = &C as _;
  |                   ^
  |
help: add `mut` or `const` here
  |
2 | pub const P: const*mut  u8 = &C as _;
  |                    +++
2 | pub const P: const*const  u8 = &C as _;
  |                    +++++

error: const trait bounds are not allowed in trait object types
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^^^^^

error[E0404]: expected trait, found builtin type `u8`
 --> src/lib.rs:2:21
  |
2 | pub const P: const* u8 = &C as _;
  |                     ^^ not a trait

error[E0658]: const trait impls are experimental
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^
  |
  = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information

error[E0782]: expected a type, found a trait
 --> src/lib.rs:2:14
  |
2 | pub const P: const* u8 = &C as _;
  |              ^^^^^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
2 | pub const P: dyn const* u8 = &C as _;
  |              +++

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-unknown-linux-gnu
release: 1.84.1
LLVM version: 19.1.5

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler 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