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

cargo build fails but building macro-expanded file works #81183

Open
osa1 opened this issue Jan 19, 2021 · 1 comment
Open

cargo build fails but building macro-expanded file works #81183

osa1 opened this issue Jan 19, 2021 · 1 comment
Labels
A-attributes Area: #[attributes(..)] A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug.

Comments

@osa1
Copy link
Contributor

osa1 commented Jan 19, 2021

Cargo.toml:

[package]
name = "instrument_test"
version = "0.1.0"
authors = []
edition = "2018"

[dependencies]
tracing = { path = "/home/omer/rust/tracing/tracing" }
tracing-core = { path = "/home/omer/rust/tracing/tracing-core" }

The 'tracing' package is https://github.com/tokio-rs/tracing master branch (fe570af).

main.rs:

use tracing::instrument;

#[instrument]
fn main() {
    //! testing
}

If I build this with current rustc master (4ba1aaf):

$ cargo +stage1 build
...
    Compiling instrument_test v0.1.0 (/home/omer/rust/instrument_test)
error: an inner attribute is not permitted in this context
 --> src/main.rs:4:1
  |
4 | / fn main() {
5 | |     //! testing
6 | | }
  | |_^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

error: aborting due to previous error

error: could not compile `instrument_test`

To learn more, run the command again with --verbose.

However if I expand the macro/attribute using the same rustc using cargo-expand and replace main.rs with the expanded code, it builds fine. Expanded code:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use tracing::instrument;
fn main() {
    //! testing
    {}
    let __tracing_attr_span = {
        use ::tracing::__macro_support::{Callsite as _, Registration};
        static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
            use ::tracing::__macro_support::{MacroCallsite, Registration};
            static META: ::tracing::Metadata<'static> = {
                ::tracing_core::metadata::Metadata::new(
                    "main",
                    "instrument_test",
                    tracing::Level::INFO,
                    Some("src/main.rs"),
                    Some(3u32),
                    Some("instrument_test"),
                    ::tracing_core::field::FieldSet::new(
                        &[],
                        ::tracing_core::callsite::Identifier(&CALLSITE),
                    ),
                    ::tracing::metadata::Kind::SPAN,
                )
            };
            static REG: Registration = Registration::new(&CALLSITE);
            MacroCallsite::new(&META, &REG)
        };
        let mut interest = ::tracing::collect::Interest::never();
        if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
            && tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
            && {
                interest = CALLSITE.interest();
                !interest.is_never()
            }
            && CALLSITE.is_enabled(interest)
        {
            let meta = CALLSITE.metadata();
            ::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
        } else {
            let span = CALLSITE.disabled_span();
            {};
            span
        }
    };
    let __tracing_attr_guard = __tracing_attr_span.enter();
    {}
}

Interestingly cargo expand prints the same error ("an inner attribute is not permitted in this context") but it's still able to expand the code, and expanded code works.

@osa1 osa1 added the C-bug Category: This is a bug. label Jan 19, 2021
@jyn514 jyn514 added A-attributes Area: #[attributes(..)] A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Jan 19, 2021
@camelid camelid added the A-proc-macros Area: Procedural macros label Jan 19, 2021
@camelid
Copy link
Member

camelid commented Jan 19, 2021

Interestingly cargo expand prints the same error ("an inner attribute is not permitted in this context") but it's still able to expand the code, and expanded code works.

I'm guessing it's just running rustc, and the error occurs after macro expansion (though I may be totally wrong).

osa1 added a commit to osa1/rust that referenced this issue Feb 24, 2021
- Currently style triggers rust-lang#81183 so we can't add `#[instrument]` to
  this function.

- Having docs above the header is more consistent with the rest of the
  code base.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 24, 2021
…etrochenkov

Move pick_by_value_method docs above function header

- Currently style triggers rust-lang#81183 so we can't add `#[instrument]` to
  this function.

- Having docs above the header is more consistent with the rest of the
  code base.
Aaron1011 added a commit to Aaron1011/rust that referenced this issue Feb 25, 2021
…etrochenkov

Move pick_by_value_method docs above function header

- Currently style triggers rust-lang#81183 so we can't add `#[instrument]` to
  this function.

- Having docs above the header is more consistent with the rest of the
  code base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: #[attributes(..)] A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants