Rollup merge of #62995 - estebank:issue-62973, r=varkor
Avoid ICE when suggestion span is at Eof Fix #62973.
This commit is contained in:
commit
a3cae5740c
4 changed files with 85 additions and 3 deletions
|
@ -226,7 +226,8 @@ impl CodeSuggestion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
|
if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
|
||||||
buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
|
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
|
||||||
|
buf.push_str(&cur_line[..end]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.push_str(&part.snippet);
|
buf.push_str(&part.snippet);
|
||||||
|
|
8
src/test/ui/parser/issue-62973.rs
Normal file
8
src/test/ui/parser/issue-62973.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// ignore-tidy-trailing-newlines
|
||||||
|
// error-pattern: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
fn p() { match s { v, E { [) {) }
|
||||||
|
|
||||||
|
|
61
src/test/ui/parser/issue-62973.stderr
Normal file
61
src/test/ui/parser/issue-62973.stderr
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
error: this file contains an un-closed delimiter
|
||||||
|
--> $DIR/issue-62973.rs:8:2
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| - - un-closed delimiter
|
||||||
|
| |
|
||||||
|
| un-closed delimiter
|
||||||
|
LL |
|
||||||
|
LL |
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: expected one of `,` or `}`, found `{`
|
||||||
|
--> $DIR/issue-62973.rs:6:25
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| - ^ expected one of `,` or `}` here
|
||||||
|
| |
|
||||||
|
| while parsing this struct
|
||||||
|
|
||||||
|
error: struct literals are not allowed here
|
||||||
|
--> $DIR/issue-62973.rs:6:16
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| ________________^
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
| |_^
|
||||||
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
||||||
|
LL | fn p() { match (s { v, E { [) {) }
|
||||||
|
LL |
|
||||||
|
LL | )
|
||||||
|
|
|
||||||
|
|
||||||
|
error: expected one of `.`, `?`, `{`, or an operator, found `}`
|
||||||
|
--> $DIR/issue-62973.rs:8:1
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| ----- while parsing this match expression
|
||||||
|
LL |
|
||||||
|
LL |
|
||||||
|
| ^ expected one of `.`, `?`, `{`, or an operator here
|
||||||
|
|
||||||
|
error: incorrect close delimiter: `)`
|
||||||
|
--> $DIR/issue-62973.rs:6:28
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| -^ incorrect close delimiter
|
||||||
|
| |
|
||||||
|
| un-closed delimiter
|
||||||
|
|
||||||
|
error: incorrect close delimiter: `)`
|
||||||
|
--> $DIR/issue-62973.rs:6:31
|
||||||
|
|
|
||||||
|
LL | fn p() { match s { v, E { [) {) }
|
||||||
|
| -^ incorrect close delimiter
|
||||||
|
| |
|
||||||
|
| un-closed delimiter
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
|
@ -152,6 +152,8 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||||
let mut skip_file_length = contains_ignore_directive(can_contain, &contents, "filelength");
|
let mut skip_file_length = contains_ignore_directive(can_contain, &contents, "filelength");
|
||||||
let mut skip_end_whitespace =
|
let mut skip_end_whitespace =
|
||||||
contains_ignore_directive(can_contain, &contents, "end-whitespace");
|
contains_ignore_directive(can_contain, &contents, "end-whitespace");
|
||||||
|
let mut skip_trailing_newlines =
|
||||||
|
contains_ignore_directive(can_contain, &contents, "trailing-newlines");
|
||||||
let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
|
let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
|
||||||
let mut leading_new_lines = false;
|
let mut leading_new_lines = false;
|
||||||
let mut trailing_new_lines = 0;
|
let mut trailing_new_lines = 0;
|
||||||
|
@ -214,10 +216,17 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||||
if leading_new_lines {
|
if leading_new_lines {
|
||||||
tidy_error!(bad, "{}: leading newline", file.display());
|
tidy_error!(bad, "{}: leading newline", file.display());
|
||||||
}
|
}
|
||||||
|
let mut err = |msg: &str| {
|
||||||
|
tidy_error!(bad, "{}: {}", file.display(), msg);
|
||||||
|
};
|
||||||
match trailing_new_lines {
|
match trailing_new_lines {
|
||||||
0 => tidy_error!(bad, "{}: missing trailing newline", file.display()),
|
0 => suppressible_tidy_err!(err, skip_trailing_newlines, "missing trailing newline"),
|
||||||
1 => {}
|
1 => {}
|
||||||
n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
|
n => suppressible_tidy_err!(
|
||||||
|
err,
|
||||||
|
skip_trailing_newlines,
|
||||||
|
&format!("too many trailing newlines ({})", n)
|
||||||
|
),
|
||||||
};
|
};
|
||||||
if lines > LINES {
|
if lines > LINES {
|
||||||
let mut err = |_| {
|
let mut err = |_| {
|
||||||
|
@ -247,6 +256,9 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||||
if let Directive::Ignore(false) = skip_end_whitespace {
|
if let Directive::Ignore(false) = skip_end_whitespace {
|
||||||
tidy_error!(bad, "{}: ignoring trailing whitespace unnecessarily", file.display());
|
tidy_error!(bad, "{}: ignoring trailing whitespace unnecessarily", file.display());
|
||||||
}
|
}
|
||||||
|
if let Directive::Ignore(false) = skip_trailing_newlines {
|
||||||
|
tidy_error!(bad, "{}: ignoring trailing newlines unnecessarily", file.display());
|
||||||
|
}
|
||||||
if let Directive::Ignore(false) = skip_copyright {
|
if let Directive::Ignore(false) = skip_copyright {
|
||||||
tidy_error!(bad, "{}: ignoring copyright unnecessarily", file.display());
|
tidy_error!(bad, "{}: ignoring copyright unnecessarily", file.display());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue