Skip to content

Commit 901c863

Browse files
Rollup merge of #113419 - spastorino:new-rpitit-28, r=compiler-errors
Avoid calling item_name for RPITIT Fixes #113405 r? `@compiler-errors`
2 parents f1c9098 + c0c1551 commit 901c863

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ impl<'tcx> InferCtxt<'tcx> {
2525
"impl has stricter requirements than trait"
2626
);
2727

28-
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
29-
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
30-
err.span_label(span, format!("definition of `{}` from trait", item_name));
28+
if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
29+
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
30+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
31+
err.span_label(span, format!("definition of `{}` from trait", item_name));
32+
}
3133
}
3234

3335
err.span_label(error_span, format!("impl has extra requirement {}", requirement));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/return-not-existing-pair.rs:12:20
3+
|
4+
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
5+
| ^^^^^^^^^^ expected lifetime parameters
6+
|
7+
help: indicate the anonymous lifetimes
8+
|
9+
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
10+
| +++++++
11+
12+
error[E0412]: cannot find type `ConnImpl` in this scope
13+
--> $DIR/return-not-existing-pair.rs:8:48
14+
|
15+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
16+
| ^^^^^^^^ not found in this scope
17+
18+
error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
19+
--> $DIR/return-not-existing-pair.rs:14:5
20+
|
21+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
22+
| ------------------------------------------------------------ `&self` used in trait
23+
...
24+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/return-not-existing-pair.rs:14:42
29+
|
30+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
31+
| ^^ expected `(&U, &T)`, found `()`
32+
|
33+
= note: expected tuple `(&'a U, &'b T)`
34+
found unit type `()`
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0186, E0308, E0412, E0726.
39+
For more information about an error, try `rustc --explain E0186`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/return-not-existing-pair.rs:12:20
3+
|
4+
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
5+
| ^^^^^^^^^^ expected lifetime parameters
6+
|
7+
help: indicate the anonymous lifetimes
8+
|
9+
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
10+
| +++++++
11+
12+
error[E0412]: cannot find type `ConnImpl` in this scope
13+
--> $DIR/return-not-existing-pair.rs:8:48
14+
|
15+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
16+
| ^^^^^^^^ not found in this scope
17+
18+
error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
19+
--> $DIR/return-not-existing-pair.rs:14:5
20+
|
21+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
22+
| ------------------------------------------------------------ `&self` used in trait
23+
...
24+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/return-not-existing-pair.rs:14:42
29+
|
30+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
31+
| ^^ expected `(&U, &T)`, found `()`
32+
|
33+
= note: expected tuple `(&'a U, &'b T)`
34+
found unit type `()`
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0186, E0308, E0412, E0726.
39+
For more information about an error, try `rustc --explain E0186`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition:2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
4+
5+
#![feature(async_fn_in_trait)]
6+
7+
trait MyTrait<'a, 'b, T> {
8+
async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
9+
//~^ ERROR: cannot find type `ConnImpl` in this scope [E0412]
10+
}
11+
12+
impl<'a, 'b, T, U> MyTrait<T> for U {
13+
//~^ ERROR: implicit elided lifetime not allowed here [E0726]
14+
async fn foo(_: T) -> (&'a U, &'b T) {}
15+
//~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186]
16+
//~| ERROR: mismatched types [E0308]
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)