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

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

Closed
matthiaskrgr opened this issue Nov 8, 2018 · 5 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Nov 8, 2018

#![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)

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 8, 2018
@estebank
Copy link
Contributor

estebank commented Nov 8, 2018

Rewording to something along the lines of "only allowed on bare fn items" (or another, more appropriate way to refer to functions) should be enough.

@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 8, 2018
@zeegomo
Copy link
Contributor

zeegomo commented Nov 10, 2018

I would like to help with that but I'm a first timer

@smokytheangel0
Copy link

the string in question is on line 56 of rust/src/libsyntax_ext/test.rs. I would suggest changing it to '#[test] is only allowed on non-impl fn items". I have no idea what steps are involved in contributing this.

@zeegomo
Copy link
Contributor

zeegomo commented Nov 11, 2018

I think '#[test] is only allowed on non associated functions' should be good, fn items inside impl are called associated functions or methods (if they have and instance of the struct to work with, i.e &self or &mut self)

pietroalbini added a commit to pietroalbini/rust that referenced this issue Nov 18, 2018
reword #[test] attribute error on fn items

fix of [rust-lang#55787](rust-lang#55787)
Reworded error message from "#[test] attribute is only allowed on fn items" to "#[test] attribute is only allowed on non associated functions"
@TheSirC
Copy link

TheSirC commented Dec 5, 2018

Should this be closed @estebank ?

@estebank estebank closed this as completed Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

5 participants