Skip to content

Rustdoc: strange issues with no_std #38129

Closed
@phil-opp

Description

@phil-opp

The following doc test fails:

#![no_std]

use embedded::components::gpio::stm32f7;

fn main() {}

with the error

error: an inner attribute is not permitted in this context
 --> <anon>:2:3
  |
2 | #![no_std]
  |   ^
  |
  = note: inner attributes and doc comments, like `#![no_std]` or `//! My crate`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes and doc comments, like `#[test]` and
                                   `/// My function`, annotate the item following them.

So rustdoc doesn't recognize the no_std attribute.

However, when I add the extern crate definition manually, it works:

#![no_std]

use embedded::components::gpio::stm32f7;

extern crate embedded; // add the import manually

fn main() {}

It also works for imports from core:

#![no_std]

use core::sync; // import something from core (instead of importing from my own crate)

fn main() {}

The strange thing is that it also works if I add a comment containing extern crate:

#![no_std]

use embedded::components::gpio::stm32f7;

// extern crate

fn main() {}

(With "it works" I mean that the no_std attribute is recognized).


Edit: I added an example project in at phil-opp/issue-38129 (see the comment below).

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions