Skip to content

"#[test] attribute is only allowed on fn items" on fn struct method #55787

Closed
@matthiaskrgr

Description

@matthiaskrgr
#![feature(test)]
extern crate test;

struct A {}

impl A {
	#[test]
	fn new() -> A {
		A {}
	}
}

#[test]
fn test() {
	let _ = A::new();
}

fn main() {}

warns however the #[test] in fact on a fn item

error: #[test] attribute is only allowed on fn items
  --> src/main.rs:8:2
   |
8  |       fn new() -> A {
   |  _____^
9  | |         A {}
10 | |     }
   | |_____^

Maybe this could be made a bit more clear?

rustc 1.32.0-nightly (25a42b2ce 2018-11-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions