Skip to content

Commit e74ab50

Browse files
authored
Rollup merge of #73953 - JohnTitor:audit-hidden-sugg, r=estebank
Audit hidden/short code suggestions Should fix #73641. Audit uses of `span_suggestion_short` and `tool_only_span_suggestion` (`span_suggestion_hidden` is already tested with `run-rustfix`). Leave some FIXMEs for futher improvements/fixes. r? @estebank
2 parents 7942d9a + 84282fd commit e74ab50

File tree

153 files changed

+1801
-313
lines changed

Some content is hidden

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

153 files changed

+1801
-313
lines changed

src/librustc_builtin_macros/format.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ impl<'a, 'b> Context<'a, 'b> {
280280
("x", "LowerHex"),
281281
("X", "UpperHex"),
282282
] {
283+
// FIXME: rustfix (`run-rustfix`) fails to apply suggestions.
284+
// > "Cannot replace slice of data that was already replaced"
283285
err.tool_only_span_suggestion(
284286
sp,
285287
&format!("use the `{}` trait", name),

src/librustc_parse/parser/diagnostics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,10 +1228,13 @@ impl<'a> Parser<'a> {
12281228
if let Some(sp) = unmatched.unclosed_span {
12291229
err.span_label(sp, "unclosed delimiter");
12301230
}
1231+
// Backticks should be removed to apply suggestions.
1232+
let mut delim = delim.to_string();
1233+
delim.retain(|c| c != '`');
12311234
err.span_suggestion_short(
12321235
self.prev_token.span.shrink_to_hi(),
1233-
&format!("{} may belong here", delim.to_string()),
1234-
delim.to_string(),
1236+
&format!("`{}` may belong here", delim),
1237+
delim,
12351238
Applicability::MaybeIncorrect,
12361239
);
12371240
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+
}

0 commit comments

Comments
 (0)