Skip to content

Misleading error on tuple struct field with docstring #122463

Open
@tbillington

Description

@tbillington

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=48a7a316c9d4825be960974fd87a8d8d

struct Foo {
    a: Vec<(
        /// Docstring
        f32,
        f32,
    )>,
}

I expected to see this happen: Add docstring to field in tuple struct

Instead, this happened: Misleading second error "constant provided when a type was expected".

   Compiling playground v0.0.1 (/playground)
error: expected type, found doc comment `/// Docstring`
 --> src/lib.rs:3:9
  |
3 |         /// Docstring
  |         ^^^^^^^^^^^^^ expected type
  |
help: expressions must be enclosed in braces to be used as const generic arguments
  |
2 ~     a: Vec<{ (
3 |         /// Docstring
4 |         f32,
5 |         f32,
6 ~     ) }>,
  |

error[E0747]: constant provided when a type was expected
 --> src/lib.rs:2:12
  |
2 |       a: Vec<(
  |  ____________^
3 | |         /// Docstring
4 | |         f32,
5 | |         f32,
6 | |     )>,
  | |_____^

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: aarch64-apple-darwin
release: 1.76.0
LLVM version: 17.0.6

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 ASTC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions