forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#43776 - zackmdavis:feature_gate_fn_must_use…
…, r=alexcrichton feature-gate #[must_use] for functions as `fn_must_use` @eddyb I [was](rust-lang#43728 (comment)) [dithering](rust-lang#43728 (comment)) on this, but [your comment](rust-lang#43302 (comment)) makes it sound like we do want a feature gate for this? Please advise. r? @eddyb
- Loading branch information
Showing
6 changed files
with
128 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
struct MyStruct; | ||
|
||
impl MyStruct { | ||
#[must_use] | ||
fn need_to_use_method() -> bool { true } //~ WARN `#[must_use]` on methods is experimental | ||
} | ||
|
||
#[must_use] | ||
fn need_to_use_it() -> bool { true } //~ WARN `#[must_use]` on functions is experimental | ||
|
||
|
||
// Feature gates are tidy-required to have a specially named (or | ||
// comment-annotated) compile-fail test (which MUST fail), but for | ||
// backwards-compatibility reasons, we want `#[must_use]` on functions to be | ||
// compilable even if the `fn_must_use` feature is absent, thus necessitating | ||
// the usage of `#[rustc_error]` here, pragmatically if awkwardly solving this | ||
// dilemma until a superior solution can be devised. | ||
#[rustc_error] | ||
fn main() {} //~ ERROR compilation successful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
warning: unused return value of `need_to_use_this_value` which must be used: it's important | ||
--> $DIR/fn_must_use.rs:30:5 | ||
--> $DIR/fn_must_use.rs:31:5 | ||
| | ||
30 | need_to_use_this_value(); | ||
31 | need_to_use_this_value(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/fn_must_use.rs:11:9 | ||
--> $DIR/fn_must_use.rs:12:9 | ||
| | ||
11 | #![warn(unused_must_use)] | ||
12 | #![warn(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used | ||
--> $DIR/fn_must_use.rs:33:5 | ||
--> $DIR/fn_must_use.rs:34:5 | ||
| | ||
33 | m.need_to_use_this_method_value(); | ||
34 | m.need_to_use_this_method_value(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|