+use crate::utils::sugg::Sugg;
use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
/// let point = Point(30, 20);
/// let x = (&point).0;
/// ```
+ /// Use instead:
+ /// ```rust
+ /// # struct Point(u32, u32);
+ /// # let point = Point(30, 20);
+ /// let x = point.0;
+ /// ```
pub REF_IN_DEREF,
complexity,
"Use of reference in auto dereference expression."
if let ExprKind::Paren(ref parened) = object.kind;
if let ExprKind::AddrOf(_, _, ref inner) = parened.kind;
then {
- let mut applicability = Applicability::MachineApplicable;
+ let applicability = if inner.span.from_expansion() {
+ Applicability::MaybeIncorrect
+ } else {
+ Applicability::MachineApplicable
+ };
+ let sugg = Sugg::ast(cx, inner, "_").maybe_par();
span_lint_and_sugg(
cx,
REF_IN_DEREF,
object.span,
"creating a reference that is immediately dereferenced",
"try this",
- snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
+ sugg.to_string(),
applicability,
);
}