forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#58743 - varkor:bulk-needstest-1, r=alexcric…
…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#26448. Closes rust-lang#26577. Closes rust-lang#26619. Closes rust-lang#27054. Closes rust-lang#44127. Closes rust-lang#44255. Closes rust-lang#55731. Closes rust-lang#57781.
- Loading branch information
Showing
17 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | | | ||
LL | | foo(); | ||
| | - 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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0515]: cannot return value referencing function parameter | ||
--> $DIR/issue-26619.rs:7:76 | ||
| | ||
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) { | ||
| -------- ^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function | ||
| | | ||
| function parameter borrowed here | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0515`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
| ^^^^^^^^^^^^^ 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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
| ^^^^^ | ||
| | ||
= 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |