Skip to content

Commit 35c4494

Browse files
committed
fn_must_use soft feature-gate warning on methods too, not only functions
This continues to be in the matter of #43302.
1 parent 8492ad2 commit 35c4494

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/libsyntax/feature_gate.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
13181318
and possibly buggy");
13191319
}
13201320

1321-
ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
1321+
ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, ref impl_items) => {
13221322
if polarity == ast::ImplPolarity::Negative {
13231323
gate_feature_post!(&self, optin_builtin_traits,
13241324
i.span,
@@ -1331,6 +1331,16 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
13311331
i.span,
13321332
"specialization is unstable");
13331333
}
1334+
1335+
for impl_item in impl_items {
1336+
if let ast::ImplItemKind::Method(..) = impl_item.node {
1337+
if attr::contains_name(&impl_item.attrs[..], "must_use") {
1338+
gate_feature_post!(&self, fn_must_use, impl_item.span,
1339+
"`#[must_use]` on methods is experimental",
1340+
GateStrength::Soft);
1341+
}
1342+
}
1343+
}
13341344
}
13351345

13361346
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {

src/test/compile-fail/feature-gate-fn_must_use.rs

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
#![feature(rustc_attrs)]
1212

13+
struct MyStruct;
14+
15+
impl MyStruct {
16+
#[must_use]
17+
fn need_to_use_method() -> bool { true } //~ WARN `#[must_use]` on methods is experimental
18+
}
19+
1320
#[must_use]
1421
fn need_to_use_it() -> bool { true } //~ WARN `#[must_use]` on functions is experimental
1522

0 commit comments

Comments
 (0)