about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBadel2 <2badel2@gmail.com>2021-11-26 22:57:13 +0100
committerBadel2 <2badel2@gmail.com>2021-11-26 23:57:21 +0100
commit0da3a0f56eda3c360e63499b4ee452e55630d9ff (patch)
tree48c13d39437db76f6c3e89763e2c6554cc21cac4
parent6d246f0c8d3063fea86abbb65a824362709541ba (diff)
downloadrust-0da3a0f56eda3c360e63499b4ee452e55630d9ff.tar.gz
rust-0da3a0f56eda3c360e63499b4ee452e55630d9ff.zip
Fix ICE #91268 by checking that the snippet ends with a `)`
-rw-r--r--compiler/rustc_ast_lowering/src/path.rs22
-rw-r--r--src/test/ui/type/issue-91268.rs9
-rw-r--r--src/test/ui/type/issue-91268.stderr50
3 files changed, 72 insertions, 9 deletions
diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs
index 929f427484d..20bf28b02af 100644
--- a/compiler/rustc_ast_lowering/src/path.rs
+++ b/compiler/rustc_ast_lowering/src/path.rs
@@ -231,15 +231,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                         if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
                             // Do not suggest going from `Trait()` to `Trait<>`
                             if !data.inputs.is_empty() {
-                                if let Some(split) = snippet.find('(') {
-                                    let trait_name = &snippet[0..split];
-                                    let args = &snippet[split + 1..snippet.len() - 1];
-                                    err.span_suggestion(
-                                        data.span,
-                                        "use angle brackets instead",
-                                        format!("{}<{}>", trait_name, args),
-                                        Applicability::MaybeIncorrect,
-                                    );
+                                // Suggest replacing `(` and `)` with `<` and `>`
+                                // The snippet may be missing the closing `)`, skip that case
+                                if snippet.ends_with(')') {
+                                    if let Some(split) = snippet.find('(') {
+                                        let trait_name = &snippet[0..split];
+                                        let args = &snippet[split + 1..snippet.len() - 1];
+                                        err.span_suggestion(
+                                            data.span,
+                                            "use angle brackets instead",
+                                            format!("{}<{}>", trait_name, args),
+                                            Applicability::MaybeIncorrect,
+                                        );
+                                    }
                                 }
                             }
                         };
diff --git a/src/test/ui/type/issue-91268.rs b/src/test/ui/type/issue-91268.rs
new file mode 100644
index 00000000000..fd2733c1c54
--- /dev/null
+++ b/src/test/ui/type/issue-91268.rs
@@ -0,0 +1,9 @@
+// error-pattern: this file contains an unclosed delimiter
+// error-pattern: cannot find type `ţ` in this scope
+// error-pattern: parenthesized type parameters may only be used with a `Fn` trait
+// error-pattern: type arguments are not allowed for this type
+// error-pattern: mismatched types
+// ignore-tidy-trailing-newlines
+// `ţ` must be the last character in this file, it cannot be followed by a newline
+fn main() {
+    0: u8(ţ
\ No newline at end of file
diff --git a/src/test/ui/type/issue-91268.stderr b/src/test/ui/type/issue-91268.stderr
new file mode 100644
index 00000000000..2fe6ba6248c
--- /dev/null
+++ b/src/test/ui/type/issue-91268.stderr
@@ -0,0 +1,50 @@
+error: this file contains an unclosed delimiter
+  --> $DIR/issue-91268.rs:9:12
+   |
+LL | fn main() {
+   |           - unclosed delimiter
+LL |     0: u8(ţ
+   |          - ^
+   |          |
+   |          unclosed delimiter
+
+error: this file contains an unclosed delimiter
+  --> $DIR/issue-91268.rs:9:12
+   |
+LL | fn main() {
+   |           - unclosed delimiter
+LL |     0: u8(ţ
+   |          - ^
+   |          |
+   |          unclosed delimiter
+
+error[E0412]: cannot find type `ţ` in this scope
+  --> $DIR/issue-91268.rs:9:11
+   |
+LL |     0: u8(ţ
+   |           ^ expecting a type here because of type ascription
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+  --> $DIR/issue-91268.rs:9:8
+   |
+LL |     0: u8(ţ
+   |        ^^^^ only `Fn` traits may use parentheses
+
+error[E0109]: type arguments are not allowed for this type
+  --> $DIR/issue-91268.rs:9:11
+   |
+LL |     0: u8(ţ
+   |           ^ type argument not allowed
+
+error[E0308]: mismatched types
+  --> $DIR/issue-91268.rs:9:5
+   |
+LL | fn main() {
+   |           - expected `()` because of default return type
+LL |     0: u8(ţ
+   |     ^^^^^^^ expected `()`, found `u8`
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0109, E0214, E0308, E0412.
+For more information about an error, try `rustc --explain E0109`.