File tree 16 files changed +264
-4
lines changed
16 files changed +264
-4
lines changed Original file line number Diff line number Diff line change @@ -188,12 +188,30 @@ avoid mutation if possible.
188
188
"## ,
189
189
190
190
E0394 : r##"
191
- From [RFC 246]:
191
+ A static was referred to by value by another static.
192
192
193
- > It is invalid for a static to reference another static by value. It is
194
- > required that all references be borrowed.
193
+ Erroneous code examples:
195
194
196
- [RFC 246]: https://github.com/rust-lang/rfcs/pull/246
195
+ ```compile_fail,E0394
196
+ static A: u32 = 0;
197
+ static B: u32 = A; // error: cannot refer to other statics by value, use the
198
+ // address-of operator or a constant instead
199
+ ```
200
+
201
+ A static cannot be referred by value. To fix this issue, either use a
202
+ constant:
203
+
204
+ ```
205
+ const A: u32 = 0; // `A` is now a constant
206
+ static B: u32 = A; // ok!
207
+ ```
208
+
209
+ Or refer to `A` by reference:
210
+
211
+ ```
212
+ static A: u32 = 0;
213
+ static B: &'static u32 = &A; // ok!
214
+ ```
197
215
"## ,
198
216
199
217
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ static A : u32 = 0 ;
12
+ static B : u32 = A ; //~ ERROR E0394
13
+
14
+ fn main ( ) {
15
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ static FOO : i32 = 42 ;
12
+ static BAR : i32 = 42 ;
13
+
14
+ static BAZ : bool = { ( & FOO as * const i32 ) == ( & BAR as * const i32 ) } ; //~ ERROR E0395
15
+
16
+ fn main ( ) {
17
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ const REG_ADDR : * const u8 = 0x5f3759df as * const u8 ;
12
+
13
+ const VALUE : u8 = unsafe { * REG_ADDR } ; //~ ERROR E0396
14
+
15
+ fn main ( ) {
16
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn foo < T > ( x : T ) {
12
+ fn bar ( y : T ) { //~ ERROR E0401
13
+ }
14
+ bar ( x) ;
15
+ }
16
+
17
+ fn main ( ) {
18
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn foo < T , T > ( s : T , u : T ) { } //~ ERROR E0403
12
+
13
+ fn main ( ) {
14
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ struct Foo ;
12
+ struct Bar ;
13
+
14
+ impl Foo for Bar { } //~ ERROR E0404
15
+
16
+ fn main ( ) {
17
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ struct Foo ;
12
+
13
+ impl SomeTrait for Foo { } //~ ERROR E0405
14
+
15
+ fn main ( ) {
16
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ trait Foo {
12
+ fn a ( ) ;
13
+ }
14
+
15
+ struct Bar ;
16
+
17
+ impl Foo for Bar {
18
+ fn a ( ) { }
19
+ fn b ( ) { } //~ ERROR E0407
20
+ }
21
+
22
+ fn main ( ) {
23
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn main ( ) {
12
+ let x = Some ( 0 ) ;
13
+
14
+ match x {
15
+ Some ( y) | None => { } //~ ERROR E0408
16
+ _ => ( )
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn main ( ) {
12
+ let x = ( 0 , 2 ) ;
13
+
14
+ match x {
15
+ ( 0 , ref y) | ( y, 0 ) => { } //~ ERROR E0409
16
+ //~^ ERROR E0308
17
+ _ => ( )
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn main ( ) {
12
+ <Self >:: foo; //~ ERROR E0411
13
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ impl Something { } //~ ERROR E0412
12
+
13
+ fn main ( ) {
14
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn foo ( f : i32 , f : i32 ) { } //~ ERROR E0415
12
+
13
+ fn main ( ) {
14
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn main ( ) {
12
+ match ( 1 , 2 ) {
13
+ ( x, x) => { } //~ ERROR E0416
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 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
+ fn main ( ) {
12
+ let x = Foo { x : 1 , y : 2 } ; //~ ERROR E0422
13
+ }
You can’t perform that action at this time.
0 commit comments