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 rust-lang/rust#142473
This commit is contained in:
commit
4bf7765388
4 changed files with 60 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
22
tests/ui/associated-types/associated-type-call.fixed
Normal file
22
tests/ui/associated-types/associated-type-call.fixed
Normal file
|
|
@ -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
tests/ui/associated-types/associated-type-call.rs
Normal file
22
tests/ui/associated-types/associated-type-call.rs
Normal file
|
|
@ -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
tests/ui/associated-types/associated-type-call.stderr
Normal file
15
tests/ui/associated-types/associated-type-call.stderr
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue