Skip to content

Commit 1022f60

Browse files
authored
Unrolled build for #142477
Rollup merge of #142477 - JonathanBrouwer:associated-type-suggestion, r=WaffleLapkin Fix incorrect suggestion when calling an associated type with a type anchor `sugg_span` here is the span of the call expression. That span here is the `<Self>::Assoc`, which is exactly what we need here (even though I would expect it to include the arguments, but I guess it doesn't) r? ``@WaffleLapkin`` One commit with failing tests and one that fixes it for reviewability closes #142473
2 parents 64033a4 + 1d036f4 commit 1022f60

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
724724
{
725725
let def_path = tcx.def_path_str(adt_def.did());
726726
err.span_suggestion(
727-
ty.span.to(item_ident.span),
727+
sugg_span,
728728
format!("to construct a value of type `{}`, use the explicit path", def_path),
729729
def_path,
730730
Applicability::MachineApplicable,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// issue: <https://github.com/rust-lang/rust/issues/142473>
2+
//
3+
//@ run-rustfix
4+
#![allow(unused)]
5+
struct T();
6+
7+
trait Trait {
8+
type Assoc;
9+
10+
fn f();
11+
}
12+
13+
impl Trait for () {
14+
type Assoc = T;
15+
16+
fn f() {
17+
T();
18+
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
19+
}
20+
}
21+
22+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// issue: <https://github.com/rust-lang/rust/issues/142473>
2+
//
3+
//@ run-rustfix
4+
#![allow(unused)]
5+
struct T();
6+
7+
trait Trait {
8+
type Assoc;
9+
10+
fn f();
11+
}
12+
13+
impl Trait for () {
14+
type Assoc = T;
15+
16+
fn f() {
17+
<Self>::Assoc();
18+
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
19+
}
20+
}
21+
22+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
2+
--> $DIR/associated-type-call.rs:17:17
3+
|
4+
LL | <Self>::Assoc();
5+
| ^^^^^ associated item not found in `()`
6+
|
7+
help: to construct a value of type `T`, use the explicit path
8+
|
9+
LL - <Self>::Assoc();
10+
LL + T();
11+
|
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)