Skip to content
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let def_path = tcx.def_path_str(adt_def.did());
err.span_suggestion(
ty.span.to(item_ident.span),
sugg_span,
format!("to construct a value of type `{}`, use the explicit path", def_path),
def_path,
Applicability::MachineApplicable,
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/associated-types/associated-type-call.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// issue: <https://github.com/rust-lang/rust/issues/142473>
//
//@ run-rustfix
#![allow(unused)]
struct T();

trait Trait {
type Assoc;

fn f();
}

impl Trait for () {
type Assoc = T;

fn f() {
T();
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
}
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/associated-types/associated-type-call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// issue: <https://github.com/rust-lang/rust/issues/142473>
//
//@ run-rustfix
#![allow(unused)]
struct T();

trait Trait {
type Assoc;

fn f();
}

impl Trait for () {
type Assoc = T;

fn f() {
<Self>::Assoc();
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
}
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/associated-types/associated-type-call.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
--> $DIR/associated-type-call.rs:17:17
|
LL | <Self>::Assoc();
| ^^^^^ associated item not found in `()`
|
help: to construct a value of type `T`, use the explicit path
|
LL - <Self>::Assoc();
LL + T();
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
Loading