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

Something weird with const generic resolution in macro_rules #62433

Closed
scottmcm opened this issue Jul 6, 2019 · 1 comment · Fixed by #63083
Closed

Something weird with const generic resolution in macro_rules #62433

scottmcm opened this issue Jul 6, 2019 · 1 comment · Fixed by #63083
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Jul 6, 2019

This works, so const generic resolution works through macros (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e93e583bc759379eae9dac80ed011361)

#![feature(const_generics)]
trait Foo {}
struct Bar<T, const N: usize>(T);
trait Qux<const N: usize> {}
macro_rules! bar {
    ($t:ty) => {
        impl<T, const N: usize> Foo for $t
        {}
    }
}
bar!(Bar<T, {N}>);

This also works, so const generics work in a where guard (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=cde12aadff1355221b94beef0782da9c)

#![feature(const_generics)]
trait Foo {}
struct Bar<T, const N: usize>(T);
trait Qux<const N: usize> {}
impl<T, const N: usize> Foo for Bar<T, {N}>
    where (): Qux<{N}>
{}

But if I combine those together, all of a sudden it has name resolution problems (https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c11ade7c9cc0f31a0fc538816bbe0719)

#![feature(const_generics)]
trait Foo {}
struct Bar<T, const N: usize>(T);
trait Qux<const N: usize> {}
macro_rules! bar {
    ($t:ty) => {
        impl<T, const N: usize> Foo for $t
            where (): Qux<{N}>
        {}
    }
}
bar!(Bar<T, {N}>);
error[E0425]: cannot find value `N` in this scope
  --> src/lib.rs:8:28
   |
8  |             where (): Qux<{N}>
   |                            ^ not found in this scope
...
12 | bar!(Bar<T, {N}>);
   | ------------------ in this macro invocation

So something seems weird, but I have no idea what it could be

@petrochenkov
Copy link
Contributor

Probably related to #58307.
The workaround should be passing const generic names to macro_rules like local variable names would be passed.

@Centril Centril added A-const-generics Area: const generics (parameters and arguments) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-resolve Area: Name resolution C-bug Category: This is a bug. labels Jul 6, 2019
scottmcm added a commit to scottmcm/rust that referenced this issue Jul 7, 2019
- uses a never-stable core::array::LengthAtMost32 to bound the impls
- includes a custom error message to avoid mentioning LengthAtMost32 too often
- doesn't use macros for the slice implementations to avoid rust-lang#62433
Centril added a commit to Centril/rust that referenced this issue Jul 29, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Centril added a commit to Centril/rust that referenced this issue Jul 30, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Centril added a commit to Centril/rust that referenced this issue Jul 30, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution 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