Skip to content

Commit

Permalink
fn_must_use soft feature-gate warning on methods too, not only functions
Browse files Browse the repository at this point in the history
This continues to be in the matter of #43302.
  • Loading branch information
zackmdavis committed Aug 23, 2017
1 parent 8492ad2 commit 35c4494
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libsyntax/feature_gate.rs
Expand Up @@ -1318,7 +1318,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
and possibly buggy");
}

ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, ref impl_items) => {
if polarity == ast::ImplPolarity::Negative {
gate_feature_post!(&self, optin_builtin_traits,
i.span,
Expand All @@ -1331,6 +1331,16 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
i.span,
"specialization is unstable");
}

for impl_item in impl_items {
if let ast::ImplItemKind::Method(..) = impl_item.node {
if attr::contains_name(&impl_item.attrs[..], "must_use") {
gate_feature_post!(&self, fn_must_use, impl_item.span,
"`#[must_use]` on methods is experimental",
GateStrength::Soft);
}
}
}
}

ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
Expand Down
7 changes: 7 additions & 0 deletions src/test/compile-fail/feature-gate-fn_must_use.rs
Expand Up @@ -10,6 +10,13 @@

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

Expand Down

0 comments on commit 35c4494

Please sign in to comment.