mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Check that we forbid nested items, but not nested closures
This commit is contained in:
parent
1829aa631f
commit
5e5d1350b6
@ -0,0 +1,23 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/itiat-allow-nested-closures.rs:21:22
|
||||||
|
|
|
||||||
|
LL | type Assoc = impl Sized;
|
||||||
|
| ---------- the found opaque type
|
||||||
|
...
|
||||||
|
LL | let _: i32 = closure();
|
||||||
|
| --- ^^^^^^^^^ expected `i32`, found opaque type
|
||||||
|
| |
|
||||||
|
| expected due to this
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/itiat-allow-nested-closures.rs:22:9
|
||||||
|
|
|
||||||
|
LL | fn bar() -> Self::Assoc {
|
||||||
|
| ----------- expected `()` because of return type
|
||||||
|
...
|
||||||
|
LL | 1i32
|
||||||
|
| ^^^^ expected `()`, found `i32`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
@ -0,0 +1,26 @@
|
|||||||
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
|
||||||
|
// revisions: ok bad
|
||||||
|
// [ok] check-pass
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
type Assoc;
|
||||||
|
fn bar() -> Self::Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
type Assoc = impl Sized;
|
||||||
|
fn bar() -> Self::Assoc {
|
||||||
|
let closure = || -> Self::Assoc {
|
||||||
|
#[cfg(ok)]
|
||||||
|
let x: Self::Assoc = 42_i32;
|
||||||
|
#[cfg(bad)]
|
||||||
|
let x: Self::Assoc = ();
|
||||||
|
x
|
||||||
|
};
|
||||||
|
let _: i32 = closure(); //[bad]~ ERROR mismatched types
|
||||||
|
1i32 //[bad]~ ERROR mismatched types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
20
tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.rs
Normal file
20
tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
type Assoc;
|
||||||
|
fn bar() -> Self::Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for () {
|
||||||
|
type Assoc = impl Sized;
|
||||||
|
fn bar() -> Self::Assoc {
|
||||||
|
fn foo() -> <() as Foo>::Assoc {
|
||||||
|
let x: <() as Foo>::Assoc = 42_i32; //~ ERROR mismatched types
|
||||||
|
x
|
||||||
|
};
|
||||||
|
let _: i32 = foo();
|
||||||
|
1i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,22 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/itiat-forbid-nested-items.rs:12:41
|
||||||
|
|
|
||||||
|
LL | type Assoc = impl Sized;
|
||||||
|
| ---------- the expected opaque type
|
||||||
|
...
|
||||||
|
LL | let x: <() as Foo>::Assoc = 42_i32;
|
||||||
|
| ------------------ ^^^^^^ expected opaque type, found `i32`
|
||||||
|
| |
|
||||||
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected opaque type `<() as Foo>::Assoc`
|
||||||
|
found type `i32`
|
||||||
|
note: this item must have the opaque type in its signature in order to be able to register hidden types
|
||||||
|
--> $DIR/itiat-forbid-nested-items.rs:11:12
|
||||||
|
|
|
||||||
|
LL | fn foo() -> <() as Foo>::Assoc {
|
||||||
|
| ^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user