Skip to content

impl Trait in macros: subst.rs "index out of bounds: the len is 1 but the index is 1" #10286

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

Closed
SkiFire13 opened this issue Sep 19, 2021 · 3 comments · Fixed by #10305
Closed
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@SkiFire13
Copy link
Contributor

#9639 has been closed, however a very similar issue is still happening to me. I encountered it the moment I added a ctor! macro call at this line. (Note that the linked crate requires beta/nightly to compile, but only due to code unrelated to the issue; the minimal repro compiles fine on stable.)
The macro call looks required for the crash to trigger, and manually expanding it solves the issue. This also happened in #9639 and the minimal repro posted there doesn't seem to address this.

Here's a minimal repro of my issue:

macro_rules! ty {
    () => {
        impl Sized
    }
}

fn foo(_: ty!()) {}

fn bar() {
    foo(());
}

It gives this error in vscode's output tab:

Panic context:
> 
version: 516eb40ba 2021-09-13 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/g%3A/WorkSpace/repro/src/lib.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Users\runneradmin\.cargo\registry\src\gb.xjqchip.workers.dev-1ecc6299db9ec823\chalk-ir-0.71.0\src\fold\subst.rs:58:19
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 516eb40ba 2021-09-13 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/g%3A/WorkSpace/repro/src/lib.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Users\runneradmin\.cargo\registry\src\gb.xjqchip.workers.dev-1ecc6299db9ec823\chalk-ir-0.71.0\src\fold\subst.rs:58:19
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 516eb40ba 2021-09-13 stable
request: rust-analyzer/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/g%3A/WorkSpace/repro/src/lib.rs",
            query: None,
            fragment: None,
        },
    },
}

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Users\runneradmin\.cargo\registry\src\gb.xjqchip.workers.dev-1ecc6299db9ec823\chalk-ir-0.71.0\src\fold\subst.rs:58:19
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I can't seem to get a full backtrace even when setting RUST_BACKTRACE=full.

@SkiFire13 SkiFire13 changed the title subst.rs "index out of bounds: the len is 1 but the index is 1" again impl Trait in macros: subst.rs "index out of bounds: the len is 1 but the index is 1" Sep 19, 2021
@flodiebold
Copy link
Member

flodiebold commented Sep 19, 2021

If that's really everything needed to trigger it, it should be pretty straightforward to turn it into a test in hir_ty/src/tests/regression.rs (the only thing to keep in mind is to add //- minicore: sized).

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now labels Sep 19, 2021
@SkiFire13
Copy link
Contributor Author

SkiFire13 commented Sep 19, 2021

it should be pretty straightforward to turn it into a test

Maybe I was too quick to go to the details, but this is still happening in rust-analyzer 516eb40ba 2021-09-13 stable and b73b32147 2021-09-18 dev. It's not a case fixed together with #9639, it's a really similar issue that's still present.

the only thing to keep in mind is to add //- minicore: sized

If that's due to the Sized trait, it's not required, any trait works (even non defined ones).

@SkiFire13
Copy link
Contributor Author

SkiFire13 commented Sep 19, 2021

Update: I've looked around trying to understand what's going on, and looks like the problem seems to be that hir_def::generics::GenericParams::fill_implicit_impl_trait_args ignores TypeRef::Macro. This is however wrong is case the macro expands to an impl Trait, like in my example. However expanding macros at this stage doesn't seem to be supported, so I'm kinda lost on what to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
2 participants