diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-13 03:33:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-13 03:33:46 +0100 |
| commit | c0dcfedd9f27f53dc0a85eff2df2034bf8282d9c (patch) | |
| tree | 2e4eeea86bd8d75bfb10f052451b9ab6c0d861d1 /src/test/ui/associated-const | |
| parent | 13a894288f5735e58f60da40a8225f3eb4357f95 (diff) | |
| parent | aa9bd68fa8134e55ded5e65abef745f96ba0e622 (diff) | |
| download | rust-c0dcfedd9f27f53dc0a85eff2df2034bf8282d9c.tar.gz rust-c0dcfedd9f27f53dc0a85eff2df2034bf8282d9c.zip | |
Rollup merge of #59083 - kyren:master, r=varkor
Fix #54822 and associated faulty tests Type checking associated constants can require trait bounds, but an empty parameter environment was provided to the trait solver. Providing an appropriate parameter environment seems to fix #54822 and also make one of the cases in src/test/ui/nll/trait-associated-constant.rs that should compile successfully do so. It also (slightly) improves the error message in src/test/ui/associated-const/associated-const-generic-obligations.rs
Diffstat (limited to 'src/test/ui/associated-const')
3 files changed, 31 insertions, 6 deletions
diff --git a/src/test/ui/associated-const/associated-const-generic-obligations.rs b/src/test/ui/associated-const/associated-const-generic-obligations.rs index e0b502edaa1..498e315b5c8 100644 --- a/src/test/ui/associated-const/associated-const-generic-obligations.rs +++ b/src/test/ui/associated-const/associated-const-generic-obligations.rs @@ -12,7 +12,7 @@ trait Bar: Foo { impl<T: Foo> Bar for T { const FROM: &'static str = "foo"; - //~^ ERROR the trait bound `T: Foo` is not satisfied [E0277] + //~^ 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 index e4b86d84caf..eeee26a7567 100644 --- a/src/test/ui/associated-const/associated-const-generic-obligations.stderr +++ b/src/test/ui/associated-const/associated-const-generic-obligations.stderr @@ -1,11 +1,15 @@ -error[E0277]: the trait bound `T: Foo` is not satisfied - --> $DIR/associated-const-generic-obligations.rs:14:5 +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"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | ^^^^^^^^^^^^ expected associated type, found reference | - = help: consider adding a `where T: Foo` bound + = note: expected type `<T as Foo>::Out` + found type `&'static str` error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0326`. diff --git a/src/test/ui/associated-const/associated-const-trait-bound.rs b/src/test/ui/associated-const/associated-const-trait-bound.rs new file mode 100644 index 00000000000..0ce46d312af --- /dev/null +++ b/src/test/ui/associated-const/associated-const-trait-bound.rs @@ -0,0 +1,21 @@ +// compile-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() {} |
