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