Skip to content

Regression in rustc JSON message format #16074

@ehuss

Description

@ehuss

Problem

Starting with #16002, the "explanation" field has disappeared from rustc's JSON output. cc @jneem

rustc's format is documented at https://doc.rust-lang.org/nightly/rustc/json.html.

Steps

Run cargo check --message-format=json on a project with the following main.rs:

fn main() {
    const OH_NO: &'static mut usize = &mut 1; // error!
}

In Rust 1.91, you should have something that says:

{
//...
        "code":
        {
            "code": "E0764",
            "explanation": "A mutable reference was used in a constant.\n\nErroneous code example:\n\n```compile_fail,E0764\nfn main() {\n    const OH_NO: &'static mut usize = &mut 1; // error!\n}\n```\n\nMutable references (`&mut`) can only be used in constant functions, not statics\nor constants. This limitation exists to prevent the creation of constants that\nhave a mutable reference in their final value. If you had a constant of\n`&mut i32` type, you could modify the value through that reference, making the\nconstant essentially mutable.\n\nWhile there could be a more fine-grained scheme in the future that allows\nmutable references if they are not \"leaked\" to the final value, a more\nconservative approach was chosen for now. `const fn` do not have this problem,\nas the borrow checker will prevent the `const fn` from returning new mutable\nreferences.\n\nRemember: you cannot use a function call inside a constant or static. However,\nyou can totally use it in constant functions:\n\n```\nconst fn foo(x: usize) -> usize {\n    let mut y = 1;\n    let z = &mut y;\n    *z += x;\n    y\n}\n\nfn main() {\n    const FOO: usize = foo(10); // ok!\n}\n```\n"
        },
// ...
}

In nightly, it is:

{
// ...
       "code":
        {
            "code": "E0764"
        }
// ...
}

Possible Solution(s)

Generally, cargo should be forwarding rustc's output as directly as possible without dropping fields or modifying its values.

Notes

No response

Version

cargo 1.92.0-nightly (801d9b498 2025-10-04)
release: 1.92.0-nightly
commit-hash: 801d9b4981dd07e3aecdca1ab86834c13615737e
commit-date: 2025-10-04
host: aarch64-apple-darwin
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.7.1 (sys:0.4.83+curl-8.15.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 15.6.1 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-json-outputArea: JSON message outputC-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewregression-from-stable-to-nightlyRegression in nightly that previously worked in stable.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions