Description
The error message for the following has changed so that that JSON spans include file names into the standard library:
struct S;
pub fn f() {
let x = vec![1,2,3];
let x = vec![S; x.len()];
}
With JSON output, previously this had a span that looked like this:
// Rust 1.43 output
{
"byte_end": 60,
"byte_start": 33,
"column_end": 61,
"column_start": 34,
"expansion": {
"def_site_span": {
"byte_end": 198,
"byte_start": 0,
"column_end": 55,
"column_start": 1,
"expansion": null,
"file_name": "<::alloc::macros::vec macros>",
"is_primary": false,
"label": null,
"line_end": 3,
"line_start": 1,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": [
{
"highlight_end": 78,
"highlight_start": 1,
"text": "($ elem : expr ; $ n : expr) => ($ crate :: vec :: from_elem ($ elem, $ n)) ;"
},
{
"highlight_end": 66,
"highlight_start": 1,
"text": "($ ($ x : expr), *) => (< [_] > :: into_vec (box [$ ($ x), *])) ;"
},
{
"highlight_end": 55,
"highlight_start": 1,
"text": "($ ($ x : expr,) *) => ($ crate :: vec ! [$ ($ x), *])"
}
]
},
"macro_decl_name": "vec!",
"span": {
"byte_end": 79,
"byte_start": 62,
"column_end": 30,
"column_start": 13,
"expansion": null,
"file_name": "src/lib.rs",
"is_primary": false,
"label": null,
"line_end": 5,
"line_start": 5,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": [
{
"highlight_end": 30,
"highlight_start": 13,
"text": " let x = vec![S; x.len()];"
}
]
}
},
"file_name": "<::alloc::macros::vec macros>",
"is_primary": true,
"label": "the trait `std::clone::Clone` is not implemented for `S`",
"line_end": 1,
"line_start": 1,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": [
{
"highlight_end": 61,
"highlight_start": 34,
"text": "($ elem : expr ; $ n : expr) => ($ crate :: vec :: from_elem ($ elem, $ n)) ;"
}
]
},
Pay attention to the "file_name" field, it now includes a span that references macros.rs
instead of <::alloc::macros::vec macros>
. There are other differences, such as missing text
rendering. The new output is:
// Rust 1.44 (nightly) output
{
"byte_end": 1284,
"byte_start": 1262,
"column_end": 31,
"column_start": 9,
"expansion": {
"def_site_span": {
"byte_end": 1420,
"byte_start": 1204,
"column_end": 2,
"column_start": 1,
"expansion": null,
"file_name": "/rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/liballoc/macros.rs",
"is_primary": false,
"label": null,
"line_end": 46,
"line_start": 38,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": []
},
"macro_decl_name": "vec!",
"span": {
"byte_end": 79,
"byte_start": 62,
"column_end": 30,
"column_start": 13,
"expansion": null,
"file_name": "src/lib.rs",
"is_primary": false,
"label": null,
"line_end": 5,
"line_start": 5,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": [
{
"highlight_end": 30,
"highlight_start": 13,
"text": " let x = vec![S; x.len()];"
}
]
}
},
"file_name": "/rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/liballoc/macros.rs",
"is_primary": true,
"label": "the trait `std::clone::Clone` is not implemented for `S`",
"line_end": 40,
"line_start": 40,
"suggested_replacement": null,
"suggestion_applicability": null,
"text": []
},
This is a problem because the path /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a
doesn't exist, so there is nothing to point to. Additionally, tools may be expecting the previous behavior of a … macros>
value in the "file_name".
Note that this seems particular to using a const expression in the example above (a literal such as 3
doesn't have the same effect).
This seems to have started with #66364 (cc @Centril).
rustc 1.44.0-nightly (38114ff16 2020-03-21)