about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-05 15:04:21 +0100
committerGitHub <noreply@github.com>2021-12-05 15:04:21 +0100
commit609d9a0108d4e6d79279fc6c5901eb5041c7aac7 (patch)
tree5eacc1fa67208fe3aff54a7e30b1432808a90567 /src/test
parenta8f8f746fc046a025d1b8c464ce28f6b828f32e9 (diff)
parent9b77a1e571041716ad0c446afd87949d40ed4de6 (diff)
downloadrust-609d9a0108d4e6d79279fc6c5901eb5041c7aac7.tar.gz
rust-609d9a0108d4e6d79279fc6c5901eb5041c7aac7.zip
Rollup merge of #91450 - hkmatsumoto:hide-type-error, r=estebank
Don't suggest types whose inner type is erroneous

Currently, we check if the returned type equals to `tcx.ty_error()` not to emit
erroneous types, but this has a pitfall; for example,
`Option<[type error]> != tcx.ty_error()` holds.

Fixes #91371.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/typeck/issue-91450-inner-ty-error.rs7
-rw-r--r--src/test/ui/typeck/issue-91450-inner-ty-error.stderr21
2 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/typeck/issue-91450-inner-ty-error.rs b/src/test/ui/typeck/issue-91450-inner-ty-error.rs
new file mode 100644
index 00000000000..0b942d6d94f
--- /dev/null
+++ b/src/test/ui/typeck/issue-91450-inner-ty-error.rs
@@ -0,0 +1,7 @@
+// Regression test for #91450.
+// This test ensures that the compiler does not suggest `Foo<[type error]>` in diagnostic messages.
+
+fn foo() -> Option<_> {} //~ ERROR: [E0308]
+//~^ ERROR: the type placeholder `_` is not allowed
+
+fn main() {}
diff --git a/src/test/ui/typeck/issue-91450-inner-ty-error.stderr b/src/test/ui/typeck/issue-91450-inner-ty-error.stderr
new file mode 100644
index 00000000000..314fe561803
--- /dev/null
+++ b/src/test/ui/typeck/issue-91450-inner-ty-error.stderr
@@ -0,0 +1,21 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-91450-inner-ty-error.rs:4:13
+   |
+LL | fn foo() -> Option<_> {}
+   |    ---      ^^^^^^^^^ expected enum `Option`, found `()`
+   |    |
+   |    implicitly returns `()` as its body has no tail or `return` expression
+   |
+   = note:   expected enum `Option<_>`
+           found unit type `()`
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types
+  --> $DIR/issue-91450-inner-ty-error.rs:4:20
+   |
+LL | fn foo() -> Option<_> {}
+   |                    ^ not allowed in type signatures
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0121, E0308.
+For more information about an error, try `rustc --explain E0121`.