@@ -17,9 +17,10 @@ use rustc_session::lint::builtin::{
17
17
AMBIGUOUS_GLOB_REEXPORTS , HIDDEN_GLOB_REEXPORTS , PUB_USE_OF_PRIVATE_EXTERN_CRATE ,
18
18
REDUNDANT_IMPORTS , UNUSED_IMPORTS ,
19
19
} ;
20
+ use rustc_session:: parse:: feature_err;
20
21
use rustc_span:: edit_distance:: find_best_match_for_name;
21
22
use rustc_span:: hygiene:: LocalExpnId ;
22
- use rustc_span:: { Ident , Span , Symbol , kw} ;
23
+ use rustc_span:: { Ident , Span , Symbol , kw, sym } ;
23
24
use smallvec:: SmallVec ;
24
25
use tracing:: debug;
25
26
@@ -828,16 +829,33 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
828
829
Err ( Undetermined ) => indeterminate_count += 1 ,
829
830
// Don't update the resolution, because it was never added.
830
831
Err ( Determined ) if target. name == kw:: Underscore => { }
831
- Ok ( binding) if binding. is_importable ( ) => {
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
837
let imported_binding = this. import ( binding, import) ;
833
838
target_bindings[ ns] . set ( Some ( imported_binding) ) ;
834
839
this. define ( parent, target, ns, imported_binding) ;
835
840
}
836
841
source_binding @ ( Ok ( ..) | Err ( Determined ) ) => {
837
- if source_binding. is_ok ( ) {
838
- this. dcx ( )
839
- . create_err ( IsNotDirectlyImportable { span : import. span , target } )
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
+ )
840
850
. emit ( ) ;
851
+ } else {
852
+ this. dcx ( )
853
+ . create_err ( IsNotDirectlyImportable {
854
+ span : import. span ,
855
+ target,
856
+ } )
857
+ . emit ( ) ;
858
+ }
841
859
}
842
860
let key = BindingKey :: new ( target, ns) ;
843
861
this. update_resolution ( parent, key, false , |_, resolution| {
0 commit comments