Skip to content

Commit ec6bdda

Browse files
authored
Rollup merge of #139880 - compiler-errors:rpitit-nameless, r=nnethercote
Don't compute name of associated item if it's an RPITIT Use `Option::then` in favor of `Option::then_some` to not compute `AssocItem::name` if it fails the condition. Alternatively, I'd be open to changing this just to an `if`. Fixes #139873 r? ```@nnethercote```
2 parents b3284ad + 11e5987 commit ec6bdda

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
204204
.iter()
205205
.flat_map(|trait_def_id| tcx.associated_items(*trait_def_id).in_definition_order())
206206
.filter_map(|item| {
207-
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag)
208-
.then_some(item.name())
207+
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag).then(|| item.name())
209208
})
210209
.collect();
211210

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/139873>.
2+
3+
// Test that we don't try to get the (nonexistent) name of the RPITIT in `Trait::foo`
4+
// when emitting an error for a missing associated item `Trait::Output`.
5+
6+
trait Trait {
7+
fn foo() -> impl Sized;
8+
fn bar() -> Self::Output;
9+
//~^ ERROR associated type `Output` not found for `Self`
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0220]: associated type `Output` not found for `Self`
2+
--> $DIR/dont-probe-missing-item-name.rs:8:23
3+
|
4+
LL | fn bar() -> Self::Output;
5+
| ^^^^^^ associated type `Output` not found
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)