Skip to content
Permalink
Browse files

Do not suggest incorrect syntax on pattern borrow error

  • Loading branch information...
estebank committed Apr 30, 2019
1 parent a55c2eb commit 0e7e9382fa1a6e50c976cd74ca420d7cb10591fa
@@ -378,12 +378,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// `fn foo(foo: &u32)`
if let Some(mut err) = err {
if let PatKind::Binding(..) = inner.node {
if let Ok(snippet) = tcx.sess.source_map()
.span_to_snippet(pat.span)
{
err.help(&format!("did you mean `{}: &{}`?",
&snippet[1..],
expected));
let parent_id = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
let parent = tcx.hir().get_by_hir_id(parent_id);
match parent {
hir::Node::Item(_) |
hir::Node::ForeignItem(_) |
hir::Node::TraitItem(_) |
hir::Node::ImplItem(_) => { // this pat is an argument
if let Ok(snippet) = tcx.sess.source_map()
.span_to_snippet(pat.span)
{ // FIXME: turn into structured suggestion, will need
// a span that also includes the the type.
err.help(&format!(
"did you mean `{}: &{}`?",
&snippet[1..],
expected,
));
}
}
_ => {} // don't provide the suggestion from above #55175
}
}
err.emit();
@@ -24,7 +24,6 @@ LL | let &&x = &1isize as &T;
|
= note: expected type `dyn T`
found type `&_`
= help: did you mean `x: &dyn T`?

error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:36:11
@@ -34,7 +33,6 @@ LL | let &&&x = &(&1isize as &T);
|
= note: expected type `dyn T`
found type `&_`
= help: did you mean `x: &dyn T`?

error[E0308]: mismatched types
--> $DIR/destructure-trait-ref.rs:41:13
@@ -16,7 +16,6 @@ LL | fn agh(&&bar: &u32) {
|
= note: expected type `u32`
found type `&_`
= help: did you mean `bar: &u32`?

error[E0308]: mismatched types
--> $DIR/issue-38371.rs:21:8

0 comments on commit 0e7e938

Please sign in to comment.
You can’t perform that action at this time.