Skip to content

Commit 8e0d7c0

Browse files
committed
accept multi-part solutions/substitutions
This is meant to be the resolution to rust-lang#141 (and, in a way, rust-lang/rust#53934). We add two test fixtures demonstrating usage and correctness. The JSON comes from a locally-built non-master compiler featuring the change to the JSON emitter to support this. (Actually, one is from `--error-format pretty-json` and the other is from `--error-format json` and subsequent auto-formatting, but the difference in inter-string-literal newlines doesn't seem to matter.)
1 parent 8a8f0be commit 8e0d7c0

7 files changed

+297
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn collect_suggestions<S: ::std::hash::BuildHasher>(
184184
})
185185
.filter_map(collect_span)
186186
.collect();
187-
if replacements.len() == 1 {
187+
if !replacements.is_empty() {
188188
Some(Solution {
189189
message: child.message.clone(),
190190
replacements,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct Point { x: isize, y: isize }
2+
3+
fn main() {
4+
let p = Point { x: 1, y: 2 };
5+
let Point { y, .. } = p;
6+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"message": "expected `}`, found `,`",
3+
"code": null,
4+
"level": "error",
5+
"spans": [
6+
{
7+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
8+
"byte_start": 166,
9+
"byte_end": 167,
10+
"line_start": 7,
11+
"line_end": 7,
12+
"column_start": 19,
13+
"column_end": 20,
14+
"is_primary": true,
15+
"text": [
16+
{
17+
"text": " let Point { .., y, } = p;",
18+
"highlight_start": 19,
19+
"highlight_end": 20
20+
}
21+
],
22+
"label": "expected `}`",
23+
"suggested_replacement": null,
24+
"suggestion_applicability": null,
25+
"expansion": null
26+
},
27+
{
28+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
29+
"byte_start": 164,
30+
"byte_end": 167,
31+
"line_start": 7,
32+
"line_end": 7,
33+
"column_start": 17,
34+
"column_end": 20,
35+
"is_primary": false,
36+
"text": [
37+
{
38+
"text": " let Point { .., y, } = p;",
39+
"highlight_start": 17,
40+
"highlight_end": 20
41+
}
42+
],
43+
"label": "`..` must be at the end and cannot have a trailing comma",
44+
"suggested_replacement": null,
45+
"suggestion_applicability": null,
46+
"expansion": null
47+
}
48+
],
49+
"children": [
50+
{
51+
"message": "move the `..` to the end of the field list",
52+
"code": null,
53+
"level": "help",
54+
"spans": [
55+
{
56+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
57+
"byte_start": 164,
58+
"byte_end": 168,
59+
"line_start": 7,
60+
"line_end": 7,
61+
"column_start": 17,
62+
"column_end": 21,
63+
"is_primary": true,
64+
"text": [
65+
{
66+
"text": " let Point { .., y, } = p;",
67+
"highlight_start": 17,
68+
"highlight_end": 21
69+
}
70+
],
71+
"label": null,
72+
"suggested_replacement": "",
73+
"suggestion_applicability": "MachineApplicable",
74+
"expansion": null
75+
},
76+
{
77+
"file_name": "$DIR/issue-53934-multiple-parts.rs",
78+
"byte_start": 171,
79+
"byte_end": 172,
80+
"line_start": 7,
81+
"line_end": 7,
82+
"column_start": 24,
83+
"column_end": 25,
84+
"is_primary": true,
85+
"text": [
86+
{
87+
"text": " let Point { .., y, } = p;",
88+
"highlight_start": 24,
89+
"highlight_end": 25
90+
}
91+
],
92+
"label": null,
93+
"suggested_replacement": ".. }",
94+
"suggestion_applicability": "MachineApplicable",
95+
"expansion": null
96+
}
97+
],
98+
"children": [],
99+
"rendered": null
100+
}
101+
],
102+
"rendered": "error: expected `}`, found `,`
103+
--> $DIR/issue-53934-multiple-parts.rs:7:19
104+
|
105+
LL | let Point { .., y, } = p;
106+
| --^
107+
| | |
108+
| | expected `}`
109+
| `..` must be at the end and cannot have a trailing comma
110+
help: move the `..` to the end of the field list
111+
|
112+
LL | let Point { y, .. } = p;
113+
| -- ^^^^
114+
115+
"
116+
}
117+
{
118+
"message": "aborting due to previous error",
119+
"code": null,
120+
"level": "error",
121+
"spans": [],
122+
"children": [],
123+
"rendered": "error: aborting due to previous error
124+
125+
"
126+
}

tests/everything/dot-dot-not-last.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct Point { x: isize, y: isize }
2+
3+
fn main() {
4+
let p = Point { x: 1, y: 2 };
5+
let Point { .., y, } = p;
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![allow(dead_code)]
2+
#![deny(explicit_outlives_requirements)]
3+
4+
use std::fmt::Debug;
5+
6+
struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> {
7+
tee: &'a T,
8+
yoo: &'b U
9+
}
10+
11+
fn main() {}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"message": "outlives requirements can be inferred",
3+
"code": {
4+
"code": "explicit_outlives_requirements",
5+
"explanation": null
6+
},
7+
"level": "error",
8+
"spans": [
9+
{
10+
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
11+
"byte_start": 128,
12+
"byte_end": 132,
13+
"line_start": 6,
14+
"line_end": 6,
15+
"column_start": 44,
16+
"column_end": 48,
17+
"is_primary": true,
18+
"text": [
19+
{
20+
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
21+
"highlight_start": 44,
22+
"highlight_end": 48
23+
}
24+
],
25+
"label": null,
26+
"suggested_replacement": null,
27+
"suggestion_applicability": null,
28+
"expansion": null
29+
},
30+
{
31+
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
32+
"byte_start": 137,
33+
"byte_end": 142,
34+
"line_start": 6,
35+
"line_end": 6,
36+
"column_start": 53,
37+
"column_end": 58,
38+
"is_primary": true,
39+
"text": [
40+
{
41+
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
42+
"highlight_start": 53,
43+
"highlight_end": 58
44+
}
45+
],
46+
"label": null,
47+
"suggested_replacement": null,
48+
"suggestion_applicability": null,
49+
"expansion": null
50+
}
51+
],
52+
"children": [
53+
{
54+
"message": "lint level defined here",
55+
"code": null,
56+
"level": "note",
57+
"spans": [
58+
{
59+
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
60+
"byte_start": 29,
61+
"byte_end": 59,
62+
"line_start": 2,
63+
"line_end": 2,
64+
"column_start": 9,
65+
"column_end": 39,
66+
"is_primary": true,
67+
"text": [
68+
{
69+
"text": "#![deny(explicit_outlives_requirements)]",
70+
"highlight_start": 9,
71+
"highlight_end": 39
72+
}
73+
],
74+
"label": null,
75+
"suggested_replacement": null,
76+
"suggestion_applicability": null,
77+
"expansion": null
78+
}
79+
],
80+
"children": [],
81+
"rendered": null
82+
},
83+
{
84+
"message": "remove these bounds",
85+
"code": null,
86+
"level": "help",
87+
"spans": [
88+
{
89+
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
90+
"byte_start": 128,
91+
"byte_end": 132,
92+
"line_start": 6,
93+
"line_end": 6,
94+
"column_start": 44,
95+
"column_end": 48,
96+
"is_primary": true,
97+
"text": [
98+
{
99+
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
100+
"highlight_start": 44,
101+
"highlight_end": 48
102+
}
103+
],
104+
"label": null,
105+
"suggested_replacement": "",
106+
"suggestion_applicability": "MachineApplicable",
107+
"expansion": null
108+
},
109+
{
110+
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
111+
"byte_start": 137,
112+
"byte_end": 142,
113+
"line_start": 6,
114+
"line_end": 6,
115+
"column_start": 53,
116+
"column_end": 58,
117+
"is_primary": true,
118+
"text": [
119+
{
120+
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
121+
"highlight_start": 53,
122+
"highlight_end": 58
123+
}
124+
],
125+
"label": null,
126+
"suggested_replacement": "",
127+
"suggestion_applicability": "MachineApplicable",
128+
"expansion": null
129+
}
130+
],
131+
"children": [],
132+
"rendered": null
133+
}
134+
],
135+
"rendered": "error: outlives requirements can be inferred\n --> /home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs:6:44\n |\n6 | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {\n | ^^^^ ^^^^^\n |\nnote: lint level defined here\n --> /home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs:2:9\n |\n2 | #![deny(explicit_outlives_requirements)]\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nhelp: remove these bounds\n |\n6 | struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> {\n | -- --\n\n"
136+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![allow(dead_code)]
2+
#![deny(explicit_outlives_requirements)]
3+
4+
use std::fmt::Debug;
5+
6+
struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {
7+
tee: &'a T,
8+
yoo: &'b U
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)