1
Fork 0

Use multispan suggestions more often

* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
This commit is contained in:
Esteban Küber 2021-06-28 11:22:47 -07:00
parent 5fb3394cbd
commit 0b8f192cfe
61 changed files with 661 additions and 442 deletions

View file

@ -444,6 +444,30 @@ impl Diagnostic {
self self
} }
/// Prints out a message with multiple suggested edits of the code.
/// See also [`Diagnostic::span_suggestion()`].
pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability,
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: suggestions
.map(|sugg| Substitution {
parts: sugg
.into_iter()
.map(|(span, snippet)| SubstitutionPart { snippet, span })
.collect(),
})
.collect(),
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
applicability,
tool_metadata: Default::default(),
});
self
}
/// Prints out a message with a suggested edit of the code. If the suggestion is presented /// Prints out a message with a suggested edit of the code. If the suggestion is presented
/// inline, it will only show the message and not the suggestion. /// inline, it will only show the message and not the suggestion.
/// ///

View file

@ -301,6 +301,20 @@ impl<'a> DiagnosticBuilder<'a> {
self self
} }
/// See [`Diagnostic::multipart_suggestions()`].
pub fn multipart_suggestions(
&mut self,
msg: &str,
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
applicability: Applicability,
) -> &mut Self {
if !self.0.allow_suggestions {
return self;
}
self.0.diagnostic.multipart_suggestions(msg, suggestions, applicability);
self
}
/// See [`Diagnostic::span_suggestion_short()`]. /// See [`Diagnostic::span_suggestion_short()`].
pub fn span_suggestion_short( pub fn span_suggestion_short(
&mut self, &mut self,

View file

@ -12,7 +12,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty}; use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
use rustc_span::source_map::DesugaringKind; use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{MultiSpan, Span, DUMMY_SP}; use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use crate::dataflow::drop_flag_effects; use crate::dataflow::drop_flag_effects;
@ -1393,18 +1393,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let args_span = use_span.args_or_use(); let args_span = use_span.args_or_use();
let suggestion = match tcx.sess.source_map().span_to_snippet(args_span) { let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
Ok(mut string) => { Ok(string) => {
if string.starts_with("async ") { if string.starts_with("async ") {
string.insert_str(6, "move "); let pos = args_span.lo() + BytePos(6);
(args_span.with_lo(pos).with_hi(pos), "move ".to_string())
} else if string.starts_with("async|") { } else if string.starts_with("async|") {
string.insert_str(5, " move"); let pos = args_span.lo() + BytePos(5);
(args_span.with_lo(pos).with_hi(pos), " move".to_string())
} else { } else {
string.insert_str(0, "move "); (args_span.shrink_to_lo(), "move ".to_string())
}; }
string
} }
Err(_) => "move |<args>| <body>".to_string(), Err(_) => (args_span, "move |<args>| <body>".to_string()),
}; };
let kind = match use_span.generator_kind() { let kind = match use_span.generator_kind() {
Some(generator_kind) => match generator_kind { Some(generator_kind) => match generator_kind {
@ -1420,8 +1421,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut err = let mut err =
self.cannot_capture_in_long_lived_closure(args_span, kind, captured_var, var_span); self.cannot_capture_in_long_lived_closure(args_span, kind, captured_var, var_span);
err.span_suggestion( err.span_suggestion_verbose(
args_span, sugg_span,
&format!( &format!(
"to force the {} to take ownership of {} (and any \ "to force the {} to take ownership of {} (and any \
other referenced variables), use the `move` keyword", other referenced variables), use the `move` keyword",

View file

@ -1770,7 +1770,7 @@ impl<'a> Parser<'a> {
let mut err = self.struct_span_err(span, &msg); let mut err = self.struct_span_err(span, &msg);
let sp = self.sess.source_map().start_point(self.token.span); let sp = self.sess.source_map().start_point(self.token.span);
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) { if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
self.sess.expr_parentheses_needed(&mut err, *sp, None); self.sess.expr_parentheses_needed(&mut err, *sp);
} }
err.span_label(span, "expected expression"); err.span_label(span, "expected expression");
err err

View file

@ -358,7 +358,7 @@ impl<'a> Parser<'a> {
&format!("expected expression, found `{}`", pprust::token_to_string(&self.token),), &format!("expected expression, found `{}`", pprust::token_to_string(&self.token),),
); );
err.span_label(self.token.span, "expected expression"); err.span_label(self.token.span, "expected expression");
self.sess.expr_parentheses_needed(&mut err, lhs.span, Some(pprust::expr_to_string(&lhs))); self.sess.expr_parentheses_needed(&mut err, lhs.span);
err.emit(); err.emit();
} }
@ -696,20 +696,18 @@ impl<'a> Parser<'a> {
let expr = let expr =
mk_expr(self, lhs, self.mk_ty(path.span, TyKind::Path(None, path))); mk_expr(self, lhs, self.mk_ty(path.span, TyKind::Path(None, path)));
let expr_str = self
.span_to_snippet(expr.span)
.unwrap_or_else(|_| pprust::expr_to_string(&expr));
self.struct_span_err(self.token.span, &msg) self.struct_span_err(self.token.span, &msg)
.span_label( .span_label(
self.look_ahead(1, |t| t.span).to(span_after_type), self.look_ahead(1, |t| t.span).to(span_after_type),
"interpreted as generic arguments", "interpreted as generic arguments",
) )
.span_label(self.token.span, format!("not interpreted as {}", op_noun)) .span_label(self.token.span, format!("not interpreted as {}", op_noun))
.span_suggestion( .multipart_suggestion(
expr.span,
&format!("try {} the cast value", op_verb), &format!("try {} the cast value", op_verb),
format!("({})", expr_str), vec![
(expr.span.shrink_to_lo(), "(".to_string()),
(expr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MachineApplicable, Applicability::MachineApplicable,
) )
.emit(); .emit();

View file

@ -763,7 +763,7 @@ impl<'a> Parser<'a> {
let sp = self.sess.source_map().start_point(self.token.span); let sp = self.sess.source_map().start_point(self.token.span);
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) { if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
self.sess.expr_parentheses_needed(&mut err, *sp, None); self.sess.expr_parentheses_needed(&mut err, *sp);
} }
Err(err) Err(err)

View file

@ -228,20 +228,12 @@ impl ParseSess {
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the /// Extend an error with a suggestion to wrap an expression with parentheses to allow the
/// parser to continue parsing the following operation as part of the same expression. /// parser to continue parsing the following operation as part of the same expression.
pub fn expr_parentheses_needed( pub fn expr_parentheses_needed(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
&self, err.multipart_suggestion(
err: &mut DiagnosticBuilder<'_>, "parentheses are required to parse this as an expression",
span: Span, vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())],
alt_snippet: Option<String>, Applicability::MachineApplicable,
) { );
if let Some(snippet) = self.source_map().span_to_snippet(span).ok().or(alt_snippet) {
err.span_suggestion(
span,
"parentheses are required to parse this as an expression",
format!("({})", snippet),
Applicability::MachineApplicable,
);
}
} }
pub fn save_proc_macro_span(&self, span: Span) -> usize { pub fn save_proc_macro_span(&self, span: Span) -> usize {

View file

@ -1163,15 +1163,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if is_object_safe { if is_object_safe {
// Suggest `-> Box<dyn Trait>` and `Box::new(returned_value)`. // Suggest `-> Box<dyn Trait>` and `Box::new(returned_value)`.
// Get all the return values and collect their span and suggestion. // Get all the return values and collect their span and suggestion.
if let Some(mut suggestions) = visitor let mut suggestions: Vec<_> = visitor
.returns .returns
.iter() .iter()
.map(|expr| { .flat_map(|expr| {
let snip = sm.span_to_snippet(expr.span).ok()?; vec![
Some((expr.span, format!("Box::new({})", snip))) (expr.span.shrink_to_lo(), "Box::new(".to_string()),
(expr.span.shrink_to_hi(), ")".to_string()),
]
.into_iter()
}) })
.collect::<Option<Vec<_>>>() .collect();
{ if !suggestions.is_empty() {
// Add the suggestion for the return type. // Add the suggestion for the return type.
suggestions.push((ret_ty.span, format!("Box<dyn {}>", trait_obj))); suggestions.push((ret_ty.span, format!("Box<dyn {}>", trait_obj)));
err.multipart_suggestion( err.multipart_suggestion(

View file

@ -13,7 +13,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut}; use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::{BytePos, Span};
use super::method::probe; use super::method::probe;
@ -415,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
checked_ty: Ty<'tcx>, checked_ty: Ty<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
) -> Option<(Span, &'static str, String, Applicability)> { ) -> Option<(Span, &'static str, String, Applicability, bool /* verbose */)> {
let sess = self.sess(); let sess = self.sess();
let sp = expr.span; let sp = expr.span;
@ -441,12 +441,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => { (&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind { if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = replace_prefix(&src, "b\"", "\"") { if let Some(_) = replace_prefix(&src, "b\"", "\"") {
let pos = sp.lo() + BytePos(1);
return Some(( return Some((
sp, sp.with_hi(pos),
"consider removing the leading `b`", "consider removing the leading `b`",
src, String::new(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }
@ -455,12 +457,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => { (&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind { if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = replace_prefix(&src, "\"", "b\"") { if let Some(_) = replace_prefix(&src, "\"", "b\"") {
return Some(( return Some((
sp, sp.shrink_to_lo(),
"consider adding a leading `b`", "consider adding a leading `b`",
src, "b".to_string(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }
@ -520,6 +523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
sugg.1, sugg.1,
sugg.2, sugg.2,
Applicability::MachineApplicable, Applicability::MachineApplicable,
false,
)); ));
} }
let field_name = if is_struct_pat_shorthand_field { let field_name = if is_struct_pat_shorthand_field {
@ -539,13 +543,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// | | // | |
// consider dereferencing here: `*opt` | // consider dereferencing here: `*opt` |
// expected mutable reference, found enum `Option` // expected mutable reference, found enum `Option`
if let Ok(src) = sm.span_to_snippet(left_expr.span) { if sm.span_to_snippet(left_expr.span).is_ok() {
return Some(( return Some((
left_expr.span, left_expr.span.shrink_to_lo(),
"consider dereferencing here to assign to the mutable \ "consider dereferencing here to assign to the mutable \
borrowed piece of memory", borrowed piece of memory",
format!("*{}", src), "*".to_string(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }
@ -557,12 +562,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"consider mutably borrowing here", "consider mutably borrowing here",
format!("{}&mut {}", field_name, sugg_expr), format!("{}&mut {}", field_name, sugg_expr),
Applicability::MachineApplicable, Applicability::MachineApplicable,
false,
), ),
hir::Mutability::Not => ( hir::Mutability::Not => (
sp, sp,
"consider borrowing here", "consider borrowing here",
format!("{}&{}", field_name, sugg_expr), format!("{}&{}", field_name, sugg_expr),
Applicability::MachineApplicable, Applicability::MachineApplicable,
false,
), ),
}); });
} }
@ -584,24 +591,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(call_span) = if let Some(call_span) =
iter::successors(Some(expr.span), |s| s.parent()).find(|&s| sp.contains(s)) iter::successors(Some(expr.span), |s| s.parent()).find(|&s| sp.contains(s))
{ {
if let Ok(code) = sm.span_to_snippet(call_span) { if sm.span_to_snippet(call_span).is_ok() {
return Some(( return Some((
sp, sp.with_hi(call_span.lo()),
"consider removing the borrow", "consider removing the borrow",
code, String::new(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }
return None; return None;
} }
if sp.contains(expr.span) { if sp.contains(expr.span) {
if let Ok(code) = sm.span_to_snippet(expr.span) { if sm.span_to_snippet(expr.span).is_ok() {
return Some(( return Some((
sp, sp.with_hi(expr.span.lo()),
"consider removing the borrow", "consider removing the borrow",
code, String::new(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }
@ -616,36 +625,59 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if steps > 0 { if steps > 0 {
// The pointer type implements `Copy` trait so the suggestion is always valid. // The pointer type implements `Copy` trait so the suggestion is always valid.
if let Ok(src) = sm.span_to_snippet(sp) { if let Ok(src) = sm.span_to_snippet(sp) {
let derefs = &"*".repeat(steps); let derefs = "*".repeat(steps);
if let Some((src, applicability)) = match mutbl_b { if let Some((span, src, applicability)) = match mutbl_b {
hir::Mutability::Mut => { hir::Mutability::Mut => {
let new_prefix = "&mut ".to_owned() + derefs; let new_prefix = "&mut ".to_owned() + &derefs;
match mutbl_a { match mutbl_a {
hir::Mutability::Mut => { hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix) replace_prefix(&src, "&mut ", &new_prefix).map(|_| {
.map(|s| (s, Applicability::MachineApplicable)) let pos = sp.lo() + BytePos(5);
let sp = sp.with_lo(pos).with_hi(pos);
(sp, derefs, Applicability::MachineApplicable)
})
} }
hir::Mutability::Not => { hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix) replace_prefix(&src, "&", &new_prefix).map(|_| {
.map(|s| (s, Applicability::Unspecified)) let pos = sp.lo() + BytePos(1);
let sp = sp.with_lo(pos).with_hi(pos);
(
sp,
format!("mut {}", derefs),
Applicability::Unspecified,
)
})
} }
} }
} }
hir::Mutability::Not => { hir::Mutability::Not => {
let new_prefix = "&".to_owned() + derefs; let new_prefix = "&".to_owned() + &derefs;
match mutbl_a { match mutbl_a {
hir::Mutability::Mut => { hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix) replace_prefix(&src, "&mut ", &new_prefix).map(|_| {
.map(|s| (s, Applicability::MachineApplicable)) let lo = sp.lo() + BytePos(1);
let hi = sp.lo() + BytePos(5);
let sp = sp.with_lo(lo).with_hi(hi);
(sp, derefs, Applicability::MachineApplicable)
})
} }
hir::Mutability::Not => { hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix) replace_prefix(&src, "&", &new_prefix).map(|_| {
.map(|s| (s, Applicability::MachineApplicable)) let pos = sp.lo() + BytePos(1);
let sp = sp.with_lo(pos).with_hi(pos);
(sp, derefs, Applicability::MachineApplicable)
})
} }
} }
} }
} { } {
return Some((sp, "consider dereferencing", src, applicability)); return Some((
span,
"consider dereferencing",
src,
applicability,
true,
));
} }
} }
} }
@ -669,6 +701,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
message, message,
suggestion, suggestion,
Applicability::MachineApplicable, Applicability::MachineApplicable,
false,
)); ));
} else if self.infcx.type_is_copy_modulo_regions( } else if self.infcx.type_is_copy_modulo_regions(
self.param_env, self.param_env,
@ -682,21 +715,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else { } else {
"consider dereferencing the type" "consider dereferencing the type"
}; };
let suggestion = if is_struct_pat_shorthand_field { let (span, suggestion) = if is_struct_pat_shorthand_field {
format!("{}: *{}", code, code) (expr.span, format!("{}: *{}", code, code))
} else if self.is_else_if_block(expr) { } else if self.is_else_if_block(expr) {
// Don't suggest nonsense like `else *if` // Don't suggest nonsense like `else *if`
return None; return None;
} else if let Some(expr) = self.maybe_get_block_expr(expr.hir_id) { } else if let Some(expr) = self.maybe_get_block_expr(expr.hir_id) {
format!("*{}", sm.span_to_snippet(expr.span).unwrap_or(code)) (expr.span.shrink_to_lo(), "*".to_string())
} else { } else {
format!("*{}", code) (expr.span.shrink_to_lo(), "*".to_string())
}; };
return Some(( return Some((
expr.span, span,
message, message,
suggestion, suggestion,
Applicability::MachineApplicable, Applicability::MachineApplicable,
true,
)); ));
} }
} }

View file

@ -344,7 +344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(sp) = if let Some(sp) =
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
{ {
tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp, None); tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
} }
err.emit(); err.emit();
oprnd_t = tcx.ty_error(); oprnd_t = tcx.ty_error();

View file

@ -213,8 +213,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>, expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
) { ) {
let expr = expr.peel_blocks(); let expr = expr.peel_blocks();
if let Some((sp, msg, suggestion, applicability)) = self.check_ref(expr, found, expected) { if let Some((sp, msg, suggestion, applicability, verbose)) =
err.span_suggestion(sp, msg, suggestion, applicability); self.check_ref(expr, found, expected)
{
if verbose {
err.span_suggestion_verbose(sp, msg, suggestion, applicability);
} else {
err.span_suggestion(sp, msg, suggestion, applicability);
}
} else if let (ty::FnDef(def_id, ..), true) = } else if let (ty::FnDef(def_id, ..), true) =
(&found.kind(), self.suggest_fn_call(err, expr, expected, found)) (&found.kind(), self.suggest_fn_call(err, expr, expected, found))
{ {
@ -234,29 +240,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None // do not suggest code that is already there (#53348) None // do not suggest code that is already there (#53348)
} else { } else {
let method_call_list = [".to_vec()", ".to_string()"]; let method_call_list = [".to_vec()", ".to_string()"];
let sugg = if receiver.ends_with(".clone()") let mut sugg = if receiver.ends_with(".clone()")
&& method_call_list.contains(&method_call.as_str()) && method_call_list.contains(&method_call.as_str())
{ {
let max_len = receiver.rfind('.').unwrap(); let max_len = receiver.rfind('.').unwrap();
format!("{}{}", &receiver[..max_len], method_call) vec![(
expr.span,
format!("{}{}", &receiver[..max_len], method_call),
)]
} else { } else {
if expr.precedence().order() < ExprPrecedence::MethodCall.order() { if expr.precedence().order() < ExprPrecedence::MethodCall.order() {
format!("({}){}", receiver, method_call) vec![
(expr.span.shrink_to_lo(), "(".to_string()),
(expr.span.shrink_to_hi(), format!("){}", method_call)),
]
} else { } else {
format!("{}{}", receiver, method_call) vec![(expr.span.shrink_to_hi(), method_call)]
} }
}; };
Some(if is_struct_pat_shorthand_field { if is_struct_pat_shorthand_field {
format!("{}: {}", receiver, sugg) sugg.insert(
} else { 0,
sugg (expr.span.shrink_to_lo(), format!("{}: ", receiver)),
}) );
}
Some(sugg)
} }
}) })
.peekable(); .peekable();
if suggestions.peek().is_some() { if suggestions.peek().is_some() {
err.span_suggestions( err.multipart_suggestions(
expr.span,
"try using a conversion method", "try using a conversion method",
suggestions, suggestions,
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
@ -283,14 +296,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return; return;
} }
let boxed_found = self.tcx.mk_box(found); let boxed_found = self.tcx.mk_box(found);
if let (true, Ok(snippet)) = ( if self.can_coerce(boxed_found, expected) {
self.can_coerce(boxed_found, expected), err.multipart_suggestion(
self.sess().source_map().span_to_snippet(expr.span),
) {
err.span_suggestion(
expr.span,
"store this in the heap by calling `Box::new`", "store this in the heap by calling `Box::new`",
format!("Box::new({})", snippet), vec![
(expr.span.shrink_to_lo(), "Box::new(".to_string()),
(expr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
err.note( err.note(
@ -357,19 +369,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let boxed_found = self.tcx.mk_box(found); let boxed_found = self.tcx.mk_box(found);
let new_found = self.tcx.mk_lang_item(boxed_found, LangItem::Pin).unwrap(); let new_found = self.tcx.mk_lang_item(boxed_found, LangItem::Pin).unwrap();
if let (true, Ok(snippet)) = ( if self.can_coerce(new_found, expected) {
self.can_coerce(new_found, expected),
self.sess().source_map().span_to_snippet(expr.span),
) {
match found.kind() { match found.kind() {
ty::Adt(def, _) if def.is_box() => { ty::Adt(def, _) if def.is_box() => {
err.help("use `Box::pin`"); err.help("use `Box::pin`");
} }
_ => { _ => {
err.span_suggestion( err.multipart_suggestion(
expr.span,
"you need to pin and box this expression", "you need to pin and box this expression",
format!("Box::pin({})", snippet), vec![
(expr.span.shrink_to_lo(), "Box::pin(".to_string()),
(expr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }
@ -547,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sp = self.tcx.sess.source_map().start_point(expr.span); let sp = self.tcx.sess.source_map().start_point(expr.span);
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) { if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }` // `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
self.tcx.sess.parse_sess.expr_parentheses_needed(err, *sp, None); self.tcx.sess.parse_sess.expr_parentheses_needed(err, *sp);
} }
} }

View file

@ -15,7 +15,7 @@ LL | fn test_boxed() -> Box<impl std::future::Future<Output = u32>> {
help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | Box::new(async move { x } ) LL | Box::new(async move { x } )
| ^^^^^^^^^^ | ^^^^
error[E0373]: async block may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: async block may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/async-borrowck-escaping-block-error.rs:11:11 --> $DIR/async-borrowck-escaping-block-error.rs:11:11
@ -34,7 +34,7 @@ LL | async { *x }
help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | async move { *x } LL | async move { *x }
| ^^^^^^^^^^^ | ^^^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -14,7 +14,7 @@ LL | Box::new((async || x)())
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | Box::new((async move || x)()) LL | Box::new((async move || x)())
| ^^^^^^^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -14,7 +14,7 @@ LL | foo(|| self.bar()).await;
help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword
| |
LL | foo(move || self.bar()).await; LL | foo(move || self.bar()).await;
| ^^^^^^^ | ^^^^
error[E0521]: borrowed data escapes outside of associated function error[E0521]: borrowed data escapes outside of associated function
--> $DIR/issue-62097.rs:13:9 --> $DIR/issue-62097.rs:13:9

View file

@ -12,9 +12,7 @@ LL | | });
help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword
| |
LL | let gameloop_handle = spawn(async move { LL | let gameloop_handle = spawn(async move {
LL | game_loop(Arc::clone(&room_ref)) | ^^^^
LL | });
|
error: aborting due to previous error error: aborting due to previous error

View file

@ -4,13 +4,14 @@ error[E0308]: mismatched types
LL | fn main() { LL | fn main() {
| - expected `()` because of default return type | - expected `()` because of default return type
LL | &panic!() LL | &panic!()
| ^^^^^^^^^ | ^^^^^^^^^ expected `()`, found reference
| |
| expected `()`, found reference
| help: consider removing the borrow: `panic!()`
| |
= note: expected unit type `()` = note: expected unit type `()`
found reference `&_` found reference `&_`
help: consider removing the borrow
|
LL | panic!()
| --
error: aborting due to previous error error: aborting due to previous error

View file

@ -14,7 +14,7 @@ LL | spawn(|| books.push(4));
help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
| |
LL | spawn(move || books.push(4)); LL | spawn(move || books.push(4));
| ^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -14,7 +14,7 @@ LL | Box::new(|| books.push(4))
help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
| |
LL | Box::new(move || books.push(4)) LL | Box::new(move || books.push(4))
| ^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -15,7 +15,7 @@ LL | fn foo () -> impl FnMut()->() {
help: to force the closure to take ownership of `p` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `p` (and any other referenced variables), use the `move` keyword
| |
LL | let mut c = move || { LL | let mut c = move || {
| ^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -27,7 +27,7 @@ LL | | })
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | bar(move || { LL | bar(move || {
| ^^^^^^^ | ^^^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -2,10 +2,9 @@ error[E0308]: mismatched types
--> $DIR/unused-substs-3.rs:16:9 --> $DIR/unused-substs-3.rs:16:9
| |
LL | t = foo; LL | t = foo;
| ^^^ | ^^^- help: try using a conversion method: `.to_vec()`
| | | |
| cyclic type of infinite size | cyclic type of infinite size
| help: try using a conversion method: `foo.to_vec()`
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,10 +2,9 @@ error[E0308]: mismatched types
--> $DIR/unused-substs-5.rs:15:9 --> $DIR/unused-substs-5.rs:15:9
| |
LL | x = q::<_, N>(x); LL | x = q::<_, N>(x);
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^- help: try using a conversion method: `.to_vec()`
| | | |
| cyclic type of infinite size | cyclic type of infinite size
| help: try using a conversion method: `q::<_, N>(x).to_vec()`
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,37 +2,42 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:8:9 --> $DIR/deref-suggestion.rs:8:9
| |
LL | foo(s); LL | foo(s);
| ^ | ^- help: try using a conversion method: `.to_string()`
| | | |
| expected struct `String`, found `&String` | expected struct `String`, found `&String`
| help: try using a conversion method: `s.to_string()`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:14:10 --> $DIR/deref-suggestion.rs:14:10
| |
LL | foo3(u); LL | foo3(u);
| ^ expected `u32`, found `&u32`
|
help: consider dereferencing the borrow
|
LL | foo3(*u);
| ^ | ^
| |
| expected `u32`, found `&u32`
| help: consider dereferencing the borrow: `*u`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:30:9 --> $DIR/deref-suggestion.rs:30:9
| |
LL | foo(&"aaa".to_owned()); LL | foo(&"aaa".to_owned());
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^ expected struct `String`, found `&String`
| | |
| expected struct `String`, found `&String` help: consider removing the borrow
| help: consider removing the borrow: `"aaa".to_owned()` |
LL | foo("aaa".to_owned());
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:32:9 --> $DIR/deref-suggestion.rs:32:9
| |
LL | foo(&mut "aaa".to_owned()); LL | foo(&mut "aaa".to_owned());
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&mut String`
| | |
| expected struct `String`, found `&mut String` help: consider removing the borrow
| help: consider removing the borrow: `"aaa".to_owned()` |
LL | foo("aaa".to_owned());
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:2:20 --> $DIR/deref-suggestion.rs:2:20
@ -75,37 +80,45 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:44:17 --> $DIR/deref-suggestion.rs:44:17
| |
LL | let r = R { i }; LL | let r = R { i };
| ^ | ^ expected `u32`, found `&{integer}`
| | |
| expected `u32`, found `&{integer}` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `i: *i` |
LL | let r = R { i: *i };
| ^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:46:20 --> $DIR/deref-suggestion.rs:46:20
| |
LL | let r = R { i: i }; LL | let r = R { i: i };
| ^ expected `u32`, found `&{integer}`
|
help: consider dereferencing the borrow
|
LL | let r = R { i: *i };
| ^ | ^
| |
| expected `u32`, found `&{integer}`
| help: consider dereferencing the borrow: `*i`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:55:9 --> $DIR/deref-suggestion.rs:55:9
| |
LL | b LL | b
| ^ expected `i32`, found `&{integer}`
|
help: consider dereferencing the borrow
|
LL | *b
| ^ | ^
| |
| expected `i32`, found `&{integer}`
| help: consider dereferencing the borrow: `*b`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:63:9 --> $DIR/deref-suggestion.rs:63:9
| |
LL | b LL | b
| ^ expected `i32`, found `&{integer}`
|
help: consider dereferencing the borrow
|
LL | *b
| ^ | ^
| |
| expected `i32`, found `&{integer}`
| help: consider dereferencing the borrow: `*b`
error[E0308]: `if` and `else` have incompatible types error[E0308]: `if` and `else` have incompatible types
--> $DIR/deref-suggestion.rs:68:12 --> $DIR/deref-suggestion.rs:68:12

View file

@ -13,7 +13,7 @@ LL | fn g() -> &_ {
help: consider removing the borrow help: consider removing the borrow
| |
LL | panic!() LL | panic!()
| ^^^^^^^^ | --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/diverging-tuple-parts-39485.rs:12:5 --> $DIR/diverging-tuple-parts-39485.rs:12:5

View file

@ -2,10 +2,9 @@ error[E0308]: mismatched types
--> $DIR/estr-subtyping.rs:10:15 --> $DIR/estr-subtyping.rs:10:15
| |
LL | wants_uniq(x); LL | wants_uniq(x);
| ^ | ^- help: try using a conversion method: `.to_string()`
| | | |
| expected struct `String`, found `&str` | expected struct `String`, found `&str`
| help: try using a conversion method: `x.to_string()`
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,73 +2,89 @@ error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:18:8 --> $DIR/if-no-match-bindings.rs:18:8
| |
LL | if b_ref() {} LL | if b_ref() {}
| ^^^^^^^ | ^^^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `*b_ref()` |
LL | if *b_ref() {}
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:19:8 --> $DIR/if-no-match-bindings.rs:19:8
| |
LL | if b_mut_ref() {} LL | if b_mut_ref() {}
| ^^^^^^^^^^^ | ^^^^^^^^^^^ expected `bool`, found `&mut bool`
| | |
| expected `bool`, found `&mut bool` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `*b_mut_ref()` |
LL | if *b_mut_ref() {}
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:20:8 --> $DIR/if-no-match-bindings.rs:20:8
| |
LL | if &true {} LL | if &true {}
| ^^^^^ | ^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider removing the borrow
| help: consider removing the borrow: `true` |
LL | if true {}
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:21:8 --> $DIR/if-no-match-bindings.rs:21:8
| |
LL | if &mut true {} LL | if &mut true {}
| ^^^^^^^^^ | ^^^^^^^^^ expected `bool`, found `&mut bool`
| | |
| expected `bool`, found `&mut bool` help: consider removing the borrow
| help: consider removing the borrow: `true` |
LL | if true {}
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:24:11 --> $DIR/if-no-match-bindings.rs:24:11
| |
LL | while b_ref() {} LL | while b_ref() {}
| ^^^^^^^ | ^^^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `*b_ref()` |
LL | while *b_ref() {}
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:25:11 --> $DIR/if-no-match-bindings.rs:25:11
| |
LL | while b_mut_ref() {} LL | while b_mut_ref() {}
| ^^^^^^^^^^^ | ^^^^^^^^^^^ expected `bool`, found `&mut bool`
| | |
| expected `bool`, found `&mut bool` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `*b_mut_ref()` |
LL | while *b_mut_ref() {}
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:26:11 --> $DIR/if-no-match-bindings.rs:26:11
| |
LL | while &true {} LL | while &true {}
| ^^^^^ | ^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider removing the borrow
| help: consider removing the borrow: `true` |
LL | while true {}
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/if-no-match-bindings.rs:27:11 --> $DIR/if-no-match-bindings.rs:27:11
| |
LL | while &mut true {} LL | while &mut true {}
| ^^^^^^^^^ | ^^^^^^^^^ expected `bool`, found `&mut bool`
| | |
| expected `bool`, found `&mut bool` help: consider removing the borrow
| help: consider removing the borrow: `true` |
LL | while true {}
| --
error: aborting due to 8 previous errors error: aborting due to 8 previous errors

View file

@ -14,7 +14,7 @@ LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'
help: to force the closure to take ownership of `prefix` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `prefix` (and any other referenced variables), use the `move` keyword
| |
LL | self.data.iter().filter(move |s| s.starts_with(prefix)).map(|s| s.as_ref()) LL | self.data.iter().filter(move |s| s.starts_with(prefix)).map(|s| s.as_ref())
| ^^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -140,14 +140,15 @@ LL | fn bam() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true { LL | if true {
LL | return Struct; LL | return Struct;
| ^^^^^^ | ^^^^^^ expected struct `Box`, found struct `Struct`
| |
| expected struct `Box`, found struct `Struct`
| help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found struct `Struct` found struct `Struct`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(Struct);
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:36:5
@ -156,14 +157,15 @@ LL | fn bam() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
... ...
LL | 42 LL | 42
| ^^ | ^^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(42)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:40:16
@ -172,14 +174,15 @@ LL | fn baq() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true { LL | if true {
LL | return 0; LL | return 0;
| ^ | ^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(0)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | return Box::new(0);
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:42:5
@ -188,14 +191,15 @@ LL | fn baq() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
... ...
LL | 42 LL | 42
| ^^ | ^^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(42)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:46:9
@ -204,14 +208,15 @@ LL | fn baz() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true { LL | if true {
LL | Struct LL | Struct
| ^^^^^^ | ^^^^^^ expected struct `Box`, found struct `Struct`
| |
| expected struct `Box`, found struct `Struct`
| help: store this in the heap by calling `Box::new`: `Box::new(Struct)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found struct `Struct` found struct `Struct`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(Struct)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:48:9
@ -220,14 +225,15 @@ LL | fn baz() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
... ...
LL | 42 LL | 42
| ^^ | ^^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(42)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:53:9
@ -236,14 +242,15 @@ LL | fn baw() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
LL | if true { LL | if true {
LL | 0 LL | 0
| ^ | ^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(0)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(0)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:55:9
@ -252,14 +259,15 @@ LL | fn baw() -> Box<dyn Trait> {
| -------------- expected `Box<(dyn Trait + 'static)>` because of return type | -------------- expected `Box<(dyn Trait + 'static)>` because of return type
... ...
LL | 42 LL | 42
| ^^ | ^^ expected struct `Box`, found integer
| |
| expected struct `Box`, found integer
| help: store this in the heap by calling `Box::new`: `Box::new(42)`
| |
= note: expected struct `Box<(dyn Trait + 'static)>` = note: expected struct `Box<(dyn Trait + 'static)>`
found type `{integer}` found type `{integer}`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Box::new(42)
| ^^^^^^^^^ ^
error[E0746]: return type cannot have an unboxed trait object error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13 --> $DIR/dyn-trait-return-should-be-impl-trait.rs:60:13

View file

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/infinite-autoderef.rs:20:13 --> $DIR/infinite-autoderef.rs:20:13
| |
LL | x = box x; LL | x = box x;
| ^^^^^ | ^^^^^ cyclic type of infinite size
| | |
| cyclic type of infinite size help: try using a conversion method
| help: try using a conversion method: `(box x).to_string()` |
LL | x = (box x).to_string();
| ^ ^^^^^^^^^^^^^
error[E0055]: reached the recursion limit while auto-dereferencing `Foo` error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
--> $DIR/infinite-autoderef.rs:25:5 --> $DIR/infinite-autoderef.rs:25:5

View file

@ -2,46 +2,66 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
--> $DIR/issue-22644.rs:8:31 --> $DIR/issue-22644.rs:8:31
| |
LL | println!("{}", a as usize < long_name); LL | println!("{}", a as usize < long_name);
| ---------- ^ --------- interpreted as generic arguments | ^ --------- interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `(a as usize)` |
help: try comparing the cast value
|
LL | println!("{}", (a as usize) < long_name);
| ^ ^
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:9:33 --> $DIR/issue-22644.rs:9:33
| |
LL | println!("{}{}", a as usize < long_name, long_name); LL | println!("{}{}", a as usize < long_name, long_name);
| ---------- ^ -------------------- interpreted as generic arguments | ^ -------------------- interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `(a as usize)` |
help: try comparing the cast value
|
LL | println!("{}{}", (a as usize) < long_name, long_name);
| ^ ^
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:11:31 --> $DIR/issue-22644.rs:11:31
| |
LL | println!("{}", a as usize < 4); LL | println!("{}", a as usize < 4);
| ---------- ^ - interpreted as generic arguments | ^ - interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `(a as usize)` |
help: try comparing the cast value
|
LL | println!("{}", (a as usize) < 4);
| ^ ^
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:13:31 --> $DIR/issue-22644.rs:13:31
| |
LL | println!("{}{}", a: usize < long_name, long_name); LL | println!("{}{}", a: usize < long_name, long_name);
| -------- ^ -------------------- interpreted as generic arguments | ^ -------------------- interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `(a: usize)` |
help: try comparing the cast value
|
LL | println!("{}{}", (a: usize) < long_name, long_name);
| ^ ^
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:15:29 --> $DIR/issue-22644.rs:15:29
| |
LL | println!("{}", a: usize < 4); LL | println!("{}", a: usize < 4);
| -------- ^ - interpreted as generic arguments | ^ - interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `(a: usize)` |
help: try comparing the cast value
|
LL | println!("{}", (a: usize) < 4);
| ^ ^
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:20:20 --> $DIR/issue-22644.rs:20:20
@ -80,10 +100,14 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a shi
--> $DIR/issue-22644.rs:32:31 --> $DIR/issue-22644.rs:32:31
| |
LL | println!("{}", a as usize << long_name); LL | println!("{}", a as usize << long_name);
| ---------- ^^ --------- interpreted as generic arguments | ^^ --------- interpreted as generic arguments
| | | | |
| | not interpreted as shift | not interpreted as shift
| help: try shifting the cast value: `(a as usize)` |
help: try shifting the cast value
|
LL | println!("{}", (a as usize) << long_name);
| ^ ^
error: expected type, found `4` error: expected type, found `4`
--> $DIR/issue-22644.rs:34:28 --> $DIR/issue-22644.rs:34:28

View file

@ -2,14 +2,16 @@ error[E0308]: mismatched types
--> $DIR/issue-32122-1.rs:16:24 --> $DIR/issue-32122-1.rs:16:24
| |
LL | let _: *const u8 = &a; LL | let _: *const u8 = &a;
| --------- ^^ | --------- ^^ expected `u8`, found struct `Foo`
| | | | |
| | expected `u8`, found struct `Foo`
| | help: consider dereferencing: `&*a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*const u8` = note: expected raw pointer `*const u8`
found reference `&Foo` found reference `&Foo`
help: consider dereferencing
|
LL | let _: *const u8 = &*a;
| ^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,14 +2,16 @@ error[E0308]: mismatched types
--> $DIR/issue-32122-2.rs:27:24 --> $DIR/issue-32122-2.rs:27:24
| |
LL | let _: *const u8 = &a; LL | let _: *const u8 = &a;
| --------- ^^ | --------- ^^ expected `u8`, found struct `Emm`
| | | | |
| | expected `u8`, found struct `Emm`
| | help: consider dereferencing: `&***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*const u8` = note: expected raw pointer `*const u8`
found reference `&Emm` found reference `&Emm`
help: consider dereferencing
|
LL | let _: *const u8 = &***a;
| ^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,15 +2,18 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a compa
--> $DIR/issue-42954.rs:7:19 --> $DIR/issue-42954.rs:7:19
| |
LL | $i as u32 < 0 LL | $i as u32 < 0
| --------- ^ - interpreted as generic arguments | ^ - interpreted as generic arguments
| | | | |
| | not interpreted as comparison | not interpreted as comparison
| help: try comparing the cast value: `($i as u32)`
... ...
LL | is_plainly_printable!(c); LL | is_plainly_printable!(c);
| ------------------------- in this macro invocation | ------------------------- in this macro invocation
| |
= note: this error originates in the macro `is_plainly_printable` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `is_plainly_printable` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try comparing the cast value
|
LL | ($i as u32) < 0
| ^ ^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,14 +2,16 @@ error[E0308]: mismatched types
--> $DIR/issue-50687-ice-on-borrow.rs:40:17 --> $DIR/issue-50687-ice-on-borrow.rs:40:17
| |
LL | let _: () = Borrow::borrow(&owned); LL | let _: () = Borrow::borrow(&owned);
| -- ^^^^^^^^^^^^^^^^^^^^^^ | -- ^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found reference
| | | | |
| | expected `()`, found reference
| | help: consider dereferencing the borrow: `*Borrow::borrow(&owned)`
| expected due to this | expected due to this
| |
= note: expected unit type `()` = note: expected unit type `()`
found reference `&_` found reference `&_`
help: consider dereferencing the borrow
|
LL | let _: () = *Borrow::borrow(&owned);
| ^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,53 +2,61 @@ error[E0308]: mismatched types
--> $DIR/issue-71676-1.rs:43:24 --> $DIR/issue-71676-1.rs:43:24
| |
LL | let _: *const u8 = &a; LL | let _: *const u8 = &a;
| --------- ^^ | --------- ^^ expected `u8`, found struct `Emm`
| | | | |
| | expected `u8`, found struct `Emm`
| | help: consider dereferencing: `&***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*const u8` = note: expected raw pointer `*const u8`
found reference `&Emm` found reference `&Emm`
help: consider dereferencing
|
LL | let _: *const u8 = &***a;
| ^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-71676-1.rs:46:22 --> $DIR/issue-71676-1.rs:46:22
| |
LL | let _: *mut u8 = &a; LL | let _: *mut u8 = &a;
| ------- ^^ | ------- ^^ types differ in mutability
| | | | |
| | types differ in mutability
| | help: consider dereferencing: `&mut ***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*mut u8` = note: expected raw pointer `*mut u8`
found reference `&Emm` found reference `&Emm`
help: consider dereferencing
|
LL | let _: *mut u8 = &mut ***a;
| ^^^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-71676-1.rs:49:24 --> $DIR/issue-71676-1.rs:49:24
| |
LL | let _: *const u8 = &mut a; LL | let _: *const u8 = &mut a;
| --------- ^^^^^^ | --------- ^^^^^^ expected `u8`, found struct `Emm`
| | | | |
| | expected `u8`, found struct `Emm`
| | help: consider dereferencing: `&***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*const u8` = note: expected raw pointer `*const u8`
found mutable reference `&mut Emm` found mutable reference `&mut Emm`
help: consider dereferencing
|
LL | let _: *const u8 = &***a;
| ^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-71676-1.rs:52:22 --> $DIR/issue-71676-1.rs:52:22
| |
LL | let _: *mut u8 = &mut a; LL | let _: *mut u8 = &mut a;
| ------- ^^^^^^ | ------- ^^^^^^ expected `u8`, found struct `Emm`
| | | | |
| | expected `u8`, found struct `Emm`
| | help: consider dereferencing: `&mut ***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*mut u8` = note: expected raw pointer `*mut u8`
found mutable reference `&mut Emm` found mutable reference `&mut Emm`
help: consider dereferencing
|
LL | let _: *mut u8 = &mut ***a;
| ^^^
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -2,14 +2,16 @@ error[E0308]: mismatched types
--> $DIR/issue-71676-2.rs:41:22 --> $DIR/issue-71676-2.rs:41:22
| |
LL | let _: *mut u8 = &a; LL | let _: *mut u8 = &a;
| ------- ^^ | ------- ^^ types differ in mutability
| | | | |
| | types differ in mutability
| | help: consider dereferencing: `&mut ***a`
| expected due to this | expected due to this
| |
= note: expected raw pointer `*mut u8` = note: expected raw pointer `*mut u8`
found reference `&Emm` found reference `&Emm`
help: consider dereferencing
|
LL | let _: *mut u8 = &mut ***a;
| ^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -21,10 +21,12 @@ error[E0308]: mismatched types
--> $DIR/issue-77218.rs:3:16 --> $DIR/issue-77218.rs:3:16
| |
LL | while Some(0) = value.get(0) { LL | while Some(0) = value.get(0) {
| ^ expected integer, found `&u8`
|
help: consider dereferencing the borrow
|
LL | while Some(*0) = value.get(0) {
| ^ | ^
| |
| expected integer, found `&u8`
| help: consider dereferencing the borrow: `*0`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-77218.rs:3:11 --> $DIR/issue-77218.rs:3:11

View file

@ -24,7 +24,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":622,"byte_end":622,"line_start":17,"line_end":17,"column_start":23,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":23,"highlight_end":23}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
@ -52,7 +52,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":672,"byte_end":678,"line_start":19,"line_end":19,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:19:22: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":672,"byte_end":678,"line_start":19,"line_end":19,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":682,"byte_end":682,"line_start":19,"line_end":19,"column_start":23,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":23,"highlight_end":23}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:19:22: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
@ -80,7 +80,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":735,"byte_end":741,"line_start":22,"line_end":22,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:23:1: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":735,"byte_end":741,"line_start":22,"line_end":22,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":746,"byte_end":746,"line_start":23,"line_end":23,"column_start":2,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":2,"highlight_end":2}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:23:1: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.

View file

@ -24,7 +24,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":597,"byte_end":603,"line_start":16,"line_end":16,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:16:22: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":606,"byte_end":607,"line_start":16,"line_end":16,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":597,"byte_end":603,"line_start":16,"line_end":16,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":607,"byte_end":607,"line_start":16,"line_end":16,"column_start":23,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1; // Error in the middle of line.","highlight_start":23,"highlight_end":23}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:16:22: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
@ -52,7 +52,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":657,"byte_end":663,"line_start":18,"line_end":18,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:18:22: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":666,"byte_end":667,"line_start":18,"line_end":18,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":657,"byte_end":663,"line_start":18,"line_end":18,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":667,"byte_end":667,"line_start":18,"line_end":18,"column_start":23,"column_end":23,"is_primary":true,"text":[{"text":" let s : String = 1","highlight_start":23,"highlight_end":23}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:18:22: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
@ -80,7 +80,7 @@ This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. different type than the matching type in the function declaration.
"},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":720,"byte_end":726,"line_start":21,"line_end":21,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:22:1: error[E0308]: mismatched types "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":730,"byte_end":731,"line_start":22,"line_end":22,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":720,"byte_end":726,"line_start":21,"line_end":21,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":" let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf.rs","byte_start":731,"byte_end":731,"line_start":22,"line_end":22,"column_start":2,"column_end":2,"is_primary":true,"text":[{"text":"1; // Error after the newline.","highlight_start":2,"highlight_end":2}],"label":null,"suggested_replacement":".to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf.rs:22:1: error[E0308]: mismatched types
"} "}
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type. {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.

View file

@ -14,7 +14,7 @@ LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a));
help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
| |
LL | [0].iter().flat_map(|a| [0].iter().map(move |_| &a)); LL | [0].iter().flat_map(|a| [0].iter().map(move |_| &a));
| ^^^^^^^^ | ^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -78,10 +78,12 @@ error[E0308]: mismatched types
LL | fn f() -> String { LL | fn f() -> String {
| ------ expected `String` because of return type | ------ expected `String` because of return type
LL | 1+2 LL | 1+2
| ^^^ | ^^^ expected struct `String`, found integer
| | |
| expected struct `String`, found integer help: try using a conversion method
| help: try using a conversion method: `(1+2).to_string()` |
LL | (1+2).to_string()
| ^ ^^^^^^^^^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/abridged.rs:59:5 --> $DIR/abridged.rs:59:5
@ -89,10 +91,12 @@ error[E0308]: mismatched types
LL | fn g() -> String { LL | fn g() -> String {
| ------ expected `String` because of return type | ------ expected `String` because of return type
LL | -2 LL | -2
| ^^ | ^^ expected struct `String`, found integer
| | |
| expected struct `String`, found integer help: try using a conversion method
| help: try using a conversion method: `(-2).to_string()` |
LL | (-2).to_string()
| ^ ^^^^^^^^^^^^^
error: aborting due to 8 previous errors error: aborting due to 8 previous errors

View file

@ -16,13 +16,14 @@ error[E0308]: mismatched types
--> $DIR/issue-52443.rs:2:10 --> $DIR/issue-52443.rs:2:10
| |
LL | [(); & { loop { continue } } ]; LL | [(); & { loop { continue } } ];
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found reference
| |
| expected `usize`, found reference
| help: consider removing the borrow: `{ loop { continue } }`
| |
= note: expected type `usize` = note: expected type `usize`
found reference `&_` found reference `&_`
help: consider removing the borrow
|
LL | [(); { loop { continue } } ];
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-52443.rs:4:17 --> $DIR/issue-52443.rs:4:17

View file

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/occurs-check-2.rs:7:9 --> $DIR/occurs-check-2.rs:7:9
| |
LL | f = box g; LL | f = box g;
| ^^^^^ | ^^^^^ cyclic type of infinite size
| | |
| cyclic type of infinite size help: try using a conversion method
| help: try using a conversion method: `(box g).to_string()` |
LL | f = (box g).to_string();
| ^ ^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/occurs-check.rs:5:9 --> $DIR/occurs-check.rs:5:9
| |
LL | f = box f; LL | f = box f;
| ^^^^^ | ^^^^^ cyclic type of infinite size
| | |
| cyclic type of infinite size help: try using a conversion method
| help: try using a conversion method: `(box f).to_string()` |
LL | f = (box f).to_string();
| ^ ^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -31,12 +31,15 @@ error[E0308]: mismatched types
| |
LL | fn foo(a: Option<u32>, b: Option<u32>) -> bool { LL | fn foo(a: Option<u32>, b: Option<u32>) -> bool {
| ---- expected `bool` because of return type | ---- expected `bool` because of return type
LL | if let Some(x) = a { true } else { false }
| ------------------------------------------ help: parentheses are required to parse this as an expression: `(if let Some(x) = a { true } else { false })`
... ...
LL | / && LL | / &&
LL | | if let Some(y) = a { true } else { false } LL | | if let Some(y) = a { true } else { false }
| |______________________________________________^ expected `bool`, found `&&bool` | |______________________________________________^ expected `bool`, found `&&bool`
|
help: parentheses are required to parse this as an expression
|
LL | (if let Some(x) = a { true } else { false })
| ^ ^
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -2,25 +2,34 @@ error: expected expression, found `+`
--> $DIR/expr-as-stmt.rs:8:9 --> $DIR/expr-as-stmt.rs:8:9
| |
LL | {2} + {2} LL | {2} + {2}
| --- ^ expected expression | ^ expected expression
| | |
| help: parentheses are required to parse this as an expression: `({2})` help: parentheses are required to parse this as an expression
|
LL | ({2}) + {2}
| ^ ^
error: expected expression, found `+` error: expected expression, found `+`
--> $DIR/expr-as-stmt.rs:13:9 --> $DIR/expr-as-stmt.rs:13:9
| |
LL | {2} + 2 LL | {2} + 2
| --- ^ expected expression | ^ expected expression
| | |
| help: parentheses are required to parse this as an expression: `({2})` help: parentheses are required to parse this as an expression
|
LL | ({2}) + 2
| ^ ^
error: expected expression, found `+` error: expected expression, found `+`
--> $DIR/expr-as-stmt.rs:19:12 --> $DIR/expr-as-stmt.rs:19:12
| |
LL | { 42 } + foo; LL | { 42 } + foo;
| ------ ^ expected expression | ^ expected expression
| | |
| help: parentheses are required to parse this as an expression: `({ 42 })` help: parentheses are required to parse this as an expression
|
LL | ({ 42 }) + foo;
| ^ ^
error: expected expression, found `>` error: expected expression, found `>`
--> $DIR/expr-as-stmt.rs:32:7 --> $DIR/expr-as-stmt.rs:32:7
@ -83,9 +92,12 @@ error[E0614]: type `{integer}` cannot be dereferenced
--> $DIR/expr-as-stmt.rs:25:11 --> $DIR/expr-as-stmt.rs:25:11
| |
LL | { 3 } * 3 LL | { 3 } * 3
| ----- ^^^ | ^^^
| | |
| help: parentheses are required to parse this as an expression: `({ 3 })` help: parentheses are required to parse this as an expression
|
LL | ({ 3 }) * 3
| ^ ^
error: aborting due to 9 previous errors error: aborting due to 9 previous errors

View file

@ -14,7 +14,7 @@ LL | WrapB::new().set(|t: bool| if t { x } else { y }) // (separate erro
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`) LL | WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-big.rs:67:26 --> $DIR/region-borrow-params-issue-29793-big.rs:67:26
@ -32,7 +32,7 @@ LL | WrapB::new().set(|t: bool| if t { x } else { y }) // (separate erro
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`) LL | WrapB::new().set(move |t: bool| if t { x } else { y }) // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -14,7 +14,7 @@ LL | return f;
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:9:17 --> $DIR/region-borrow-params-issue-29793-small.rs:9:17
@ -32,7 +32,7 @@ LL | return f;
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:24:17 --> $DIR/region-borrow-params-issue-29793-small.rs:24:17
@ -50,7 +50,7 @@ LL | f
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:24:17 --> $DIR/region-borrow-params-issue-29793-small.rs:24:17
@ -68,7 +68,7 @@ LL | f
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:55:17 --> $DIR/region-borrow-params-issue-29793-small.rs:55:17
@ -86,7 +86,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:55:17 --> $DIR/region-borrow-params-issue-29793-small.rs:55:17
@ -104,7 +104,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:66:17 --> $DIR/region-borrow-params-issue-29793-small.rs:66:17
@ -122,7 +122,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:66:17 --> $DIR/region-borrow-params-issue-29793-small.rs:66:17
@ -140,7 +140,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:90:21 --> $DIR/region-borrow-params-issue-29793-small.rs:90:21
@ -158,7 +158,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:90:21 --> $DIR/region-borrow-params-issue-29793-small.rs:90:21
@ -176,7 +176,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:104:21 --> $DIR/region-borrow-params-issue-29793-small.rs:104:21
@ -194,7 +194,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:104:21 --> $DIR/region-borrow-params-issue-29793-small.rs:104:21
@ -212,7 +212,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:132:21 --> $DIR/region-borrow-params-issue-29793-small.rs:132:21
@ -230,7 +230,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:132:21 --> $DIR/region-borrow-params-issue-29793-small.rs:132:21
@ -248,7 +248,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:147:21 --> $DIR/region-borrow-params-issue-29793-small.rs:147:21
@ -266,7 +266,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:147:21 --> $DIR/region-borrow-params-issue-29793-small.rs:147:21
@ -284,7 +284,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:175:21 --> $DIR/region-borrow-params-issue-29793-small.rs:175:21
@ -302,7 +302,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:175:21 --> $DIR/region-borrow-params-issue-29793-small.rs:175:21
@ -320,7 +320,7 @@ LL | return Box::new(f);
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:189:21 --> $DIR/region-borrow-params-issue-29793-small.rs:189:21
@ -338,7 +338,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function error[E0373]: closure may outlive the current function, but it borrows `y`, which is owned by the current function
--> $DIR/region-borrow-params-issue-29793-small.rs:189:21 --> $DIR/region-borrow-params-issue-29793-small.rs:189:21
@ -356,7 +356,7 @@ LL | Box::new(f)
help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword help: to force the closure to take ownership of `y` (and any other referenced variables), use the `move` keyword
| |
LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`) LL | let f = move |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
| ^^^^^^^^^^^^^^ | ^^^^
error: aborting due to 20 previous errors error: aborting due to 20 previous errors

View file

@ -478,10 +478,12 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:32:8 --> $DIR/disallowed-positions.rs:32:8
| |
LL | if &let 0 = 0 {} LL | if &let 0 = 0 {}
| ^^^^^^^^^^ | ^^^^^^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider removing the borrow
| help: consider removing the borrow: `let 0 = 0` |
LL | if let 0 = 0 {}
| --
error[E0614]: type `bool` cannot be dereferenced error[E0614]: type `bool` cannot be dereferenced
--> $DIR/disallowed-positions.rs:36:8 --> $DIR/disallowed-positions.rs:36:8
@ -678,10 +680,12 @@ error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:96:11 --> $DIR/disallowed-positions.rs:96:11
| |
LL | while &let 0 = 0 {} LL | while &let 0 = 0 {}
| ^^^^^^^^^^ | ^^^^^^^^^^ expected `bool`, found `&bool`
| | |
| expected `bool`, found `&bool` help: consider removing the borrow
| help: consider removing the borrow: `let 0 = 0` |
LL | while let 0 = 0 {}
| --
error[E0614]: type `bool` cannot be dereferenced error[E0614]: type `bool` cannot be dereferenced
--> $DIR/disallowed-positions.rs:100:11 --> $DIR/disallowed-positions.rs:100:11

View file

@ -38,10 +38,12 @@ error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:17:9 --> $DIR/coerce-suggestions.rs:17:9
| |
LL | f = box f; LL | f = box f;
| ^^^^^ | ^^^^^ cyclic type of infinite size
| | |
| cyclic type of infinite size help: try using a conversion method
| help: try using a conversion method: `(box f).to_string()` |
LL | f = (box f).to_string();
| ^ ^^^^^^^^^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:21:9 --> $DIR/coerce-suggestions.rs:21:9

View file

@ -2,10 +2,9 @@ error[E0308]: mismatched types
--> $DIR/bad-const-type.rs:1:20 --> $DIR/bad-const-type.rs:1:20
| |
LL | static i: String = 10; LL | static i: String = 10;
| ^^ | ^^- help: try using a conversion method: `.to_string()`
| | | |
| expected struct `String`, found integer | expected struct `String`, found integer
| help: try using a conversion method: `10.to_string()`
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,40 +2,46 @@ error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:2:20 --> $DIR/str-lit-type-mismatch.rs:2:20
| |
LL | let x: &[u8] = "foo"; LL | let x: &[u8] = "foo";
| ----- ^^^^^ | ----- ^^^^^ expected slice `[u8]`, found `str`
| | | | |
| | expected slice `[u8]`, found `str`
| | help: consider adding a leading `b`: `b"foo"`
| expected due to this | expected due to this
| |
= note: expected reference `&[u8]` = note: expected reference `&[u8]`
found reference `&'static str` found reference `&'static str`
help: consider adding a leading `b`
|
LL | let x: &[u8] = b"foo";
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:3:23 --> $DIR/str-lit-type-mismatch.rs:3:23
| |
LL | let y: &[u8; 4] = "baaa"; LL | let y: &[u8; 4] = "baaa";
| -------- ^^^^^^ | -------- ^^^^^^ expected array `[u8; 4]`, found `str`
| | | | |
| | expected array `[u8; 4]`, found `str`
| | help: consider adding a leading `b`: `b"baaa"`
| expected due to this | expected due to this
| |
= note: expected reference `&[u8; 4]` = note: expected reference `&[u8; 4]`
found reference `&'static str` found reference `&'static str`
help: consider adding a leading `b`
|
LL | let y: &[u8; 4] = b"baaa";
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:4:19 --> $DIR/str-lit-type-mismatch.rs:4:19
| |
LL | let z: &str = b"foo"; LL | let z: &str = b"foo";
| ---- ^^^^^^ | ---- ^^^^^^ expected `str`, found array `[u8; 3]`
| | | | |
| | expected `str`, found array `[u8; 3]`
| | help: consider removing the leading `b`: `"foo"`
| expected due to this | expected due to this
| |
= note: expected reference `&str` = note: expected reference `&str`
found reference `&'static [u8; 3]` found reference `&'static [u8; 3]`
help: consider removing the leading `b`
|
LL | let z: &str = "foo";
| --
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -5,13 +5,14 @@ LL | fn foo<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static,
| - this type parameter ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type | - this type parameter ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type
LL | // We could instead use an `async` block, but this way we have no std spans. LL | // We could instead use an `async` block, but this way we have no std spans.
LL | x LL | x
| ^ | ^ expected struct `Pin`, found type parameter `F`
| |
| expected struct `Pin`, found type parameter `F`
| help: you need to pin and box this expression: `Box::pin(x)`
| |
= note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` = note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
found type parameter `F` found type parameter `F`
help: you need to pin and box this expression
|
LL | Box::pin(x)
| ^^^^^^^^^ ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/expected-boxed-future-isnt-pinned.rs:18:5 --> $DIR/expected-boxed-future-isnt-pinned.rs:18:5
@ -31,14 +32,15 @@ error[E0308]: mismatched types
LL | fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> { LL | fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
| - this type parameter | - this type parameter
LL | Pin::new(x) LL | Pin::new(x)
| ^ | ^ expected struct `Box`, found type parameter `F`
| |
| expected struct `Box`, found type parameter `F`
| help: store this in the heap by calling `Box::new`: `Box::new(x)`
| |
= note: expected struct `Box<dyn Future<Output = i32> + Send>` = note: expected struct `Box<dyn Future<Output = i32> + Send>`
found type parameter `F` found type parameter `F`
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
help: store this in the heap by calling `Box::new`
|
LL | Pin::new(Box::new(x))
| ^^^^^^^^^ ^
error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
--> $DIR/expected-boxed-future-isnt-pinned.rs:22:5 --> $DIR/expected-boxed-future-isnt-pinned.rs:22:5

View file

@ -2,41 +2,53 @@ error[E0308]: mismatched types
--> $DIR/format-borrow.rs:2:21 --> $DIR/format-borrow.rs:2:21
| |
LL | let a: String = &String::from("a"); LL | let a: String = &String::from("a");
| ------ ^^^^^^^^^^^^^^^^^^ | ------ ^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&String`
| | | | |
| | expected struct `String`, found `&String`
| | help: consider removing the borrow: `String::from("a")`
| expected due to this | expected due to this
|
help: consider removing the borrow
|
LL | let a: String = String::from("a");
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/format-borrow.rs:4:21 --> $DIR/format-borrow.rs:4:21
| |
LL | let b: String = &format!("b"); LL | let b: String = &format!("b");
| ------ ^^^^^^^^^^^^^ | ------ ^^^^^^^^^^^^^ expected struct `String`, found `&String`
| | | | |
| | expected struct `String`, found `&String`
| | help: consider removing the borrow: `format!("b")`
| expected due to this | expected due to this
|
help: consider removing the borrow
|
LL | let b: String = format!("b");
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/format-borrow.rs:6:21 --> $DIR/format-borrow.rs:6:21
| |
LL | let c: String = &mut format!("c"); LL | let c: String = &mut format!("c");
| ------ ^^^^^^^^^^^^^^^^^ | ------ ^^^^^^^^^^^^^^^^^ expected struct `String`, found `&mut String`
| | | | |
| | expected struct `String`, found `&mut String`
| | help: consider removing the borrow: `format!("c")`
| expected due to this | expected due to this
|
help: consider removing the borrow
|
LL | let c: String = format!("c");
| --
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/format-borrow.rs:8:21 --> $DIR/format-borrow.rs:8:21
| |
LL | let d: String = &mut (format!("d")); LL | let d: String = &mut (format!("d"));
| ------ ^^^^^^^^^^^^^^^^^^^ | ------ ^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&mut String`
| | | | |
| | expected struct `String`, found `&mut String`
| | help: consider removing the borrow: `format!("d")`
| expected due to this | expected due to this
|
help: consider removing the borrow
|
LL | let d: String = format!("d"));
| --
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/issue-52820.rs:9:9 --> $DIR/issue-52820.rs:9:9
| |
LL | guts, LL | guts,
| ^^^^ | ^^^^ expected struct `String`, found `&str`
| | |
| expected struct `String`, found `&str` help: try using a conversion method
| help: try using a conversion method: `guts: guts.to_string()` |
LL | guts: guts.to_string(),
| ^^^^^ ^^^^^^^^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-52820.rs:10:17 --> $DIR/issue-52820.rs:10:17

View file

@ -2,30 +2,35 @@ error[E0308]: mismatched types
--> $DIR/issue-59819.rs:28:18 --> $DIR/issue-59819.rs:28:18
| |
LL | let y: i32 = x; LL | let y: i32 = x;
| --- ^ | --- ^ expected `i32`, found struct `Foo`
| | | | |
| | expected `i32`, found struct `Foo`
| | help: consider dereferencing the type: `*x`
| expected due to this | expected due to this
|
help: consider dereferencing the type
|
LL | let y: i32 = *x;
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-59819.rs:30:18 --> $DIR/issue-59819.rs:30:18
| |
LL | let b: i32 = a; LL | let b: i32 = a;
| --- ^ | --- ^ expected `i32`, found `&{integer}`
| | | | |
| | expected `i32`, found `&{integer}`
| | help: consider dereferencing the borrow: `*a`
| expected due to this | expected due to this
|
help: consider dereferencing the borrow
|
LL | let b: i32 = *a;
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-59819.rs:34:21 --> $DIR/issue-59819.rs:34:21
| |
LL | let g: String = f; LL | let g: String = f;
| ------ ^ | ------ ^- help: try using a conversion method: `.to_string()`
| | | | | |
| | expected struct `String`, found struct `Bar` | | expected struct `String`, found struct `Bar`
| | help: try using a conversion method: `f.to_string()`
| expected due to this | expected due to this
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -6,12 +6,14 @@ LL | | a
| | - expected because of this | | - expected because of this
LL | | } else { LL | | } else {
LL | | b LL | | b
| | ^ | | ^ expected `usize`, found `&usize`
| | |
| | expected `usize`, found `&usize`
| | help: consider dereferencing the borrow: `*b`
LL | | }; LL | | };
| |_____- `if` and `else` have incompatible types | |_____- `if` and `else` have incompatible types
|
help: consider dereferencing the borrow
|
LL | *b
| ^
error[E0308]: `if` and `else` have incompatible types error[E0308]: `if` and `else` have incompatible types
--> $DIR/issue-82361.rs:16:9 --> $DIR/issue-82361.rs:16:9
@ -21,12 +23,14 @@ LL | | 1
| | - expected because of this | | - expected because of this
LL | | } else { LL | | } else {
LL | | &1 LL | | &1
| | ^^ | | ^^ expected integer, found `&{integer}`
| | |
| | expected integer, found `&{integer}`
| | help: consider removing the borrow: `1`
LL | | }; LL | | };
| |_____- `if` and `else` have incompatible types | |_____- `if` and `else` have incompatible types
|
help: consider removing the borrow
|
LL | 1
| --
error[E0308]: `if` and `else` have incompatible types error[E0308]: `if` and `else` have incompatible types
--> $DIR/issue-82361.rs:22:9 --> $DIR/issue-82361.rs:22:9
@ -36,12 +40,14 @@ LL | | 1
| | - expected because of this | | - expected because of this
LL | | } else { LL | | } else {
LL | | &mut 1 LL | | &mut 1
| | ^^^^^^ | | ^^^^^^ expected integer, found `&mut {integer}`
| | |
| | expected integer, found `&mut {integer}`
| | help: consider removing the borrow: `1`
LL | | }; LL | | };
| |_____- `if` and `else` have incompatible types | |_____- `if` and `else` have incompatible types
|
help: consider removing the borrow
|
LL | 1
| --
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -6,10 +6,9 @@ LL | | "A".to_string()
| | --------------- expected because of this | | --------------- expected because of this
LL | | } else { LL | | } else {
LL | | "B" LL | | "B"
| | ^^^ | | ^^^- help: try using a conversion method: `.to_string()`
| | | | | |
| | expected struct `String`, found `&str` | | expected struct `String`, found `&str`
| | help: try using a conversion method: `"B".to_string()`
LL | | }; LL | | };
| |_____- `if` and `else` have incompatible types | |_____- `if` and `else` have incompatible types

View file

@ -9,7 +9,7 @@ LL | opt = None;
help: consider dereferencing here to assign to the mutable borrowed piece of memory help: consider dereferencing here to assign to the mutable borrowed piece of memory
| |
LL | *opt = None; LL | *opt = None;
| ^^^^ | ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:6:11 --> $DIR/mut-ref-reassignment.rs:6:11
@ -31,7 +31,7 @@ LL | opt = Some(String::new())
help: consider dereferencing here to assign to the mutable borrowed piece of memory help: consider dereferencing here to assign to the mutable borrowed piece of memory
| |
LL | *opt = Some(String::new()) LL | *opt = Some(String::new())
| ^^^^ | ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/mut-ref-reassignment.rs:14:11 --> $DIR/mut-ref-reassignment.rs:14:11

View file

@ -2,44 +2,43 @@ error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:5:41 --> $DIR/conversion-methods.rs:5:41
| |
LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—"; LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—";
| ------ ^^^^^^^^^^^^^^^^^^^^^ | ------ ^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
| | | | | |
| | expected struct `String`, found `&str` | | expected struct `String`, found `&str`
| | help: try using a conversion method: `"'Tis a fond Ambush—".to_string()`
| expected due to this | expected due to this
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:6:40 --> $DIR/conversion-methods.rs:6:40
| |
LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise");
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_path_buf()`
| | | | | |
| | expected struct `PathBuf`, found `&Path` | | expected struct `PathBuf`, found `&Path`
| | help: try using a conversion method: `Path::new("/ern/her/own/surprise").to_path_buf()`
| expected due to this | expected due to this
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:9:40 --> $DIR/conversion-methods.rs:9:40
| |
LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here
| ------ ^ | ------ ^- help: try using a conversion method: `.to_string()`
| | | | | |
| | expected struct `String`, found integer | | expected struct `String`, found integer
| | help: try using a conversion method: `2.to_string()`
| expected due to this | expected due to this
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/conversion-methods.rs:12:47 --> $DIR/conversion-methods.rs:12:47
| |
LL | let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3]; LL | let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3];
| ---------- ^^^^^^^^^^ | ---------- ^^^^^^^^^^ expected struct `Vec`, found `&[{integer}; 3]`
| | | | |
| | expected struct `Vec`, found `&[{integer}; 3]`
| | help: try using a conversion method: `(&[1, 2, 3]).to_vec()`
| expected due to this | expected due to this
| |
= note: expected struct `Vec<usize>` = note: expected struct `Vec<usize>`
found reference `&[{integer}; 3]` found reference `&[{integer}; 3]`
help: try using a conversion method
|
LL | let _prove_piercing_earnest: Vec<usize> = (&[1, 2, 3]).to_vec();
| ^ ^^^^^^^^^^
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -25,10 +25,12 @@ error[E0308]: mismatched types
--> $DIR/ice-6250.rs:12:14 --> $DIR/ice-6250.rs:12:14
| |
LL | Some(reference) = cache.data.get(key) { LL | Some(reference) = cache.data.get(key) {
| ^^^^^^^^^ | ^^^^^^^^^ expected integer, found `&i32`
| | |
| expected integer, found `&i32` help: consider dereferencing the borrow
| help: consider dereferencing the borrow: `*reference` |
LL | Some(*reference) = cache.data.get(key) {
| ^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/ice-6250.rs:12:9 --> $DIR/ice-6250.rs:12:9