]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dst/dst-index.rs
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
[rust.git] / src / test / ui / dst / dst-index.rs
1 // Test that overloaded index expressions with DST result types
2 // can't be used as rvalues
3
4 use std::ops::Index;
5 use std::fmt::Debug;
6
7 #[derive(Copy, Clone)]
8 struct S;
9
10 impl Index<usize> for S {
11     type Output = str;
12
13     fn index(&self, _: usize) -> &str {
14         "hello"
15     }
16 }
17
18 #[derive(Copy, Clone)]
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
27     }
28 }
29
30 fn main() {
31     S[0];
32     //~^ ERROR cannot move out of index of `S`
33     //~^^ ERROR E0161
34     T[0];
35     //~^ ERROR cannot move out of index of `T`
36     //~^^ ERROR E0161
37 }