Skip to content

Commit 14277ef

Browse files
committed
Better account for associated const found for fn call expr
1 parent 7688567 commit 14277ef

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14211421
),
14221422
);
14231423
}
1424-
} else if let Mode::Path = mode {
1424+
} else if let Mode::Path = mode
1425+
&& args.unwrap_or(&[]).is_empty()
1426+
{
14251427
// We have an associated item syntax and we found something that isn't an fn.
14261428
err.span_suggestion_verbose(
14271429
span,

tests/ui/traits/item-privacy.stderr

+10-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ LL | S::a(&S);
5858
| ^ function or associated item not found in `S`
5959
|
6060
= help: items from traits can only be used if the trait is implemented and in scope
61+
help: there is an associated constant `B` with a similar name
62+
--> $DIR/item-privacy.rs:29:9
63+
|
64+
LL | const B: u8 = 0;
65+
| ^^^^^^^^^^^
6166
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
6267
|
6368
LL + use method::A;
6469
|
65-
help: there is an associated constant with a similar name
66-
|
67-
LL | S::B(&S);
68-
| ~
6970

7071
error[E0599]: no function or associated item named `b` found for struct `S` in the current scope
7172
--> $DIR/item-privacy.rs:80:8
@@ -77,14 +78,15 @@ LL | S::b(&S);
7778
| ^ function or associated item not found in `S`
7879
|
7980
= help: items from traits can only be used if the trait is in scope
81+
help: there is an associated constant `B` with a similar name
82+
--> $DIR/item-privacy.rs:29:9
83+
|
84+
LL | const B: u8 = 0;
85+
| ^^^^^^^^^^^
8086
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
8187
|
8288
LL + use method::B;
8389
|
84-
help: there is an associated constant with a similar name
85-
|
86-
LL | S::B(&S);
87-
| ~
8890

8991
error[E0624]: method `a` is private
9092
--> $DIR/item-privacy.rs:84:14

0 commit comments

Comments
 (0)