1
Fork 0

fn_must_use soft feature-gate warning on methods too, not only functions

This continues to be in the matter of #43302.
This commit is contained in:
Zack M. Davis 2017-08-22 17:27:00 -07:00
parent 8492ad2479
commit 35c449419c
2 changed files with 18 additions and 1 deletions

View file

@ -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,
@ -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, .. }) => {

View file

@ -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