Fix suggestion for removing &mut from &mut macro!().
This commit is contained in:
parent
716394d658
commit
b4524f8bf0
1 changed files with 11 additions and 3 deletions
|
@ -16,6 +16,7 @@ use rustc_span::Span;
|
||||||
use super::method::probe;
|
use super::method::probe;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
pub fn emit_coerce_suggestions(
|
pub fn emit_coerce_suggestions(
|
||||||
|
@ -577,12 +578,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// We have `&T`, check if what was expected was `T`. If so,
|
// We have `&T`, check if what was expected was `T`. If so,
|
||||||
// we may want to suggest removing a `&`.
|
// we may want to suggest removing a `&`.
|
||||||
if sm.is_imported(expr.span) {
|
if sm.is_imported(expr.span) {
|
||||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
// Go through the spans from which this span was expanded,
|
||||||
if let Some(src) = src.strip_prefix('&') {
|
// and find the one that's pointing inside `sp`.
|
||||||
|
//
|
||||||
|
// E.g. for `&format!("")`, where we want the span to the
|
||||||
|
// `format!()` invocation instead of its expansion.
|
||||||
|
if let Some(call_span) =
|
||||||
|
iter::successors(Some(expr.span), |s| s.parent()).find(|&s| sp.contains(s))
|
||||||
|
{
|
||||||
|
if let Ok(code) = sm.span_to_snippet(call_span) {
|
||||||
return Some((
|
return Some((
|
||||||
sp,
|
sp,
|
||||||
"consider removing the borrow",
|
"consider removing the borrow",
|
||||||
src.to_string(),
|
code,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue