From 494dd0b71936813e3a5565d5ea88c6fdf07240e3 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 22 Feb 2020 08:28:56 -0800 Subject: [PATCH] Remove trait --- src/librustc_lint/builtin.rs | 69 +++++++++++++----------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 705097d4644..54b5b922ac7 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -738,52 +738,33 @@ fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) { } } -trait UnusedDocCommentExt { - fn warn_if_doc( - &self, - cx: &EarlyContext<'_>, - node_span: Span, - node_kind: &str, - attrs: &[ast::Attribute], - ); -} +fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &[ast::Attribute]) { + let mut attrs = attrs.into_iter().peekable(); -impl UnusedDocCommentExt for UnusedDocComment { - fn warn_if_doc( - &self, - cx: &EarlyContext<'_>, - node_span: Span, - node_kind: &str, - attrs: &[ast::Attribute], - ) { - let mut attrs = attrs.into_iter().peekable(); - - // Accumulate a single span for sugared doc comments. - let mut sugared_span: Option = None; + // Accumulate a single span for sugared doc comments. + let mut sugared_span: Option = None; - while let Some(attr) = attrs.next() { - if attr.is_doc_comment() { - sugared_span = Some( - sugared_span.map_or_else(|| attr.span, |span| span.with_hi(attr.span.hi())), - ); - } + while let Some(attr) = attrs.next() { + if attr.is_doc_comment() { + sugared_span = + Some(sugared_span.map_or_else(|| attr.span, |span| span.with_hi(attr.span.hi()))); + } - if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() { - continue; - } + if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() { + continue; + } - let span = sugared_span.take().unwrap_or_else(|| attr.span); + let span = sugared_span.take().unwrap_or_else(|| attr.span); - if attr.is_doc_comment() || attr.check_name(sym::doc) { - cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, |lint| { - let mut err = lint.build("unused doc comment"); - err.span_label( - node_span, - format!("rustdoc does not generate documentation for {}", node_kind), - ); - err.emit(); - }); - } + if attr.is_doc_comment() || attr.check_name(sym::doc) { + cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, |lint| { + let mut err = lint.build("unused doc comment"); + err.span_label( + node_span, + format!("rustdoc does not generate documentation for {}", node_kind), + ); + err.emit(); + }); } } } @@ -797,16 +778,16 @@ fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) { ast::StmtKind::Semi(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Mac(..) => return, }; - self.warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs()); + warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs()); } fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) { let arm_span = arm.pat.span.with_hi(arm.body.span.hi()); - self.warn_if_doc(cx, arm_span, "match arms", &arm.attrs); + warn_if_doc(cx, arm_span, "match arms", &arm.attrs); } fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - self.warn_if_doc(cx, expr.span, "expressions", &expr.attrs); + warn_if_doc(cx, expr.span, "expressions", &expr.attrs); } } -- 2.44.0