Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle inference variables in CollectAllMismatches correctly #106322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {

fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
self.infcx.probe(|_| {
if a.is_ty_infer() || b.is_ty_infer() {
if a.is_ty_var() || b.is_ty_var() {
Ok(a)
} else {
self.infcx.super_combine_tys(self, a, b).or_else(|e| {
Expand All @@ -71,10 +71,13 @@ impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
a: ty::Const<'tcx>,
b: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
if a == b {
return Ok(a);
}
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
self.infcx.probe(|_| {
if a.is_ct_infer() || b.is_ct_infer() {
Ok(a)
} else {
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
}
})
}

fn binders<T: Relate<'tcx>>(
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/consts/ct-var-in-collect_all_mismatches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct Foo<T, const N: usize> {
array: [T; N],
}

trait Bar<const N: usize> {}

impl<T, const N: usize> Foo<T, N> {
fn trigger(self) {
self.unsatisfied()
//~^ ERROR the trait bound `T: Bar<N>` is not satisfied
}

fn unsatisfied(self)
where
T: Bar<N>,
{
}
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/consts/ct-var-in-collect_all_mismatches.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0277]: the trait bound `T: Bar<N>` is not satisfied
--> $DIR/ct-var-in-collect_all_mismatches.rs:9:14
|
LL | self.unsatisfied()
| ^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `T`
|
note: required by a bound in `Foo::<T, N>::unsatisfied`
--> $DIR/ct-var-in-collect_all_mismatches.rs:15:12
|
LL | fn unsatisfied(self)
| ----------- required by a bound in this
LL | where
LL | T: Bar<N>,
| ^^^^^^ required by this bound in `Foo::<T, N>::unsatisfied`
help: consider restricting type parameter `T`
|
LL | impl<T: Bar<N>, const N: usize> Foo<T, N> {
| ++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
4 changes: 4 additions & 0 deletions tests/ui/iterators/invalid-iterator-chain-with-int-infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let x = Some(()).iter().map(|()| 1).sum::<f32>();
//~^ ERROR a value of type `f32` cannot be made by summing an iterator over elements of type `{integer}`
}
24 changes: 24 additions & 0 deletions tests/ui/iterators/invalid-iterator-chain-with-int-infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error[E0277]: a value of type `f32` cannot be made by summing an iterator over elements of type `{integer}`
--> $DIR/invalid-iterator-chain-with-int-infer.rs:2:41
|
LL | let x = Some(()).iter().map(|()| 1).sum::<f32>();
| ^^^ value of type `f32` cannot be made by summing a `std::iter::Iterator<Item={integer}>`
|
= help: the trait `Sum<{integer}>` is not implemented for `f32`
= help: the following other types implement trait `Sum<A>`:
<f32 as Sum<&'a f32>>
<f32 as Sum>
note: the method call chain might not have had the expected associated types
--> $DIR/invalid-iterator-chain-with-int-infer.rs:2:29
|
LL | let x = Some(()).iter().map(|()| 1).sum::<f32>();
| -------- ------ ^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here
| | |
| | `Iterator::Item` is `&()` here
| this expression has type `Option<()>`
note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.