forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#118112 - compiler-errors:index-ambiguity-ic…
…e, r=aliemjay Don't ICE when ambiguity is found when selecting `Index` implementation in typeck Fixes rust-lang#118111 The problem here is when we're manually "selecting" an impl for `base_ty: Index<?0>`, we don't consider placeholder region errors (leak check) or ambiguous predicates. Those can lead to us not actually emitting any fulfillment errors on line 3131.
- Loading branch information
Showing
3 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Test against ICE in #118111 | ||
|
||
use std::ops::Index; | ||
|
||
struct Map<T, F> { | ||
f: F, | ||
inner: T, | ||
} | ||
|
||
impl<T, F, Idx> Index<Idx> for Map<T, F> | ||
where | ||
T: Index<Idx>, | ||
F: FnOnce(&T, Idx) -> Idx, | ||
{ | ||
type Output = T::Output; | ||
|
||
fn index(&self, index: Idx) -> &Self::Output { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() { | ||
Map { inner: [0_usize], f: |_, i: usize| 1_usize }[0]; | ||
//~^ ERROR cannot index into a value of type | ||
// Problem here is that | ||
// `f: |_, i: usize| ...` | ||
// should be | ||
// `f: |_: &_, i: usize| ...` | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ui/typeck/bad-index-modulo-higher-ranked-regions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0608]: cannot index into a value of type `Map<[usize; 1], {closure@$DIR/bad-index-modulo-higher-ranked-regions.rs:23:32: 23:45}>` | ||
--> $DIR/bad-index-modulo-higher-ranked-regions.rs:23:55 | ||
| | ||
LL | Map { inner: [0_usize], f: |_, i: usize| 1_usize }[0]; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0608`. |