Skip to content
Draft
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
13 changes: 12 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// as potential fallback candidates (#142006). To temporarily mask that issue, let's not
// select at all if there are no early inherent candidates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs to be moved above the Type branch then, otherwise it no longer makes sense

if candidates.is_empty() {
return Ok(None);
return match assoc_tag {
ty::AssocTag::Type => Ok(None),
ty::AssocTag::Const => Err(self.report_unresolved_inherent_assoc_item(
Copy link
Member

@fmease fmease Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so we're clear, this is not the correct fix long term because we need to probe trait candidates, too, if there are no inherent candidates.

Moreover, adding this error back in just means we're likely just papering over some deeper mGCA issue that ultimately needs to be fixed some other way, possible. Well, I haven't really looked into the cause of the ICEs but Boxy knew of their existence all the way back when she worked on #140247.

name,
self_ty,
candidates,
vec![],
span,
assoc_tag,
)),
ty::AssocTag::Fn => unreachable!(),
};
}

let (applicable_candidates, fulfillment_errors) =
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/associated-inherent-types/iat-const-resolution.rs
Copy link
Member

@fmease fmease Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should reside in tests/ui/const-generics/mgca/& be called differently. mGCA just reuses the feature gate of IATs for type-level assoc const resolution since they share the impl. Otherwise, mGCA is completely unrelated to IATs.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! regression test for #148949, #149809
#![expect(incomplete_features)]
#![feature(min_generic_const_args)]
#![feature(inherent_associated_types)]
struct Foo<'a> {
x: &'a (),
}

impl<'a> Foo<'a> {
fn bar(_: [u8; Foo::X]) {}
//~^ ERROR: associated constant `X` not found for `Foo<'_>` in the current scope
// #[type_const]
// const Y: usize = 10;
// fn foo(_: [u8; Foo::Y]) {}
// associated constant `Y` not found for `Foo<'_>` in the current scope
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/associated-inherent-types/iat-const-resolution.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0220]: associated constant `X` not found for `Foo<'_>` in the current scope
--> $DIR/iat-const-resolution.rs:10:25
|
LL | struct Foo<'a> {
| -------------- associated constant `X` not found for this struct
...
LL | fn bar(_: [u8; Foo::X]) {}
| ^ associated item not found in `Foo<'_>`
|
= note: the associated constant was found for


error: aborting due to 1 previous error

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