use rustc_middle::ty::subst::{GenericArgKind, Subst};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::lint::FutureIncompatibleInfo;
+use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use crate::nonstandard_style::{method_context, MethodLateContext};
-use log::{debug, trace};
use std::fmt::Write;
+use tracing::{debug, trace};
// hardwired lints from librustc_middle
pub use rustc_session::lint::builtin::*;
impl EarlyLintPass for UnsafeCode {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
- if attr.check_name(sym::allow_internal_unsafe) {
+ if cx.sess().check_name(attr, sym::allow_internal_unsafe) {
self.report_unsafe(cx, attr.span, |lint| {
lint.build(
"`allow_internal_unsafe` allows defining \
impl_lint_pass!(MissingDoc => [MISSING_DOCS]);
-fn has_doc(attr: &ast::Attribute) -> bool {
+fn has_doc(sess: &Session, attr: &ast::Attribute) -> bool {
if attr.is_doc_comment() {
return true;
}
- if !attr.check_name(sym::doc) {
+ if !sess.check_name(attr, sym::doc) {
return false;
}
}
}
- let has_doc = attrs.iter().any(|a| has_doc(a));
+ let has_doc = attrs.iter().any(|a| has_doc(cx.sess(), a));
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
}
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
- fn enter_lint_attrs(&mut self, _: &LateContext<'_>, attrs: &[ast::Attribute]) {
+ fn enter_lint_attrs(&mut self, cx: &LateContext<'_>, attrs: &[ast::Attribute]) {
let doc_hidden = self.doc_hidden()
|| attrs.iter().any(|attr| {
- attr.check_name(sym::doc)
+ cx.sess().check_name(attr, sym::doc)
&& match attr.meta_item_list() {
None => false,
Some(l) => attr::list_contains_name(&l, sym::hidden),
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate");
for macro_def in krate.exported_macros {
- let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
+ let has_doc = macro_def.attrs.iter().any(|a| has_doc(cx.sess(), a));
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(def_id) = real_trait.as_local() {
- let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
+ let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in items {
cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(def_id) = ty_def.did.as_local() {
- impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
+ impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id));
}
}
});
return;
}
}
- if attr.check_name(sym::no_start) || attr.check_name(sym::crate_id) {
+ if cx.sess().check_name(attr, sym::no_start) || cx.sess().check_name(attr, sym::crate_id) {
let path_str = pprust::path_to_string(&attr.get_normal_item().path);
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
lint_deprecated_attr(cx, attr, &msg, None);
let span = sugared_span.take().unwrap_or_else(|| attr.span);
- if attr.is_doc_comment() || attr.check_name(sym::doc) {
+ if attr.is_doc_comment() || cx.sess().check_name(attr, sym::doc) {
cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, |lint| {
let mut err = lint.build("unused doc comment");
err.span_label(
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Fn(.., ref generics, _) => {
- if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
+ if let Some(no_mangle_attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
for param in generics.params {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
}
}
hir::ItemKind::Const(..) => {
- if attr::contains_name(&it.attrs, sym::no_mangle) {
+ if cx.sess().contains_name(&it.attrs, sym::no_mangle) {
// Const items do not refer to a particular location in memory, and therefore
// don't have anything to attach a symbol to
cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, |lint| {
);
impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
- fn check_attribute(&mut self, ctx: &LateContext<'_>, attr: &ast::Attribute) {
- if attr.check_name(sym::feature) {
+ fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
+ if cx.sess().check_name(attr, sym::feature) {
if let Some(items) = attr.meta_item_list() {
for item in items {
- ctx.struct_span_lint(UNSTABLE_FEATURES, item.span(), |lint| {
+ cx.struct_span_lint(UNSTABLE_FEATURES, item.span(), |lint| {
lint.build("unstable feature").emit()
});
}
return;
}
- if let Some(attr) = attr::find_by_name(&it.attrs, sym::rustc_test_marker) {
+ if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::rustc_test_marker) {
cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| {
lint.build("cannot test inner items").emit()
});
overridden_link_name,
tcx.get_attrs(did.to_def_id())
.iter()
- .find(|at| at.check_name(sym::link_name))
+ .find(|at| tcx.sess.check_name(at, sym::link_name))
.unwrap()
.span,
)