Skip to content

rustc invalidly complains that I need to add #![feature(proc_macro)] even when its already there. #52599

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
emmatyping opened this issue Jul 21, 2018 · 5 comments

Comments

@emmatyping
Copy link

emmatyping commented Jul 21, 2018

Summary

When I try to use a crate with proc macros, I cannot, even if I enable the feature and macro_use the crate.

Code

From https://github.com/termoshtt/accel#example (with an added #[macro_use] on line 4)

#![feature(proc_macro, custom_attribute)]
extern crate accel;
#[macro_use]
extern crate accel_derive;

use accel_derive::kernel;
use accel::*;

#[kernel]
#[crate("accel-core" = "0.2.0")]
#[build_path(".rust2ptx")]
pub unsafe fn add(a: *const f64, b: *const f64, c: *mut f64, n: usize) {
    let i = accel_core::index();
    if (i as usize) < n {
        *c.offset(i) = *a.offset(i) + *b.offset(i);
    }
}

fn main() {
    let n = 32;
    let mut a = UVec::new(n).unwrap();
    let mut b = UVec::new(n).unwrap();
    let mut c = UVec::new(n).unwrap();

    for i in 0..n {
        a[i] = i as f64;
        b[i] = 2.0 * i as f64;
    }
    println!("a = {:?}", a.as_slice());
    println!("b = {:?}", b.as_slice());

    let grid = Grid::x(1);
    let block = Block::x(n as u32);
    add(grid, block, a.as_ptr(), b.as_ptr(), c.as_mut_ptr(), n);

    device::sync().unwrap();
    println!("c = {:?}", c.as_slice());
}

Expected results:

It compiles.

Actual results:

It fails, with the following:

error[E0432]: unresolved import `accel_derive::kernel`==============>  ] 32/33: cuda-test                
 --> src/main.rs:6:5
  |
6 | use accel_derive::kernel;
  |     ^^^^^^^^^^^^^^^^^^^^ no `kernel` in the root

error[E0658]: attribute procedural macros are experimental (see issue #38356)
 --> src/main.rs:9:1
  |
3 | #[macro_use]
  | ------------ procedural macro imported here
...
9 | #[kernel]
  | ^^^^^^^^^
  |
  = help: add #![feature(proc_macro)] to the crate attributes to enable

error[E0433]: failed to resolve. Use of undeclared type or module `accel_core`
  --> src/main.rs:13:13
   |
13 |     let i = accel_core::index();
   |             ^^^^^^^^^^ Use of undeclared type or module `accel_core`

error: expected one of `)` or `,`, found `=`
  --> src/main.rs:10:22
   |
10 | #[crate("accel-core" = "0.2.0")]
   |                      ^ expected one of `)` or `,` here

error: unexpected token: `"0.2.0"`
  --> src/main.rs:10:24
   |
10 | #[crate("accel-core" = "0.2.0")]
   |                        ^^^^^^^ unexpected token after this

error: aborting due to 5 previous errors

Some errors occurred: E0432, E0433, E0658.
For more information about an error, try `rustc --explain E0432`.
error: Could not compile `cuda-test`.

Note that I don't expect to get this working at this point, I wanted to report what to me (and someone on #rust who suggested I open this) a bug.

rustc data:

rustc 1.29.0-nightly (12ed235ad 2018-07-18)
binary: rustc
commit-hash: 12ed235adc62e63b16bb4f715b143c37a5efa00d
commit-date: 2018-07-18
host: x86_64-unknown-linux-gnu
release: 1.29.0-nightly
LLVM version: 7.0
@Mark-Simulacrum
Copy link
Member

I believe this has since been fixed so it's possible that you just need to update your nightly version, though I'm uncertain if the relevant patch has landed and been published yet.

cc @alexcrichton

@emmatyping
Copy link
Author

@Mark-Simulacrum I seem not to have any updates available, at least according to rustup. Perhaps #49219 is what you were thinking of?

@Mark-Simulacrum
Copy link
Member

No, I was thinking of #52458.

@alexcrichton
Copy link
Member

Indeed that should do it! Mind testing the most recent nightly to be sure?

@emmatyping
Copy link
Author

Thanks so much! It works like I charm, got Accel working 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants