]> git.lizzy.rs Git - rust.git/commitdiff
Migrate from `associated-const` to `associated-consts`
authorYuki Okushi <huyuumi.dev@gmail.com>
Thu, 15 Oct 2020 01:24:32 +0000 (10:24 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Thu, 15 Oct 2020 01:24:32 +0000 (10:24 +0900)
74 files changed:
src/test/ui/associated-const/associated-const-ambiguity-report.rs [deleted file]
src/test/ui/associated-const/associated-const-ambiguity-report.stderr [deleted file]
src/test/ui/associated-const/associated-const-array-len.rs [deleted file]
src/test/ui/associated-const/associated-const-array-len.stderr [deleted file]
src/test/ui/associated-const/associated-const-dead-code.rs [deleted file]
src/test/ui/associated-const/associated-const-dead-code.stderr [deleted file]
src/test/ui/associated-const/associated-const-generic-obligations.rs [deleted file]
src/test/ui/associated-const/associated-const-generic-obligations.stderr [deleted file]
src/test/ui/associated-const/associated-const-impl-wrong-lifetime.rs [deleted file]
src/test/ui/associated-const/associated-const-impl-wrong-lifetime.stderr [deleted file]
src/test/ui/associated-const/associated-const-impl-wrong-type.rs [deleted file]
src/test/ui/associated-const/associated-const-impl-wrong-type.stderr [deleted file]
src/test/ui/associated-const/associated-const-in-trait.rs [deleted file]
src/test/ui/associated-const/associated-const-in-trait.stderr [deleted file]
src/test/ui/associated-const/associated-const-no-item.rs [deleted file]
src/test/ui/associated-const/associated-const-no-item.stderr [deleted file]
src/test/ui/associated-const/associated-const-private-impl.rs [deleted file]
src/test/ui/associated-const/associated-const-private-impl.stderr [deleted file]
src/test/ui/associated-const/associated-const-trait-bound.rs [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arms.rs [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arms.stderr [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arrays.rs [deleted file]
src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr [deleted file]
src/test/ui/associated-const/defaults-cyclic-fail.rs [deleted file]
src/test/ui/associated-const/defaults-cyclic-fail.stderr [deleted file]
src/test/ui/associated-const/defaults-cyclic-pass.rs [deleted file]
src/test/ui/associated-const/defaults-not-assumed-fail.rs [deleted file]
src/test/ui/associated-const/defaults-not-assumed-fail.stderr [deleted file]
src/test/ui/associated-const/defaults-not-assumed-pass.rs [deleted file]
src/test/ui/associated-const/issue-63496.rs [deleted file]
src/test/ui/associated-const/issue-63496.stderr [deleted file]
src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr [deleted file]
src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr [deleted file]
src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr [deleted file]
src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs [deleted file]
src/test/ui/associated-consts/associated-const-ambiguity-report.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-ambiguity-report.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-array-len.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-array-len.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-dead-code.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-dead-code.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-generic-obligations.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-generic-obligations.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-impl-wrong-type.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-impl-wrong-type.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-in-trait.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-in-trait.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-no-item.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-no-item.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-private-impl.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-private-impl.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-trait-bound.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arms.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arms.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.stderr [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arrays.rs [new file with mode: 0644]
src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr [new file with mode: 0644]
src/test/ui/associated-consts/defaults-cyclic-fail.rs [new file with mode: 0644]
src/test/ui/associated-consts/defaults-cyclic-fail.stderr [new file with mode: 0644]
src/test/ui/associated-consts/defaults-cyclic-pass.rs [new file with mode: 0644]
src/test/ui/associated-consts/defaults-not-assumed-fail.rs [new file with mode: 0644]
src/test/ui/associated-consts/defaults-not-assumed-fail.stderr [new file with mode: 0644]
src/test/ui/associated-consts/defaults-not-assumed-pass.rs [new file with mode: 0644]
src/test/ui/associated-consts/issue-63496.rs [new file with mode: 0644]
src/test/ui/associated-consts/issue-63496.stderr [new file with mode: 0644]
src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.noopt.stderr [new file with mode: 0644]
src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt.stderr [new file with mode: 0644]
src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr [new file with mode: 0644]
src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.rs [new file with mode: 0644]

diff --git a/src/test/ui/associated-const/associated-const-ambiguity-report.rs b/src/test/ui/associated-const/associated-const-ambiguity-report.rs
deleted file mode 100644 (file)
index 927d2c6..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-trait Foo {
-    const ID: i32;
-}
-
-trait Bar {
-    const ID: i32;
-}
-
-impl Foo for i32 {
-    const ID: i32 = 1;
-}
-
-impl Bar for i32 {
-    const ID: i32 = 3;
-}
-
-const X: i32 = <i32>::ID; //~ ERROR E0034
-
-fn main() {
-    assert_eq!(1, X);
-}
diff --git a/src/test/ui/associated-const/associated-const-ambiguity-report.stderr b/src/test/ui/associated-const/associated-const-ambiguity-report.stderr
deleted file mode 100644 (file)
index c5e32af..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-error[E0034]: multiple applicable items in scope
-  --> $DIR/associated-const-ambiguity-report.rs:17:23
-   |
-LL | const X: i32 = <i32>::ID;
-   |                       ^^ multiple `ID` found
-   |
-note: candidate #1 is defined in an impl of the trait `Foo` for the type `i32`
-  --> $DIR/associated-const-ambiguity-report.rs:10:5
-   |
-LL |     const ID: i32 = 1;
-   |     ^^^^^^^^^^^^^^^^^^
-note: candidate #2 is defined in an impl of the trait `Bar` for the type `i32`
-  --> $DIR/associated-const-ambiguity-report.rs:14:5
-   |
-LL |     const ID: i32 = 3;
-   |     ^^^^^^^^^^^^^^^^^^
-help: disambiguate the associated constant for candidate #1
-   |
-LL | const X: i32 = Foo::ID;
-   |                ^^^^^^^
-help: disambiguate the associated constant for candidate #2
-   |
-LL | const X: i32 = Bar::ID;
-   |                ^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0034`.
diff --git a/src/test/ui/associated-const/associated-const-array-len.rs b/src/test/ui/associated-const/associated-const-array-len.rs
deleted file mode 100644 (file)
index 17d7824..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-trait Foo {
-    const ID: usize;
-}
-
-const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
-//~^ ERROR the trait bound `i32: Foo` is not satisfied
-
-fn main() {
-    assert_eq!(1, X);
-}
diff --git a/src/test/ui/associated-const/associated-const-array-len.stderr b/src/test/ui/associated-const/associated-const-array-len.stderr
deleted file mode 100644 (file)
index 2fdfa3d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0277]: the trait bound `i32: Foo` is not satisfied
-  --> $DIR/associated-const-array-len.rs:5:16
-   |
-LL |     const ID: usize;
-   |     ---------------- required by `Foo::ID`
-...
-LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
-   |                ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/associated-const/associated-const-dead-code.rs b/src/test/ui/associated-const/associated-const-dead-code.rs
deleted file mode 100644 (file)
index e659bdb..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#![deny(dead_code)]
-
-struct MyFoo;
-
-impl MyFoo {
-    const BAR: u32 = 1;
-    //~^ ERROR associated constant is never used: `BAR`
-}
-
-fn main() {
-    let _: MyFoo = MyFoo;
-}
diff --git a/src/test/ui/associated-const/associated-const-dead-code.stderr b/src/test/ui/associated-const/associated-const-dead-code.stderr
deleted file mode 100644 (file)
index 9b6bbb6..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-error: associated constant is never used: `BAR`
-  --> $DIR/associated-const-dead-code.rs:6:5
-   |
-LL |     const BAR: u32 = 1;
-   |     ^^^^^^^^^^^^^^^^^^^
-   |
-note: the lint level is defined here
-  --> $DIR/associated-const-dead-code.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/associated-const/associated-const-generic-obligations.rs b/src/test/ui/associated-const/associated-const-generic-obligations.rs
deleted file mode 100644 (file)
index 498e315..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-trait Foo {
-    type Out: Sized;
-}
-
-impl Foo for String {
-    type Out = String;
-}
-
-trait Bar: Foo {
-    const FROM: Self::Out;
-}
-
-impl<T: Foo> Bar for T {
-    const FROM: &'static str = "foo";
-    //~^ ERROR implemented const `FROM` has an incompatible type for trait [E0326]
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/associated-const-generic-obligations.stderr b/src/test/ui/associated-const/associated-const-generic-obligations.stderr
deleted file mode 100644 (file)
index d8bac07..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-error[E0326]: implemented const `FROM` has an incompatible type for trait
-  --> $DIR/associated-const-generic-obligations.rs:14:17
-   |
-LL |     const FROM: Self::Out;
-   |                 --------- type in trait
-...
-LL |     const FROM: &'static str = "foo";
-   |                 ^^^^^^^^^^^^ expected associated type, found `&str`
-   |
-   = note: expected associated type `<T as Foo>::Out`
-                    found reference `&'static str`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0326`.
diff --git a/src/test/ui/associated-const/associated-const-impl-wrong-lifetime.rs b/src/test/ui/associated-const/associated-const-impl-wrong-lifetime.rs
deleted file mode 100644 (file)
index 08260ec..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-trait Foo {
-    const NAME: &'static str;
-}
-
-
-impl<'a> Foo for &'a () {
-    const NAME: &'a str = "unit";
-    //~^ ERROR mismatched types [E0308]
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/associated-const-impl-wrong-lifetime.stderr b/src/test/ui/associated-const/associated-const-impl-wrong-lifetime.stderr
deleted file mode 100644 (file)
index 0cce10b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-error[E0308]: mismatched types
-  --> $DIR/associated-const-impl-wrong-lifetime.rs:7:5
-   |
-LL |     const NAME: &'a str = "unit";
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
-   |
-   = note: expected reference `&'static str`
-              found reference `&'a str`
-note: the lifetime `'a` as defined on the impl at 6:6...
-  --> $DIR/associated-const-impl-wrong-lifetime.rs:6:6
-   |
-LL | impl<'a> Foo for &'a () {
-   |      ^^
-   = note: ...does not necessarily outlive the static lifetime
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/associated-const/associated-const-impl-wrong-type.rs b/src/test/ui/associated-const/associated-const-impl-wrong-type.rs
deleted file mode 100644 (file)
index 1aad749..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-trait Foo {
-    const BAR: u32;
-}
-
-struct SignedBar;
-
-impl Foo for SignedBar {
-    const BAR: i32 = -1;
-    //~^ ERROR implemented const `BAR` has an incompatible type for trait [E0326]
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/associated-const-impl-wrong-type.stderr b/src/test/ui/associated-const/associated-const-impl-wrong-type.stderr
deleted file mode 100644 (file)
index acdf33b..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0326]: implemented const `BAR` has an incompatible type for trait
-  --> $DIR/associated-const-impl-wrong-type.rs:8:16
-   |
-LL |     const BAR: u32;
-   |                --- type in trait
-...
-LL |     const BAR: i32 = -1;
-   |                ^^^ expected `u32`, found `i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0326`.
diff --git a/src/test/ui/associated-const/associated-const-in-trait.rs b/src/test/ui/associated-const/associated-const-in-trait.rs
deleted file mode 100644 (file)
index cc3acd5..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// #29924
-
-#![feature(const_fn, associated_consts)]
-
-trait Trait {
-    const N: usize;
-}
-
-impl dyn Trait {
-    //~^ ERROR the trait `Trait` cannot be made into an object [E0038]
-    const fn n() -> usize { Self::N }
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/associated-const-in-trait.stderr b/src/test/ui/associated-const/associated-const-in-trait.stderr
deleted file mode 100644 (file)
index a8a8d01..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0038]: the trait `Trait` cannot be made into an object
-  --> $DIR/associated-const-in-trait.rs:9:6
-   |
-LL | trait Trait {
-   |       ----- this trait cannot be made into an object...
-LL |     const N: usize;
-   |           - ...because it contains this associated `const`
-...
-LL | impl dyn Trait {
-   |      ^^^^^^^^^ the trait `Trait` cannot be made into an object
-   |
-   = help: consider moving `N` to another trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0038`.
diff --git a/src/test/ui/associated-const/associated-const-no-item.rs b/src/test/ui/associated-const/associated-const-no-item.rs
deleted file mode 100644 (file)
index 024d14e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-trait Foo {
-    const ID: i32;
-}
-
-const X: i32 = <i32>::ID;
-//~^ ERROR no associated item named `ID` found
-
-fn main() {
-    assert_eq!(1, X);
-}
diff --git a/src/test/ui/associated-const/associated-const-no-item.stderr b/src/test/ui/associated-const/associated-const-no-item.stderr
deleted file mode 100644 (file)
index fe27da5..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0599]: no associated item named `ID` found for type `i32` in the current scope
-  --> $DIR/associated-const-no-item.rs:5:23
-   |
-LL | const X: i32 = <i32>::ID;
-   |                       ^^ associated item not found in `i32`
-   |
-   = help: items from traits can only be used if the trait is implemented and in scope
-note: `Foo` defines an item `ID`, perhaps you need to implement it
-  --> $DIR/associated-const-no-item.rs:1:1
-   |
-LL | trait Foo {
-   | ^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/associated-const/associated-const-private-impl.rs b/src/test/ui/associated-const/associated-const-private-impl.rs
deleted file mode 100644 (file)
index 3ee3134..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-mod bar1 {
-    pub use self::bar2::Foo;
-    mod bar2 {
-        pub struct Foo;
-
-        impl Foo {
-            const ID: i32 = 1;
-        }
-    }
-}
-
-fn main() {
-    assert_eq!(1, bar1::Foo::ID);
-    //~^ERROR associated constant `ID` is private
-}
diff --git a/src/test/ui/associated-const/associated-const-private-impl.stderr b/src/test/ui/associated-const/associated-const-private-impl.stderr
deleted file mode 100644 (file)
index 1b9d7ac..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0624]: associated constant `ID` is private
-  --> $DIR/associated-const-private-impl.rs:13:30
-   |
-LL |     assert_eq!(1, bar1::Foo::ID);
-   |                              ^^ private associated constant
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0624`.
diff --git a/src/test/ui/associated-const/associated-const-trait-bound.rs b/src/test/ui/associated-const/associated-const-trait-bound.rs
deleted file mode 100644 (file)
index 403cdbd..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// build-pass (FIXME(62277): could be check-pass?)
-
-trait ConstDefault {
-    const DEFAULT: Self;
-}
-
-trait Foo: Sized {}
-
-trait FooExt: Foo {
-    type T: ConstDefault;
-}
-
-trait Bar<F: FooExt> {
-    const T: F::T;
-}
-
-impl<F: FooExt> Bar<F> for () {
-    const T: F::T = <F::T as ConstDefault>::DEFAULT;
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arms.rs b/src/test/ui/associated-const/associated-const-type-parameter-arms.rs
deleted file mode 100644 (file)
index 3f260d8..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-pub enum EFoo { A, B, C, D }
-
-pub trait Foo {
-    const X: EFoo;
-}
-
-struct Abc;
-
-impl Foo for Abc {
-    const X: EFoo = EFoo::B;
-}
-
-struct Def;
-impl Foo for Def {
-    const X: EFoo = EFoo::D;
-}
-
-pub fn test<A: Foo, B: Foo>(arg: EFoo) {
-    match arg {
-        A::X => println!("A::X"),
-        //~^ error: associated consts cannot be referenced in patterns [E0158]
-        B::X => println!("B::X"),
-        //~^ error: associated consts cannot be referenced in patterns [E0158]
-        _ => (),
-    }
-}
-
-fn main() {
-}
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arms.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arms.stderr
deleted file mode 100644 (file)
index 1ccf9fe..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-error[E0158]: associated consts cannot be referenced in patterns
-  --> $DIR/associated-const-type-parameter-arms.rs:20:9
-   |
-LL |         A::X => println!("A::X"),
-   |         ^^^^
-
-error[E0158]: associated consts cannot be referenced in patterns
-  --> $DIR/associated-const-type-parameter-arms.rs:22:9
-   |
-LL |         B::X => println!("B::X"),
-   |         ^^^^
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0158`.
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs
deleted file mode 100644 (file)
index 8fe79b9..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-pub trait Foo {
-    const Y: usize;
-}
-
-struct Abc;
-impl Foo for Abc {
-    const Y: usize = 8;
-}
-
-struct Def;
-impl Foo for Def {
-    const Y: usize = 33;
-}
-
-pub fn test<A: Foo, B: Foo>() {
-    let _array = [4; <A as Foo>::Y];
-    //~^ ERROR constant expression depends on a generic parameter
-}
-
-fn main() {
-}
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr
deleted file mode 100644 (file)
index 0bc019b..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-error: constant expression depends on a generic parameter
-  --> $DIR/associated-const-type-parameter-arrays-2.rs:16:22
-   |
-LL |     let _array = [4; <A as Foo>::Y];
-   |                      ^^^^^^^^^^^^^
-   |
-   = note: this may fail depending on what value the parameter takes
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs
deleted file mode 100644 (file)
index d518210..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-pub trait Foo {
-    const Y: usize;
-}
-
-struct Abc;
-impl Foo for Abc {
-    const Y: usize = 8;
-}
-
-struct Def;
-impl Foo for Def {
-    const Y: usize = 33;
-}
-
-pub fn test<A: Foo, B: Foo>() {
-    let _array: [u32; <A as Foo>::Y];
-    //~^ ERROR the trait bound `A: Foo` is not satisfied [E0277]
-}
-
-fn main() {
-}
diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr
deleted file mode 100644 (file)
index ac40e39..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0277]: the trait bound `A: Foo` is not satisfied
-  --> $DIR/associated-const-type-parameter-arrays.rs:16:23
-   |
-LL |     const Y: usize;
-   |     --------------- required by `Foo::Y`
-...
-LL |     let _array: [u32; <A as Foo>::Y];
-   |                       ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A`
-   |
-help: consider further restricting this bound
-   |
-LL | pub fn test<A: Foo + Foo, B: Foo>() {
-   |                    ^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/associated-const/defaults-cyclic-fail.rs b/src/test/ui/associated-const/defaults-cyclic-fail.rs
deleted file mode 100644 (file)
index 9fb1bbe..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// build-fail
-//~^ ERROR cycle detected when normalizing `<() as Tr>::A`
-
-// Cyclic assoc. const defaults don't error unless *used*
-trait Tr {
-    const A: u8 = Self::B;
-
-    const B: u8 = Self::A;
-}
-
-// This impl is *allowed* unless its assoc. consts are used
-impl Tr for () {}
-
-fn main() {
-    // This triggers the cycle error
-    assert_eq!(<() as Tr>::A, 0);
-}
diff --git a/src/test/ui/associated-const/defaults-cyclic-fail.stderr b/src/test/ui/associated-const/defaults-cyclic-fail.stderr
deleted file mode 100644 (file)
index 616ac90..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-error[E0391]: cycle detected when normalizing `<() as Tr>::A`
-   |
-note: ...which requires simplifying constant for the type system `Tr::A`...
-  --> $DIR/defaults-cyclic-fail.rs:6:5
-   |
-LL |     const A: u8 = Self::B;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires simplifying constant for the type system `Tr::A`...
-  --> $DIR/defaults-cyclic-fail.rs:6:5
-   |
-LL |     const A: u8 = Self::B;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires const-evaluating + checking `Tr::A`...
-  --> $DIR/defaults-cyclic-fail.rs:6:5
-   |
-LL |     const A: u8 = Self::B;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-   = note: ...which requires normalizing `<() as Tr>::B`...
-note: ...which requires simplifying constant for the type system `Tr::B`...
-  --> $DIR/defaults-cyclic-fail.rs:8:5
-   |
-LL |     const B: u8 = Self::A;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires simplifying constant for the type system `Tr::B`...
-  --> $DIR/defaults-cyclic-fail.rs:8:5
-   |
-LL |     const B: u8 = Self::A;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires const-evaluating + checking `Tr::B`...
-  --> $DIR/defaults-cyclic-fail.rs:8:5
-   |
-LL |     const B: u8 = Self::A;
-   |     ^^^^^^^^^^^^^^^^^^^^^^
-   = note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle
-note: cycle used when const-evaluating + checking `main::promoted[2]`
-  --> $DIR/defaults-cyclic-fail.rs:14:1
-   |
-LL | fn main() {
-   | ^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/associated-const/defaults-cyclic-pass.rs b/src/test/ui/associated-const/defaults-cyclic-pass.rs
deleted file mode 100644 (file)
index 82105f2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// run-pass
-
-// Cyclic assoc. const defaults don't error unless *used*
-trait Tr {
-    const A: u8 = Self::B;
-    const B: u8 = Self::A;
-}
-
-// This impl is *allowed* unless its assoc. consts are used, matching the
-// behavior without defaults.
-impl Tr for () {}
-
-// Overriding either constant breaks the cycle
-impl Tr for u8 {
-    const A: u8 = 42;
-}
-
-impl Tr for u16 {
-    const B: u8 = 0;
-}
-
-impl Tr for u32 {
-    const A: u8 = 100;
-    const B: u8 = 123;
-}
-
-fn main() {
-    assert_eq!(<u8 as Tr>::A, 42);
-    assert_eq!(<u8 as Tr>::B, 42);
-
-    assert_eq!(<u16 as Tr>::A, 0);
-    assert_eq!(<u16 as Tr>::B, 0);
-
-    assert_eq!(<u32 as Tr>::A, 100);
-    assert_eq!(<u32 as Tr>::B, 123);
-}
diff --git a/src/test/ui/associated-const/defaults-not-assumed-fail.rs b/src/test/ui/associated-const/defaults-not-assumed-fail.rs
deleted file mode 100644 (file)
index d7a48cb..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// build-fail
-
-trait Tr {
-    const A: u8 = 255;
-
-    // This should not be a constant evaluation error (overflow). The value of
-    // `Self::A` must not be assumed to hold inside the trait.
-    const B: u8 = Self::A + 1;
-    //~^ ERROR any use of this value will cause an error
-}
-
-// An impl that doesn't override any constant will NOT cause a const eval error
-// just because it's defined, but only if the bad constant is used anywhere.
-// This matches the behavior without defaults.
-impl Tr for () {}
-
-// An impl that overrides either constant with a suitable value will be fine.
-impl Tr for u8 {
-    const A: u8 = 254;
-}
-
-impl Tr for u16 {
-    const B: u8 = 0;
-}
-
-impl Tr for u32 {
-    const A: u8 = 254;
-    const B: u8 = 0;
-}
-
-fn main() {
-    assert_eq!(<() as Tr>::A, 255);
-    assert_eq!(<() as Tr>::B, 0);    // causes the error above
-    //~^ ERROR evaluation of constant expression failed
-    //~| ERROR erroneous constant used
-
-    assert_eq!(<u8 as Tr>::A, 254);
-    assert_eq!(<u8 as Tr>::B, 255);
-
-    assert_eq!(<u16 as Tr>::A, 255);
-    assert_eq!(<u16 as Tr>::B, 0);
-
-    assert_eq!(<u32 as Tr>::A, 254);
-    assert_eq!(<u32 as Tr>::B, 0);
-}
diff --git a/src/test/ui/associated-const/defaults-not-assumed-fail.stderr b/src/test/ui/associated-const/defaults-not-assumed-fail.stderr
deleted file mode 100644 (file)
index 1497633..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-error: any use of this value will cause an error
-  --> $DIR/defaults-not-assumed-fail.rs:8:19
-   |
-LL |     const B: u8 = Self::A + 1;
-   |     --------------^^^^^^^^^^^-
-   |                   |
-   |                   attempt to compute `u8::MAX + 1_u8`, which would overflow
-   |
-   = note: `#[deny(const_err)]` on by default
-
-error[E0080]: evaluation of constant expression failed
-  --> $DIR/defaults-not-assumed-fail.rs:33:5
-   |
-LL |     assert_eq!(<() as Tr>::B, 0);    // causes the error above
-   |     ^^^^^^^^^^^-------------^^^^^
-   |                |
-   |                referenced constant has errors
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: erroneous constant used
-  --> $DIR/defaults-not-assumed-fail.rs:33:5
-   |
-LL |     assert_eq!(<() as Tr>::B, 0);    // causes the error above
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/associated-const/defaults-not-assumed-pass.rs b/src/test/ui/associated-const/defaults-not-assumed-pass.rs
deleted file mode 100644 (file)
index c08e05c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// run-pass
-
-trait Tr {
-    const A: u8 = 255;
-
-    // This should not be a constant evaluation error (overflow). The value of
-    // `Self::A` must not be assumed to hold inside the trait.
-    const B: u8 = Self::A + 1;
-}
-
-// An impl that doesn't override any constant will NOT cause a const eval error
-// just because it's defined, but only if the bad constant is used anywhere.
-// This matches the behavior without defaults.
-impl Tr for () {}
-
-// An impl that overrides either constant with a suitable value will be fine.
-impl Tr for u8 {
-    const A: u8 = 254;
-}
-
-impl Tr for u16 {
-    const B: u8 = 0;
-}
-
-impl Tr for u32 {
-    const A: u8 = 254;
-    const B: u8 = 0;
-}
-
-fn main() {
-    assert_eq!(<() as Tr>::A, 255);
-    //assert_eq!(<() as Tr>::B, 0);  // using this is an error
-
-    assert_eq!(<u8 as Tr>::A, 254);
-    assert_eq!(<u8 as Tr>::B, 255);
-
-    assert_eq!(<u16 as Tr>::A, 255);
-    assert_eq!(<u16 as Tr>::B, 0);
-
-    assert_eq!(<u32 as Tr>::A, 254);
-    assert_eq!(<u32 as Tr>::B, 0);
-}
diff --git a/src/test/ui/associated-const/issue-63496.rs b/src/test/ui/associated-const/issue-63496.rs
deleted file mode 100644 (file)
index f9f663a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-trait A {
-    const C: usize;
-
-    fn f() -> ([u8; A::C], [u8; A::C]);
-    //~^ ERROR: type annotations needed
-    //~| ERROR: type annotations needed
-}
-
-fn main() {}
diff --git a/src/test/ui/associated-const/issue-63496.stderr b/src/test/ui/associated-const/issue-63496.stderr
deleted file mode 100644 (file)
index 34e9470..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-error[E0283]: type annotations needed
-  --> $DIR/issue-63496.rs:4:21
-   |
-LL |     const C: usize;
-   |     --------------- required by `A::C`
-LL | 
-LL |     fn f() -> ([u8; A::C], [u8; A::C]);
-   |                     ^^^^
-   |                     |
-   |                     cannot infer type
-   |                     help: use the fully qualified path to an implementation: `<Type as A>::C`
-   |
-   = note: cannot satisfy `_: A`
-   = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
-
-error[E0283]: type annotations needed
-  --> $DIR/issue-63496.rs:4:33
-   |
-LL |     const C: usize;
-   |     --------------- required by `A::C`
-LL | 
-LL |     fn f() -> ([u8; A::C], [u8; A::C]);
-   |                                 ^^^^
-   |                                 |
-   |                                 cannot infer type
-   |                                 help: use the fully qualified path to an implementation: `<Type as A>::C`
-   |
-   = note: cannot satisfy `_: A`
-   = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0283`.
diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.noopt.stderr
deleted file mode 100644 (file)
index f59287b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
-   |
-LL |     const NEG: i32 = -i32::MIN + T::NEG;
-   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-   |
-   = note: `#[deny(arithmetic_overflow)]` on by default
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
-   |
-LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
-   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
-   |
-LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
-   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
-   |
-LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
-   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
-   |
-LL |     const DIV: i32 = (1/0) + T::DIV;
-   |                      ^^^^^ attempt to divide `1_i32` by zero
-   |
-   = note: `#[deny(unconditional_panic)]` on by default
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
-   |
-LL |     const DIV_REV: i32 = T::DIV + (1/0);
-   |                                   ^^^^^ attempt to divide `1_i32` by zero
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
-   |
-LL |     const OOB: i32 = [1][1] + T::OOB;
-   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
-   |
-LL |     const OOB_REV: i32 = T::OOB + [1][1];
-   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: aborting due to 8 previous errors
-
diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt.stderr
deleted file mode 100644 (file)
index f59287b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
-   |
-LL |     const NEG: i32 = -i32::MIN + T::NEG;
-   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-   |
-   = note: `#[deny(arithmetic_overflow)]` on by default
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
-   |
-LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
-   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
-   |
-LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
-   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
-   |
-LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
-   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
-   |
-LL |     const DIV: i32 = (1/0) + T::DIV;
-   |                      ^^^^^ attempt to divide `1_i32` by zero
-   |
-   = note: `#[deny(unconditional_panic)]` on by default
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
-   |
-LL |     const DIV_REV: i32 = T::DIV + (1/0);
-   |                                   ^^^^^ attempt to divide `1_i32` by zero
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
-   |
-LL |     const OOB: i32 = [1][1] + T::OOB;
-   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
-   |
-LL |     const OOB_REV: i32 = T::OOB + [1][1];
-   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: aborting due to 8 previous errors
-
diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr
deleted file mode 100644 (file)
index f59287b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
-   |
-LL |     const NEG: i32 = -i32::MIN + T::NEG;
-   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-   |
-   = note: `#[deny(arithmetic_overflow)]` on by default
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
-   |
-LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
-   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
-   |
-LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
-   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this arithmetic operation will overflow
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
-   |
-LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
-   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
-   |
-LL |     const DIV: i32 = (1/0) + T::DIV;
-   |                      ^^^^^ attempt to divide `1_i32` by zero
-   |
-   = note: `#[deny(unconditional_panic)]` on by default
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
-   |
-LL |     const DIV_REV: i32 = T::DIV + (1/0);
-   |                                   ^^^^^ attempt to divide `1_i32` by zero
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
-   |
-LL |     const OOB: i32 = [1][1] + T::OOB;
-   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: this operation will panic at runtime
-  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
-   |
-LL |     const OOB_REV: i32 = T::OOB + [1][1];
-   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
-
-error: aborting due to 8 previous errors
-
diff --git a/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs b/src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs
deleted file mode 100644 (file)
index 850f65a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// revisions: noopt opt opt_with_overflow_checks
-//[noopt]compile-flags: -C opt-level=0
-//[opt]compile-flags: -O
-//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
-
-#![crate_type="lib"]
-
-use std::i32;
-
-pub trait Foo {
-    const NEG: i32;
-    const NEG_REV: i32;
-
-    const ADD: i32;
-    const ADD_REV: i32;
-
-    const DIV: i32;
-    const DIV_REV: i32;
-
-    const OOB: i32;
-    const OOB_REV: i32;
-}
-
-// These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
-// like normal run-time code. But codegen works a bit different in const context, so this test
-// makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
-// operands (so that the generic operand comes first).
-impl<T: Foo> Foo for Vec<T> {
-    const NEG: i32 = -i32::MIN + T::NEG;
-    //~^ ERROR arithmetic operation will overflow
-    const NEG_REV: i32 = T::NEG + (-i32::MIN);
-    //~^ ERROR arithmetic operation will overflow
-
-    const ADD: i32 = (i32::MAX+1) + T::ADD;
-    //~^ ERROR arithmetic operation will overflow
-    const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
-    //~^ ERROR arithmetic operation will overflow
-
-    const DIV: i32 = (1/0) + T::DIV;
-    //~^ ERROR operation will panic
-    const DIV_REV: i32 = T::DIV + (1/0);
-    //~^ ERROR operation will panic
-
-    const OOB: i32 = [1][1] + T::OOB;
-    //~^ ERROR operation will panic
-    const OOB_REV: i32 = T::OOB + [1][1];
-    //~^ ERROR operation will panic
-}
diff --git a/src/test/ui/associated-consts/associated-const-ambiguity-report.rs b/src/test/ui/associated-consts/associated-const-ambiguity-report.rs
new file mode 100644 (file)
index 0000000..927d2c6
--- /dev/null
@@ -0,0 +1,21 @@
+trait Foo {
+    const ID: i32;
+}
+
+trait Bar {
+    const ID: i32;
+}
+
+impl Foo for i32 {
+    const ID: i32 = 1;
+}
+
+impl Bar for i32 {
+    const ID: i32 = 3;
+}
+
+const X: i32 = <i32>::ID; //~ ERROR E0034
+
+fn main() {
+    assert_eq!(1, X);
+}
diff --git a/src/test/ui/associated-consts/associated-const-ambiguity-report.stderr b/src/test/ui/associated-consts/associated-const-ambiguity-report.stderr
new file mode 100644 (file)
index 0000000..c5e32af
--- /dev/null
@@ -0,0 +1,28 @@
+error[E0034]: multiple applicable items in scope
+  --> $DIR/associated-const-ambiguity-report.rs:17:23
+   |
+LL | const X: i32 = <i32>::ID;
+   |                       ^^ multiple `ID` found
+   |
+note: candidate #1 is defined in an impl of the trait `Foo` for the type `i32`
+  --> $DIR/associated-const-ambiguity-report.rs:10:5
+   |
+LL |     const ID: i32 = 1;
+   |     ^^^^^^^^^^^^^^^^^^
+note: candidate #2 is defined in an impl of the trait `Bar` for the type `i32`
+  --> $DIR/associated-const-ambiguity-report.rs:14:5
+   |
+LL |     const ID: i32 = 3;
+   |     ^^^^^^^^^^^^^^^^^^
+help: disambiguate the associated constant for candidate #1
+   |
+LL | const X: i32 = Foo::ID;
+   |                ^^^^^^^
+help: disambiguate the associated constant for candidate #2
+   |
+LL | const X: i32 = Bar::ID;
+   |                ^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0034`.
diff --git a/src/test/ui/associated-consts/associated-const-array-len.rs b/src/test/ui/associated-consts/associated-const-array-len.rs
new file mode 100644 (file)
index 0000000..17d7824
--- /dev/null
@@ -0,0 +1,10 @@
+trait Foo {
+    const ID: usize;
+}
+
+const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
+//~^ ERROR the trait bound `i32: Foo` is not satisfied
+
+fn main() {
+    assert_eq!(1, X);
+}
diff --git a/src/test/ui/associated-consts/associated-const-array-len.stderr b/src/test/ui/associated-consts/associated-const-array-len.stderr
new file mode 100644 (file)
index 0000000..2fdfa3d
--- /dev/null
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `i32: Foo` is not satisfied
+  --> $DIR/associated-const-array-len.rs:5:16
+   |
+LL |     const ID: usize;
+   |     ---------------- required by `Foo::ID`
+...
+LL | const X: [i32; <i32 as Foo>::ID] = [0, 1, 2];
+   |                ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/associated-consts/associated-const-dead-code.rs b/src/test/ui/associated-consts/associated-const-dead-code.rs
new file mode 100644 (file)
index 0000000..e659bdb
--- /dev/null
@@ -0,0 +1,12 @@
+#![deny(dead_code)]
+
+struct MyFoo;
+
+impl MyFoo {
+    const BAR: u32 = 1;
+    //~^ ERROR associated constant is never used: `BAR`
+}
+
+fn main() {
+    let _: MyFoo = MyFoo;
+}
diff --git a/src/test/ui/associated-consts/associated-const-dead-code.stderr b/src/test/ui/associated-consts/associated-const-dead-code.stderr
new file mode 100644 (file)
index 0000000..9b6bbb6
--- /dev/null
@@ -0,0 +1,14 @@
+error: associated constant is never used: `BAR`
+  --> $DIR/associated-const-dead-code.rs:6:5
+   |
+LL |     const BAR: u32 = 1;
+   |     ^^^^^^^^^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/associated-const-dead-code.rs:1:9
+   |
+LL | #![deny(dead_code)]
+   |         ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/associated-consts/associated-const-generic-obligations.rs b/src/test/ui/associated-consts/associated-const-generic-obligations.rs
new file mode 100644 (file)
index 0000000..498e315
--- /dev/null
@@ -0,0 +1,18 @@
+trait Foo {
+    type Out: Sized;
+}
+
+impl Foo for String {
+    type Out = String;
+}
+
+trait Bar: Foo {
+    const FROM: Self::Out;
+}
+
+impl<T: Foo> Bar for T {
+    const FROM: &'static str = "foo";
+    //~^ ERROR implemented const `FROM` has an incompatible type for trait [E0326]
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/associated-const-generic-obligations.stderr b/src/test/ui/associated-consts/associated-const-generic-obligations.stderr
new file mode 100644 (file)
index 0000000..d8bac07
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0326]: implemented const `FROM` has an incompatible type for trait
+  --> $DIR/associated-const-generic-obligations.rs:14:17
+   |
+LL |     const FROM: Self::Out;
+   |                 --------- type in trait
+...
+LL |     const FROM: &'static str = "foo";
+   |                 ^^^^^^^^^^^^ expected associated type, found `&str`
+   |
+   = note: expected associated type `<T as Foo>::Out`
+                    found reference `&'static str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0326`.
diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.rs b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.rs
new file mode 100644 (file)
index 0000000..08260ec
--- /dev/null
@@ -0,0 +1,11 @@
+trait Foo {
+    const NAME: &'static str;
+}
+
+
+impl<'a> Foo for &'a () {
+    const NAME: &'a str = "unit";
+    //~^ ERROR mismatched types [E0308]
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr
new file mode 100644 (file)
index 0000000..0cce10b
--- /dev/null
@@ -0,0 +1,18 @@
+error[E0308]: mismatched types
+  --> $DIR/associated-const-impl-wrong-lifetime.rs:7:5
+   |
+LL |     const NAME: &'a str = "unit";
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+   |
+   = note: expected reference `&'static str`
+              found reference `&'a str`
+note: the lifetime `'a` as defined on the impl at 6:6...
+  --> $DIR/associated-const-impl-wrong-lifetime.rs:6:6
+   |
+LL | impl<'a> Foo for &'a () {
+   |      ^^
+   = note: ...does not necessarily outlive the static lifetime
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-type.rs b/src/test/ui/associated-consts/associated-const-impl-wrong-type.rs
new file mode 100644 (file)
index 0000000..1aad749
--- /dev/null
@@ -0,0 +1,12 @@
+trait Foo {
+    const BAR: u32;
+}
+
+struct SignedBar;
+
+impl Foo for SignedBar {
+    const BAR: i32 = -1;
+    //~^ ERROR implemented const `BAR` has an incompatible type for trait [E0326]
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-type.stderr b/src/test/ui/associated-consts/associated-const-impl-wrong-type.stderr
new file mode 100644 (file)
index 0000000..acdf33b
--- /dev/null
@@ -0,0 +1,12 @@
+error[E0326]: implemented const `BAR` has an incompatible type for trait
+  --> $DIR/associated-const-impl-wrong-type.rs:8:16
+   |
+LL |     const BAR: u32;
+   |                --- type in trait
+...
+LL |     const BAR: i32 = -1;
+   |                ^^^ expected `u32`, found `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0326`.
diff --git a/src/test/ui/associated-consts/associated-const-in-trait.rs b/src/test/ui/associated-consts/associated-const-in-trait.rs
new file mode 100644 (file)
index 0000000..cc3acd5
--- /dev/null
@@ -0,0 +1,14 @@
+// #29924
+
+#![feature(const_fn, associated_consts)]
+
+trait Trait {
+    const N: usize;
+}
+
+impl dyn Trait {
+    //~^ ERROR the trait `Trait` cannot be made into an object [E0038]
+    const fn n() -> usize { Self::N }
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/associated-const-in-trait.stderr b/src/test/ui/associated-consts/associated-const-in-trait.stderr
new file mode 100644 (file)
index 0000000..a8a8d01
--- /dev/null
@@ -0,0 +1,16 @@
+error[E0038]: the trait `Trait` cannot be made into an object
+  --> $DIR/associated-const-in-trait.rs:9:6
+   |
+LL | trait Trait {
+   |       ----- this trait cannot be made into an object...
+LL |     const N: usize;
+   |           - ...because it contains this associated `const`
+...
+LL | impl dyn Trait {
+   |      ^^^^^^^^^ the trait `Trait` cannot be made into an object
+   |
+   = help: consider moving `N` to another trait
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0038`.
diff --git a/src/test/ui/associated-consts/associated-const-no-item.rs b/src/test/ui/associated-consts/associated-const-no-item.rs
new file mode 100644 (file)
index 0000000..024d14e
--- /dev/null
@@ -0,0 +1,10 @@
+trait Foo {
+    const ID: i32;
+}
+
+const X: i32 = <i32>::ID;
+//~^ ERROR no associated item named `ID` found
+
+fn main() {
+    assert_eq!(1, X);
+}
diff --git a/src/test/ui/associated-consts/associated-const-no-item.stderr b/src/test/ui/associated-consts/associated-const-no-item.stderr
new file mode 100644 (file)
index 0000000..fe27da5
--- /dev/null
@@ -0,0 +1,16 @@
+error[E0599]: no associated item named `ID` found for type `i32` in the current scope
+  --> $DIR/associated-const-no-item.rs:5:23
+   |
+LL | const X: i32 = <i32>::ID;
+   |                       ^^ associated item not found in `i32`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Foo` defines an item `ID`, perhaps you need to implement it
+  --> $DIR/associated-const-no-item.rs:1:1
+   |
+LL | trait Foo {
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/associated-consts/associated-const-private-impl.rs b/src/test/ui/associated-consts/associated-const-private-impl.rs
new file mode 100644 (file)
index 0000000..3ee3134
--- /dev/null
@@ -0,0 +1,15 @@
+mod bar1 {
+    pub use self::bar2::Foo;
+    mod bar2 {
+        pub struct Foo;
+
+        impl Foo {
+            const ID: i32 = 1;
+        }
+    }
+}
+
+fn main() {
+    assert_eq!(1, bar1::Foo::ID);
+    //~^ERROR associated constant `ID` is private
+}
diff --git a/src/test/ui/associated-consts/associated-const-private-impl.stderr b/src/test/ui/associated-consts/associated-const-private-impl.stderr
new file mode 100644 (file)
index 0000000..1b9d7ac
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0624]: associated constant `ID` is private
+  --> $DIR/associated-const-private-impl.rs:13:30
+   |
+LL |     assert_eq!(1, bar1::Foo::ID);
+   |                              ^^ private associated constant
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0624`.
diff --git a/src/test/ui/associated-consts/associated-const-trait-bound.rs b/src/test/ui/associated-consts/associated-const-trait-bound.rs
new file mode 100644 (file)
index 0000000..403cdbd
--- /dev/null
@@ -0,0 +1,21 @@
+// build-pass (FIXME(62277): could be check-pass?)
+
+trait ConstDefault {
+    const DEFAULT: Self;
+}
+
+trait Foo: Sized {}
+
+trait FooExt: Foo {
+    type T: ConstDefault;
+}
+
+trait Bar<F: FooExt> {
+    const T: F::T;
+}
+
+impl<F: FooExt> Bar<F> for () {
+    const T: F::T = <F::T as ConstDefault>::DEFAULT;
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arms.rs b/src/test/ui/associated-consts/associated-const-type-parameter-arms.rs
new file mode 100644 (file)
index 0000000..3f260d8
--- /dev/null
@@ -0,0 +1,29 @@
+pub enum EFoo { A, B, C, D }
+
+pub trait Foo {
+    const X: EFoo;
+}
+
+struct Abc;
+
+impl Foo for Abc {
+    const X: EFoo = EFoo::B;
+}
+
+struct Def;
+impl Foo for Def {
+    const X: EFoo = EFoo::D;
+}
+
+pub fn test<A: Foo, B: Foo>(arg: EFoo) {
+    match arg {
+        A::X => println!("A::X"),
+        //~^ error: associated consts cannot be referenced in patterns [E0158]
+        B::X => println!("B::X"),
+        //~^ error: associated consts cannot be referenced in patterns [E0158]
+        _ => (),
+    }
+}
+
+fn main() {
+}
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arms.stderr b/src/test/ui/associated-consts/associated-const-type-parameter-arms.stderr
new file mode 100644 (file)
index 0000000..1ccf9fe
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0158]: associated consts cannot be referenced in patterns
+  --> $DIR/associated-const-type-parameter-arms.rs:20:9
+   |
+LL |         A::X => println!("A::X"),
+   |         ^^^^
+
+error[E0158]: associated consts cannot be referenced in patterns
+  --> $DIR/associated-const-type-parameter-arms.rs:22:9
+   |
+LL |         B::X => println!("B::X"),
+   |         ^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0158`.
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.rs b/src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.rs
new file mode 100644 (file)
index 0000000..8fe79b9
--- /dev/null
@@ -0,0 +1,21 @@
+pub trait Foo {
+    const Y: usize;
+}
+
+struct Abc;
+impl Foo for Abc {
+    const Y: usize = 8;
+}
+
+struct Def;
+impl Foo for Def {
+    const Y: usize = 33;
+}
+
+pub fn test<A: Foo, B: Foo>() {
+    let _array = [4; <A as Foo>::Y];
+    //~^ ERROR constant expression depends on a generic parameter
+}
+
+fn main() {
+}
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.stderr b/src/test/ui/associated-consts/associated-const-type-parameter-arrays-2.stderr
new file mode 100644 (file)
index 0000000..0bc019b
--- /dev/null
@@ -0,0 +1,10 @@
+error: constant expression depends on a generic parameter
+  --> $DIR/associated-const-type-parameter-arrays-2.rs:16:22
+   |
+LL |     let _array = [4; <A as Foo>::Y];
+   |                      ^^^^^^^^^^^^^
+   |
+   = note: this may fail depending on what value the parameter takes
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arrays.rs b/src/test/ui/associated-consts/associated-const-type-parameter-arrays.rs
new file mode 100644 (file)
index 0000000..d518210
--- /dev/null
@@ -0,0 +1,21 @@
+pub trait Foo {
+    const Y: usize;
+}
+
+struct Abc;
+impl Foo for Abc {
+    const Y: usize = 8;
+}
+
+struct Def;
+impl Foo for Def {
+    const Y: usize = 33;
+}
+
+pub fn test<A: Foo, B: Foo>() {
+    let _array: [u32; <A as Foo>::Y];
+    //~^ ERROR the trait bound `A: Foo` is not satisfied [E0277]
+}
+
+fn main() {
+}
diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr b/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr
new file mode 100644 (file)
index 0000000..ac40e39
--- /dev/null
@@ -0,0 +1,17 @@
+error[E0277]: the trait bound `A: Foo` is not satisfied
+  --> $DIR/associated-const-type-parameter-arrays.rs:16:23
+   |
+LL |     const Y: usize;
+   |     --------------- required by `Foo::Y`
+...
+LL |     let _array: [u32; <A as Foo>::Y];
+   |                       ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A`
+   |
+help: consider further restricting this bound
+   |
+LL | pub fn test<A: Foo + Foo, B: Foo>() {
+   |                    ^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/associated-consts/defaults-cyclic-fail.rs b/src/test/ui/associated-consts/defaults-cyclic-fail.rs
new file mode 100644 (file)
index 0000000..9fb1bbe
--- /dev/null
@@ -0,0 +1,17 @@
+// build-fail
+//~^ ERROR cycle detected when normalizing `<() as Tr>::A`
+
+// Cyclic assoc. const defaults don't error unless *used*
+trait Tr {
+    const A: u8 = Self::B;
+
+    const B: u8 = Self::A;
+}
+
+// This impl is *allowed* unless its assoc. consts are used
+impl Tr for () {}
+
+fn main() {
+    // This triggers the cycle error
+    assert_eq!(<() as Tr>::A, 0);
+}
diff --git a/src/test/ui/associated-consts/defaults-cyclic-fail.stderr b/src/test/ui/associated-consts/defaults-cyclic-fail.stderr
new file mode 100644 (file)
index 0000000..616ac90
--- /dev/null
@@ -0,0 +1,43 @@
+error[E0391]: cycle detected when normalizing `<() as Tr>::A`
+   |
+note: ...which requires simplifying constant for the type system `Tr::A`...
+  --> $DIR/defaults-cyclic-fail.rs:6:5
+   |
+LL |     const A: u8 = Self::B;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires simplifying constant for the type system `Tr::A`...
+  --> $DIR/defaults-cyclic-fail.rs:6:5
+   |
+LL |     const A: u8 = Self::B;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires const-evaluating + checking `Tr::A`...
+  --> $DIR/defaults-cyclic-fail.rs:6:5
+   |
+LL |     const A: u8 = Self::B;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   = note: ...which requires normalizing `<() as Tr>::B`...
+note: ...which requires simplifying constant for the type system `Tr::B`...
+  --> $DIR/defaults-cyclic-fail.rs:8:5
+   |
+LL |     const B: u8 = Self::A;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires simplifying constant for the type system `Tr::B`...
+  --> $DIR/defaults-cyclic-fail.rs:8:5
+   |
+LL |     const B: u8 = Self::A;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires const-evaluating + checking `Tr::B`...
+  --> $DIR/defaults-cyclic-fail.rs:8:5
+   |
+LL |     const B: u8 = Self::A;
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   = note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle
+note: cycle used when const-evaluating + checking `main::promoted[2]`
+  --> $DIR/defaults-cyclic-fail.rs:14:1
+   |
+LL | fn main() {
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/associated-consts/defaults-cyclic-pass.rs b/src/test/ui/associated-consts/defaults-cyclic-pass.rs
new file mode 100644 (file)
index 0000000..82105f2
--- /dev/null
@@ -0,0 +1,36 @@
+// run-pass
+
+// Cyclic assoc. const defaults don't error unless *used*
+trait Tr {
+    const A: u8 = Self::B;
+    const B: u8 = Self::A;
+}
+
+// This impl is *allowed* unless its assoc. consts are used, matching the
+// behavior without defaults.
+impl Tr for () {}
+
+// Overriding either constant breaks the cycle
+impl Tr for u8 {
+    const A: u8 = 42;
+}
+
+impl Tr for u16 {
+    const B: u8 = 0;
+}
+
+impl Tr for u32 {
+    const A: u8 = 100;
+    const B: u8 = 123;
+}
+
+fn main() {
+    assert_eq!(<u8 as Tr>::A, 42);
+    assert_eq!(<u8 as Tr>::B, 42);
+
+    assert_eq!(<u16 as Tr>::A, 0);
+    assert_eq!(<u16 as Tr>::B, 0);
+
+    assert_eq!(<u32 as Tr>::A, 100);
+    assert_eq!(<u32 as Tr>::B, 123);
+}
diff --git a/src/test/ui/associated-consts/defaults-not-assumed-fail.rs b/src/test/ui/associated-consts/defaults-not-assumed-fail.rs
new file mode 100644 (file)
index 0000000..d7a48cb
--- /dev/null
@@ -0,0 +1,45 @@
+// build-fail
+
+trait Tr {
+    const A: u8 = 255;
+
+    // This should not be a constant evaluation error (overflow). The value of
+    // `Self::A` must not be assumed to hold inside the trait.
+    const B: u8 = Self::A + 1;
+    //~^ ERROR any use of this value will cause an error
+}
+
+// An impl that doesn't override any constant will NOT cause a const eval error
+// just because it's defined, but only if the bad constant is used anywhere.
+// This matches the behavior without defaults.
+impl Tr for () {}
+
+// An impl that overrides either constant with a suitable value will be fine.
+impl Tr for u8 {
+    const A: u8 = 254;
+}
+
+impl Tr for u16 {
+    const B: u8 = 0;
+}
+
+impl Tr for u32 {
+    const A: u8 = 254;
+    const B: u8 = 0;
+}
+
+fn main() {
+    assert_eq!(<() as Tr>::A, 255);
+    assert_eq!(<() as Tr>::B, 0);    // causes the error above
+    //~^ ERROR evaluation of constant expression failed
+    //~| ERROR erroneous constant used
+
+    assert_eq!(<u8 as Tr>::A, 254);
+    assert_eq!(<u8 as Tr>::B, 255);
+
+    assert_eq!(<u16 as Tr>::A, 255);
+    assert_eq!(<u16 as Tr>::B, 0);
+
+    assert_eq!(<u32 as Tr>::A, 254);
+    assert_eq!(<u32 as Tr>::B, 0);
+}
diff --git a/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr b/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr
new file mode 100644 (file)
index 0000000..1497633
--- /dev/null
@@ -0,0 +1,31 @@
+error: any use of this value will cause an error
+  --> $DIR/defaults-not-assumed-fail.rs:8:19
+   |
+LL |     const B: u8 = Self::A + 1;
+   |     --------------^^^^^^^^^^^-
+   |                   |
+   |                   attempt to compute `u8::MAX + 1_u8`, which would overflow
+   |
+   = note: `#[deny(const_err)]` on by default
+
+error[E0080]: evaluation of constant expression failed
+  --> $DIR/defaults-not-assumed-fail.rs:33:5
+   |
+LL |     assert_eq!(<() as Tr>::B, 0);    // causes the error above
+   |     ^^^^^^^^^^^-------------^^^^^
+   |                |
+   |                referenced constant has errors
+   |
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: erroneous constant used
+  --> $DIR/defaults-not-assumed-fail.rs:33:5
+   |
+LL |     assert_eq!(<() as Tr>::B, 0);    // causes the error above
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+   |
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/associated-consts/defaults-not-assumed-pass.rs b/src/test/ui/associated-consts/defaults-not-assumed-pass.rs
new file mode 100644 (file)
index 0000000..c08e05c
--- /dev/null
@@ -0,0 +1,42 @@
+// run-pass
+
+trait Tr {
+    const A: u8 = 255;
+
+    // This should not be a constant evaluation error (overflow). The value of
+    // `Self::A` must not be assumed to hold inside the trait.
+    const B: u8 = Self::A + 1;
+}
+
+// An impl that doesn't override any constant will NOT cause a const eval error
+// just because it's defined, but only if the bad constant is used anywhere.
+// This matches the behavior without defaults.
+impl Tr for () {}
+
+// An impl that overrides either constant with a suitable value will be fine.
+impl Tr for u8 {
+    const A: u8 = 254;
+}
+
+impl Tr for u16 {
+    const B: u8 = 0;
+}
+
+impl Tr for u32 {
+    const A: u8 = 254;
+    const B: u8 = 0;
+}
+
+fn main() {
+    assert_eq!(<() as Tr>::A, 255);
+    //assert_eq!(<() as Tr>::B, 0);  // using this is an error
+
+    assert_eq!(<u8 as Tr>::A, 254);
+    assert_eq!(<u8 as Tr>::B, 255);
+
+    assert_eq!(<u16 as Tr>::A, 255);
+    assert_eq!(<u16 as Tr>::B, 0);
+
+    assert_eq!(<u32 as Tr>::A, 254);
+    assert_eq!(<u32 as Tr>::B, 0);
+}
diff --git a/src/test/ui/associated-consts/issue-63496.rs b/src/test/ui/associated-consts/issue-63496.rs
new file mode 100644 (file)
index 0000000..f9f663a
--- /dev/null
@@ -0,0 +1,9 @@
+trait A {
+    const C: usize;
+
+    fn f() -> ([u8; A::C], [u8; A::C]);
+    //~^ ERROR: type annotations needed
+    //~| ERROR: type annotations needed
+}
+
+fn main() {}
diff --git a/src/test/ui/associated-consts/issue-63496.stderr b/src/test/ui/associated-consts/issue-63496.stderr
new file mode 100644 (file)
index 0000000..34e9470
--- /dev/null
@@ -0,0 +1,33 @@
+error[E0283]: type annotations needed
+  --> $DIR/issue-63496.rs:4:21
+   |
+LL |     const C: usize;
+   |     --------------- required by `A::C`
+LL | 
+LL |     fn f() -> ([u8; A::C], [u8; A::C]);
+   |                     ^^^^
+   |                     |
+   |                     cannot infer type
+   |                     help: use the fully qualified path to an implementation: `<Type as A>::C`
+   |
+   = note: cannot satisfy `_: A`
+   = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
+
+error[E0283]: type annotations needed
+  --> $DIR/issue-63496.rs:4:33
+   |
+LL |     const C: usize;
+   |     --------------- required by `A::C`
+LL | 
+LL |     fn f() -> ([u8; A::C], [u8; A::C]);
+   |                                 ^^^^
+   |                                 |
+   |                                 cannot infer type
+   |                                 help: use the fully qualified path to an implementation: `<Type as A>::C`
+   |
+   = note: cannot satisfy `_: A`
+   = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0283`.
diff --git a/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.noopt.stderr b/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.noopt.stderr
new file mode 100644 (file)
index 0000000..f59287b
--- /dev/null
@@ -0,0 +1,54 @@
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
+   |
+LL |     const NEG: i32 = -i32::MIN + T::NEG;
+   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+   |
+   = note: `#[deny(arithmetic_overflow)]` on by default
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
+   |
+LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
+   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
+   |
+LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
+   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
+   |
+LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
+   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
+   |
+LL |     const DIV: i32 = (1/0) + T::DIV;
+   |                      ^^^^^ attempt to divide `1_i32` by zero
+   |
+   = note: `#[deny(unconditional_panic)]` on by default
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
+   |
+LL |     const DIV_REV: i32 = T::DIV + (1/0);
+   |                                   ^^^^^ attempt to divide `1_i32` by zero
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
+   |
+LL |     const OOB: i32 = [1][1] + T::OOB;
+   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
+   |
+LL |     const OOB_REV: i32 = T::OOB + [1][1];
+   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: aborting due to 8 previous errors
+
diff --git a/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt.stderr b/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt.stderr
new file mode 100644 (file)
index 0000000..f59287b
--- /dev/null
@@ -0,0 +1,54 @@
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
+   |
+LL |     const NEG: i32 = -i32::MIN + T::NEG;
+   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+   |
+   = note: `#[deny(arithmetic_overflow)]` on by default
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
+   |
+LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
+   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
+   |
+LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
+   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
+   |
+LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
+   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
+   |
+LL |     const DIV: i32 = (1/0) + T::DIV;
+   |                      ^^^^^ attempt to divide `1_i32` by zero
+   |
+   = note: `#[deny(unconditional_panic)]` on by default
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
+   |
+LL |     const DIV_REV: i32 = T::DIV + (1/0);
+   |                                   ^^^^^ attempt to divide `1_i32` by zero
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
+   |
+LL |     const OOB: i32 = [1][1] + T::OOB;
+   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
+   |
+LL |     const OOB_REV: i32 = T::OOB + [1][1];
+   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: aborting due to 8 previous errors
+
diff --git a/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr b/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.opt_with_overflow_checks.stderr
new file mode 100644 (file)
index 0000000..f59287b
--- /dev/null
@@ -0,0 +1,54 @@
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
+   |
+LL |     const NEG: i32 = -i32::MIN + T::NEG;
+   |                      ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+   |
+   = note: `#[deny(arithmetic_overflow)]` on by default
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
+   |
+LL |     const NEG_REV: i32 = T::NEG + (-i32::MIN);
+   |                                   ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
+   |
+LL |     const ADD: i32 = (i32::MAX+1) + T::ADD;
+   |                      ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this arithmetic operation will overflow
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
+   |
+LL |     const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
+   |                                    ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
+   |
+LL |     const DIV: i32 = (1/0) + T::DIV;
+   |                      ^^^^^ attempt to divide `1_i32` by zero
+   |
+   = note: `#[deny(unconditional_panic)]` on by default
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
+   |
+LL |     const DIV_REV: i32 = T::DIV + (1/0);
+   |                                   ^^^^^ attempt to divide `1_i32` by zero
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
+   |
+LL |     const OOB: i32 = [1][1] + T::OOB;
+   |                      ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: this operation will panic at runtime
+  --> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
+   |
+LL |     const OOB_REV: i32 = T::OOB + [1][1];
+   |                                   ^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error: aborting due to 8 previous errors
+
diff --git a/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.rs b/src/test/ui/associated-consts/issue-69020-assoc-const-arith-overflow.rs
new file mode 100644 (file)
index 0000000..850f65a
--- /dev/null
@@ -0,0 +1,48 @@
+// revisions: noopt opt opt_with_overflow_checks
+//[noopt]compile-flags: -C opt-level=0
+//[opt]compile-flags: -O
+//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
+
+#![crate_type="lib"]
+
+use std::i32;
+
+pub trait Foo {
+    const NEG: i32;
+    const NEG_REV: i32;
+
+    const ADD: i32;
+    const ADD_REV: i32;
+
+    const DIV: i32;
+    const DIV_REV: i32;
+
+    const OOB: i32;
+    const OOB_REV: i32;
+}
+
+// These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
+// like normal run-time code. But codegen works a bit different in const context, so this test
+// makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
+// operands (so that the generic operand comes first).
+impl<T: Foo> Foo for Vec<T> {
+    const NEG: i32 = -i32::MIN + T::NEG;
+    //~^ ERROR arithmetic operation will overflow
+    const NEG_REV: i32 = T::NEG + (-i32::MIN);
+    //~^ ERROR arithmetic operation will overflow
+
+    const ADD: i32 = (i32::MAX+1) + T::ADD;
+    //~^ ERROR arithmetic operation will overflow
+    const ADD_REV: i32 =  T::ADD + (i32::MAX+1);
+    //~^ ERROR arithmetic operation will overflow
+
+    const DIV: i32 = (1/0) + T::DIV;
+    //~^ ERROR operation will panic
+    const DIV_REV: i32 = T::DIV + (1/0);
+    //~^ ERROR operation will panic
+
+    const OOB: i32 = [1][1] + T::OOB;
+    //~^ ERROR operation will panic
+    const OOB_REV: i32 = T::OOB + [1][1];
+    //~^ ERROR operation will panic
+}