Skip to content

Add a cfail mode for doc comments #24565

Closed
@Manishearth

Description

@Manishearth

Many times the docs mention an error message in non-compiling Rust code to illustrate a concept. For example, the move semantics chapter illustrates how moves can cause errors.

However, it's possible that the error message may update in the future, or that the code (which is marked as rust,ignore and doesn't get fed to the doctests) will fall prey to a different error. Both (especially the latter) can be confusing to a newbie.

I propose we add a "cfail" mode to code blocks, which runs the code as a compile-fail test (via compiletest), and will fail the doctest if the error doesn't match. Something like this:

```rust,cfail
let v = vec![1, 2, 3];

let v2 = v;

println!("v[0] is: {}", v[0]);
//~^ ERROR use of moved value `v`
``‌`

We could choose to make the inline error hidden, though it might actually be helpful and could be kept visible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc 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