From bd1c6372f052ccd6fc7a754273cb7e8763bd83ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 10 Jun 2018 15:42:56 -0700 Subject: [PATCH 1/2] Initial draft of untestable-function lint --- text/0000-lint-test-inner-function.md | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 text/0000-lint-test-inner-function.md diff --git a/text/0000-lint-test-inner-function.md b/text/0000-lint-test-inner-function.md new file mode 100644 index 00000000000..f3b3c234c8c --- /dev/null +++ b/text/0000-lint-test-inner-function.md @@ -0,0 +1,79 @@ +- Feature Name: lint-test-inner-function +- Start Date: 2018-06-10 +- RFC PR: (leave this empty) +- Rust Issue: (leave this empty) + +# Summary +[summary]: #summary + +Add a lint that warns when marking an inner function as `#[test]`. + +# Motivation +[motivation]: #motivation + +`#[test]` is used to mark funcitons to be run as part of a test suite. The +functions being marked need to be addressable for this to work. Currently, +marking an inner function as `#[test]` will not raise any errors or warnings, +but the test will silently not be run. By adding a lint that identifies these +cases, users are less likely to fail to notice. + +# Guide-level explanation +[guide-level-explanation]: #guide-level-explanation + +This is a lint that triggers when a `#[test]` annotation is found in a non +addressable function, warning that that function cannot be tested. + +For example, in the following code, `bar` will never be called as part of a +test run: + +```rust +fn foo() { + #[test] + fn bar() { + assert!(true); + } +} +``` + +The output should resemble the following: + +``` +error: cannot test inner function + --> $DIR/test-inner-fn.rs:15:5 + | +LL | #[test] //~ ERROR cannot test inner function [untestable_method] + | ^^^^^^^ + | + = note: requested on the command line with `-D untestable-method` +``` + +# Reference-level explanation +[reference-level-explanation]: #reference-level-explanation + +This is a new lint that shouldn't interact with others. Due to the interaction +with `cfg` attributes, the lint might only warn when run as part of a `--test` +compilation. This would be acceptable. + +# Drawbacks +[drawbacks]: #drawbacks + +Can't think of any reason not to do this. + +# Rationale and alternatives +[alternatives]: #alternatives + +Adding as a lint allows users to silence the error if they so wish. + +Not addressing this issue will let this problem continue happening without +warning to end users. + +# Prior art +[prior-art]: #prior-art + +This would act in the same way as other lints warning for potentially +problematic valid code. + +# Unresolved questions +[unresolved]: #unresolved-questions + +None. From 6cf0bf1297788ba9ddeda50d2f9ea6ae3ba9fd8c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 2 Sep 2018 23:23:46 +0200 Subject: [PATCH 2/2] RFC 2471 --- ...t-inner-function.md => 2471-lint-test-inner-function.md} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename text/{0000-lint-test-inner-function.md => 2471-lint-test-inner-function.md} (90%) diff --git a/text/0000-lint-test-inner-function.md b/text/2471-lint-test-inner-function.md similarity index 90% rename from text/0000-lint-test-inner-function.md rename to text/2471-lint-test-inner-function.md index f3b3c234c8c..49ebe8c11e4 100644 --- a/text/0000-lint-test-inner-function.md +++ b/text/2471-lint-test-inner-function.md @@ -1,7 +1,7 @@ -- Feature Name: lint-test-inner-function +- Feature Name: `lint_test_inner_function` - Start Date: 2018-06-10 -- RFC PR: (leave this empty) -- Rust Issue: (leave this empty) +- RFC PR: [rust-lang/rfcs#2471](https://github.com/rust-lang/rfcs/pull/2471) +- Rust Issue: [rust-lang/rust#53911](https://github.com/rust-lang/rust/issues/53911) # Summary [summary]: #summary