Skip to content

Commit 807ebac

Browse files
committed
Insert whitespace to avoid ident concatenation in suggestion
1 parent a29efcc commit 807ebac

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

Diff for: compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ impl<'a> Parser<'a> {
10481048
self.parse_remaining_bounds(bounds, true)?;
10491049
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
10501050
let sp = vec![lo, self.prev_token.span];
1051-
let sugg: Vec<_> = sp.iter().map(|sp| (*sp, String::new())).collect();
1051+
let sugg = vec![(lo, String::from(" ")), (self.prev_token.span, String::new())];
10521052
self.struct_span_err(sp, "incorrect braces around trait bounds")
10531053
.multipart_suggestion(
10541054
"remove the parentheses",

Diff for: tests/ui/parser/trait-object-delimiters.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ fn foo1(_: &dyn Drop + AsRef<str>) {} //~ ERROR ambiguous `+` in a type
55

66
fn foo2(_: &dyn (Drop + AsRef<str>)) {} //~ ERROR incorrect braces around trait bounds
77

8+
fn foo2_no_space(_: &dyn(Drop + AsRef<str>)) {} //~ ERROR incorrect braces around trait bounds
9+
810
fn foo3(_: &dyn {Drop + AsRef<str>}) {} //~ ERROR expected parameter name, found `{`
911
//~^ ERROR expected one of `!`, `(`, `)`, `*`, `,`, `?`, `for`, `~`, lifetime, or path, found `{`
1012
//~| ERROR at least one trait is required for an object type

Diff for: tests/ui/parser/trait-object-delimiters.stderr

+20-8
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,43 @@ LL | fn foo2(_: &dyn (Drop + AsRef<str>)) {}
1313
help: remove the parentheses
1414
|
1515
LL - fn foo2(_: &dyn (Drop + AsRef<str>)) {}
16-
LL + fn foo2(_: &dyn Drop + AsRef<str>) {}
16+
LL + fn foo2(_: &dyn Drop + AsRef<str>) {}
17+
|
18+
19+
error: incorrect braces around trait bounds
20+
--> $DIR/trait-object-delimiters.rs:8:25
21+
|
22+
LL | fn foo2_no_space(_: &dyn(Drop + AsRef<str>)) {}
23+
| ^ ^
24+
|
25+
help: remove the parentheses
26+
|
27+
LL - fn foo2_no_space(_: &dyn(Drop + AsRef<str>)) {}
28+
LL + fn foo2_no_space(_: &dyn Drop + AsRef<str>) {}
1729
|
1830

1931
error: expected parameter name, found `{`
20-
--> $DIR/trait-object-delimiters.rs:8:17
32+
--> $DIR/trait-object-delimiters.rs:10:17
2133
|
2234
LL | fn foo3(_: &dyn {Drop + AsRef<str>}) {}
2335
| ^ expected parameter name
2436

2537
error: expected one of `!`, `(`, `)`, `*`, `,`, `?`, `for`, `~`, lifetime, or path, found `{`
26-
--> $DIR/trait-object-delimiters.rs:8:17
38+
--> $DIR/trait-object-delimiters.rs:10:17
2739
|
2840
LL | fn foo3(_: &dyn {Drop + AsRef<str>}) {}
2941
| -^ expected one of 10 possible tokens
3042
| |
3143
| help: missing `,`
3244

3345
error: expected identifier, found `<`
34-
--> $DIR/trait-object-delimiters.rs:12:17
46+
--> $DIR/trait-object-delimiters.rs:14:17
3547
|
3648
LL | fn foo4(_: &dyn <Drop + AsRef<str>>) {}
3749
| ^ expected identifier
3850

3951
error: invalid `dyn` keyword
40-
--> $DIR/trait-object-delimiters.rs:14:25
52+
--> $DIR/trait-object-delimiters.rs:16:25
4153
|
4254
LL | fn foo5(_: &(dyn Drop + dyn AsRef<str>)) {}
4355
| ^^^ help: remove this keyword
@@ -56,13 +68,13 @@ LL | fn foo1(_: &dyn Drop + AsRef<str>) {}
5668
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
5769

5870
error[E0224]: at least one trait is required for an object type
59-
--> $DIR/trait-object-delimiters.rs:8:13
71+
--> $DIR/trait-object-delimiters.rs:10:13
6072
|
6173
LL | fn foo3(_: &dyn {Drop + AsRef<str>}) {}
6274
| ^^^
6375

6476
error[E0225]: only auto traits can be used as additional traits in a trait object
65-
--> $DIR/trait-object-delimiters.rs:14:29
77+
--> $DIR/trait-object-delimiters.rs:16:29
6678
|
6779
LL | fn foo5(_: &(dyn Drop + dyn AsRef<str>)) {}
6880
| ---- ^^^^^^^^^^ additional non-auto trait
@@ -72,7 +84,7 @@ LL | fn foo5(_: &(dyn Drop + dyn AsRef<str>)) {}
7284
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Drop + AsRef<str> {}`
7385
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
7486

75-
error: aborting due to 9 previous errors
87+
error: aborting due to 10 previous errors
7688

7789
Some errors have detailed explanations: E0224, E0225.
7890
For more information about an error, try `rustc --explain E0224`.

0 commit comments

Comments
 (0)