taiki-e / futures-async-stream

Async stream for Rust and the futures crate.
https://docs.rs/futures-async-stream
Apache License 2.0
175 stars 9 forks source link

cargo +nightly clippy E0658 error #65

Closed BohuTANG closed 3 years ago

BohuTANG commented 3 years ago

futures-async-stream is great, but I had some problems trying it out. I'm not sure if it's related to futures-async-stream(If it's not, then sorry).

  1. rustc version:

    rustc --version
    rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
  2. code snippe Cargo.toml

    [dependencies]
    futures = "0.3"
    futures-async-stream = "0.2"
#![feature(generators, proc_macro_hygiene, stmt_expr_attributes)]

use futures::stream::Stream;
use futures_async_stream::stream;

pub struct SourceTransform {}

impl SourceTransform {
    pub fn create() -> Self {
        SourceTransform {}
    }

    pub fn execute(&self) -> impl Stream<Item = i32> {
        #[stream]
        async move {
            for i in 0..10 {
                yield i;
            }
        }
    }
}
  1. cargo +nightly clippy
error[E0658]: attributes on expressions are experimental
  --> src/transforms/transform_source.rs:18:9
   |
18 |         #[stream]
   |         ^^^^^^^^^
   |
   = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
   = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error[E0658]: custom attributes cannot be applied to expressions
  --> src/transforms/transform_source.rs:18:9
   |
18 |         #[stream]
   |         ^^^^^^^^^
   |
   = note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
   = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: yield syntax is experimental
  --> src/transforms/transform_source.rs:21:17
   |
21 |                 yield i;
   |                 ^^^^^^^
   |
   = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
   = help: add `#![feature(generators)]` to the crate attributes to enable

error[E0658]: yield syntax is experimental
  --> src/transforms/transform_source.rs:18:9
   |
18 |         #[stream]
   |         ^^^^^^^^^
   |
   = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
   = help: add `#![feature(generators)]` to the crate attributes to enable
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0658`.
taiki-e commented 3 years ago

Thanks for the report. I couldn't reproduce this with the snippet you provide, so I have a few questions:

![feature(generators, proc_macro_hygiene, stmt_expr_attributes)]

Are these attributes set at the crate level (lib.rs or main.rs)? #![feature(..)] do not work at the module level. As unused_attributes warn this, futures-async-stream docs don't explain about this carefully.

  1. cargo +nightly clippy

Does this issue also happen with Cargo's subcommand, like cargo build?

BohuTANG commented 3 years ago

It's on module level, if I set it on the lib.rs, it's another problem. Any way to do it in the module level? If not, does rust attribute not allow it?

taiki-e commented 3 years ago

There is no way to enable unstable features at the module level. What problems do you have when using it at the crate level?

BohuTANG commented 3 years ago

Oh, my mistake. It works now.