Tweak borrow suggestion

This commit is contained in:
Michael Goulet 2023-04-18 19:44:27 +00:00
parent ad6b20bf52
commit a9051d861c
26 changed files with 288 additions and 211 deletions

View File

@ -1334,52 +1334,55 @@ pub fn check_ref(
));
}
if let Ok(src) = sm.span_to_snippet(sugg_sp) {
let needs_parens = match expr.kind {
// parenthesize if needed (Issue #46756)
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
// parenthesize borrows of range literals (Issue #54505)
_ if is_range_literal(expr) => true,
_ => false,
};
let needs_parens = match expr.kind {
// parenthesize if needed (Issue #46756)
hir::ExprKind::Cast(_, _) | hir::ExprKind::Binary(_, _, _) => true,
// parenthesize borrows of range literals (Issue #54505)
_ if is_range_literal(expr) => true,
_ => false,
};
if let Some(sugg) = self.can_use_as_ref(expr) {
return Some((
sugg.0,
sugg.1.to_string(),
sugg.2,
Applicability::MachineApplicable,
false,
false,
));
}
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};
if let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Assign(..),
..
})) = self.tcx.hir().find_parent(expr.hir_id)
{
if mutability.is_mut() {
// Suppressing this diagnostic, we'll properly print it in `check_expr_assign`
return None;
}
}
let sugg_expr = if needs_parens { format!("({src})") } else { src };
if let Some(sugg) = self.can_use_as_ref(expr) {
return Some((
sp,
format!("consider {}borrowing here", mutability.mutably_str()),
format!("{prefix}{}{sugg_expr}", mutability.ref_prefix_str()),
sugg.0,
sugg.1.to_string(),
sugg.2,
Applicability::MachineApplicable,
false,
false,
));
}
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};
if let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Assign(..),
..
})) = self.tcx.hir().find_parent(expr.hir_id)
{
if mutability.is_mut() {
// Suppressing this diagnostic, we'll properly print it in `check_expr_assign`
return None;
}
}
let (sp, sugg_expr, verbose) = if needs_parens {
let src = sm.span_to_snippet(sugg_sp).ok()?;
(sp, format!("({src})"), false)
} else {
(sp.shrink_to_lo(), "".to_string(), true)
};
return Some((
sp,
format!("consider {}borrowing here", mutability.mutably_str()),
format!("{prefix}{}{sugg_expr}", mutability.ref_prefix_str()),
Applicability::MachineApplicable,
verbose,
false,
));
}
}
(

View File

@ -16,7 +16,7 @@ LL | fn foo(a: &A, d: D, e: &E, g: G) {}
help: consider borrowing here
|
LL | foo(&&A, B, C, D, &E, F, G);
| ~~
| +
help: remove the extra arguments
|
LL - foo(&&A, B, C, D, E, F, G);

View File

@ -2,14 +2,16 @@ error[E0308]: mismatched types
--> $DIR/issue-102206.rs:6:27
|
LL | std::mem::size_of_val(foo());
| --------------------- ^^^^^
| | |
| | expected `&_`, found future
| | help: consider borrowing here: `&foo()`
| --------------------- ^^^^^ expected `&_`, found future
| |
| arguments to this function are incorrect
|
note: function defined here
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
help: consider borrowing here
|
LL | std::mem::size_of_val(&foo());
| +
error: aborting due to previous error

View File

@ -2,11 +2,14 @@ error[E0308]: mismatched types
--> $DIR/coercion-slice.rs:4:21
|
LL | let _: &[i32] = [0];
| ------ ^^^
| | |
| | expected `&[i32]`, found `[{integer}; 1]`
| | help: consider borrowing here: `&[0]`
| ------ ^^^ expected `&[i32]`, found `[{integer}; 1]`
| |
| expected due to this
|
help: consider borrowing here
|
LL | let _: &[i32] = &[0];
| +
error: aborting due to previous error

View File

@ -98,19 +98,23 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:40:17
|
LL | let s = S { u };
| ^
| |
| expected `&u32`, found integer
| help: consider borrowing here: `u: &u`
| ^ expected `&u32`, found integer
|
help: consider borrowing here
|
LL | let s = S { u: &u };
| ++++
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:42:20
|
LL | let s = S { u: u };
| ^
| |
| expected `&u32`, found integer
| help: consider borrowing here: `&u`
| ^ expected `&u32`, found integer
|
help: consider borrowing here
|
LL | let s = S { u: &u };
| +
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:45:17

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/issue-11374.rs:26:15
|
LL | c.read_to(v);
| ------- ^
| | |
| | expected `&mut [u8]`, found `Vec<_>`
| | help: consider mutably borrowing here: `&mut v`
| ------- ^ expected `&mut [u8]`, found `Vec<_>`
| |
| arguments to this method are incorrect
|
= note: expected mutable reference `&mut [u8]`
@ -15,6 +13,10 @@ note: method defined here
|
LL | pub fn read_to(&mut self, vec: &mut [u8]) {
| ^^^^^^^ --------------
help: consider mutably borrowing here
|
LL | c.read_to(&mut v);
| ++++
error: aborting due to previous error

View File

@ -2,11 +2,14 @@ error[E0308]: mismatched types
--> $DIR/issue-17033.rs:2:10
|
LL | (*p)(())
| ---- ^^
| | |
| | expected `&mut ()`, found `()`
| | help: consider mutably borrowing here: `&mut ()`
| ---- ^^ expected `&mut ()`, found `()`
| |
| arguments to this function are incorrect
|
help: consider mutably borrowing here
|
LL | (*p)(&mut ())
| ++++
error: aborting due to previous error

View File

@ -19,7 +19,7 @@ LL | fn print_x(_: &dyn Foo<Item=bool>, extra: &str) {
help: consider borrowing here
|
LL | print_x(&X);
| ~~
| +
help: provide the argument
|
LL | print_x(/* &dyn Foo<Item = bool> */, /* &str */);

View File

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/issue-46302.rs:3:27
|
LL | let u: &str = if true { s[..2] } else { s };
| ^^^^^^
| |
| expected `&str`, found `str`
| help: consider borrowing here: `&s[..2]`
| ^^^^^^ expected `&str`, found `str`
|
help: consider borrowing here
|
LL | let u: &str = if true { &s[..2] } else { s };
| +
error: aborting due to previous error

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/issue-61106.rs:3:9
|
LL | foo(x.clone());
| --- ^^^^^^^^^
| | |
| | expected `&str`, found `String`
| | help: consider borrowing here: `&x`
| --- ^^^^^^^^^ expected `&str`, found `String`
| |
| arguments to this function are incorrect
|
note: function defined here
@ -13,6 +11,10 @@ note: function defined here
|
LL | fn foo(_: &str) {}
| ^^^ -------
help: consider borrowing here
|
LL | foo(&x.clone());
| +
error: aborting due to previous error

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/method-self-arg-1.rs:11:14
|
LL | Foo::bar(x);
| -------- ^
| | |
| | expected `&Foo`, found `Foo`
| | help: consider borrowing here: `&x`
| -------- ^ expected `&Foo`, found `Foo`
| |
| arguments to this function are incorrect
|
note: method defined here
@ -13,6 +11,10 @@ note: method defined here
|
LL | fn bar(&self) {}
| ^^^ -----
help: consider borrowing here
|
LL | Foo::bar(&x);
| +
error[E0308]: mismatched types
--> $DIR/method-self-arg-1.rs:13:14

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/dont-point-return-on-E0308.rs:11:11
|
LL | f(());
| - ^^
| | |
| | expected `&()`, found `()`
| | help: consider borrowing here: `&()`
| - ^^ expected `&()`, found `()`
| |
| arguments to this function are incorrect
|
note: function defined here
@ -13,6 +11,10 @@ note: function defined here
|
LL | async fn f(_: &()) {}
| ^ ------
help: consider borrowing here
|
LL | f(&());
| +
error: aborting due to previous error

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/mut-cross-borrowing.rs:7:7
|
LL | f(x)
| - ^
| | |
| | expected `&mut isize`, found `Box<{integer}>`
| | help: consider mutably borrowing here: `&mut x`
| - ^ expected `&mut isize`, found `Box<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected mutable reference `&mut isize`
@ -15,6 +13,10 @@ note: function defined here
|
LL | fn f(_: &mut isize) {}
| ^ -------------
help: consider mutably borrowing here
|
LL | f(&mut x)
| ++++
error: aborting due to previous error

View File

@ -16,60 +16,60 @@ fn main() {
take_range(&std::ops::Range { start: 0, end: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::Range { start: 0, end: 1 }
//~| SUGGESTION &
take_range(&::std::ops::Range { start: 0, end: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::Range { start: 0, end: 1 }
//~| SUGGESTION &
take_range(&std::ops::RangeFrom { start: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeFrom { start: 1 }
//~| SUGGESTION &
take_range(&::std::ops::RangeFrom { start: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeFrom { start: 1 }
//~| SUGGESTION &
take_range(&std::ops::RangeFull {});
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeFull {}
//~| SUGGESTION &
take_range(&::std::ops::RangeFull {});
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeFull {}
//~| SUGGESTION &
take_range(&std::ops::RangeInclusive::new(0, 1));
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeInclusive::new(0, 1)
//~| SUGGESTION &
take_range(&::std::ops::RangeInclusive::new(0, 1));
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeInclusive::new(0, 1)
//~| SUGGESTION &
take_range(&std::ops::RangeTo { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeTo { end: 5 }
//~| SUGGESTION &
take_range(&::std::ops::RangeTo { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeTo { end: 5 }
//~| SUGGESTION &
take_range(&std::ops::RangeToInclusive { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeToInclusive { end: 5 }
//~| SUGGESTION &
take_range(&::std::ops::RangeToInclusive { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeToInclusive { end: 5 }
//~| SUGGESTION &
}

View File

@ -16,60 +16,60 @@ fn main() {
take_range(std::ops::Range { start: 0, end: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::Range { start: 0, end: 1 }
//~| SUGGESTION &
take_range(::std::ops::Range { start: 0, end: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::Range { start: 0, end: 1 }
//~| SUGGESTION &
take_range(std::ops::RangeFrom { start: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeFrom { start: 1 }
//~| SUGGESTION &
take_range(::std::ops::RangeFrom { start: 1 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeFrom { start: 1 }
//~| SUGGESTION &
take_range(std::ops::RangeFull {});
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeFull {}
//~| SUGGESTION &
take_range(::std::ops::RangeFull {});
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeFull {}
//~| SUGGESTION &
take_range(std::ops::RangeInclusive::new(0, 1));
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeInclusive::new(0, 1)
//~| SUGGESTION &
take_range(::std::ops::RangeInclusive::new(0, 1));
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeInclusive::new(0, 1)
//~| SUGGESTION &
take_range(std::ops::RangeTo { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeTo { end: 5 }
//~| SUGGESTION &
take_range(::std::ops::RangeTo { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeTo { end: 5 }
//~| SUGGESTION &
take_range(std::ops::RangeToInclusive { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &std::ops::RangeToInclusive { end: 5 }
//~| SUGGESTION &
take_range(::std::ops::RangeToInclusive { end: 5 });
//~^ ERROR mismatched types [E0308]
//~| HELP consider borrowing here
//~| SUGGESTION &::std::ops::RangeToInclusive { end: 5 }
//~| SUGGESTION &
}

View File

@ -2,10 +2,8 @@ error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:16:16
|
LL | take_range(std::ops::Range { start: 0, end: 1 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `Range<{integer}>`
| | help: consider borrowing here: `&std::ops::Range { start: 0, end: 1 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `Range<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -15,15 +13,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::Range { start: 0, end: 1 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:21:16
|
LL | take_range(::std::ops::Range { start: 0, end: 1 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `Range<{integer}>`
| | help: consider borrowing here: `&::std::ops::Range { start: 0, end: 1 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `Range<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -33,15 +33,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::Range { start: 0, end: 1 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:26:16
|
LL | take_range(std::ops::RangeFrom { start: 1 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeFrom<{integer}>`
| | help: consider borrowing here: `&std::ops::RangeFrom { start: 1 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeFrom<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -51,15 +53,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::RangeFrom { start: 1 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:31:16
|
LL | take_range(::std::ops::RangeFrom { start: 1 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeFrom<{integer}>`
| | help: consider borrowing here: `&::std::ops::RangeFrom { start: 1 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeFrom<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -69,15 +73,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::RangeFrom { start: 1 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:36:16
|
LL | take_range(std::ops::RangeFull {});
| ---------- ^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeFull`
| | help: consider borrowing here: `&std::ops::RangeFull {}`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeFull`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -87,15 +93,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::RangeFull {});
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:41:16
|
LL | take_range(::std::ops::RangeFull {});
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeFull`
| | help: consider borrowing here: `&::std::ops::RangeFull {}`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeFull`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -105,15 +113,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::RangeFull {});
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:46:16
|
LL | take_range(std::ops::RangeInclusive::new(0, 1));
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeInclusive<{integer}>`
| | help: consider borrowing here: `&std::ops::RangeInclusive::new(0, 1)`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeInclusive<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -123,15 +133,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::RangeInclusive::new(0, 1));
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:51:16
|
LL | take_range(::std::ops::RangeInclusive::new(0, 1));
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeInclusive<{integer}>`
| | help: consider borrowing here: `&::std::ops::RangeInclusive::new(0, 1)`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeInclusive<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -141,15 +153,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::RangeInclusive::new(0, 1));
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:56:16
|
LL | take_range(std::ops::RangeTo { end: 5 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeTo<{integer}>`
| | help: consider borrowing here: `&std::ops::RangeTo { end: 5 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeTo<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -159,15 +173,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::RangeTo { end: 5 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:61:16
|
LL | take_range(::std::ops::RangeTo { end: 5 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeTo<{integer}>`
| | help: consider borrowing here: `&::std::ops::RangeTo { end: 5 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeTo<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -177,15 +193,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::RangeTo { end: 5 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:66:16
|
LL | take_range(std::ops::RangeToInclusive { end: 5 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeToInclusive<{integer}>`
| | help: consider borrowing here: `&std::ops::RangeToInclusive { end: 5 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeToInclusive<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -195,15 +213,17 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&std::ops::RangeToInclusive { end: 5 });
| +
error[E0308]: mismatched types
--> $DIR/issue-54505-no-literals.rs:71:16
|
LL | take_range(::std::ops::RangeToInclusive { end: 5 });
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `&_`, found `RangeToInclusive<{integer}>`
| | help: consider borrowing here: `&::std::ops::RangeToInclusive { end: 5 }`
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `RangeToInclusive<{integer}>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -213,6 +233,10 @@ note: function defined here
|
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ -------------------------
help: consider borrowing here
|
LL | take_range(&::std::ops::RangeToInclusive { end: 5 });
| +
error: aborting due to 12 previous errors

View File

@ -10,11 +10,14 @@ error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:9:19
|
LL | let x: &str = String::new();
| ---- ^^^^^^^^^^^^^
| | |
| | expected `&str`, found `String`
| | help: consider borrowing here: `&String::new()`
| ---- ^^^^^^^^^^^^^ expected `&str`, found `String`
| |
| expected due to this
|
help: consider borrowing here
|
LL | let x: &str = &String::new();
| +
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:12:10

View File

@ -78,10 +78,12 @@ error[E0308]: mismatched types
--> $DIR/issue-39018.rs:29:17
|
LL | let _ = a + b;
| ^
| |
| expected `&str`, found `String`
| help: consider borrowing here: `&b`
| ^ expected `&str`, found `String`
|
help: consider borrowing here
|
LL | let _ = a + &b;
| +
error[E0369]: cannot add `String` to `&String`
--> $DIR/issue-39018.rs:30:15

View File

@ -10,10 +10,12 @@ error[E0308]: mismatched types
--> $DIR/str-array-assignment.rs:5:27
|
LL | let u: &str = if true { s[..2] } else { s };
| ^^^^^^
| |
| expected `&str`, found `str`
| help: consider borrowing here: `&s[..2]`
| ^^^^^^ expected `&str`, found `str`
|
help: consider borrowing here
|
LL | let u: &str = if true { &s[..2] } else { s };
| +
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/str-array-assignment.rs:7:7
@ -33,11 +35,14 @@ error[E0308]: mismatched types
--> $DIR/str-array-assignment.rs:9:17
|
LL | let w: &str = s[..2];
| ---- ^^^^^^
| | |
| | expected `&str`, found `str`
| | help: consider borrowing here: `&s[..2]`
| ---- ^^^^^^ expected `&str`, found `str`
| |
| expected due to this
|
help: consider borrowing here
|
LL | let w: &str = &s[..2];
| +
error: aborting due to 4 previous errors

View File

@ -14,7 +14,7 @@ macro_rules! bla {
() => {
x(123);
//~^ ERROR mismatched types
//~| SUGGESTION &mut 123
//~| SUGGESTION &mut
};
($v:expr) => {
x($v)
@ -25,5 +25,5 @@ fn main() {
bla!();
bla!(456);
//~^ ERROR mismatched types
//~| SUGGESTION &mut 456
//~| SUGGESTION &mut
}

View File

@ -18,10 +18,8 @@ error[E0308]: mismatched types
--> $DIR/suggest-ref-macro.rs:15:11
|
LL | x(123);
| - ^^^
| | |
| | expected `&mut i32`, found integer
| | help: consider mutably borrowing here: `&mut 123`
| - ^^^ expected `&mut i32`, found integer
| |
| arguments to this function are incorrect
...
LL | bla!();
@ -33,6 +31,10 @@ note: function defined here
LL | fn x(_: &mut i32) {}
| ^ -----------
= note: this error originates in the macro `bla` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider mutably borrowing here
|
LL | x(&mut 123);
| ++++
error[E0308]: mismatched types
--> $DIR/suggest-ref-macro.rs:26:10
@ -41,16 +43,17 @@ LL | x($v)
| - arguments to this function are incorrect
...
LL | bla!(456);
| ^^^
| |
| expected `&mut i32`, found integer
| help: consider mutably borrowing here: `&mut 456`
| ^^^ expected `&mut i32`, found integer
|
note: function defined here
--> $DIR/suggest-ref-macro.rs:11:4
|
LL | fn x(_: &mut i32) {}
| ^ -----------
help: consider mutably borrowing here
|
LL | bla!(&mut 456);
| ++++
error: aborting due to 3 previous errors

View File

@ -378,10 +378,8 @@ error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:47:23
|
LL | want::<&Foo<foo>>(f);
| ----------------- ^
| | |
| | expected `&Foo<foo>`, found `Foo<foo>`
| | help: consider borrowing here: `&f`
| ----------------- ^ expected `&Foo<foo>`, found `Foo<foo>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&Foo<foo>`
@ -391,6 +389,10 @@ note: function defined here
|
LL | fn want<T>(t: T) {}
| ^^^^ ----
help: consider borrowing here
|
LL | want::<&Foo<foo>>(&f);
| +
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:48:26
@ -556,10 +558,8 @@ error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:61:26
|
LL | want::<&Foo<foo, B>>(f);
| -------------------- ^
| | |
| | expected `&Foo<foo, B>`, found `Foo<foo, B>`
| | help: consider borrowing here: `&f`
| -------------------- ^ expected `&Foo<foo, B>`, found `Foo<foo, B>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&Foo<foo, B>`
@ -569,6 +569,10 @@ note: function defined here
|
LL | fn want<T>(t: T) {}
| ^^^^ ----
help: consider borrowing here
|
LL | want::<&Foo<foo, B>>(&f);
| +
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:65:19

View File

@ -42,13 +42,14 @@ error[E0308]: mismatched types
LL | fn index<'a, K, V>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| - this type parameter
LL | map[k]
| ^
| |
| expected `&K`, found type parameter `K`
| help: consider borrowing here: `&k`
| ^ expected `&K`, found type parameter `K`
|
= note: expected reference `&K`
found type parameter `K`
help: consider borrowing here
|
LL | map[&k]
| +
error[E0308]: mismatched types
--> $DIR/bad-index-due-to-nested.rs:20:5
@ -56,13 +57,14 @@ error[E0308]: mismatched types
LL | fn index<'a, K, V>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| - this type parameter ----- expected `&'a V` because of return type
LL | map[k]
| ^^^^^^
| |
| expected `&V`, found type parameter `V`
| help: consider borrowing here: `&map[k]`
| ^^^^^^ expected `&V`, found type parameter `V`
|
= note: expected reference `&'a V`
found type parameter `V`
help: consider borrowing here
|
LL | &map[k]
| +
error: aborting due to 4 previous errors

View File

@ -2,16 +2,18 @@ error[E0308]: mismatched types
--> $DIR/bad-type-in-vec-contains.rs:5:21
|
LL | primes.contains(3);
| -------- ^
| | |
| | expected `&_`, found integer
| | help: consider borrowing here: `&3`
| -------- ^ expected `&_`, found integer
| |
| arguments to this method are incorrect
|
= note: expected reference `&_`
found type `{integer}`
note: method defined here
--> $SRC_DIR/core/src/slice/mod.rs:LL:COL
help: consider borrowing here
|
LL | primes.contains(&3);
| +
error: aborting due to previous error

View File

@ -20,10 +20,8 @@ error[E0308]: mismatched types
--> $DIR/issue-13853.rs:37:13
|
LL | iterate(graph);
| ------- ^^^^^
| | |
| | expected `&_`, found `Vec<Stuff>`
| | help: consider borrowing here: `&graph`
| ------- ^^^^^ expected `&_`, found `Vec<Stuff>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&_`
@ -33,6 +31,10 @@ note: function defined here
|
LL | fn iterate<N: Node, G: Graph<N>>(graph: &G) {
| ^^^^^^^ ---------
help: consider borrowing here
|
LL | iterate(&graph);
| +
error: aborting due to 3 previous errors

View File

@ -16,11 +16,14 @@ error[E0308]: mismatched types
--> $DIR/suggest-borrow.rs:3:20
|
LL | let x: &[u8] = vec!(1, 2, 3)[..];
| ----- ^^^^^^^^^^^^^^^^^
| | |
| | expected `&[u8]`, found `[{integer}]`
| | help: consider borrowing here: `&vec!(1, 2, 3)[..]`
| ----- ^^^^^^^^^^^^^^^^^ expected `&[u8]`, found `[{integer}]`
| |
| expected due to this
|
help: consider borrowing here
|
LL | let x: &[u8] = &vec!(1, 2, 3)[..];
| +
error[E0308]: mismatched types
--> $DIR/suggest-borrow.rs:4:19