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

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

Open
Rudxain opened this issue Feb 5, 2025 · 0 comments
Open

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

Rudxain opened this issue Feb 5, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rudxain
Copy link
Contributor

Rudxain commented Feb 5, 2025

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

@Rudxain Rudxain added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2025
@Rudxain Rudxain changed the title const* causing multiple unrelated errors and a suggestion that won't compile const* suggestions won't compile, and no suggestion for *const Feb 5, 2025
@workingjubilee workingjubilee added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Feb 6, 2025
@fmease fmease added the A-parser Area: The parsing of Rust source code to an AST label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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

3 participants