Skip to content

Commit 48184ab

Browse files
Rollup merge of #164695 - estebank:type-err-trait-context, r=oli-obk
[tiny] Include trait definition line when pointing at assoc function in E0308 ``` error[E0308]: mismatched types --> $DIR/too-long.rs:37:28 | LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l); | --- ^ expected `i32`, found `&i32` | | | arguments to this method are incorrect | note: method defined here --> $DIR/too-long.rs:4:8 | LL | impl Qux { LL | fn foo( | ^^^ ... LL | f: i32, | ------ help: consider dereferencing the borrow | LL | qux.foo(a, b, c, d, e, *f, g, h, i, j, k, l); | + ```
2 parents ec4833c + 9d5ab1d commit 48184ab

49 files changed

Lines changed: 296 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19111911
}
19121912
}
19131913
}
1914+
let def_kind = self.tcx.def_kind(def_id);
1915+
if let DefKind::AssocFn = def_kind {
1916+
spans.push_span_context(self.tcx.def_span(self.tcx.parent(def_id)).shrink_to_lo());
1917+
}
19141918
err.span_note(spans, format!("{} defined here", self.tcx.def_descr(def_id)));
1915-
if let DefKind::Fn | DefKind::AssocFn = self.tcx.def_kind(def_id)
1919+
if let DefKind::Fn | DefKind::AssocFn = def_kind
19161920
&& let ty::Param(_) =
19171921
self.tcx.fn_sig(def_id).instantiate_identity().skip_binder().output().kind()
19181922
&& let parent = self.tcx.hir_get_parent_item(call_expr.hir_id).def_id

‎tests/ui/argument-suggestions/too-long.stderr‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l);
99
note: method defined here
1010
--> $DIR/too-long.rs:4:8
1111
|
12+
LL | impl Qux {
1213
LL | fn foo(
1314
| ^^^
1415
...

‎tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.svg‎

Lines changed: 14 additions & 12 deletions
Loading

‎tests/ui/associated-types/associated-type-projection-from-supertrait.stderr‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ LL | fn f() { ModelT.chip_paint(Blue); }
3737
note: method defined here
3838
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
3939
|
40+
LL | pub trait Car : Vehicle {
41+
LL | fn honk(&self) { }
4042
LL | fn chip_paint(&self, c: Self::Color) { }
4143
| ^^^^^^^^^^ --------------
4244

@@ -51,6 +53,8 @@ LL | fn g() { ModelU.chip_paint(Black); }
5153
note: method defined here
5254
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
5355
|
56+
LL | pub trait Car : Vehicle {
57+
LL | fn honk(&self) { }
5458
LL | fn chip_paint(&self, c: Self::Color) { }
5559
| ^^^^^^^^^^ --------------
5660

‎tests/ui/coercion/hr_alias_normalization_leaking_vars.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ LL | LendingIterator::for_each(&(), f);
2525
note: method defined here
2626
--> $DIR/hr_alias_normalization_leaking_vars.rs:28:8
2727
|
28+
LL | trait LendingIterator {
29+
LL | type Item<'q>;
2830
LL | fn for_each(&self, _f: Box<fn(Self::Item<'_>)>) {}
2931
| ^^^^^^^^ ---------------------------
3032

‎tests/ui/delegation/correct_body_owner_parent_found_in_diagnostics.stderr‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW
7777
note: method defined here
7878
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:13:8
7979
|
80+
LL | trait Trait {
8081
LL | fn foo(&self) -> u8 { 0 }
8182
| ^^^ -----
8283

@@ -106,6 +107,8 @@ LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW
106107
note: method defined here
107108
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:14:8
108109
|
110+
LL | trait Trait {
111+
LL | fn foo(&self) -> u8 { 0 }
109112
LL | fn bar(&self) -> u8 { 1 }
110113
| ^^^ -----
111114

@@ -135,6 +138,8 @@ LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW
135138
note: method defined here
136139
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:15:8
137140
|
141+
LL | trait Trait {
142+
...
138143
LL | fn meh(&self) -> u8 { 2 }
139144
| ^^^ -----
140145

‎tests/ui/delegation/delegation-first-arg.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ LL | reuse <S as Trait>::static_empty { self.0 }
7070
note: associated function defined here
7171
--> $DIR/delegation-first-arg.rs:8:8
7272
|
73+
LL | trait Trait: Sized {
74+
...
7375
LL | fn static_empty() {}
7476
| ^^^^^^^^^^^^
7577
help: remove the extra argument

‎tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ LL | reuse Trait::foo;
2020
note: method defined here
2121
--> $DIR/duplicate-definition-inside-trait-impl.rs:4:8
2222
|
23+
LL | trait Trait {
2324
LL | fn foo(&self) -> u32 { 0 }
2425
| ^^^ -----
2526
help: provide the argument

‎tests/ui/delegation/explicit-paths.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ LL | reuse <F as Trait>::foo1 { self }
4949
note: method defined here
5050
--> $DIR/explicit-paths.rs:5:8
5151
|
52+
LL | trait Trait {
5253
LL | fn foo1(&self, x: i32) -> i32 { x }
5354
| ^^^^ -----
5455

@@ -89,6 +90,7 @@ LL | reuse <S2 as Trait>::foo1;
8990
note: method defined here
9091
--> $DIR/explicit-paths.rs:5:8
9192
|
93+
LL | trait Trait {
9294
LL | fn foo1(&self, x: i32) -> i32 { x }
9395
| ^^^^ -----
9496

‎tests/ui/delegation/generics/infer-defaults.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ LL | W(S).bar(((), (), ()), &[1]);
3434
note: method defined here
3535
--> $DIR/infer-defaults.rs:71:12
3636
|
37+
LL | trait Trait<'a, X, Y, T = (), const N: usize = 2> {
38+
LL | fn foo(&self, t: (T, T, T), slice: &[usize; N]) {}
3739
LL | fn bar(&self, t: (T, T, T), slice: &[usize; N]) {}
3840
| ^^^ ------------------
3941

0 commit comments

Comments
 (0)