rustc: introduce {ast,hir}::AnonConst to consolidate so-called "embedded constants".

This commit is contained in:
Eduard-Mihai Burtescu 2018-05-17 21:28:50 +03:00
parent 072b0f617f
commit 26aad25487
35 changed files with 334 additions and 306 deletions

View file

@ -0,0 +1,15 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Functions {
Square = |x| x, //~ ERROR mismatched types
}
fn main() {}

View file

@ -0,0 +1,15 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo (
fn([u8; |x: u8| {}]), //~ ERROR mismatched types
);
fn main() {}

View file

@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
[1; || {}]; //~ ERROR mismatched types
}

View file

@ -0,0 +1,17 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
Bar = (|x: i32| { }, 42).1,
}
fn main() {
assert_eq!(Foo::Bar as usize, 42);
}

View file

@ -1,11 +1,11 @@
error[E0391]: cycle detected when processing `X::A::{{initializer}}`
error[E0391]: cycle detected when processing `X::A::{{constant}}`
--> $DIR/issue-23302-1.rs:14:9
|
LL | A = X::A as isize, //~ ERROR E0391
| ^^^^^^^^^^^^^
|
= note: ...which again requires processing `X::A::{{initializer}}`, completing the cycle
note: cycle used when const-evaluating `X::A::{{initializer}}`
= note: ...which again requires processing `X::A::{{constant}}`, completing the cycle
note: cycle used when const-evaluating `X::A::{{constant}}`
--> $DIR/issue-23302-1.rs:14:9
|
LL | A = X::A as isize, //~ ERROR E0391

View file

@ -1,11 +1,11 @@
error[E0391]: cycle detected when processing `Y::A::{{initializer}}`
error[E0391]: cycle detected when processing `Y::A::{{constant}}`
--> $DIR/issue-23302-2.rs:14:9
|
LL | A = Y::B as isize, //~ ERROR E0391
| ^^^^^^^^^^^^^
|
= note: ...which again requires processing `Y::A::{{initializer}}`, completing the cycle
note: cycle used when const-evaluating `Y::A::{{initializer}}`
= note: ...which again requires processing `Y::A::{{constant}}`, completing the cycle
note: cycle used when const-evaluating `Y::A::{{constant}}`
--> $DIR/issue-23302-2.rs:14:9
|
LL | A = Y::B as isize, //~ ERROR E0391

View file

@ -1,4 +1,4 @@
error[E0391]: cycle detected when processing `Foo::B::{{initializer}}`
error[E0391]: cycle detected when processing `Foo::B::{{constant}}`
--> $DIR/issue-36163.rs:14:9
|
LL | B = A, //~ ERROR E0391
@ -9,8 +9,8 @@ note: ...which requires processing `A`...
|
LL | const A: isize = Foo::B as isize;
| ^^^^^^^^^^^^^^^
= note: ...which again requires processing `Foo::B::{{initializer}}`, completing the cycle
note: cycle used when const-evaluating `Foo::B::{{initializer}}`
= note: ...which again requires processing `Foo::B::{{constant}}`, completing the cycle
note: cycle used when const-evaluating `Foo::B::{{constant}}`
--> $DIR/issue-36163.rs:14:9
|
LL | B = A, //~ ERROR E0391