Skip to content

Commit b0ad8d7

Browse files
committed
add tests
1 parent 0afbf75 commit b0ad8d7

4 files changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #114056. Fixed by #111516.
2+
struct P<Q>(Q);
3+
impl<Q> P<Q> {
4+
fn foo(&self) {
5+
self.partial_cmp(())
6+
//~^ ERROR the method `partial_cmp` exists for reference `&P<Q>`
7+
}
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0599]: the method `partial_cmp` exists for reference `&P<Q>`, but its trait bounds were not satisfied
2+
--> $DIR/leaked-vars-issue-114056.rs:5:14
3+
|
4+
LL | struct P<Q>(Q);
5+
| ----------- doesn't satisfy `P<Q>: Iterator` or `P<Q>: PartialOrd<_>`
6+
...
7+
LL | self.partial_cmp(())
8+
| ^^^^^^^^^^^ method cannot be called on `&P<Q>` due to unsatisfied trait bounds
9+
|
10+
= note: the following trait bounds were not satisfied:
11+
`P<Q>: PartialOrd<_>`
12+
which is required by `&P<Q>: PartialOrd<&_>`
13+
`&P<Q>: Iterator`
14+
which is required by `&mut &P<Q>: Iterator`
15+
`P<Q>: Iterator`
16+
which is required by `&mut P<Q>: Iterator`
17+
note: the trait `Iterator` must be implemented
18+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
19+
help: consider annotating `P<Q>` with `#[derive(PartialEq, PartialOrd)]`
20+
|
21+
LL + #[derive(PartialEq, PartialOrd)]
22+
LL | struct P<Q>(Q);
23+
|
24+
25+
error: aborting due to 1 previous error
26+
27+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for #122098. Has been slightly minimized, fixed by #122189.
2+
trait LendingIterator: Sized {
3+
type Item<'q>;
4+
5+
fn for_each(self, f: Box<dyn FnMut(Self::Item<'_>)>) {}
6+
}
7+
8+
struct Query;
9+
fn main() {
10+
LendingIterator::for_each(Query, Box::new);
11+
//~^ ERROR the trait bound `Query: LendingIterator` is not satisfied
12+
//~| ERROR mismatched types
13+
//~| ERROR the trait bound `Query: LendingIterator` is not satisfied
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0277]: the trait bound `Query: LendingIterator` is not satisfied
2+
--> $DIR/leaked-vars-issue-122098.rs:10:31
3+
|
4+
LL | LendingIterator::for_each(Query, Box::new);
5+
| ------------------------- ^^^^^ the trait `LendingIterator` is not implemented for `Query`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
help: this trait has no implementations, consider adding one
10+
--> $DIR/leaked-vars-issue-122098.rs:2:1
11+
|
12+
LL | trait LendingIterator: Sized {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/leaked-vars-issue-122098.rs:10:38
17+
|
18+
LL | LendingIterator::for_each(Query, Box::new);
19+
| ------------------------- ^^^^^^^^ expected `Box<dyn FnMut(...)>`, found fn item
20+
| |
21+
| arguments to this function are incorrect
22+
|
23+
= note: expected struct `Box<(dyn for<'a> FnMut(<Query as LendingIterator>::Item<'a>) + 'static)>`
24+
found fn item `fn(_) -> Box<_> {Box::<_>::new}`
25+
note: method defined here
26+
--> $DIR/leaked-vars-issue-122098.rs:5:8
27+
|
28+
LL | fn for_each(self, f: Box<dyn FnMut(Self::Item<'_>)>) {}
29+
| ^^^^^^^^ ---------------------------------
30+
31+
error[E0277]: the trait bound `Query: LendingIterator` is not satisfied
32+
--> $DIR/leaked-vars-issue-122098.rs:10:38
33+
|
34+
LL | LendingIterator::for_each(Query, Box::new);
35+
| ^^^^^^^^ the trait `LendingIterator` is not implemented for `Query`
36+
|
37+
help: this trait has no implementations, consider adding one
38+
--> $DIR/leaked-vars-issue-122098.rs:2:1
39+
|
40+
LL | trait LendingIterator: Sized {
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: aborting due to 3 previous errors
44+
45+
Some errors have detailed explanations: E0277, E0308.
46+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)