Skip to content

Use def span for associated function suggestions #46860

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

Merged
merged 1 commit into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
impl_ty);
if let Some(note_span) = note_span {
// We have a span pointing to the method. Show note with snippet.
err.span_note(note_span, &note_str);
err.span_note(self.tcx.sess.codemap().def_span(note_span), &note_str);
} else {
err.note(&note_str);
}
Expand All @@ -131,7 +131,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let item = self
.associated_item(trait_did, item_name, Namespace::Value)
.unwrap();
let item_span = self.tcx.def_span(item.def_id);
let item_span = self.tcx.sess.codemap()
.def_span(self.tcx.def_span(item.def_id));
span_note!(err,
item_span,
"candidate #{} is defined in the trait `{}`",
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/span/issue-37767.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ note: candidate #1 is defined in the trait `A`
--> $DIR/issue-37767.rs:12:5
|
12 | fn foo(&mut self) {}
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
= help: to disambiguate the method call, write `A::foo(&a)` instead
note: candidate #2 is defined in the trait `B`
--> $DIR/issue-37767.rs:16:5
|
16 | fn foo(&mut self) {}
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
= help: to disambiguate the method call, write `B::foo(&a)` instead

error[E0034]: multiple applicable items in scope
Expand All @@ -27,13 +27,13 @@ note: candidate #1 is defined in the trait `C`
--> $DIR/issue-37767.rs:24:5
|
24 | fn foo(&self) {}
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^
= help: to disambiguate the method call, write `C::foo(&a)` instead
note: candidate #2 is defined in the trait `D`
--> $DIR/issue-37767.rs:28:5
|
28 | fn foo(&self) {}
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^
= help: to disambiguate the method call, write `D::foo(&a)` instead

error[E0034]: multiple applicable items in scope
Expand All @@ -46,13 +46,13 @@ note: candidate #1 is defined in the trait `E`
--> $DIR/issue-37767.rs:36:5
|
36 | fn foo(self) {}
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
= help: to disambiguate the method call, write `E::foo(a)` instead
note: candidate #2 is defined in the trait `F`
--> $DIR/issue-37767.rs:40:5
|
40 | fn foo(self) {}
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
= help: to disambiguate the method call, write `F::foo(a)` instead

error: aborting due to 3 previous errors
Expand Down
12 changes: 4 additions & 8 deletions src/test/ui/span/issue-7575.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ error[E0599]: no method named `fff` found for type `Myisize` in the current scop
note: candidate #1 is defined in an impl for the type `Myisize`
--> $DIR/issue-7575.rs:51:5
|
51 | / fn fff(i: isize) -> isize {
52 | | i
53 | | }
| |_____^
51 | fn fff(i: isize) -> isize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `is_str` found for type `T` in the current scope
--> $DIR/issue-7575.rs:82:7
Expand All @@ -60,10 +58,8 @@ error[E0599]: no method named `is_str` found for type `T` in the current scope
note: candidate #1 is defined in the trait `ManyImplTrait`
--> $DIR/issue-7575.rs:57:5
|
57 | / fn is_str() -> bool {
58 | | false
59 | | }
| |_____^
57 | fn is_str() -> bool {
| ^^^^^^^^^^^^^^^^^^^
= help: to disambiguate the method call, write `ManyImplTrait::is_str(t)` instead
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `is_str`, perhaps you need to implement it:
Expand Down