use rustc_typeck::hir_ty_to_ty;
use syntax_pos::{InnerSpan, Span, DUMMY_SP};
-use crate::utils::{in_constant, in_macro_or_desugar, is_copy, span_lint_and_then};
+use crate::utils::{in_constant, is_copy, qpath_res, span_lint_and_then};
declare_clippy_lint! {
/// **What it does:** Checks for declaration of `const` items which is interior
"referencing const with interior mutability"
}
+#[allow(dead_code)]
#[derive(Copy, Clone)]
enum Source {
Item { item: Span },
impl Source {
fn lint(&self) -> (&'static Lint, &'static str, Span) {
match self {
- Source::Item { item } | Source::Assoc { item, .. } => (
+ Self::Item { item } | Self::Assoc { item, .. } => (
DECLARE_INTERIOR_MUTABLE_CONST,
"a const item should never be interior mutable",
*item,
),
- Source::Expr { expr } => (
+ Self::Expr { expr } => (
BORROW_INTERIOR_MUTABLE_CONST,
"a const item with interior mutability should not be borrowed",
*expr,
let (lint, msg, span) = source.lint();
span_lint_and_then(cx, lint, span, msg, |db| {
- if in_macro_or_desugar(span) {
+ if span.from_expansion() {
return; // Don't give suggestions into macros.
}
match source {
}
// Make sure it is a const item.
- match cx.tables.qpath_res(qpath, expr.hir_id) {
+ match qpath_res(cx, qpath, expr.hir_id) {
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {},
_ => return,
};
if parent_id == cur_expr.hir_id {
break;
}
- if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find_by_hir_id(parent_id) {
+ if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find(parent_id) {
match &parent_expr.node {
ExprKind::AddrOf(..) => {
// `&e` => `e` must be referenced.