Skip to content

Don't compute name of associated item if it's an RPITIT #139880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.iter()
.flat_map(|trait_def_id| tcx.associated_items(*trait_def_id).in_definition_order())
.filter_map(|item| {
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag)
.then_some(item.name())
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag).then(|| item.name())
})
.collect();

Expand Down
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/in-trait/dont-probe-missing-item-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression test for <https://github.com/rust-lang/rust/issues/139873>.

// Test that we don't try to get the (nonexistent) name of the RPITIT in `Trait::foo`
// when emitting an error for a missing associated item `Trait::Output`.

trait Trait {
fn foo() -> impl Sized;
fn bar() -> Self::Output;
//~^ ERROR associated type `Output` not found for `Self`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0220]: associated type `Output` not found for `Self`
--> $DIR/dont-probe-missing-item-name.rs:8:23
|
LL | fn bar() -> Self::Output;
| ^^^^^^ associated type `Output` not found

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0220`.
Loading