Skip to content

Commit 2427364

Browse files
committed
Make is_importable stop rejecting assoc const and fn
1 parent b759390 commit 2427364

33 files changed

+490
-264
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -829,33 +829,27 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
829829
Err(Undetermined) => indeterminate_count += 1,
830830
// Don't update the resolution, because it was never added.
831831
Err(Determined) if target.name == kw::Underscore => {}
832-
Ok(binding)
833-
if binding.is_importable()
834-
|| binding.is_assoc_const_or_fn()
835-
&& this.tcx.features().import_trait_associated_functions() =>
836-
{
832+
Ok(binding) if binding.is_importable() => {
833+
if binding.is_assoc_const_or_fn()
834+
&& !this.tcx.features().import_trait_associated_functions()
835+
{
836+
feature_err(
837+
this.tcx.sess,
838+
sym::import_trait_associated_functions,
839+
import.span,
840+
"`use` associated items of traits is unstable",
841+
)
842+
.emit();
843+
}
837844
let imported_binding = this.import(binding, import);
838845
target_bindings[ns].set(Some(imported_binding));
839846
this.define(parent, target, ns, imported_binding);
840847
}
841848
source_binding @ (Ok(..) | Err(Determined)) => {
842-
if let Ok(binding) = source_binding {
843-
if binding.is_assoc_const_or_fn() {
844-
feature_err(
845-
this.tcx.sess,
846-
sym::import_trait_associated_functions,
847-
import.span,
848-
"`use` associated items of traits is unstable",
849-
)
849+
if source_binding.is_ok() {
850+
this.dcx()
851+
.create_err(IsNotDirectlyImportable { span: import.span, target })
850852
.emit();
851-
} else {
852-
this.dcx()
853-
.create_err(IsNotDirectlyImportable {
854-
span: import.span,
855-
target,
856-
})
857-
.emit();
858-
}
859853
}
860854
let key = BindingKey::new(target, ns);
861855
this.update_resolution(parent, key, false, |_, resolution| {

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,7 @@ impl<'ra> NameBindingData<'ra> {
920920
}
921921

922922
fn is_importable(&self) -> bool {
923-
!matches!(
924-
self.res(),
925-
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _)
926-
)
923+
!matches!(self.res(), Res::Def(DefKind::AssocTy, _))
927924
}
928925

929926
fn is_assoc_const_or_fn(&self) -> bool {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ 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+
|
1823

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

tests/ui/delegation/bad-resolve.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ 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+
|
6570

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

tests/ui/delegation/explicit-paths.stderr

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,58 @@ 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
2430

2531
error[E0425]: cannot find function `foo4` in `F`
2632
--> $DIR/explicit-paths.rs:38:18
2733
|
2834
LL | reuse F::foo4 { &self.0 }
2935
| ^^^^ not found in `F`
3036
|
31-
note: function `fn_to_other::foo4` exists but is inaccessible
37+
note: these items exist but are inaccessible
3238
--> $DIR/explicit-paths.rs:27:5
3339
|
3440
LL | reuse S::foo4;
35-
| ^^^^^^^^^^^^^^ not accessible
41+
| ^^^^^^^^^^^^^^ `fn_to_other::foo4`: not accessible
42+
...
43+
LL | reuse F::foo4 { &F }
44+
| ^^^^^^^^^^^^^ `trait_assoc_fn_to_other::Trait2::foo4`: not accessible
3645

3746
error[E0425]: cannot find function `foo4` in `F`
3847
--> $DIR/explicit-paths.rs:51:18
3948
|
4049
LL | reuse F::foo4 { &self.0 }
4150
| ^^^^ not found in `F`
4251
|
43-
note: function `fn_to_other::foo4` exists but is inaccessible
52+
note: these items exist but are inaccessible
4453
--> $DIR/explicit-paths.rs:27:5
4554
|
4655
LL | reuse S::foo4;
47-
| ^^^^^^^^^^^^^^ not accessible
56+
| ^^^^^^^^^^^^^^ `fn_to_other::foo4`: not accessible
57+
...
58+
LL | reuse F::foo4 { &F }
59+
| ^^^^^^^^^^^^^ `trait_assoc_fn_to_other::Trait2::foo4`: not accessible
4860

4961
error[E0425]: cannot find function `foo4` in `F`
5062
--> $DIR/explicit-paths.rs:65:18
5163
|
5264
LL | reuse F::foo4 { &F }
5365
| ^^^^ not found in `F`
5466
|
55-
note: function `fn_to_other::foo4` exists but is inaccessible
56-
--> $DIR/explicit-paths.rs:27:5
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 }
5775
|
58-
LL | reuse S::foo4;
59-
| ^^^^^^^^^^^^^^ not accessible
6076

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ 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+
|
616

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

1832
error: aborting due to 2 previous errors
1933

tests/ui/imports/import-trait-method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ trait Foo {
44

55
use Foo::foo; //~ ERROR `use` associated items of traits is unstable [E0658]
66

7-
fn main() { foo(); }
7+
fn main() { foo(); } //~ ERROR type annotations needed

tests/ui/imports/import-trait-method.stderr

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ LL | use Foo::foo;
88
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error: aborting due to 1 previous error
11+
error[E0283]: type annotations needed
12+
--> $DIR/import-trait-method.rs:7:13
13+
|
14+
LL | fn main() { foo(); }
15+
| ^^^^^ cannot infer type
16+
|
17+
= note: cannot satisfy `_: Foo`
18+
19+
error: aborting due to 2 previous errors
1220

13-
For more information about this error, try `rustc --explain E0658`.
21+
Some errors have detailed explanations: E0283, E0658.
22+
For more information about an error, try `rustc --explain E0283`.

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,39 +313,26 @@ 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 value `i` in this scope
317-
--> $DIR/syntax-errors.rs:23:36
316+
error[E0425]: cannot find function `count` in this scope
317+
--> $DIR/syntax-errors.rs:23:30
318318
|
319319
LL | ( $( $i:ident ),* ) => { count(i) };
320-
| ^ not found in this scope
320+
| ^^^^^ not found in this scope
321321
...
322322
LL | no_curly__no_rhs_dollar__round!(a, b, c);
323323
| ---------------------------------------- in this macro invocation
324324
|
325325
= 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-
327-
error[E0425]: cannot find value `i` in this scope
328-
--> $DIR/syntax-errors.rs:30:29
329-
|
330-
LL | ( $i:ident ) => { count(i) };
331-
| ^ not found in this scope
332-
...
333-
LL | no_curly__no_rhs_dollar__no_round!(a);
334-
| ------------------------------------- in this macro invocation
326+
help: consider importing this associated function
335327
|
336-
= 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)
337-
338-
error[E0425]: cannot find value `a` in this scope
339-
--> $DIR/syntax-errors.rs:152:37
328+
LL + use std::iter::Iterator::count;
340329
|
341-
LL | no_curly__rhs_dollar__no_round!(a);
342-
| ^ not found in this scope
343330

344-
error[E0425]: cannot find function `count` in this scope
345-
--> $DIR/syntax-errors.rs:23:30
331+
error[E0425]: cannot find value `i` in this scope
332+
--> $DIR/syntax-errors.rs:23:36
346333
|
347334
LL | ( $( $i:ident ),* ) => { count(i) };
348-
| ^^^^^ not found in this scope
335+
| ^ not found in this scope
349336
...
350337
LL | no_curly__no_rhs_dollar__round!(a, b, c);
351338
| ---------------------------------------- in this macro invocation
@@ -358,6 +345,21 @@ error[E0425]: cannot find function `count` in this scope
358345
LL | ( $i:ident ) => { count(i) };
359346
| ^^^^^ not found in this scope
360347
...
348+
LL | no_curly__no_rhs_dollar__no_round!(a);
349+
| ------------------------------------- in this macro invocation
350+
|
351+
= 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
353+
|
354+
LL + use std::iter::Iterator::count;
355+
|
356+
357+
error[E0425]: cannot find value `i` in this scope
358+
--> $DIR/syntax-errors.rs:30:29
359+
|
360+
LL | ( $i:ident ) => { count(i) };
361+
| ^ not found in this scope
362+
...
361363
LL | no_curly__no_rhs_dollar__no_round!(a);
362364
| ------------------------------------- in this macro invocation
363365
|
@@ -373,6 +375,16 @@ LL | no_curly__rhs_dollar__no_round!(a);
373375
| ---------------------------------- in this macro invocation
374376
|
375377
= 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
376388

377389
error: aborting due to 39 previous errors
378390

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ 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+
|
611

712
error: aborting due to 1 previous error
813

0 commit comments

Comments
 (0)