提交 c97c03cd 编写于 作者: N Niko Matsakis

tests: changes in response to #5656

上级 03396473
// Copyright 2012 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.
#[legacy_mode]
struct Foo<'self> {
s: &'self str,
u: ~()
}
pub impl<'self> Foo<'self> {
fn get_s(&self) -> &'self str {
self.s
}
}
fn bar(s: &str, f: &fn(Option<Foo>)) {
f(Some(Foo {s: s, u: ~()}));
}
fn main() {
do bar(~"testing") |opt| {
io::println(opt.unwrap().get_s()); //~ ERROR illegal borrow:
};
}
......@@ -10,7 +10,7 @@
trait A {
fn a(&self) {
|| self.b() //~ ERROR type `&'self Self` does not implement any method in scope named `b`
|| self.b() //~ ERROR type `&Self` does not implement any method in scope named `b`
}
}
fn main() {}
// Copyright 2012 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.
// n.b. This should be a run-pass test, but for now I'm testing
// that we don't see an "unknown scope" error.
fn vec_peek<'r, T>(v: &'r [T]) -> Option< (&'r T, &'r [T]) > {
if v.len() == 0 {
None
} else {
let vec_len = v.len();
let head = &v[0];
// note: this *shouldn't* be an illegal borrow! See #3888
let tail = v.slice(1, vec_len); //~ ERROR illegal borrow: borrowed value does not live long enough
Some( (head, tail) )
}
}
fn test_peek_empty_stack() {
let v : &[int] = &[];
assert!((None == vec_peek(v)));
}
fn test_peek_empty_unique() {
let v : ~[int] = ~[];
assert!((None == vec_peek(v)));
}
fn test_peek_empty_managed() {
let v : @[int] = @[];
assert!((None == vec_peek(v)));
}
fn main() {}
......@@ -18,7 +18,7 @@ trait BikeMethods {
impl BikeMethods for Bike {
fn woops() -> ~str { ~"foo" }
//~^ ERROR method `woops` is declared as static in its impl, but not in its trait
//~^ ERROR has a `&const self` declaration in the trait, but not in the impl
}
pub fn main() {
......
......@@ -18,12 +18,12 @@ struct c<'self> {
f: @b<'self>
}
trait set_f {
trait set_f<'self> {
fn set_f_ok(&self, b: @b<'self>);
fn set_f_bad(&self, b: @b);
}
impl<'self> set_f for c<'self> {
impl<'self> set_f<'self> for c<'self> {
fn set_f_ok(&self, b: @b<'self>) {
self.f = b;
}
......
......@@ -14,7 +14,7 @@ trait foo {
}
impl foo for int {
fn bar(&self) {} //~ ERROR method `bar` is declared as static in its trait, but not in its impl
fn bar(&self) {} //~ ERROR method `bar` has a `&self` declaration in the impl, but not in the trait
}
fn main() {}
......@@ -59,7 +59,7 @@ fn clear(&mut self) {}
}
impl<T> Map<int, T> for cat<T> {
fn each(&self, f: &fn(&int, &T) -> bool) {
fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) {
let mut n = int::abs(self.meows);
while n > 0 {
if !f(&n, &self.name) { break; }
......@@ -73,7 +73,7 @@ fn each_key(&self, f: &fn(v: &int) -> bool) {
for self.each |k, _| { if !f(k) { break; } loop;};
}
fn each_value(&self, f: &fn(v: &T) -> bool) {
fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) {
for self.each |_, v| { if !f(v) { break; } loop;};
}
......@@ -86,7 +86,7 @@ fn insert(&mut self, k: int, _: T) -> bool {
true
}
fn find(&self, k: &int) -> Option<&'self T> {
fn find<'a>(&'a self, k: &int) -> Option<&'a T> {
if *k <= self.meows {
Some(&self.name)
} else {
......@@ -94,7 +94,7 @@ fn find(&self, k: &int) -> Option<&'self T> {
}
}
fn find_mut(&mut self, _k: &int) -> Option<&'self mut T> { fail!() }
fn find_mut<'a>(&'a mut self, _k: &int) -> Option<&'a mut T> { fail!() }
fn remove(&mut self, k: &int) -> bool {
if self.find(k).is_some() {
......@@ -106,7 +106,7 @@ fn remove(&mut self, k: &int) -> bool {
}
pub impl<T> cat<T> {
fn get(&self, k: &int) -> &'self T {
fn get<'a>(&'a self, k: &int) -> &'a T {
match self.find(k) {
Some(v) => { v }
None => { fail!(~"epic fail"); }
......
......@@ -58,7 +58,7 @@ pub impl thing {
fn foo(@self) -> int { *self.x.a }
fn bar(~self) -> int { *self.x.a }
fn quux(&self) -> int { *self.x.a }
fn baz(&self) -> &'self A { &self.x }
fn baz<'a>(&'a self) -> &'a A { &self.x }
fn spam(self) -> int { *self.x.a }
}
......
......@@ -11,7 +11,7 @@
struct Foo { x: int }
pub impl Foo {
fn stuff(&mut self) -> &'self mut Foo {
fn stuff<'a>(&'a mut self) -> &'a mut Foo {
return self;
}
}
......
// Copyright 2013 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 how region-parameterization inference
// interacts with explicit self types.
//
// Issue #5224.
trait Getter {
// This trait does not need to be
// region-parameterized, because 'self
// is bound in the self type:
fn get(&self) -> &'self int;
}
struct Foo {
field: int
}
impl Getter for Foo {
fn get(&self) -> &'self int { &self.field }
}
fn get_int<G: Getter>(g: &G) -> int {
*g.get()
}
pub fn main() {
let foo = Foo { field: 22 };
assert!(get_int(&foo) == 22);
}
......@@ -16,7 +16,7 @@ trait get_chowder<'self> {
fn get_chowder(&self) -> &'self int;
}
impl<'self> get_chowder for Clam<'self> {
impl<'self> get_chowder<'self> for Clam<'self> {
fn get_chowder(&self) -> &'self int { return self.chowder; }
}
......
......@@ -16,7 +16,7 @@ trait get_ctxt<'self> {
struct HasCtxt<'self> { c: &'self Ctxt }
impl<'self> get_ctxt for HasCtxt<'self> {
impl<'self> get_ctxt<'self> for HasCtxt<'self> {
fn get_ctxt(&self) -> &'self Ctxt {
self.c
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册