-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E0034: provide disambiguated syntax for candidates #38168
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
Seems good to me. I'll just wait for someone else's opinion. |
@@ -70,7 +70,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
rcvr_ty: Ty<'tcx>, | |||
item_name: ast::Name, | |||
rcvr_expr: Option<&hir::Expr>, | |||
error: MethodError<'tcx>) { | |||
error: MethodError<'tcx>, | |||
args: Option<&'gcx [hir::Expr]>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the None
case here, could you pass an empty slice, and then not require Option<...>
? If not, you should add a comment, explaining when and why to use None
.
@@ -130,6 +131,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
"candidate #{} is defined in the trait `{}`", | |||
idx + 1, | |||
self.tcx.item_path_str(trait_did)); | |||
err.span_help(span, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this a non-span help, since the span is already part of the error, I don't think it is necessary to show the span twice.
&format!("to use it here write `{}::{}({}{})` instead", | ||
self.tcx.item_path_str(trait_did), | ||
item_name, | ||
if rcvr_ty.is_region_ptr() { "&" } else { "" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to check for &mut
here?
@@ -4075,7 +4079,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
_ => Def::Err, | |||
}; | |||
if item_name != keywords::Invalid.name() { | |||
self.report_method_error(span, ty, item_name, None, error); | |||
self.report_method_error(span, ty, item_name, None, error, None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there no args here? Is it just that we don't have access to them, or are they inappropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the former, then I'd prefer to output foo(...)
rather than foo()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the former, then I'd prefer to output foo(...) rather than foo()
This is the case now.
@@ -130,6 +131,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
"candidate #{} is defined in the trait `{}`", | |||
idx + 1, | |||
self.tcx.item_path_str(trait_did)); | |||
err.span_help(span, | |||
&format!("to use it here write `{}::{}({}{})` instead", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the text to "to disambiguate the method call, write ...
"
@@ -1088,6 +1088,17 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { | |||
} | |||
} | |||
|
|||
pub fn is_mutable(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better named is_mutable_pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
6b5df90
to
e32f042
Compare
r=me, but failing tests |
For a given file ```rust trait A { fn foo(&self) {} } trait B : A { fn foo(&self) {} } fn bar<T: B>(a: &T) { a.foo() } ``` provide the following output ``` error[E0034]: multiple applicable items in scope --> file.rs:6:5 | 6 | a.foo(1) | ^^^ multiple `foo` found | note: candidate rust-lang#1 is defined in the trait `A` --> file.rs:2:11 | 2 | trait A { fn foo(&self, a: usize) {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to use it here write `A::foo(&a, 1)` instead --> file.rs:6:5 | 6 | a.foo(1) | ^^^ note: candidate rust-lang#2 is defined in the trait `B` --> file.rs:3:15 | 3 | trait B : A { fn foo(&self, a: usize) {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to use it here write `B::foo(&a, 1)` instead --> file.rs:6:5 | 6 | a.foo(1) | ^^^ ```
@nrc tests fixed after rebase/squash. |
@bors: r+ |
📌 Commit f595ea2 has been approved by |
E0034: provide disambiguated syntax for candidates For a given file ```rust trait A { fn foo(&self) {} } trait B : A { fn foo(&self) {} } fn bar<T: B>(a: &T) { a.foo() } ``` provide the following output ``` error[E0034]: multiple applicable items in scope --> file.rs:6:5 | 6 | a.foo(1) | ^^^ multiple `foo` found | note: candidate #1 is defined in the trait `A` --> file.rs:2:11 | 2 | trait A { fn foo(&self, a: usize) {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to use it here write `A::foo(&a, 1)` instead --> file.rs:6:5 | 6 | a.foo(1) | ^^^ note: candidate #2 is defined in the trait `B` --> file.rs:3:15 | 3 | trait B : A { fn foo(&self, a: usize) {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to use it here write `B::foo(&a, 1)` instead --> file.rs:6:5 | 6 | a.foo(1) | ^^^ ``` Fix #37767.
☀️ Test successful - status-appveyor, status-travis |
For a given file
provide the following output
Fix #37767.