@@ -426,6 +426,23 @@ pub(crate) enum AliasPossibility {
426426 Maybe ,
427427}
428428
429+ /// Whether resolving `impl` or `mut` restriction paths
430+ #[ derive( Debug , Clone , Copy ) ]
431+ pub ( crate ) enum ResolvingRestrictionKind {
432+ Impl ,
433+ Mut ,
434+ }
435+
436+ impl IntoDiagArg for ResolvingRestrictionKind {
437+ fn into_diag_arg ( self , _: & mut Option < std:: path:: PathBuf > ) -> DiagArgValue {
438+ use std:: borrow:: Cow ;
439+ match self {
440+ ResolvingRestrictionKind :: Impl => DiagArgValue :: Str ( Cow :: Borrowed ( "impl" ) ) ,
441+ ResolvingRestrictionKind :: Mut => DiagArgValue :: Str ( Cow :: Borrowed ( "mut" ) ) ,
442+ }
443+ }
444+ }
445+
429446#[ derive( Copy , Clone , Debug ) ]
430447pub ( crate ) enum PathSource < ' a , ' ast , ' ra > {
431448 /// Type paths `Path`.
@@ -1489,11 +1506,12 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
14891506 ty,
14901507 is_placeholder : _,
14911508 default,
1492- mut_restriction : _ ,
1509+ mut_restriction,
14931510 safety : _,
14941511 } = f;
14951512 walk_list ! ( self , visit_attribute, attrs) ;
14961513 try_visit ! ( self . visit_vis( vis) ) ;
1514+ self . resolve_restriction_path ( & mut_restriction. kind , ResolvingRestrictionKind :: Mut ) ;
14971515 visit_opt ! ( self , visit_ident, ident) ;
14981516 try_visit ! ( self . visit_ty( ty) ) ;
14991517 if let Some ( v) = & default {
@@ -2864,7 +2882,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28642882
28652883 ItemKind :: Trait ( Trait { generics, bounds, items, impl_restriction, .. } ) => {
28662884 // resolve paths for `impl` restrictions
2867- self . resolve_impl_restriction_path ( impl_restriction) ;
2885+ self . resolve_restriction_path (
2886+ & impl_restriction. kind ,
2887+ ResolvingRestrictionKind :: Impl ,
2888+ ) ;
28682889
28692890 // Create a new rib for the trait-wide type parameters.
28702891 self . with_generic_param_rib (
@@ -4480,8 +4501,12 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44804501 }
44814502 }
44824503
4483- fn resolve_impl_restriction_path ( & mut self , restriction : & ' ast ast:: ImplRestriction ) {
4484- match & restriction. kind {
4504+ fn resolve_restriction_path (
4505+ & mut self ,
4506+ restriction : & ' ast ast:: RestrictionKind ,
4507+ kind : ResolvingRestrictionKind ,
4508+ ) {
4509+ match & restriction {
44854510 ast:: RestrictionKind :: Unrestricted => ( ) ,
44864511 ast:: RestrictionKind :: Restricted { path, id, shorthand : _ } => {
44874512 self . smart_resolve_path ( * id, & None , path, PathSource :: Module ) ;
@@ -4494,7 +4519,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44944519 ) {
44954520 self . r
44964521 . dcx ( )
4497- . create_err ( crate :: diagnostics:: RestrictionAncestorOnly ( path. span ) )
4522+ . create_err ( crate :: diagnostics:: RestrictionAncestorOnly {
4523+ span : path. span ,
4524+ kind,
4525+ } )
44984526 . emit ( ) ;
44994527 }
45004528 }
0 commit comments