rust/tests/ui/issues/issue-22312.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
530 B
Rust
Raw Normal View History

use std::ops::Index;
pub trait Array2D: Index<usize> + Sized {
fn rows(&self) -> usize;
fn columns(&self) -> usize;
fn get<'a>(&'a self, y: usize, x: usize) -> Option<&'a <Self as Index<usize>>::Output> {
if y >= self.rows() || x >= self.columns() {
return None;
}
let i = y * self.columns() + x;
2019-05-28 18:46:13 +00:00
let indexer = &(*self as &dyn Index<usize, Output = <Self as Index<usize>>::Output>);
2017-06-09 20:04:29 +00:00
//~^ERROR non-primitive cast
Some(indexer.index(i))
}
}
fn main() {}