about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-10-27 08:44:51 +0900
committerGitHub <noreply@github.com>2020-10-27 08:44:51 +0900
commit9d7db4891bf6a8445b05a50cddb2d45883e2cb41 (patch)
treec458299aebba9fb40a316276d89187538bbeddc8
parentf3c94374b9ce51acb9ff49307e9f5cae6daee95e (diff)
parent59232187617c6bc2c7ca1bc748b8d93fc685430f (diff)
downloadrust-9d7db4891bf6a8445b05a50cddb2d45883e2cb41.tar.gz
rust-9d7db4891bf6a8445b05a50cddb2d45883e2cb41.zip
Rollup merge of #78298 - Aaron1011:fix/nll-ranked-test, r=Mark-Simulacrum
Add test for bad NLL higher-ranked subtype

Fixes #57642
-rw-r--r--src/test/ui/nll/issue-57642-higher-ranked-subtype.rs41
-rw-r--r--src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr31
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/ui/nll/issue-57642-higher-ranked-subtype.rs b/src/test/ui/nll/issue-57642-higher-ranked-subtype.rs
new file mode 100644
index 00000000000..36c54628317
--- /dev/null
+++ b/src/test/ui/nll/issue-57642-higher-ranked-subtype.rs
@@ -0,0 +1,41 @@
+// Regression test for issue #57642
+// Tests that we reject a bad higher-ranked subtype
+// with `#![feature(nll)]`
+
+#![feature(nll)]
+
+trait X {
+    type G;
+    fn make_g() -> Self::G;
+}
+
+impl<'a> X for fn(&'a ()) {
+    type G = &'a ();
+
+    fn make_g() -> Self::G {
+        &()
+    }
+}
+
+trait Y {
+    type F;
+    fn make_f() -> Self::F;
+}
+
+impl<T> Y for fn(T) {
+    type F = fn(T);
+
+    fn make_f() -> Self::F {
+        |_| {}
+    }
+}
+
+fn higher_ranked_region_has_lost_its_binder() {
+    let x = <fn (&())>::make_g(); //~ ERROR no function
+}
+
+fn magical() {
+    let x = <fn (&())>::make_f(); //~ ERROR no function
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr b/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
new file mode 100644
index 00000000000..f6909819342
--- /dev/null
+++ b/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
@@ -0,0 +1,31 @@
+error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'r> fn(&'r ())` in the current scope
+  --> $DIR/issue-57642-higher-ranked-subtype.rs:34:25
+   |
+LL |     let x = <fn (&())>::make_g();
+   |                         ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
+   |
+   = note: the method `make_g` exists but the following trait bounds were not satisfied:
+           `for<'r> fn(&'r ()): X`
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `X` defines an item `make_g`, perhaps you need to implement it
+  --> $DIR/issue-57642-higher-ranked-subtype.rs:7:1
+   |
+LL | trait X {
+   | ^^^^^^^
+
+error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'r> fn(&'r ())` in the current scope
+  --> $DIR/issue-57642-higher-ranked-subtype.rs:38:25
+   |
+LL |     let x = <fn (&())>::make_f();
+   |                         ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Y` defines an item `make_f`, perhaps you need to implement it
+  --> $DIR/issue-57642-higher-ranked-subtype.rs:20:1
+   |
+LL | trait Y {
+   | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.