Skip to content

Commit e1994fb

Browse files
Merge #241
241: Fix unused doc lint firing on `#[pre_init]` and add a test r=adamgreig a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
2 parents 22145ae + a0a1786 commit e1994fb

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

cortex-m-rt/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ compiletest_rs = "0.4.0"
3131
name = "device"
3232
required-features = ["device"]
3333

34+
[[example]]
35+
name = "warnings"
36+
required-features = ["device"]
37+
3438
[[test]]
3539
name = "compiletest"
3640
required-features = ["device"]

cortex-m-rt/examples/warnings.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Tests that a crate can still build with all warnings enabled.
2+
//!
3+
//! The code generated by the `cortex-m-rt` macros might need to manually
4+
//! `#[allow]` some of them (even though Rust does that by default for a few
5+
//! warnings too).
6+
7+
#![no_std]
8+
#![no_main]
9+
#![deny(warnings, missing_docs, rust_2018_idioms)]
10+
11+
extern crate cortex_m_rt;
12+
extern crate panic_halt;
13+
14+
use cortex_m_rt::{entry, exception, interrupt, pre_init, ExceptionFrame};
15+
16+
#[allow(non_camel_case_types)]
17+
enum interrupt {
18+
INT,
19+
}
20+
21+
extern "C" {
22+
fn INT();
23+
}
24+
25+
union Vector {
26+
#[allow(dead_code)]
27+
handler: unsafe extern "C" fn(),
28+
}
29+
30+
#[link_section = ".vector_table.interrupts"]
31+
#[no_mangle]
32+
#[used]
33+
static __INTERRUPTS: [Vector; 1] = [Vector { handler: INT }];
34+
35+
/// Dummy interrupt.
36+
#[interrupt]
37+
fn INT() {}
38+
39+
#[exception]
40+
fn HardFault(_eh: &ExceptionFrame) -> ! {
41+
loop {}
42+
}
43+
44+
#[entry]
45+
fn main() -> ! {
46+
loop {}
47+
}
48+
49+
#[pre_init]
50+
unsafe fn pre_init() {}

cortex-m-rt/macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
767767

768768
quote!(
769769
#[export_name = "__pre_init"]
770+
#[allow(missing_docs)] // we make a private fn public, which can trigger this lint
770771
#(#attrs)*
771772
pub unsafe fn #ident() #block
772773
)

0 commit comments

Comments
 (0)