rust-lang / rust-lang/rust

struct constructor of an alias ty under mgca produces error

Open
#160,844 5 comments 0 reactions 1 assignee View on GitHub

@khyperia is already working on this.

Since Aug 10, 2026.

A-associated-items A-const-generics C-bug F-adt_const_params F-min_generic_const_args S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

unsure whether to file this under min_generic_const_args, adt_const_params, inherent_associated_types, or something else ;-;

discovered when investigating how to progress with inherent_associated_types

//@ check-pass
#![feature(min_generic_const_args, adt_const_params)]
#![expect(incomplete_features)]

use std::marker::ConstParamTy;

#[derive(PartialEq, Eq, ConstParamTy)]
struct Struct {}

fn f<const S: Struct>() {}

trait Trait {
    type Assoc;
    fn g();
}

impl Trait for () {
    type Assoc = Struct;

    fn g() {
        let _ = Self::Assoc {}; // ok!
        f::<core::direct_const_arg!(Struct {})>(); // ok!
        f::<core::direct_const_arg!(Self::Assoc {})>(); // kaboom
    }
}

fn main() {}
error: struct expression with invalid base path
  --> src/main.rs:22:37
   |
22 |         f::<core::direct_const_arg!(Self::Assoc {})>();
   |                                     ^^^^^^^^^^^^^^

pardon the wonky setup, it can probably be minimized a bit, just wanting to avoid more_qualified_paths. I think (I am unsure) that this should compile.

relevant line of code:

https://github.com/rust-lang/rust/blob/8a2fbe3ea881ec68b9f06510fd1a1484cdf5bb6b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs#L2679

relevant PR: https://github.com/rust-lang/rust/pull/149114

Speculation on my part:

The easiest way to resolve this is to have ResolvedStructPath have its res: Result<Res, ErrorGuaranteed> field ripped out if at all possible. I haven't quite investigated why it exists, I thiiink it's only used in two places: this spot in mGCA direct arg lowering (hence me filing this issue), and fn_ctxt/checks.rs check_struct_path https://github.com/rust-lang/rust/blob/8a2fbe3ea881ec68b9f06510fd1a1484cdf5bb6b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs#L1049 ... removing it would be real nice to make inherent_associated_types easier to implement.

Anyway, just filing an issue to track it for now, will fully investigate later.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.