diff options
| author | bors <bors@rust-lang.org> | 2021-07-03 01:42:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-03 01:42:06 +0000 |
| commit | cd48e61c5d8f83fbfbfc28db0b0bce1354d0ced1 (patch) | |
| tree | fa2742d26eae638d47bae349b0b6a831879af62c /src | |
| parent | 798baebde1fe77e5a660490ec64e727a5d79970d (diff) | |
| parent | 58f6cb4557b2d63d311420bbf6bc63aa119f8306 (diff) | |
| download | rust-cd48e61c5d8f83fbfbfc28db0b0bce1354d0ced1.tar.gz rust-cd48e61c5d8f83fbfbfc28db0b0bce1354d0ced1.zip | |
Auto merge of #86795 - JohnTitor:fix-bind, r=jackh726
Fix const-generics ICE related to binding Fixes #83765, fixes #85848 r? `@jackh726` as you're familiar with `Binding`. I'd like to get some views if the current approach is right path.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/const-generics/issues/issue-83765.rs | 38 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issues/issue-83765.stderr | 29 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issues/issue-85848.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issues/issue-85848.stderr | 44 |
4 files changed, 142 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/issues/issue-83765.rs new file mode 100644 index 00000000000..f34badc693e --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.rs @@ -0,0 +1,38 @@ +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +trait TensorDimension { + const DIM: usize; +} + +trait TensorSize: TensorDimension { + fn size(&self) -> [usize; Self::DIM]; +} + +trait Broadcastable: TensorSize + Sized { + type Element; + fn lazy_updim<const NEWDIM: usize>(&self, size: [usize; NEWDIM]) {} +} + +struct BMap<'a, R, T: Broadcastable, F: Fn(T::Element) -> R, const DIM: usize> { + reference: &'a T, + closure: F, +} + +impl<'a, R, T: Broadcastable, F: Fn(T::Element) -> R, const DIM: usize> TensorDimension + for BMap<'a, R, T, F, DIM> +{ + const DIM: usize = DIM; +} +impl<'a, R, T: Broadcastable, F: Fn(T::Element) -> R, const DIM: usize> TensorSize + for BMap<'a, R, T, F, DIM> +{ + fn size(&self) -> [usize; DIM] { + //~^ ERROR: method not compatible with trait [E0308] + self.reference.size() + //~^ ERROR: unconstrained generic constant + //~| ERROR: mismatched types + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/issues/issue-83765.stderr new file mode 100644 index 00000000000..ef785bf07eb --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.stderr @@ -0,0 +1,29 @@ +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:30:5 + | +LL | fn size(&self) -> [usize; DIM] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:32:24 + | +LL | self.reference.size() + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:32:9 + | +LL | self.reference.size() + | ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM` + | + = note: expected type `DIM` + found type `Self::DIM` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-85848.rs b/src/test/ui/const-generics/issues/issue-85848.rs new file mode 100644 index 00000000000..478719869b2 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-85848.rs @@ -0,0 +1,31 @@ +#![feature(const_generics, const_fn_trait_bound, const_evaluatable_checked)] +#![allow(incomplete_features)] + +trait _Contains<T> { + const does_contain: bool; +} + +trait Contains<T, const Satisfied: bool> {} + +trait Delegates<T> {} + +impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + +const fn contains<A, B>() -> bool +where + A: _Contains<B>, +{ + A::does_contain +} + +impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + +fn writes_to_path<C>(cap: &C) { + writes_to_specific_path(&cap); + //~^ ERROR: the trait bound `(): _Contains<&C>` is not satisfied [E0277] + //~| ERROR: unconstrained generic constant +} + +fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-85848.stderr b/src/test/ui/const-generics/issues/issue-85848.stderr new file mode 100644 index 00000000000..5e65136a6bc --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-85848.stderr @@ -0,0 +1,44 @@ +error[E0277]: the trait bound `(): _Contains<&C>` is not satisfied + --> $DIR/issue-85848.rs:24:5 + | +LL | writes_to_specific_path(&cap); + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `_Contains<&C>` is not implemented for `()` +... +LL | fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + | ------------- required by this bound in `writes_to_specific_path` + | +note: required because of the requirements on the impl of `Contains<(), true>` for `&C` + --> $DIR/issue-85848.rs:21:12 + | +LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ +note: required because of the requirements on the impl of `Delegates<()>` for `&C` + --> $DIR/issue-85848.rs:12:12 + | +LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + | ^^^^^^^^^^^^ ^ + +error: unconstrained generic constant + --> $DIR/issue-85848.rs:24:5 + | +LL | writes_to_specific_path(&cap); + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn writes_to_specific_path<C: Delegates<()>>(cap: &C) {} + | ------------- required by this bound in `writes_to_specific_path` + | + = help: try adding a `where` bound using this expression: `where [(); { contains::<T, U>() }]:` +note: required because of the requirements on the impl of `Contains<(), true>` for `&C` + --> $DIR/issue-85848.rs:21:12 + | +LL | impl<T, U> Contains<T, { contains::<T, U>() }> for U where T: _Contains<U> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ +note: required because of the requirements on the impl of `Delegates<()>` for `&C` + --> $DIR/issue-85848.rs:12:12 + | +LL | impl<T, U> Delegates<U> for T where T: Contains<U, true> {} + | ^^^^^^^^^^^^ ^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. |
