use rustc_parse::parser::ForceCollect;
use rustc_session::parse::ParseSess;
use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::def_id::LocalDefId;
use rustc_span::edition::Edition;
use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span};
use rustc_span::{sym, FileName, Pos};
use url::Url;
declare_clippy_lint! {
- /// **What it does:** Checks for the presence of `_`, `::` or camel-case words
+ /// ### What it does
+ /// Checks for the presence of `_`, `::` or camel-case words
/// outside ticks in documentation.
///
- /// **Why is this bad?** *Rustdoc* supports markdown formatting, `_`, `::` and
+ /// ### Why is this bad?
+ /// *Rustdoc* supports markdown formatting, `_`, `::` and
/// camel-case probably indicates some code which should be included between
/// ticks. `_` can also be used for emphasis in markdown, this lint tries to
/// consider that.
///
- /// **Known problems:** Lots of bad docs won’t be fixed, what the lint checks
+ /// ### Known problems
+ /// Lots of bad docs won’t be fixed, what the lint checks
/// for is limited, and there are still false positives. HTML elements and their
/// content are not linted.
///
/// `[`SmallVec<[T; INLINE_CAPACITY]>`]` and then [`SmallVec<[T; INLINE_CAPACITY]>`]: SmallVec
/// would fail.
///
- /// **Examples:**
+ /// ### Examples
/// ```rust
/// /// Do something with the foo_bar parameter. See also
/// /// that::other::module::foo.
}
declare_clippy_lint! {
- /// **What it does:** Checks for the doc comments of publicly visible
+ /// ### What it does
+ /// Checks for the doc comments of publicly visible
/// unsafe functions and warns if there is no `# Safety` section.
///
- /// **Why is this bad?** Unsafe functions should document their safety
+ /// ### Why is this bad?
+ /// Unsafe functions should document their safety
/// preconditions, so that users can be sure they are using them safely.
///
- /// **Known problems:** None.
- ///
- /// **Examples:**
+ /// ### Examples
/// ```rust
///# type Universe = ();
/// /// This function should really be documented
}
declare_clippy_lint! {
- /// **What it does:** Checks the doc comments of publicly visible functions that
+ /// ### What it does
+ /// Checks the doc comments of publicly visible functions that
/// return a `Result` type and warns if there is no `# Errors` section.
///
- /// **Why is this bad?** Documenting the type of errors that can be returned from a
+ /// ### Why is this bad?
+ /// Documenting the type of errors that can be returned from a
/// function can help callers write code to handle the errors appropriately.
///
- /// **Known problems:** None.
- ///
- /// **Examples:**
- ///
+ /// ### Examples
/// Since the following function returns a `Result` it has an `# Errors` section in
/// its doc comment:
///
}
declare_clippy_lint! {
- /// **What it does:** Checks the doc comments of publicly visible functions that
+ /// ### What it does
+ /// Checks the doc comments of publicly visible functions that
/// may panic and warns if there is no `# Panics` section.
///
- /// **Why is this bad?** Documenting the scenarios in which panicking occurs
+ /// ### Why is this bad?
+ /// Documenting the scenarios in which panicking occurs
/// can help callers who do not want to panic to avoid those situations.
///
- /// **Known problems:** None.
- ///
- /// **Examples:**
- ///
+ /// ### Examples
/// Since the following function may panic it has a `# Panics` section in
/// its doc comment:
///
}
declare_clippy_lint! {
- /// **What it does:** Checks for `fn main() { .. }` in doctests
+ /// ### What it does
+ /// Checks for `fn main() { .. }` in doctests
///
- /// **Why is this bad?** The test can be shorter (and likely more readable)
+ /// ### Why is this bad?
+ /// The test can be shorter (and likely more readable)
/// if the `fn main()` is left implicit.
///
- /// **Known problems:** None.
- ///
- /// **Examples:**
+ /// ### Examples
/// ``````rust
/// /// An example of a doctest with a `main()` function
/// ///
panic_span: None,
};
fpu.visit_expr(&body.value);
- lint_for_missing_headers(
- cx,
- item.hir_id(),
- item.span,
- sig,
- headers,
- Some(body_id),
- fpu.panic_span,
- );
+ lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
}
},
hir::ItemKind::Impl(ref impl_) => {
let headers = check_attrs(cx, &self.valid_idents, attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) {
- lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);
+ lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None);
}
}
}
panic_span: None,
};
fpu.visit_expr(&body.value);
- lint_for_missing_headers(
- cx,
- item.hir_id(),
- item.span,
- sig,
- headers,
- Some(body_id),
- fpu.panic_span,
- );
+ lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
}
}
}
fn lint_for_missing_headers<'tcx>(
cx: &LateContext<'tcx>,
- hir_id: hir::HirId,
+ def_id: LocalDefId,
span: impl Into<MultiSpan> + Copy,
sig: &hir::FnSig<'_>,
headers: DocHeaders,
body_id: Option<hir::BodyId>,
panic_span: Option<Span>,
) {
- if !cx.access_levels.is_exported(hir_id) {
+ if !cx.access_levels.is_exported(def_id) {
return; // Private functions do not require doc comments
}
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
);
}
if !headers.errors {
+ let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) {
span_lint(
cx,
let filename = FileName::anon_source_code(&code);
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
- let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
- let handler = Handler::with_emitter(false, None, box emitter);
+ let emitter = EmitterWriter::new(Box::new(io::sink()), None, false, false, false, None, false);
+ let handler = Handler::with_emitter(false, None, Box::new(emitter));
let sess = ParseSess::with_span_handler(handler, sm);
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {