Skip to content

Commit

Permalink
Rollup merge of rust-lang#58743 - varkor:bulk-needstest-1, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

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.
  • Loading branch information
Centril authored Mar 9, 2019
2 parents 7c6d8cc + c38c959 commit eec629b
Show file tree
Hide file tree
Showing 20 changed files with 335 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/ui/asm/invalid-inline-asm-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ignore-wasm
// ignore-emscripten

#![feature(asm)]

fn main() {
let a: usize;

unsafe {
asm!("" : "=d"(a) : : : );
//~^ ERROR couldn't allocate output register for constraint 'd'
}
}
8 changes: 8 additions & 0 deletions src/test/ui/asm/invalid-inline-asm-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: couldn't allocate output register for constraint 'd'
--> $DIR/invalid-inline-asm-2.rs:10:9
|
LL | asm!("" : "=d"(a) : : : );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

12 changes: 12 additions & 0 deletions src/test/ui/asm/invalid-inline-asm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ignore-wasm
// ignore-emscripten

#![feature(asm)]

fn main() {
let byte = 0;
let port = 0x80;

unsafe { asm!("out %al, %dx" :: "a" (byte), "d" (port) :: "volatile"); }
//~^ ERROR couldn't allocate input reg for constraint 'a'
}
8 changes: 8 additions & 0 deletions src/test/ui/asm/invalid-inline-asm.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: couldn't allocate input reg for constraint 'a'
--> $DIR/invalid-inline-asm.rs:10:14
|
LL | unsafe { asm!("out %al, %dx" :: "a" (byte), "d" (port) :: "volatile"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

10 changes: 10 additions & 0 deletions src/test/ui/block-expression-remove-semicolon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn foo() -> i32 {
0
}

fn main() {
let x: i32 = {
//~^ ERROR mismatched types
foo(); //~ HELP consider removing this semicolon
};
}
17 changes: 17 additions & 0 deletions src/test/ui/block-expression-remove-semicolon.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/block-expression-remove-semicolon.rs:6:18
|
LL | let x: i32 = {
| __________________^
LL | | //~^ ERROR mismatched types
LL | | foo(); //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
LL | | };
| |_____^ expected i32, found ()
|
= note: expected type `i32`
found type `()`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
19 changes: 19 additions & 0 deletions src/test/ui/borrowck/issue-10876.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// run-pass

#![feature(nll)]

enum Nat {
S(Box<Nat>),
Z
}
fn test(x: &mut Nat) {
let mut p = &mut *x;
loop {
match p {
&mut Nat::Z => break,
&mut Nat::S(ref mut n) => p = &mut *n
}
}
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/issues/issue-26448-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-pass

pub trait Foo<T> {
fn foo(self) -> T;
}

impl<'a, T> Foo<T> for &'a str where &'a str: Into<T> {
fn foo(self) -> T {
panic!();
}
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/issues/issue-26448-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass

pub struct Bar<T> {
items: Vec<&'static str>,
inner: T,
}

pub trait IntoBar<T> {
fn into_bar(self) -> Bar<T>;
}

impl<'a, T> IntoBar<T> for &'a str where &'a str: Into<T> {
fn into_bar(self) -> Bar<T> {
Bar {
items: Vec::new(),
inner: self.into(),
}
}
}

fn main() {}
25 changes: 25 additions & 0 deletions src/test/ui/issues/issue-26448-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// run-pass

pub struct Item {
_inner: &'static str,
}

pub struct Bar<T> {
items: Vec<Item>,
inner: T,
}

pub trait IntoBar<T> {
fn into_bar(self) -> Bar<T>;
}

impl<'a, T> IntoBar<T> for &'a str where &'a str: Into<T> {
fn into_bar(self) -> Bar<T> {
Bar {
items: Vec::new(),
inner: self.into(),
}
}
}

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/issues/issue-26619.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![feature(slice_patterns)]

pub struct History<'a> { pub _s: &'a str }

impl<'a> History<'a> {
pub fn get_page(&self) {
for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
//~^ ERROR borrowed value does not live long enough
println!("{:?}", s);
}
}

fn make_entry(&self, s: &'a String) -> Option<&str> {
let parts: Vec<_> = s.split('|').collect();
println!("{:?} -> {:?}", s, parts);

if let [commit, ..] = &parts[..] { Some(commit) } else { None }
}
}

fn main() {
let h = History{ _s: "" };
h.get_page();
}
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-26619.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/issue-26619.rs:7:66
|
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
| ^^^^^^^^ -- temporary value needs to live until here
| | |
| | temporary value dropped here while still borrowed
| temporary value does not live long enough

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-44127.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass

#![feature(decl_macro)]

pub struct Foo {
bar: u32,
}
pub macro pattern($a:pat) {
Foo { bar: $a }
}

fn main() {
match (Foo { bar: 3 }) {
pattern!(3) => println!("Test OK"),
_ => unreachable!(),
}
}
29 changes: 29 additions & 0 deletions src/test/ui/issues/issue-44255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// run-pass

use std::marker::PhantomData;

fn main() {
let _arr = [1; <Multiply<Five, Five>>::VAL];
}

trait TypeVal<T> {
const VAL: T;
}

struct Five;

impl TypeVal<usize> for Five {
const VAL: usize = 5;
}

struct Multiply<N, M> {
_n: PhantomData<N>,
_m: PhantomData<M>,
}

impl<N, M> TypeVal<usize> for Multiply<N, M>
where N: TypeVal<usize>,
M: TypeVal<usize>,
{
const VAL: usize = N::VAL * M::VAL;
}
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-46101.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![feature(use_extern_macros)]
trait Foo {}
#[derive(Foo::Anything)] //~ ERROR failed to resolve: partially resolved path in a derive macro
struct S;
14 changes: 14 additions & 0 deletions src/test/ui/issues/issue-46101.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0433]: failed to resolve: partially resolved path in a derive macro
--> $DIR/issue-46101.rs:3:10
|
LL | #[derive(Foo::Anything)] //~ ERROR failed to resolve: partially resolved path in a derive macro
| ^^^^^^^^^^^^^ partially resolved path in a derive macro

error[E0601]: `main` function not found in crate `issue_46101`
|
= note: consider adding a `main` function to `$DIR/issue-46101.rs`

error: aborting due to 2 previous errors

Some errors occurred: E0433, E0601.
For more information about an error, try `rustc --explain E0433`.
52 changes: 52 additions & 0 deletions src/test/ui/issues/issue-55731.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::marker::PhantomData;

trait DistributedIterator {
fn reduce(self)
where
Self: Sized,
{
unreachable!()
}
}

trait DistributedIteratorMulti<Source> {
type Item;
}

struct Connect<I>(PhantomData<fn(I)>);
impl<I: for<'a> DistributedIteratorMulti<&'a ()>> DistributedIterator for Connect<I> where {}

struct Cloned<Source>(PhantomData<fn(Source)>);
impl<'a, Source> DistributedIteratorMulti<&'a Source> for Cloned<&'a Source> {
type Item = ();
}

struct Map<I, F> {
i: I,
f: F,
}
impl<I: DistributedIteratorMulti<Source>, F, Source> DistributedIteratorMulti<Source> for Map<I, F>
where
F: A<<I as DistributedIteratorMulti<Source>>::Item>,
{
type Item = ();
}

trait A<B> {}

struct X;
impl A<()> for X {}

fn multi<I>(_reducer: I)
where
I: for<'a> DistributedIteratorMulti<&'a ()>,
{
DistributedIterator::reduce(Connect::<I>(PhantomData))
}

fn main() {
multi(Map { //~ ERROR implementation of `DistributedIteratorMulti` is not general enough
i: Cloned(PhantomData),
f: X,
});
}
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-55731.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: implementation of `DistributedIteratorMulti` is not general enough
--> $DIR/issue-55731.rs:48:5
|
LL | multi(Map { //~ ERROR implementation of `DistributedIteratorMulti` is not general enough
| ^^^^^
|
= note: `DistributedIteratorMulti<&'0 ()>` would have to be implemented for the type `Cloned<&()>`, for any lifetime `'0`
= note: but `DistributedIteratorMulti<&'1 ()>` is actually implemented for the type `Cloned<&'1 ()>`, for some specific lifetime `'1`

error: aborting due to previous error

20 changes: 20 additions & 0 deletions src/test/ui/issues/issue-57781.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// run-pass

use std::cell::UnsafeCell;
use std::collections::HashMap;

struct OnceCell<T> {
_value: UnsafeCell<Option<T>>,
}

impl<T> OnceCell<T> {
const INIT: OnceCell<T> = OnceCell {
_value: UnsafeCell::new(None),
};
}

pub fn crash<K, T>() {
let _ = OnceCell::<HashMap<K, T>>::INIT;
}

fn main() {}
6 changes: 6 additions & 0 deletions src/test/ui/primitive-binop-lhs-mut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-pass

fn main() {
let x = Box::new(0);
assert_eq!(0, *x + { drop(x); let _ = Box::new(main); 0 });
}

0 comments on commit eec629b

Please sign in to comment.