Auto merge of #6030 - rail-rain:fix_use_snippet_in_types, r=matthiaskrgr
fix some use of `snippet` in `types.rs` changelog: none
This commit is contained in:
@@ -321,14 +321,15 @@ impl Types {
|
|||||||
if let Some(def_id) = res.opt_def_id() {
|
if let Some(def_id) = res.opt_def_id() {
|
||||||
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
||||||
if let Some(span) = match_borrows_parameter(cx, qpath) {
|
if let Some(span) = match_borrows_parameter(cx, qpath) {
|
||||||
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_ALLOCATION,
|
REDUNDANT_ALLOCATION,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
"usage of `Box<&T>`",
|
"usage of `Box<&T>`",
|
||||||
"try",
|
"try",
|
||||||
snippet(cx, span, "..").to_string(),
|
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
|
||||||
Applicability::MachineApplicable,
|
applicability,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
@@ -345,14 +346,15 @@ impl Types {
|
|||||||
}
|
}
|
||||||
} else if cx.tcx.is_diagnostic_item(sym::Rc, def_id) {
|
} else if cx.tcx.is_diagnostic_item(sym::Rc, def_id) {
|
||||||
if let Some(span) = match_type_parameter(cx, qpath, &paths::RC) {
|
if let Some(span) = match_type_parameter(cx, qpath, &paths::RC) {
|
||||||
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_ALLOCATION,
|
REDUNDANT_ALLOCATION,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
"usage of `Rc<Rc<T>>`",
|
"usage of `Rc<Rc<T>>`",
|
||||||
"try",
|
"try",
|
||||||
snippet(cx, span, "..").to_string(),
|
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
|
||||||
Applicability::MachineApplicable,
|
applicability,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
@@ -368,26 +370,31 @@ impl Types {
|
|||||||
GenericArg::Type(ty) => ty.span,
|
GenericArg::Type(ty) => ty.span,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_ALLOCATION,
|
REDUNDANT_ALLOCATION,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
"usage of `Rc<Box<T>>`",
|
"usage of `Rc<Box<T>>`",
|
||||||
"try",
|
"try",
|
||||||
format!("Rc<{}>", snippet(cx, inner_span, "..")),
|
format!(
|
||||||
Applicability::MachineApplicable,
|
"Rc<{}>",
|
||||||
|
snippet_with_applicability(cx, inner_span, "..", &mut applicability)
|
||||||
|
),
|
||||||
|
applicability,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
if let Some(span) = match_borrows_parameter(cx, qpath) {
|
if let Some(span) = match_borrows_parameter(cx, qpath) {
|
||||||
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
REDUNDANT_ALLOCATION,
|
REDUNDANT_ALLOCATION,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
"usage of `Rc<&T>`",
|
"usage of `Rc<&T>`",
|
||||||
"try",
|
"try",
|
||||||
snippet(cx, span, "..").to_string(),
|
snippet_with_applicability(cx, span, "..", &mut applicability).to_string(),
|
||||||
Applicability::MachineApplicable,
|
applicability,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
@@ -546,7 +553,6 @@ impl Types {
|
|||||||
// details.
|
// details.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
BORROWED_BOX,
|
BORROWED_BOX,
|
||||||
@@ -556,8 +562,12 @@ impl Types {
|
|||||||
format!(
|
format!(
|
||||||
"&{}{}",
|
"&{}{}",
|
||||||
ltopt,
|
ltopt,
|
||||||
&snippet_with_applicability(cx, inner.span, "..", &mut applicability)
|
&snippet(cx, inner.span, "..")
|
||||||
),
|
),
|
||||||
|
// To make this `MachineApplicable`, at least one needs to check if it isn't a trait item
|
||||||
|
// because the trait impls of it will break otherwise;
|
||||||
|
// and there may be other cases that result in invalid code.
|
||||||
|
// For example, type coercion doesn't work nicely.
|
||||||
Applicability::Unspecified,
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
|
|||||||
Reference in New Issue
Block a user