Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Mar 11, 2024
1 parent 0afbf75 commit b0ad8d7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/ui/snapshot/leaked-vars-issue-114056.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for #114056. Fixed by #111516.
struct P<Q>(Q);
impl<Q> P<Q> {
fn foo(&self) {
self.partial_cmp(())
//~^ ERROR the method `partial_cmp` exists for reference `&P<Q>`
}
}

fn main() {}
27 changes: 27 additions & 0 deletions tests/ui/snapshot/leaked-vars-issue-114056.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0599]: the method `partial_cmp` exists for reference `&P<Q>`, but its trait bounds were not satisfied
--> $DIR/leaked-vars-issue-114056.rs:5:14
|
LL | struct P<Q>(Q);
| ----------- doesn't satisfy `P<Q>: Iterator` or `P<Q>: PartialOrd<_>`
...
LL | self.partial_cmp(())
| ^^^^^^^^^^^ method cannot be called on `&P<Q>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`P<Q>: PartialOrd<_>`
which is required by `&P<Q>: PartialOrd<&_>`
`&P<Q>: Iterator`
which is required by `&mut &P<Q>: Iterator`
`P<Q>: Iterator`
which is required by `&mut P<Q>: Iterator`
note: the trait `Iterator` must be implemented
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
help: consider annotating `P<Q>` with `#[derive(PartialEq, PartialOrd)]`
|
LL + #[derive(PartialEq, PartialOrd)]
LL | struct P<Q>(Q);
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
14 changes: 14 additions & 0 deletions tests/ui/snapshot/leaked-vars-issue-122098.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Regression test for #122098. Has been slightly minimized, fixed by #122189.
trait LendingIterator: Sized {
type Item<'q>;

fn for_each(self, f: Box<dyn FnMut(Self::Item<'_>)>) {}
}

struct Query;
fn main() {
LendingIterator::for_each(Query, Box::new);
//~^ ERROR the trait bound `Query: LendingIterator` is not satisfied
//~| ERROR mismatched types
//~| ERROR the trait bound `Query: LendingIterator` is not satisfied
}
46 changes: 46 additions & 0 deletions tests/ui/snapshot/leaked-vars-issue-122098.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
error[E0277]: the trait bound `Query: LendingIterator` is not satisfied
--> $DIR/leaked-vars-issue-122098.rs:10:31
|
LL | LendingIterator::for_each(Query, Box::new);
| ------------------------- ^^^^^ the trait `LendingIterator` is not implemented for `Query`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> $DIR/leaked-vars-issue-122098.rs:2:1
|
LL | trait LendingIterator: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/leaked-vars-issue-122098.rs:10:38
|
LL | LendingIterator::for_each(Query, Box::new);
| ------------------------- ^^^^^^^^ expected `Box<dyn FnMut(...)>`, found fn item
| |
| arguments to this function are incorrect
|
= note: expected struct `Box<(dyn for<'a> FnMut(<Query as LendingIterator>::Item<'a>) + 'static)>`
found fn item `fn(_) -> Box<_> {Box::<_>::new}`
note: method defined here
--> $DIR/leaked-vars-issue-122098.rs:5:8
|
LL | fn for_each(self, f: Box<dyn FnMut(Self::Item<'_>)>) {}
| ^^^^^^^^ ---------------------------------

error[E0277]: the trait bound `Query: LendingIterator` is not satisfied
--> $DIR/leaked-vars-issue-122098.rs:10:38
|
LL | LendingIterator::for_each(Query, Box::new);
| ^^^^^^^^ the trait `LendingIterator` is not implemented for `Query`
|
help: this trait has no implementations, consider adding one
--> $DIR/leaked-vars-issue-122098.rs:2:1
|
LL | trait LendingIterator: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

0 comments on commit b0ad8d7

Please sign in to comment.