Skip to content

Commit 0ae0643

Browse files
Skip reporting item name when checking RPITIT GAT's associated type bounds hold
1 parent 9339f44 commit 0ae0643

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

compiler/rustc_infer/src/infer/error_reporting/note.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
243243
}
244244
infer::CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => {
245245
let mut err = self.report_concrete_failure(*parent, sub, sup);
246-
let trait_item_span = self.tcx.def_span(trait_item_def_id);
247-
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
248-
err.span_label(
249-
trait_item_span,
250-
format!("definition of `{}` from trait", item_name),
251-
);
246+
247+
// Don't mention the item name if it's an RPITIT, since that'll just confuse
248+
// folks.
249+
if !self.tcx.is_impl_trait_in_trait(impl_item_def_id.to_def_id()) {
250+
let trait_item_span = self.tcx.def_span(trait_item_def_id);
251+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
252+
err.span_label(
253+
trait_item_span,
254+
format!("definition of `{}` from trait", item_name),
255+
);
256+
}
257+
252258
self.suggest_copy_trait_method_bounds(
253259
trait_item_def_id,
254260
impl_item_def_id,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// issue: 114145
2+
3+
#![feature(return_position_impl_trait_in_trait)]
4+
5+
trait Iterable {
6+
type Item<'a>
7+
where
8+
Self: 'a;
9+
10+
fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>;
11+
}
12+
13+
impl<'a, I: 'a + Iterable> Iterable for &'a I {
14+
type Item<'b> = I::Item<'a>
15+
where
16+
'b: 'a;
17+
//~^ ERROR impl has stricter requirements than trait
18+
19+
fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
20+
//~^ ERROR the type `&'a I` does not fulfill the required lifetime
21+
(*self).iter()
22+
}
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0276]: impl has stricter requirements than trait
2+
--> $DIR/bad-item-bound-within-rpitit.rs:16:13
3+
|
4+
LL | type Item<'a>
5+
| ------------- definition of `Item` from trait
6+
...
7+
LL | 'b: 'a;
8+
| ^^ impl has extra requirement `'b: 'a`
9+
|
10+
help: copy the `where` clause predicates from the trait
11+
|
12+
LL | where Self: 'b;
13+
| ~~~~~~~~~~~~~~
14+
15+
error[E0477]: the type `&'a I` does not fulfill the required lifetime
16+
--> $DIR/bad-item-bound-within-rpitit.rs:19:5
17+
|
18+
LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
note: type must outlive the anonymous lifetime as defined here
22+
--> $DIR/bad-item-bound-within-rpitit.rs:10:28
23+
|
24+
LL | fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>;
25+
| ^^
26+
27+
error: aborting due to 2 previous errors
28+
29+
Some errors have detailed explanations: E0276, E0477.
30+
For more information about an error, try `rustc --explain E0276`.

0 commit comments

Comments
 (0)