Skip to content

Commit 4372ee7

Browse files
committed
---
yaml --- r: 274661 b: refs/heads/stable c: 77c8850 h: refs/heads/master i: 274659: da1c4c0
1 parent a231257 commit 4372ee7

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 8801bdb6b09569b187bb4c83f6121533afc69820
32+
refs/heads/stable: 77c8850e6f03d9e2b7efcdf57abc5786440e3fd7
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Original regression test for Issue #30438.
12+
13+
use std::ops::Index;
14+
15+
struct Test<'a> {
16+
s: &'a String
17+
}
18+
19+
impl <'a> Index<usize> for Test<'a> {
20+
type Output = Test<'a>;
21+
fn index(&self, _: usize) -> &Self::Output {
22+
return &Test { s: &self.s};
23+
//~^ ERROR: borrowed value does not live long enough
24+
}
25+
}
26+
27+
fn main() {
28+
let s = "Hello World".to_string();
29+
let test = Test{s: &s};
30+
let r = &test[0];
31+
println!("{}", test.s); // OK since test is valid
32+
println!("{}", r.s); // Segfault since value pointed by r has already been dropped
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Modified regression test for Issue #30438 that exposed an
12+
// independent issue (see discussion on ticket).
13+
14+
use std::ops::Index;
15+
16+
struct Test<'a> {
17+
s: &'a String
18+
}
19+
20+
impl <'a> Index<usize> for Test<'a> {
21+
type Output = Test<'a>;
22+
fn index(&self, _: usize) -> &Self::Output {
23+
&Test { s: &self.s}
24+
//~^ ERROR: borrowed value does not live long enough
25+
}
26+
}
27+
28+
fn main() {
29+
let s = "Hello World".to_string();
30+
let test = Test{s: &s};
31+
let r = &test[0];
32+
println!("{}", test.s); // OK since test is valid
33+
println!("{}", r.s); // Segfault since value pointed by r has already been dropped
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Simplfied regression test for #30438, inspired by arielb1.
12+
13+
trait Trait { type Out; }
14+
15+
struct Test<'a> { s: &'a str }
16+
17+
fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
18+
let x = Test { s: "this cannot last" };
19+
&x
20+
//~^ ERROR: `x` does not live long enough
21+
}
22+
23+
impl<'b> Trait for Test<'b> { type Out = Test<'b>; }
24+
25+
fn main() {
26+
let orig = Test { s: "Hello World" };
27+
let r = silly(&orig);
28+
println!("{}", orig.s); // OK since `orig` is valid
29+
println!("{}", r.s); // Segfault (method does not return a sane value)
30+
}

0 commit comments

Comments
 (0)