Skip to content

Commit b6e34a0

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#10876. Closes rust-lang#22892. Closes rust-lang#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#28587. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
2 parents 11552e4 + 5ab5747 commit b6e34a0

20 files changed

+329
-0
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(asm)]
2+
3+
fn main() {
4+
let a: usize;
5+
6+
unsafe {
7+
asm!("" : "=d"(a) : : : );
8+
//~^ ERROR couldn't allocate output register for constraint 'd'
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: couldn't allocate output register for constraint 'd'
2+
--> $DIR/invalid-inline-asm-2.rs:7:9
3+
|
4+
LL | asm!("" : "=d"(a) : : : );
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

src/test/ui/asm/invalid-inline-asm.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(asm)]
2+
3+
fn main() {
4+
let byte = 0;
5+
let port = 0x80;
6+
7+
unsafe { asm!("out %al, %dx" :: "a" (byte), "d" (port) :: "volatile"); }
8+
//~^ ERROR couldn't allocate input reg for constraint 'a'
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: couldn't allocate input reg for constraint 'a'
2+
--> $DIR/invalid-inline-asm.rs:7:14
3+
|
4+
LL | unsafe { asm!("out %al, %dx" :: "a" (byte), "d" (port) :: "volatile"); }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
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+
}
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 | | //~^ ERROR mismatched types
7+
LL | | foo(); //~ HELP consider removing this semicolon
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

+19
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

+13
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

+21
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

+25
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() {}

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

+24
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

+12
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

+17
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+
}

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

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-pass
2+
3+
use std::marker::PhantomData;
4+
5+
fn main() {
6+
let _arr = [1; <Multiply<Five, Five>>::VAL];
7+
}
8+
9+
trait TypeVal<T> {
10+
const VAL: T;
11+
}
12+
13+
struct Five;
14+
15+
impl TypeVal<usize> for Five {
16+
const VAL: usize = 5;
17+
}
18+
19+
struct Multiply<N, M> {
20+
_n: PhantomData<N>,
21+
_m: PhantomData<M>,
22+
}
23+
24+
impl<N, M> TypeVal<usize> for Multiply<N, M>
25+
where N: TypeVal<usize>,
26+
M: TypeVal<usize>,
27+
{
28+
const VAL: usize = N::VAL * M::VAL;
29+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(use_extern_macros)]
2+
trait Foo {}
3+
#[derive(Foo::Anything)] //~ ERROR failed to resolve: partially resolved path in a derive macro
4+
struct S;

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

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0433]: failed to resolve: partially resolved path in a derive macro
2+
--> $DIR/issue-46101.rs:3:10
3+
|
4+
LL | #[derive(Foo::Anything)] //~ ERROR failed to resolve: partially resolved path in a derive macro
5+
| ^^^^^^^^^^^^^ partially resolved path in a derive macro
6+
7+
error[E0601]: `main` function not found in crate `issue_46101`
8+
|
9+
= note: consider adding a `main` function to `$DIR/issue-46101.rs`
10+
11+
error: aborting due to 2 previous errors
12+
13+
Some errors occurred: E0433, E0601.
14+
For more information about an error, try `rustc --explain E0433`.

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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::marker::PhantomData;
2+
3+
trait DistributedIterator {
4+
fn reduce(self)
5+
where
6+
Self: Sized,
7+
{
8+
unreachable!()
9+
}
10+
}
11+
12+
trait DistributedIteratorMulti<Source> {
13+
type Item;
14+
}
15+
16+
struct Connect<I>(PhantomData<fn(I)>);
17+
impl<I: for<'a> DistributedIteratorMulti<&'a ()>> DistributedIterator for Connect<I> where {}
18+
19+
struct Cloned<Source>(PhantomData<fn(Source)>);
20+
impl<'a, Source> DistributedIteratorMulti<&'a Source> for Cloned<&'a Source> {
21+
type Item = ();
22+
}
23+
24+
struct Map<I, F> {
25+
i: I,
26+
f: F,
27+
}
28+
impl<I: DistributedIteratorMulti<Source>, F, Source> DistributedIteratorMulti<Source> for Map<I, F>
29+
where
30+
F: A<<I as DistributedIteratorMulti<Source>>::Item>,
31+
{
32+
type Item = ();
33+
}
34+
35+
trait A<B> {}
36+
37+
struct X;
38+
impl A<()> for X {}
39+
40+
fn multi<I>(_reducer: I)
41+
where
42+
I: for<'a> DistributedIteratorMulti<&'a ()>,
43+
{
44+
DistributedIterator::reduce(Connect::<I>(PhantomData))
45+
}
46+
47+
fn main() {
48+
multi(Map { //~ ERROR implementation of `DistributedIteratorMulti` is not general enough
49+
i: Cloned(PhantomData),
50+
f: X,
51+
});
52+
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: implementation of `DistributedIteratorMulti` is not general enough
2+
--> $DIR/issue-55731.rs:48:5
3+
|
4+
LL | multi(Map { //~ ERROR implementation of `DistributedIteratorMulti` is not general enough
5+
| ^^^^^
6+
|
7+
= note: `DistributedIteratorMulti<&'0 ()>` would have to be implemented for the type `Cloned<&()>`, for any lifetime `'0`
8+
= note: but `DistributedIteratorMulti<&'1 ()>` is actually implemented for the type `Cloned<&'1 ()>`, for some specific lifetime `'1`
9+
10+
error: aborting due to previous error
11+

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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
3+
use std::cell::UnsafeCell;
4+
use std::collections::HashMap;
5+
6+
struct OnceCell<T> {
7+
_value: UnsafeCell<Option<T>>,
8+
}
9+
10+
impl<T> OnceCell<T> {
11+
const INIT: OnceCell<T> = OnceCell {
12+
_value: UnsafeCell::new(None),
13+
};
14+
}
15+
16+
pub fn crash<K, T>() {
17+
let _ = OnceCell::<HashMap<K, T>>::INIT;
18+
}
19+
20+
fn main() {}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-pass
2+
3+
fn main() {
4+
let x = Box::new(0);
5+
assert_eq!(0, *x + { drop(x); let _ = Box::new(main); 0 });
6+
}

0 commit comments

Comments
 (0)