File tree 6 files changed +170
-1
lines changed
6 files changed +170
-1
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ feature( impl_trait_in_bindings) ]
12
+
13
+ use std:: fmt:: Debug ;
14
+
15
+ const FOO : impl Debug + Clone + PartialEq < i32 > = 42 ;
16
+
17
+ static BAR : impl Debug + Clone + PartialEq < i32 > = 42 ;
18
+
19
+ fn a < T : Clone > ( x : T ) {
20
+ let y: impl Clone = x;
21
+ let _ = y. clone ( ) ;
22
+ }
23
+
24
+ fn b < T : Clone > ( x : T ) {
25
+ let f = move || {
26
+ let y: impl Clone = x;
27
+ let _ = y. clone ( ) ;
28
+ } ;
29
+ f ( ) ;
30
+ }
31
+
32
+ trait Foo < T : Clone > {
33
+ fn a ( x : T ) {
34
+ let y: impl Clone = x;
35
+ let _ = y. clone ( ) ;
36
+ }
37
+ }
38
+
39
+ impl < T : Clone > Foo < T > for i32 {
40
+ fn a ( x : T ) {
41
+ let y: impl Clone = x;
42
+ let _ = y. clone ( ) ;
43
+ }
44
+ }
45
+
46
+ fn main ( ) {
47
+ let foo: impl Debug + Clone + PartialEq < i32 > = 42 ;
48
+
49
+ assert_eq ! ( FOO . clone( ) , 42 ) ;
50
+ assert_eq ! ( BAR . clone( ) , 42 ) ;
51
+ assert_eq ! ( foo. clone( ) , 42 ) ;
52
+
53
+ a ( 42 ) ;
54
+ b ( 42 ) ;
55
+ i32:: a ( 42 ) ;
56
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ feature( impl_trait_in_bindings) ]
12
+
13
+ const FOO : impl Copy = 42 ;
14
+
15
+ static BAR : impl Copy = 42 ;
16
+
17
+ fn main ( ) {
18
+ let foo: impl Copy = 42 ;
19
+
20
+ let _ = FOO . count_ones ( ) ;
21
+ let _ = BAR . count_ones ( ) ;
22
+ let _ = foo. count_ones ( ) ;
23
+ }
Original file line number Diff line number Diff line change
1
+ error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
2
+ --> $DIR/bindings-opaque.rs:20:17
3
+ |
4
+ LL | let _ = FOO.count_ones();
5
+ | ^^^^^^^^^^
6
+
7
+ error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
8
+ --> $DIR/bindings-opaque.rs:21:17
9
+ |
10
+ LL | let _ = BAR.count_ones();
11
+ | ^^^^^^^^^^
12
+
13
+ error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
14
+ --> $DIR/bindings-opaque.rs:22:17
15
+ |
16
+ LL | let _ = foo.count_ones();
17
+ | ^^^^^^^^^^
18
+
19
+ error: aborting due to 3 previous errors
20
+
21
+ For more information about this error, try `rustc --explain E0599`.
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ feature( impl_trait_in_bindings) ]
12
+
13
+ fn a < T : Clone > ( x : T ) {
14
+ const foo: impl Clone = x;
15
+ }
16
+
17
+ fn b < T : Clone > ( x : T ) {
18
+ let _ = move || {
19
+ const foo: impl Clone = x;
20
+ } ;
21
+ }
22
+
23
+ trait Foo < T : Clone > {
24
+ fn a ( x : T ) {
25
+ const foo: impl Clone = x;
26
+ }
27
+ }
28
+
29
+ impl < T : Clone > Foo < T > for i32 {
30
+ fn a ( x : T ) {
31
+ const foo: impl Clone = x;
32
+ }
33
+ }
34
+
35
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0434]: can't capture dynamic environment in a fn item
2
+ --> $DIR/bindings.rs:14:29
3
+ |
4
+ LL | const foo: impl Clone = x;
5
+ | ^
6
+ |
7
+ = help: use the `|| { ... }` closure form instead
8
+
9
+ error[E0434]: can't capture dynamic environment in a fn item
10
+ --> $DIR/bindings.rs:19:33
11
+ |
12
+ LL | const foo: impl Clone = x;
13
+ | ^
14
+ |
15
+ = help: use the `|| { ... }` closure form instead
16
+
17
+ error[E0434]: can't capture dynamic environment in a fn item
18
+ --> $DIR/bindings.rs:25:33
19
+ |
20
+ LL | const foo: impl Clone = x;
21
+ | ^
22
+ |
23
+ = help: use the `|| { ... }` closure form instead
24
+
25
+ error[E0434]: can't capture dynamic environment in a fn item
26
+ --> $DIR/bindings.rs:31:33
27
+ |
28
+ LL | const foo: impl Clone = x;
29
+ | ^
30
+ |
31
+ = help: use the `|| { ... }` closure form instead
32
+
33
+ error: aborting due to 4 previous errors
34
+
35
+ For more information about this error, try `rustc --explain E0434`.
Original file line number Diff line number Diff line change @@ -232,4 +232,3 @@ fn main() {
232
232
let _in_return_in_local_variable = || -> impl Fn ( ) { || { } } ;
233
233
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
234
234
}
235
-
You can’t perform that action at this time.
0 commit comments