2014-11-01 01:42:48 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Test that overloaded index expressions with DST result types
|
|
|
|
// work and don't ICE.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-03-05 20:33:58 -06:00
|
|
|
#![feature(core)]
|
|
|
|
|
2014-11-01 01:42:48 -05:00
|
|
|
use std::ops::Index;
|
2015-01-20 17:45:07 -06:00
|
|
|
use std::fmt::Debug;
|
2014-11-01 01:42:48 -05:00
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
impl Index<usize> for S {
|
2015-01-03 09:40:36 -06:00
|
|
|
type Output = str;
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn index<'a>(&'a self, _: usize) -> &'a str {
|
2014-11-01 01:42:48 -05:00
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct T;
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
impl Index<usize> for T {
|
2015-01-20 17:45:07 -06:00
|
|
|
type Output = Debug + 'static;
|
2015-01-03 09:40:36 -06:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn index<'a>(&'a self, idx: usize) -> &'a (Debug + 'static) {
|
|
|
|
static X: usize = 42;
|
2015-01-20 17:45:07 -06:00
|
|
|
&X as &(Debug + 'static)
|
2014-11-01 01:42:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(&S[0], "hello");
|
2015-01-06 18:16:35 -06:00
|
|
|
&T[0];
|
2015-01-20 17:45:07 -06:00
|
|
|
// let x = &x as &Debug;
|
2014-11-01 01:42:48 -05:00
|
|
|
}
|