Skip to content

Commit 39b3949

Browse files
committed
Do not emit suggestions to import assoc const or fn if import_trait_associated_function is not enabled
1 parent 2427364 commit 39b3949

28 files changed

+228
-444
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11831183
let in_module_is_extern = !in_module.def_id().is_local();
11841184
in_module.for_each_child(self, |this, ident, ns, name_binding| {
11851185
// avoid non-importable candidates
1186-
if !name_binding.is_importable() {
1186+
if !name_binding.is_importable()
1187+
// FIXME(import_trait_associated_functions): remove this when `import_trait_associated_functions` is stable
1188+
|| name_binding.is_assoc_const_or_fn()
1189+
&& !this.tcx.features().import_trait_associated_functions()
1190+
{
11871191
return;
11881192
}
11891193

compiler/rustc_resolve/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,8 @@ impl<'ra> NameBindingData<'ra> {
923923
!matches!(self.res(), Res::Def(DefKind::AssocTy, _))
924924
}
925925

926+
// FIXME(import_trait_associated_functions): associate `const` or `fn` are not importable unless
927+
// the feature `import_trait_associated_functions` is enable
926928
fn is_assoc_const_or_fn(&self) -> bool {
927929
matches!(self.res(), Res::Def(DefKind::AssocConst | DefKind::AssocFn, _))
928930
}

tests/ui/associated-type-bounds/return-type-notation/not-a-method.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ error[E0576]: cannot find function `method` in this scope
1515
|
1616
LL | method(..): Send,
1717
| ^^^^^^ not found in this scope
18-
|
19-
help: consider importing this associated function
20-
|
21-
LL + use Tr::method;
22-
|
2318

2419
error[E0412]: cannot find type `method` in this scope
2520
--> $DIR/not-a-method.rs:36:5

tests/ui/delegation/bad-resolve.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ error[E0425]: cannot find function `foo` in this scope
6262
|
6363
LL | reuse foo { &self.0 }
6464
| ^^^ not found in this scope
65-
|
66-
help: consider importing this associated function
67-
|
68-
LL + use Trait::foo;
69-
|
7065

7166
error[E0425]: cannot find function `foo2` in trait `Trait`
7267
--> $DIR/bad-resolve.rs:37:18

tests/ui/delegation/explicit-paths.stderr

+8-24
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,42 @@ error[E0425]: cannot find function `foo4` in `S`
2121
|
2222
LL | reuse S::foo4;
2323
| ^^^^ not found in `S`
24-
|
25-
note: associated function `trait_assoc_fn_to_other::Trait2::foo4` exists but is inaccessible
26-
--> $DIR/explicit-paths.rs:65:9
27-
|
28-
LL | reuse F::foo4 { &F }
29-
| ^^^^^^^^^^^^^ not accessible
3024

3125
error[E0425]: cannot find function `foo4` in `F`
3226
--> $DIR/explicit-paths.rs:38:18
3327
|
3428
LL | reuse F::foo4 { &self.0 }
3529
| ^^^^ not found in `F`
3630
|
37-
note: these items exist but are inaccessible
31+
note: function `fn_to_other::foo4` exists but is inaccessible
3832
--> $DIR/explicit-paths.rs:27:5
3933
|
4034
LL | reuse S::foo4;
41-
| ^^^^^^^^^^^^^^ `fn_to_other::foo4`: not accessible
42-
...
43-
LL | reuse F::foo4 { &F }
44-
| ^^^^^^^^^^^^^ `trait_assoc_fn_to_other::Trait2::foo4`: not accessible
35+
| ^^^^^^^^^^^^^^ not accessible
4536

4637
error[E0425]: cannot find function `foo4` in `F`
4738
--> $DIR/explicit-paths.rs:51:18
4839
|
4940
LL | reuse F::foo4 { &self.0 }
5041
| ^^^^ not found in `F`
5142
|
52-
note: these items exist but are inaccessible
43+
note: function `fn_to_other::foo4` exists but is inaccessible
5344
--> $DIR/explicit-paths.rs:27:5
5445
|
5546
LL | reuse S::foo4;
56-
| ^^^^^^^^^^^^^^ `fn_to_other::foo4`: not accessible
57-
...
58-
LL | reuse F::foo4 { &F }
59-
| ^^^^^^^^^^^^^ `trait_assoc_fn_to_other::Trait2::foo4`: not accessible
47+
| ^^^^^^^^^^^^^^ not accessible
6048

6149
error[E0425]: cannot find function `foo4` in `F`
6250
--> $DIR/explicit-paths.rs:65:18
6351
|
6452
LL | reuse F::foo4 { &F }
6553
| ^^^^ not found in `F`
6654
|
67-
help: consider importing this associated function
68-
|
69-
LL + use trait_assoc_fn_to_other::Trait2::foo4;
70-
|
71-
help: if you import `foo4`, refer to it directly
72-
|
73-
LL - reuse F::foo4 { &F }
74-
LL + reuse foo4 { &F }
55+
note: function `fn_to_other::foo4` exists but is inaccessible
56+
--> $DIR/explicit-paths.rs:27:5
7557
|
58+
LL | reuse S::foo4;
59+
| ^^^^^^^^^^^^^^ not accessible
7660

7761
error[E0119]: conflicting implementations of trait `Trait` for type `S`
7862
--> $DIR/explicit-paths.rs:74:5

tests/ui/delegation/ice-issue-124342.stderr

-14
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ error[E0425]: cannot find function `foo` in module `to_reuse`
33
|
44
LL | reuse to_reuse::foo { foo }
55
| ^^^ not found in `to_reuse`
6-
|
7-
help: consider importing this associated function
8-
|
9-
LL + use Trait::foo;
10-
|
11-
help: if you import `foo`, refer to it directly
12-
|
13-
LL - reuse to_reuse::foo { foo }
14-
LL + reuse foo { foo }
15-
|
166

177
error[E0425]: cannot find value `foo` in this scope
188
--> $DIR/ice-issue-124342.rs:7:27
@@ -24,10 +14,6 @@ help: you might have meant to refer to the associated function
2414
|
2515
LL | reuse to_reuse::foo { Self::foo }
2616
| ++++++
27-
help: consider importing this associated function
28-
|
29-
LL + use Trait::foo;
30-
|
3117

3218
error: aborting due to 2 previous errors
3319

tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr

+21-33
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,6 @@ LL | unknown_metavar!(a);
313313
|
314314
= note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info)
315315

316-
error[E0425]: cannot find function `count` in this scope
317-
--> $DIR/syntax-errors.rs:23:30
318-
|
319-
LL | ( $( $i:ident ),* ) => { count(i) };
320-
| ^^^^^ not found in this scope
321-
...
322-
LL | no_curly__no_rhs_dollar__round!(a, b, c);
323-
| ---------------------------------------- in this macro invocation
324-
|
325-
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
326-
help: consider importing this associated function
327-
|
328-
LL + use std::iter::Iterator::count;
329-
|
330-
331316
error[E0425]: cannot find value `i` in this scope
332317
--> $DIR/syntax-errors.rs:23:36
333318
|
@@ -339,26 +324,39 @@ LL | no_curly__no_rhs_dollar__round!(a, b, c);
339324
|
340325
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
341326

342-
error[E0425]: cannot find function `count` in this scope
343-
--> $DIR/syntax-errors.rs:30:23
327+
error[E0425]: cannot find value `i` in this scope
328+
--> $DIR/syntax-errors.rs:30:29
344329
|
345330
LL | ( $i:ident ) => { count(i) };
346-
| ^^^^^ not found in this scope
331+
| ^ not found in this scope
347332
...
348333
LL | no_curly__no_rhs_dollar__no_round!(a);
349334
| ------------------------------------- in this macro invocation
350335
|
351336
= note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
352-
help: consider importing this associated function
337+
338+
error[E0425]: cannot find value `a` in this scope
339+
--> $DIR/syntax-errors.rs:152:37
340+
|
341+
LL | no_curly__rhs_dollar__no_round!(a);
342+
| ^ not found in this scope
343+
344+
error[E0425]: cannot find function `count` in this scope
345+
--> $DIR/syntax-errors.rs:23:30
353346
|
354-
LL + use std::iter::Iterator::count;
347+
LL | ( $( $i:ident ),* ) => { count(i) };
348+
| ^^^^^ not found in this scope
349+
...
350+
LL | no_curly__no_rhs_dollar__round!(a, b, c);
351+
| ---------------------------------------- in this macro invocation
355352
|
353+
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
356354

357-
error[E0425]: cannot find value `i` in this scope
358-
--> $DIR/syntax-errors.rs:30:29
355+
error[E0425]: cannot find function `count` in this scope
356+
--> $DIR/syntax-errors.rs:30:23
359357
|
360358
LL | ( $i:ident ) => { count(i) };
361-
| ^ not found in this scope
359+
| ^^^^^ not found in this scope
362360
...
363361
LL | no_curly__no_rhs_dollar__no_round!(a);
364362
| ------------------------------------- in this macro invocation
@@ -375,16 +373,6 @@ LL | no_curly__rhs_dollar__no_round!(a);
375373
| ---------------------------------- in this macro invocation
376374
|
377375
= note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
378-
help: consider importing this associated function
379-
|
380-
LL + use std::iter::Iterator::count;
381-
|
382-
383-
error[E0425]: cannot find value `a` in this scope
384-
--> $DIR/syntax-errors.rs:152:37
385-
|
386-
LL | no_curly__rhs_dollar__no_round!(a);
387-
| ^ not found in this scope
388376

389377
error: aborting due to 39 previous errors
390378

tests/ui/methods/suggest-method-on-call-for-ambig-receiver.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ error[E0425]: cannot find function `consume` in this scope
33
|
44
LL | consume(right);
55
| ^^^^^^^ not found in this scope
6-
|
7-
help: consider importing this associated function
8-
|
9-
LL + use std::io::BufRead::consume;
10-
|
116

127
error: aborting due to 1 previous error
138

tests/ui/methods/suggest-method-on-call-with-macro-rcvr.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error[E0425]: cannot find function `len` in this scope
44
LL | let hello = len(vec![]);
55
| ^^^ not found in this scope
66
|
7-
help: consider importing this associated function
7+
help: use the `.` operator to call the method `len` on `&Vec<_>`
88
|
9-
LL + use std::iter::ExactSizeIterator::len;
9+
LL - let hello = len(vec![]);
10+
LL + let hello = vec![].len();
1011
|
1112

1213
error: aborting due to 1 previous error

tests/ui/resolve/associated-fn-called-as-fn.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
struct S;
2-
//~^ HELP consider importing one of these associated functions
3-
//~| HELP consider importing one of these associated functions
42

53
impl Foo for S {
64
fn parse(s: &str) {

tests/ui/resolve/associated-fn-called-as-fn.stderr

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find function `collect_primary` in this scope
2-
--> $DIR/associated-fn-called-as-fn.rs:9:30
2+
--> $DIR/associated-fn-called-as-fn.rs:7:30
33
|
44
LL | '0'..='9' => collect_primary(&c),
55
| ^^^^^^^^^^^^^^^
@@ -8,15 +8,9 @@ help: you might have meant to call the associated function
88
|
99
LL | '0'..='9' => Self::collect_primary(&c),
1010
| ++++++
11-
help: consider importing one of these associated functions
12-
|
13-
LL + use Bar::collect_primary;
14-
|
15-
LL + use Foo::collect_primary;
16-
|
1711

1812
error[E0425]: cannot find function `collect_primary` in this scope
19-
--> $DIR/associated-fn-called-as-fn.rs:26:30
13+
--> $DIR/associated-fn-called-as-fn.rs:24:30
2014
|
2115
LL | '0'..='9' => collect_primary(&c),
2216
| ^^^^^^^^^^^^^^^
@@ -25,12 +19,6 @@ help: you might have meant to call the associated function
2519
|
2620
LL | '0'..='9' => Self::collect_primary(&c),
2721
| ++++++
28-
help: consider importing one of these associated functions
29-
|
30-
LL + use Bar::collect_primary;
31-
|
32-
LL + use Foo::collect_primary;
33-
|
3422

3523
error: aborting due to 2 previous errors
3624

tests/ui/resolve/bad-env-capture.stderr

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ LL | fn bar() { log(debug, x); }
66
|
77
= help: use the `|| { ... }` closure form instead
88

9-
error[E0425]: cannot find function `log` in this scope
10-
--> $DIR/bad-env-capture.rs:4:16
11-
|
12-
LL | fn bar() { log(debug, x); }
13-
| ^^^ not found in this scope
14-
|
15-
help: consider importing this associated function
16-
|
17-
LL + use std::simd::StdFloat::log;
18-
|
19-
209
error[E0425]: cannot find value `debug` in this scope
2110
--> $DIR/bad-env-capture.rs:4:20
2211
|
2312
LL | fn bar() { log(debug, x); }
2413
| ^^^^^ not found in this scope
2514

15+
error[E0425]: cannot find function `log` in this scope
16+
--> $DIR/bad-env-capture.rs:4:16
17+
|
18+
LL | fn bar() { log(debug, x); }
19+
| ^^^ not found in this scope
20+
2621
error: aborting due to 3 previous errors
2722

2823
Some errors have detailed explanations: E0425, E0434.

tests/ui/resolve/bad-env-capture2.stderr

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ LL | fn bar() { log(debug, x); }
66
|
77
= help: use the `|| { ... }` closure form instead
88

9-
error[E0425]: cannot find function `log` in this scope
10-
--> $DIR/bad-env-capture2.rs:3:16
11-
|
12-
LL | fn bar() { log(debug, x); }
13-
| ^^^ not found in this scope
14-
|
15-
help: consider importing this associated function
16-
|
17-
LL + use std::simd::StdFloat::log;
18-
|
19-
209
error[E0425]: cannot find value `debug` in this scope
2110
--> $DIR/bad-env-capture2.rs:3:20
2211
|
2312
LL | fn bar() { log(debug, x); }
2413
| ^^^^^ not found in this scope
2514

15+
error[E0425]: cannot find function `log` in this scope
16+
--> $DIR/bad-env-capture2.rs:3:16
17+
|
18+
LL | fn bar() { log(debug, x); }
19+
| ^^^ not found in this scope
20+
2621
error: aborting due to 3 previous errors
2722

2823
Some errors have detailed explanations: E0425, E0434.

tests/ui/resolve/bad-env-capture3.stderr

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ LL | fn bar() { log(debug, x); }
66
|
77
= help: use the `|| { ... }` closure form instead
88

9-
error[E0425]: cannot find function `log` in this scope
10-
--> $DIR/bad-env-capture3.rs:4:20
11-
|
12-
LL | fn bar() { log(debug, x); }
13-
| ^^^ not found in this scope
14-
|
15-
help: consider importing this associated function
16-
|
17-
LL + use std::simd::StdFloat::log;
18-
|
19-
209
error[E0425]: cannot find value `debug` in this scope
2110
--> $DIR/bad-env-capture3.rs:4:24
2211
|
2312
LL | fn bar() { log(debug, x); }
2413
| ^^^^^ not found in this scope
2514

15+
error[E0425]: cannot find function `log` in this scope
16+
--> $DIR/bad-env-capture3.rs:4:20
17+
|
18+
LL | fn bar() { log(debug, x); }
19+
| ^^^ not found in this scope
20+
2621
error: aborting due to 3 previous errors
2722

2823
Some errors have detailed explanations: E0425, E0434.

0 commit comments

Comments
 (0)