Skip to content

Commit f8860f2

Browse files
committed
Auto merge of #58743 - varkor:bulk-needstest-1, r=alexcrichton
Add tests for several E-needstest issues This PR adds a number of tests for various `E-needstest` errors. These tend to have been left open for a long time and seem unlikely to be closed otherwise. Closes #10876. Closes #26448. Closes #26577. Closes #26619. Closes #27054. Closes #44127. Closes #44255. Closes #55731. Closes #57781.
2 parents 7c19e1e + 5b3e1be commit f8860f2

17 files changed

+305
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo() -> i32 {
2+
0
3+
}
4+
5+
fn main() {
6+
let x: i32 = {
7+
//~^ ERROR mismatched types
8+
foo(); //~ HELP consider removing this semicolon
9+
};
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/block-expression-remove-semicolon.rs:6:18
3+
|
4+
LL | let x: i32 = {
5+
| __________________^
6+
LL | |
7+
LL | | foo();
8+
| | - help: consider removing this semicolon
9+
LL | | };
10+
| |_____^ expected i32, found ()
11+
|
12+
= note: expected type `i32`
13+
found type `()`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/borrowck/issue-10876.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
3+
#![feature(nll)]
4+
5+
enum Nat {
6+
S(Box<Nat>),
7+
Z
8+
}
9+
fn test(x: &mut Nat) {
10+
let mut p = &mut *x;
11+
loop {
12+
match p {
13+
&mut Nat::Z => break,
14+
&mut Nat::S(ref mut n) => p = &mut *n
15+
}
16+
}
17+
}
18+
19+
fn main() {}

src/test/ui/issues/issue-26448-1.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
3+
pub trait Foo<T> {
4+
fn foo(self) -> T;
5+
}
6+
7+
impl<'a, T> Foo<T> for &'a str where &'a str: Into<T> {
8+
fn foo(self) -> T {
9+
panic!();
10+
}
11+
}
12+
13+
fn main() {}

src/test/ui/issues/issue-26448-2.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
pub struct Bar<T> {
4+
items: Vec<&'static str>,
5+
inner: T,
6+
}
7+
8+
pub trait IntoBar<T> {
9+
fn into_bar(self) -> Bar<T>;
10+
}
11+
12+
impl<'a, T> IntoBar<T> for &'a str where &'a str: Into<T> {
13+
fn into_bar(self) -> Bar<T> {
14+
Bar {
15+
items: Vec::new(),
16+
inner: self.into(),
17+
}
18+
}
19+
}
20+
21+
fn main() {}

src/test/ui/issues/issue-26448-3.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// run-pass
2+
3+
pub struct Item {
4+
_inner: &'static str,
5+
}
6+
7+
pub struct Bar<T> {
8+
items: Vec<Item>,
9+
inner: T,
10+
}
11+
12+
pub trait IntoBar<T> {
13+
fn into_bar(self) -> Bar<T>;
14+
}
15+
16+
impl<'a, T> IntoBar<T> for &'a str where &'a str: Into<T> {
17+
fn into_bar(self) -> Bar<T> {
18+
Bar {
19+
items: Vec::new(),
20+
inner: self.into(),
21+
}
22+
}
23+
}
24+
25+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0515]: cannot return value referencing function parameter
2+
--> $DIR/issue-26619.rs:7:76
3+
|
4+
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
5+
| -------- ^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
6+
| |
7+
| function parameter borrowed here
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0515`.

src/test/ui/issues/issue-26619.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(slice_patterns)]
2+
3+
pub struct History<'a> { pub _s: &'a str }
4+
5+
impl<'a> History<'a> {
6+
pub fn get_page(&self) {
7+
for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
8+
//~^ ERROR borrowed value does not live long enough
9+
println!("{:?}", s);
10+
}
11+
}
12+
13+
fn make_entry(&self, s: &'a String) -> Option<&str> {
14+
let parts: Vec<_> = s.split('|').collect();
15+
println!("{:?} -> {:?}", s, parts);
16+
17+
if let [commit, ..] = &parts[..] { Some(commit) } else { None }
18+
}
19+
}
20+
21+
fn main() {
22+
let h = History{ _s: "" };
23+
h.get_page();
24+
}

src/test/ui/issues/issue-26619.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/issue-26619.rs:7:66
3+
|
4+
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
5+
| ^^^^^^^^ -- temporary value needs to live until here
6+
| | |
7+
| | temporary value dropped here while still borrowed
8+
| temporary value does not live long enough
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0597`.

src/test/ui/issues/issue-44127.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![feature(decl_macro)]
4+
5+
pub struct Foo {
6+
bar: u32,
7+
}
8+
pub macro pattern($a:pat) {
9+
Foo { bar: $a }
10+
}
11+
12+
fn main() {
13+
match (Foo { bar: 3 }) {
14+
pattern!(3) => println!("Test OK"),
15+
_ => unreachable!(),
16+
}
17+
}

0 commit comments

Comments
 (0)