Skip to content

Commit 58dc3bb

Browse files
committed
Regression tests for issues that led me to revise typeck.
Close #23729 Close #23827 Close #24356
1 parent 32d5f74 commit 58dc3bb

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

src/test/compile-fail/issue-23729.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 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+
// Regression test for #23729
12+
13+
fn main() {
14+
let fib = {
15+
struct Recurrence {
16+
mem: [u64; 2],
17+
pos: usize,
18+
}
19+
20+
impl Iterator for Recurrence {
21+
//~^ ERROR not all trait items implemented, missing: `Item` [E0046]
22+
#[inline]
23+
fn next(&mut self) -> Option<u64> {
24+
if self.pos < 2 {
25+
let next_val = self.mem[self.pos];
26+
self.pos += 1;
27+
Some(next_val)
28+
} else {
29+
let next_val = (self.mem[0] + self.mem[1]);
30+
self.mem[0] = self.mem[1];
31+
self.mem[1] = next_val;
32+
Some(next_val)
33+
}
34+
}
35+
}
36+
37+
Recurrence { mem: [0, 1], pos: 0 }
38+
};
39+
40+
for e in fib.take(10) {
41+
println!("{}", e)
42+
}
43+
}

src/test/compile-fail/issue-23827.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 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+
// Regression test for #23827
12+
13+
#![feature(core, unboxed_closures)]
14+
15+
pub struct Prototype {
16+
pub target: u32
17+
}
18+
19+
trait Component {
20+
fn apply(self, e: u32);
21+
}
22+
23+
impl<C: Component> Fn<(C,)> for Prototype {
24+
extern "rust-call" fn call(&self, (comp,): (C,)) -> Prototype {
25+
comp.apply(self.target);
26+
*self
27+
}
28+
}
29+
30+
impl<C: Component> FnMut<(C,)> for Prototype {
31+
extern "rust-call" fn call_mut(&mut self, (comp,): (C,)) -> Prototype {
32+
Fn::call(*&self, (comp,))
33+
}
34+
}
35+
36+
impl<C: Component> FnOnce<(C,)> for Prototype {
37+
//~^ ERROR not all trait items implemented, missing: `Output` [E0046]
38+
extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype {
39+
Fn::call(&self, (comp,))
40+
}
41+
}
42+
43+
fn main() {}

src/test/compile-fail/issue-24356.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2015 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+
// Regression test for #24356
12+
13+
// ignore-tidy-linelength
14+
15+
fn main() {
16+
{
17+
use std::ops::Deref;
18+
19+
struct Thing(i8);
20+
21+
/*
22+
// Correct impl
23+
impl Deref for Thing {
24+
type Target = i8;
25+
fn deref(&self) -> &i8 { &self.0 }
26+
}
27+
*/
28+
29+
// Causes ICE
30+
impl Deref for Thing {
31+
//~^ ERROR not all trait items implemented, missing: `Target` [E0046]
32+
fn deref(&self) -> i8 { self.0 }
33+
//~^ ERROR method `deref` has an incompatible type for trait: expected &-ptr, found i8 [E0053]
34+
}
35+
36+
let thing = Thing(72);
37+
38+
*thing
39+
};
40+
}

0 commit comments

Comments
 (0)