Skip to content
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

Can not use argument impl Trait in type alias #139055

Closed
LHolten opened this issue Mar 28, 2025 · 5 comments · Fixed by #139063
Closed

Can not use argument impl Trait in type alias #139055

LHolten opened this issue Mar 28, 2025 · 5 comments · Fixed by #139063
Assignees
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LHolten
Copy link
Contributor

LHolten commented Mar 28, 2025

I tried this code:

type X = [(); {
    
    fn hello(x: impl Clone) {
        
    }
    
    3
}];

I expect this to compile, but instead i get this error.

error[E0658]: `impl Trait` in type aliases is unstable
 --> src/lib.rs:3:17
  |
3 |     fn hello(x: impl Clone) {
  |                 ^^^^^^^^^^
  |

Meta

Bug also reproduces on nightly.

rustc --version --verbose:

rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7
@LHolten LHolten added the C-bug Category: This is a bug. label Mar 28, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 28, 2025
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 28, 2025
@fmease
Copy link
Member

fmease commented Mar 28, 2025

Yeep, that's the fragile visitors in ast_passes. In this case, we won't reset the context on AnonConst.

@fmease
Copy link
Member

fmease commented Mar 28, 2025

I've already reported the general issue here #119924 in the past incl. your specific issue #119924 (comment)

@fmease fmease self-assigned this Mar 28, 2025
@fmease
Copy link
Member

fmease commented Mar 28, 2025

I guess you found this by fuzzing? If not, I can say I never thought sb. would stumble upon this for real ^^

@LHolten
Copy link
Contributor Author

LHolten commented Mar 28, 2025

I actually stumbled into this while developing a macro that defines a new type wherever you are supposed to provide a type.
As you can see this is extremely useful and extremely cursed code :D

trait Sneak {
    type Out;
}

macro_rules! new_type {
    ($($fields:tt)*) => {
        <[(); {
            struct Bar {$($fields)*}
            impl Sneak for [(); line!() as usize] {
                type Out = Bar;
            }
            line!() as usize
        }] as Sneak>::Out
    };
}

type Test = new_type!(x: u32);
type Test2 = new_type!(x: String);

fn test(val: Test) -> Test2 {
    let Test { x } = val;
    Test2 { x: "hi".to_owned() }
}

P.S. I would appreciate anyone who uses this trick to credit me for the idea :P
(oh and you can expect to see this used to great effect in rust_query sometime soonish)

@fmease
Copy link
Member

fmease commented Mar 28, 2025

Nice! I'll send a fix shortly!

@bors bors closed this as completed in 52aed95 Mar 29, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 29, 2025
Rollup merge of rust-lang#139063 - fmease:fix-tait-atpit-gating, r=oli-obk

Fix TAIT & ATPIT feature gating in the presence of anon consts

Fixes rust-lang#139055 (rust-lang#119924 (comment)).

r? oli-obk or anybody else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants