Skip to content

Commit

Permalink
accept multi-part solutions/substitutions
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
zackmdavis committed Feb 6, 2019
1 parent 8a8f0be commit 8e0d7c0
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn collect_suggestions<S: ::std::hash::BuildHasher>(
})
.filter_map(collect_span)
.collect();
if replacements.len() == 1 {
if !replacements.is_empty() {
Some(Solution {
message: child.message.clone(),
replacements,
Expand Down
6 changes: 6 additions & 0 deletions tests/everything/dot-dot-not-last.fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Point { x: isize, y: isize }

fn main() {
let p = Point { x: 1, y: 2 };
let Point { y, .. } = p;
}
126 changes: 126 additions & 0 deletions tests/everything/dot-dot-not-last.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"message": "expected `}`, found `,`",
"code": null,
"level": "error",
"spans": [
{
"file_name": "$DIR/issue-53934-multiple-parts.rs",
"byte_start": 166,
"byte_end": 167,
"line_start": 7,
"line_end": 7,
"column_start": 19,
"column_end": 20,
"is_primary": true,
"text": [
{
"text": " let Point { .., y, } = p;",
"highlight_start": 19,
"highlight_end": 20
}
],
"label": "expected `}`",
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
},
{
"file_name": "$DIR/issue-53934-multiple-parts.rs",
"byte_start": 164,
"byte_end": 167,
"line_start": 7,
"line_end": 7,
"column_start": 17,
"column_end": 20,
"is_primary": false,
"text": [
{
"text": " let Point { .., y, } = p;",
"highlight_start": 17,
"highlight_end": 20
}
],
"label": "`..` must be at the end and cannot have a trailing comma",
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
}
],
"children": [
{
"message": "move the `..` to the end of the field list",
"code": null,
"level": "help",
"spans": [
{
"file_name": "$DIR/issue-53934-multiple-parts.rs",
"byte_start": 164,
"byte_end": 168,
"line_start": 7,
"line_end": 7,
"column_start": 17,
"column_end": 21,
"is_primary": true,
"text": [
{
"text": " let Point { .., y, } = p;",
"highlight_start": 17,
"highlight_end": 21
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "$DIR/issue-53934-multiple-parts.rs",
"byte_start": 171,
"byte_end": 172,
"line_start": 7,
"line_end": 7,
"column_start": 24,
"column_end": 25,
"is_primary": true,
"text": [
{
"text": " let Point { .., y, } = p;",
"highlight_start": 24,
"highlight_end": 25
}
],
"label": null,
"suggested_replacement": ".. }",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],
"children": [],
"rendered": null
}
],
"rendered": "error: expected `}`, found `,`
--> $DIR/issue-53934-multiple-parts.rs:7:19
|
LL | let Point { .., y, } = p;
| --^
| | |
| | expected `}`
| `..` must be at the end and cannot have a trailing comma
help: move the `..` to the end of the field list
|
LL | let Point { y, .. } = p;
| -- ^^^^

"
}
{
"message": "aborting due to previous error",
"code": null,
"level": "error",
"spans": [],
"children": [],
"rendered": "error: aborting due to previous error

"
}
6 changes: 6 additions & 0 deletions tests/everything/dot-dot-not-last.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Point { x: isize, y: isize }

fn main() {
let p = Point { x: 1, y: 2 };
let Point { .., y, } = p;
}
11 changes: 11 additions & 0 deletions tests/everything/explicit-outlives-multispan.fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(dead_code)]
#![deny(explicit_outlives_requirements)]

use std::fmt::Debug;

struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T, U: Debug> {
tee: &'a T,
yoo: &'b U
}

fn main() {}
136 changes: 136 additions & 0 deletions tests/everything/explicit-outlives-multispan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"message": "outlives requirements can be inferred",
"code": {
"code": "explicit_outlives_requirements",
"explanation": null
},
"level": "error",
"spans": [
{
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
"byte_start": 128,
"byte_end": 132,
"line_start": 6,
"line_end": 6,
"column_start": 44,
"column_end": 48,
"is_primary": true,
"text": [
{
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
"highlight_start": 44,
"highlight_end": 48
}
],
"label": null,
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
},
{
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
"byte_start": 137,
"byte_end": 142,
"line_start": 6,
"line_end": 6,
"column_start": 53,
"column_end": 58,
"is_primary": true,
"text": [
{
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
"highlight_start": 53,
"highlight_end": 58
}
],
"label": null,
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
}
],
"children": [
{
"message": "lint level defined here",
"code": null,
"level": "note",
"spans": [
{
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
"byte_start": 29,
"byte_end": 59,
"line_start": 2,
"line_end": 2,
"column_start": 9,
"column_end": 39,
"is_primary": true,
"text": [
{
"text": "#![deny(explicit_outlives_requirements)]",
"highlight_start": 9,
"highlight_end": 39
}
],
"label": null,
"suggested_replacement": null,
"suggestion_applicability": null,
"expansion": null
}
],
"children": [],
"rendered": null
},
{
"message": "remove these bounds",
"code": null,
"level": "help",
"spans": [
{
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
"byte_start": 128,
"byte_end": 132,
"line_start": 6,
"line_end": 6,
"column_start": 44,
"column_end": 48,
"is_primary": true,
"text": [
{
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
"highlight_start": 44,
"highlight_end": 48
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "/home/zmd/Code/rustfix/tests/everything/explicit-outlives-multispan.rs",
"byte_start": 137,
"byte_end": 142,
"line_start": 6,
"line_end": 6,
"column_start": 53,
"column_end": 58,
"is_primary": true,
"text": [
{
"text": "struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {",
"highlight_start": 53,
"highlight_end": 58
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],
"children": [],
"rendered": null
}
],
"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"
}
11 changes: 11 additions & 0 deletions tests/everything/explicit-outlives-multispan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(dead_code)]
#![deny(explicit_outlives_requirements)]

use std::fmt::Debug;

struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> {
tee: &'a T,
yoo: &'b U
}

fn main() {}

0 comments on commit 8e0d7c0

Please sign in to comment.