blob: 8aa65bbfdc9e7bd233ef93860622538b063b83b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// run-pass
#![allow(unused_variables)]
// Test that overloaded index expressions with DST result types
// work and don't ICE.
use std::ops::Index;
use std::fmt::Debug;
struct S;
impl Index<usize> for S {
type Output = str;
fn index<'a>(&'a self, _: usize) -> &'a str {
"hello"
}
}
struct T;
impl Index<usize> for T {
type Output = dyn Debug + 'static;
fn index<'a>(&'a self, idx: usize) -> &'a (dyn Debug + 'static) {
static X: usize = 42;
&X as &(dyn Debug + 'static)
}
}
fn main() {
assert_eq!(&S[0], "hello");
let _ = &T[0];
// let x = &x as &Debug;
}
|