Skip to content

Commit e70d888

Browse files
committed
Use def span for associated function suggestions
1 parent b39c4bc commit e70d888

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/librustc_typeck/check/method/suggest.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
122122
impl_ty);
123123
if let Some(note_span) = note_span {
124124
// We have a span pointing to the method. Show note with snippet.
125-
err.span_note(note_span, &note_str);
125+
err.span_note(self.tcx.sess.codemap().def_span(note_span), &note_str);
126126
} else {
127127
err.note(&note_str);
128128
}
@@ -131,7 +131,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
131131
let item = self
132132
.associated_item(trait_did, item_name, Namespace::Value)
133133
.unwrap();
134-
let item_span = self.tcx.def_span(item.def_id);
134+
let item_span = self.tcx.sess.codemap()
135+
.def_span(self.tcx.def_span(item.def_id));
135136
span_note!(err,
136137
item_span,
137138
"candidate #{} is defined in the trait `{}`",

src/test/ui/span/issue-37767.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ note: candidate #1 is defined in the trait `A`
88
--> $DIR/issue-37767.rs:12:5
99
|
1010
12 | fn foo(&mut self) {}
11-
| ^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^
1212
= help: to disambiguate the method call, write `A::foo(&a)` instead
1313
note: candidate #2 is defined in the trait `B`
1414
--> $DIR/issue-37767.rs:16:5
1515
|
1616
16 | fn foo(&mut self) {}
17-
| ^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^^^^^^^^
1818
= help: to disambiguate the method call, write `B::foo(&a)` instead
1919

2020
error[E0034]: multiple applicable items in scope
@@ -27,13 +27,13 @@ note: candidate #1 is defined in the trait `C`
2727
--> $DIR/issue-37767.rs:24:5
2828
|
2929
24 | fn foo(&self) {}
30-
| ^^^^^^^^^^^^^^^^
30+
| ^^^^^^^^^^^^^
3131
= help: to disambiguate the method call, write `C::foo(&a)` instead
3232
note: candidate #2 is defined in the trait `D`
3333
--> $DIR/issue-37767.rs:28:5
3434
|
3535
28 | fn foo(&self) {}
36-
| ^^^^^^^^^^^^^^^^
36+
| ^^^^^^^^^^^^^
3737
= help: to disambiguate the method call, write `D::foo(&a)` instead
3838

3939
error[E0034]: multiple applicable items in scope
@@ -46,13 +46,13 @@ note: candidate #1 is defined in the trait `E`
4646
--> $DIR/issue-37767.rs:36:5
4747
|
4848
36 | fn foo(self) {}
49-
| ^^^^^^^^^^^^^^^
49+
| ^^^^^^^^^^^^
5050
= help: to disambiguate the method call, write `E::foo(a)` instead
5151
note: candidate #2 is defined in the trait `F`
5252
--> $DIR/issue-37767.rs:40:5
5353
|
5454
40 | fn foo(self) {}
55-
| ^^^^^^^^^^^^^^^
55+
| ^^^^^^^^^^^^
5656
= help: to disambiguate the method call, write `F::foo(a)` instead
5757

5858
error: aborting due to 3 previous errors

src/test/ui/span/issue-7575.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ error[E0599]: no method named `fff` found for type `Myisize` in the current scop
4444
note: candidate #1 is defined in an impl for the type `Myisize`
4545
--> $DIR/issue-7575.rs:51:5
4646
|
47-
51 | / fn fff(i: isize) -> isize {
48-
52 | | i
49-
53 | | }
50-
| |_____^
47+
51 | fn fff(i: isize) -> isize {
48+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5149

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

0 commit comments

Comments
 (0)