Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for bad NLL higher-ranked subtype #78298

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/test/ui/nll/issue-57642-higher-ranked-subtype.rs
Original file line number Diff line number Diff line change
@@ -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() {}
31 changes: 31 additions & 0 deletions src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
Original file line number Diff line number Diff line change
@@ -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`.