mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Auto merge of #4989 - rust-lang:no-unmangled-must-use, r=flip1995
No #[no_mangle] must_use_candidate functions This fixes #4984. changelog: none
This commit is contained in:
commit
fddc9801dd
4 changed files with 25 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::utils::{
|
||||
attrs::is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res, return_ty,
|
||||
snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method,
|
||||
attr_by_name, attrs::is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res,
|
||||
return_ty, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method,
|
||||
type_is_unsafe_function,
|
||||
};
|
||||
use matches::matches;
|
||||
|
@ -236,7 +236,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
|||
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
|
||||
return;
|
||||
}
|
||||
if cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(&item.attrs) {
|
||||
if cx.access_levels.is_exported(item.hir_id)
|
||||
&& !is_proc_macro(&item.attrs)
|
||||
&& attr_by_name(&item.attrs, "no_mangle").is_none()
|
||||
{
|
||||
check_must_use_candidate(
|
||||
cx,
|
||||
&sig.decl,
|
||||
|
|
|
@ -1253,13 +1253,16 @@ pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr<'_>, cx: &LateContext<'a, 'b>)
|
|||
}
|
||||
}
|
||||
|
||||
// Finds the attribute with the given name, if any
|
||||
pub fn attr_by_name<'a>(attrs: &'a [Attribute], name: &'_ str) -> Option<&'a Attribute> {
|
||||
attrs
|
||||
.iter()
|
||||
.find(|attr| attr.ident().map_or(false, |ident| ident.as_str() == name))
|
||||
}
|
||||
|
||||
// Finds the `#[must_use]` attribute, if any
|
||||
pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> {
|
||||
attrs.iter().find(|attr| {
|
||||
attr.ident().map_or(false, |ident| {
|
||||
let ident: &str = &ident.as_str();
|
||||
"must_use" == ident
|
||||
})
|
||||
})
|
||||
attr_by_name(attrs, "must_use")
|
||||
}
|
||||
|
||||
// Returns whether the type has #[must_use] attribute
|
||||
|
|
|
@ -83,6 +83,11 @@ pub unsafe fn mutates_static() -> usize {
|
|||
COUNTER
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn unmangled(i: bool) -> bool {
|
||||
!i
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, pure(1));
|
||||
}
|
||||
|
|
|
@ -83,6 +83,11 @@ pub unsafe fn mutates_static() -> usize {
|
|||
COUNTER
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn unmangled(i: bool) -> bool {
|
||||
!i
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(1, pure(1));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue