diff options
Diffstat (limited to 'src/librustc/lint/builtin.rs')
| -rw-r--r-- | src/librustc/lint/builtin.rs | 64 | 
1 files changed, 31 insertions, 33 deletions
| diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 3c06bae177c..9b5e94e87a1 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1292,46 +1292,36 @@ impl LintPass for UnsafeCode { } fn check_item(&mut self, cx: &Context, it: &ast::Item) { - use syntax::ast::Unsafety::Unsafe; - - fn check_method(cx: &Context, meth: &P<ast::Method>) { - if let ast::Method_::MethDecl(_, _, _, _, Unsafe, _, _, _) = meth.node { - cx.span_lint(UNSAFE_CODE, meth.span, "implementation of an `unsafe` method"); - } - } - match it.node { - ast::ItemFn(_, Unsafe, _, _, _) => - cx.span_lint(UNSAFE_CODE, it.span, "declaration of an `unsafe` function"), + ast::ItemTrait(ast::Unsafety::Unsafe, _, _, _) => + cx.span_lint(UNSAFE_CODE, it.span, "declaration of an `unsafe` trait"), - ast::ItemTrait(trait_safety, _, _, ref items) => { - if trait_safety == Unsafe { - cx.span_lint(UNSAFE_CODE, it.span, "declaration of an `unsafe` trait"); - } + ast::ItemImpl(ast::Unsafety::Unsafe, _, _, _, _, _) => + cx.span_lint(UNSAFE_CODE, it.span, "implementation of an `unsafe` trait"), - for it in items { - match *it { - ast::RequiredMethod(ast::TypeMethod { unsafety: Unsafe, span, ..}) => - cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` method"), - ast::ProvidedMethod(ref meth) => check_method(cx, meth), - _ => (), - } - } - }, + _ => return, + } + } - ast::ItemImpl(impl_safety, _, _, _, _, ref impls) => { - if impl_safety == Unsafe { - cx.span_lint(UNSAFE_CODE, it.span, "implementation of an `unsafe` trait"); - } + fn check_fn(&mut self, cx: &Context, fk: visit::FnKind, _: &ast::FnDecl, + _: &ast::Block, span: Span, _: ast::NodeId) { + match fk { + visit::FkItemFn(_, _, ast::Unsafety::Unsafe, _) => + cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` function"), - for item in impls { - if let ast::ImplItem::MethodImplItem(ref meth) = *item { - check_method(cx, meth); - } + visit::FkMethod(_, _, m) => { + if let ast::Method_::MethDecl(_, _, _, _, ast::Unsafety::Unsafe, _, _, _) = m.node { + cx.span_lint(UNSAFE_CODE, m.span, "implementation of an `unsafe` method") } }, - _ => return, + _ => (), + } + } + + fn check_ty_method(&mut self, cx: &Context, ty_method: &ast::TypeMethod) { + if let ast::TypeMethod { unsafety: ast::Unsafety::Unsafe, span, ..} = *ty_method { + cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` method") } } } @@ -1577,6 +1567,14 @@ impl LintPass for MissingDoc { tm.span, "a type method"); } + fn check_trait_method(&mut self, cx: &Context, it: &ast::TraitItem) { + if let ast::TraitItem::TypeTraitItem(ref ty) = *it { + let assoc_ty = &ty.ty_param; + self.check_missing_docs_attrs(cx, Some(assoc_ty.id), &ty.attrs, + assoc_ty.span, "an associated type"); + } + } + fn check_struct_field(&mut self, cx: &Context, sf: &ast::StructField) { if let ast::NamedField(_, vis) = sf.node.kind { if vis == ast::Public || self.in_variant { @@ -1848,7 +1846,7 @@ impl LintPass for UnconditionalRecursion { continue } visited.insert(cfg_id); - let node_id = cfg.graph.node_data(idx).id; + let node_id = cfg.graph.node_data(idx).id(); // is this a recursive call? if node_id != ast::DUMMY_NODE_ID && checker(cx.tcx, impl_node_id, id, name, node_id) { | 
