Skip to content

#[cfg(not(test))] doesn't work in dependencies #59168

Closed
@nhynes

Description

@nhynes

I have something that looks like

// crateA/lib.rs

#[cfg(not(test))]
extern "C" {
	fn ext_fn();
}

#[cfg(test)]
fn ext_fn() {
	unimplemented!();
}

pub fn do_ext() {
	unsafe { ext_fn() };
}
// crateB/lib.rs
crateA::do_ext()

but despite using cargo test, I still get a link error saying that ext_fn isn't found. Is #[cfg(not(test))] a valid attribute?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions