Skip to content

Commit 0da3a0f

Browse files
committed
Fix ICE #91268 by checking that the snippet ends with a )
1 parent 6d246f0 commit 0da3a0f

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

compiler/rustc_ast_lowering/src/path.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
231231
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
232232
// Do not suggest going from `Trait()` to `Trait<>`
233233
if !data.inputs.is_empty() {
234-
if let Some(split) = snippet.find('(') {
235-
let trait_name = &snippet[0..split];
236-
let args = &snippet[split + 1..snippet.len() - 1];
237-
err.span_suggestion(
238-
data.span,
239-
"use angle brackets instead",
240-
format!("{}<{}>", trait_name, args),
241-
Applicability::MaybeIncorrect,
242-
);
234+
// Suggest replacing `(` and `)` with `<` and `>`
235+
// The snippet may be missing the closing `)`, skip that case
236+
if snippet.ends_with(')') {
237+
if let Some(split) = snippet.find('(') {
238+
let trait_name = &snippet[0..split];
239+
let args = &snippet[split + 1..snippet.len() - 1];
240+
err.span_suggestion(
241+
data.span,
242+
"use angle brackets instead",
243+
format!("{}<{}>", trait_name, args),
244+
Applicability::MaybeIncorrect,
245+
);
246+
}
243247
}
244248
}
245249
};

src/test/ui/type/issue-91268.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error-pattern: this file contains an unclosed delimiter
2+
// error-pattern: cannot find type `ţ` in this scope
3+
// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
4+
// error-pattern: type arguments are not allowed for this type
5+
// error-pattern: mismatched types
6+
// ignore-tidy-trailing-newlines
7+
// `ţ` must be the last character in this file, it cannot be followed by a newline
8+
fn main() {
9+
0: u8(ţ

src/test/ui/type/issue-91268.stderr

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-91268.rs:9:12
3+
|
4+
LL | fn main() {
5+
| - unclosed delimiter
6+
LL | 0: u8(ţ
7+
| - ^
8+
| |
9+
| unclosed delimiter
10+
11+
error: this file contains an unclosed delimiter
12+
--> $DIR/issue-91268.rs:9:12
13+
|
14+
LL | fn main() {
15+
| - unclosed delimiter
16+
LL | 0: u8(ţ
17+
| - ^
18+
| |
19+
| unclosed delimiter
20+
21+
error[E0412]: cannot find type `ţ` in this scope
22+
--> $DIR/issue-91268.rs:9:11
23+
|
24+
LL | 0: u8(ţ
25+
| ^ expecting a type here because of type ascription
26+
27+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
28+
--> $DIR/issue-91268.rs:9:8
29+
|
30+
LL | 0: u8(ţ
31+
| ^^^^ only `Fn` traits may use parentheses
32+
33+
error[E0109]: type arguments are not allowed for this type
34+
--> $DIR/issue-91268.rs:9:11
35+
|
36+
LL | 0: u8(ţ
37+
| ^ type argument not allowed
38+
39+
error[E0308]: mismatched types
40+
--> $DIR/issue-91268.rs:9:5
41+
|
42+
LL | fn main() {
43+
| - expected `()` because of default return type
44+
LL | 0: u8(ţ
45+
| ^^^^^^^ expected `()`, found `u8`
46+
47+
error: aborting due to 6 previous errors
48+
49+
Some errors have detailed explanations: E0109, E0214, E0308, E0412.
50+
For more information about an error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)