Skip to content

Commit ec31b4e

Browse files
committed
Audit uses of span_suggestion_short
1 parent 9491f18 commit ec31b4e

File tree

146 files changed

+1758
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1758
-300
lines changed

src/librustc_parse/parser/diagnostics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,10 +1219,13 @@ impl<'a> Parser<'a> {
12191219
if let Some(sp) = unmatched.unclosed_span {
12201220
err.span_label(sp, "unclosed delimiter");
12211221
}
1222+
// Backticks should be removed to apply suggestions.
1223+
let mut delim = delim.to_string();
1224+
delim.retain(|c| c != '`');
12221225
err.span_suggestion_short(
12231226
self.prev_token.span.shrink_to_hi(),
1224-
&format!("{} may belong here", delim.to_string()),
1225-
delim.to_string(),
1227+
&format!("`{}` may belong here", delim),
1228+
delim,
12261229
Applicability::MaybeIncorrect,
12271230
);
12281231
if unmatched.found_delim.is_none() {

src/librustc_parse/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
699699
// misses a separator.
700700
expect_err
701701
.span_suggestion_short(
702-
sp,
702+
self.sess.source_map().next_point(sp),
703703
&format!("missing `{}`", token_str),
704704
token_str,
705705
Applicability::MaybeIncorrect,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-rustfix
2+
3+
fn foo() -> i32 {
4+
0
5+
}
6+
7+
fn main() {
8+
let _x: i32 = {
9+
//~^ ERROR mismatched types
10+
foo() //~ HELP consider removing this semicolon
11+
};
12+
}

src/test/ui/block-expression-remove-semicolon.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// run-rustfix
2+
13
fn foo() -> i32 {
2-
0
4+
0
35
}
46

57
fn main() {
6-
let x: i32 = {
8+
let _x: i32 = {
79
//~^ ERROR mismatched types
810
foo(); //~ HELP consider removing this semicolon
911
};

src/test/ui/block-expression-remove-semicolon.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0308]: mismatched types
2-
--> $DIR/block-expression-remove-semicolon.rs:6:18
2+
--> $DIR/block-expression-remove-semicolon.rs:8:19
33
|
4-
LL | let x: i32 = {
5-
| __________________^
4+
LL | let _x: i32 = {
5+
| ___________________^
66
LL | |
77
LL | | foo();
88
| | - help: consider removing this semicolon
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-rustfix
2+
3+
pub fn f() -> String { //~ ERROR mismatched types
4+
0u8;
5+
"bla".to_string()
6+
}
7+
8+
pub fn g() -> String { //~ ERROR mismatched types
9+
"this won't work".to_string();
10+
"removeme".to_string()
11+
}
12+
13+
fn main() {}

src/test/ui/block-result/consider-removing-last-semi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
fn f() -> String { //~ ERROR mismatched types
1+
// run-rustfix
2+
3+
pub fn f() -> String { //~ ERROR mismatched types
24
0u8;
35
"bla".to_string();
46
}
57

6-
fn g() -> String { //~ ERROR mismatched types
8+
pub fn g() -> String { //~ ERROR mismatched types
79
"this won't work".to_string();
810
"removeme".to_string();
911
}

src/test/ui/block-result/consider-removing-last-semi.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0308]: mismatched types
2-
--> $DIR/consider-removing-last-semi.rs:1:11
2+
--> $DIR/consider-removing-last-semi.rs:3:15
33
|
4-
LL | fn f() -> String {
5-
| - ^^^^^^ expected struct `std::string::String`, found `()`
6-
| |
7-
| implicitly returns `()` as its body has no tail or `return` expression
4+
LL | pub fn f() -> String {
5+
| - ^^^^^^ expected struct `std::string::String`, found `()`
6+
| |
7+
| implicitly returns `()` as its body has no tail or `return` expression
88
LL | 0u8;
99
LL | "bla".to_string();
1010
| - help: consider removing this semicolon
1111

1212
error[E0308]: mismatched types
13-
--> $DIR/consider-removing-last-semi.rs:6:11
13+
--> $DIR/consider-removing-last-semi.rs:8:15
1414
|
15-
LL | fn g() -> String {
16-
| - ^^^^^^ expected struct `std::string::String`, found `()`
17-
| |
18-
| implicitly returns `()` as its body has no tail or `return` expression
15+
LL | pub fn g() -> String {
16+
| - ^^^^^^ expected struct `std::string::String`, found `()`
17+
| |
18+
| implicitly returns `()` as its body has no tail or `return` expression
1919
LL | "this won't work".to_string();
2020
LL | "removeme".to_string();
2121
| - help: consider removing this semicolon
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// #41425 -- error message "mismatched types" has wrong types
2+
// run-rustfix
3+
4+
fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
5+
x + 1
6+
}
7+
8+
fn foo() -> Result<u8, u64> { //~ ERROR mismatched types
9+
Ok(1)
10+
}
11+
12+
fn main() {
13+
let x = plus_one(5);
14+
let _ = foo();
15+
println!("X = {}", x);
16+
}

src/test/ui/coercion/coercion-missing-tail-expected-type.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// #41425 -- error message "mismatched types" has wrong types
2+
// run-rustfix
23

34
fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
45
x + 1;
@@ -10,5 +11,6 @@ fn foo() -> Result<u8, u64> { //~ ERROR mismatched types
1011

1112
fn main() {
1213
let x = plus_one(5);
14+
let _ = foo();
1315
println!("X = {}", x);
1416
}

0 commit comments

Comments
 (0)