@@ -128,15 +128,20 @@ impl TryFrom<ResolveRes> for Res {
128128 }
129129}
130130
131- #[ derive( Debug ) ]
132131/// A link failed to resolve.
132+ #[ derive( Debug ) ]
133133enum ResolutionFailure < ' a > {
134134 /// This resolved, but with the wrong namespace.
135- ///
136- /// `Namespace` is the namespace specified with a disambiguator
137- /// (as opposed to the actual namespace of the `Res`).
138- WrongNamespace ( Res , /* disambiguated */ Namespace ) ,
139- /// The link failed to resolve. `resolution_failure` should look to see if there's
135+ WrongNamespace {
136+ /// What the link resolved to.
137+ res : Res ,
138+ /// The expected namespace for the resolution, determined from the link's disambiguator.
139+ ///
140+ /// E.g., for `[fn@Result]` this is [`Namespace::ValueNS`],
141+ /// even though `Result`'s actual namespace is [`Namespace::TypeNS`].
142+ expected_ns : Namespace ,
143+ } ,
144+ /// The link failed to resolve. [`resolution_failure`] should look to see if there's
140145 /// a more helpful error that can be given.
141146 NotResolved {
142147 /// The scope the link was resolved in.
@@ -151,12 +156,11 @@ enum ResolutionFailure<'a> {
151156 unresolved : Cow < ' a , str > ,
152157 } ,
153158 /// This happens when rustdoc can't determine the parent scope for an item.
154- ///
155159 /// It is always a bug in rustdoc.
156160 NoParentItem ,
157161 /// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
158162 MalformedGenerics ( MalformedGenerics ) ,
159- /// Used to communicate that this should be ignored, but shouldn't be reported to the user
163+ /// Used to communicate that this should be ignored, but shouldn't be reported to the user.
160164 ///
161165 /// This happens when there is no disambiguator and one of the namespaces
162166 /// failed to resolve.
@@ -210,7 +214,7 @@ impl ResolutionFailure<'a> {
210214 /// Returns the full resolution of the link, if present.
211215 fn full_res ( & self ) -> Option < Res > {
212216 match self {
213- Self :: WrongNamespace ( res, _ ) => Some ( * res) ,
217+ Self :: WrongNamespace { res, expected_ns : _ } => Some ( * res) ,
214218 _ => None ,
215219 }
216220 }
@@ -1308,20 +1312,20 @@ impl LinkCollector<'_, '_> {
13081312 let extra_fragment = & key. extra_fragment ;
13091313
13101314 match disambiguator. map ( Disambiguator :: ns) {
1311- Some ( ns @ ( ValueNS | TypeNS ) ) => {
1312- match self . resolve ( path_str, ns , base_node, extra_fragment) {
1315+ Some ( expected_ns @ ( ValueNS | TypeNS ) ) => {
1316+ match self . resolve ( path_str, expected_ns , base_node, extra_fragment) {
13131317 Ok ( res) => Some ( res) ,
13141318 Err ( ErrorKind :: Resolve ( box mut kind) ) => {
13151319 // We only looked in one namespace. Try to give a better error if possible.
13161320 if kind. full_res ( ) . is_none ( ) {
1317- let other_ns = if ns == ValueNS { TypeNS } else { ValueNS } ;
1321+ let other_ns = if expected_ns == ValueNS { TypeNS } else { ValueNS } ;
13181322 // FIXME: really it should be `resolution_failure` that does this, not `resolve_with_disambiguator`
13191323 // See https://github.com/rust-lang/rust/pull/76955#discussion_r493953382 for a good approach
13201324 for & new_ns in & [ other_ns, MacroNS ] {
13211325 if let Some ( res) =
13221326 self . check_full_res ( new_ns, path_str, base_node, extra_fragment)
13231327 {
1324- kind = ResolutionFailure :: WrongNamespace ( res, ns ) ;
1328+ kind = ResolutionFailure :: WrongNamespace { res, expected_ns } ;
13251329 break ;
13261330 }
13271331 }
@@ -1396,7 +1400,7 @@ impl LinkCollector<'_, '_> {
13961400 // Constructors are picked up in the type namespace.
13971401 match res {
13981402 Res :: Def ( DefKind :: Ctor ( ..) , _) => {
1399- Err ( ResolutionFailure :: WrongNamespace ( res, TypeNS ) )
1403+ Err ( ResolutionFailure :: WrongNamespace { res, expected_ns : TypeNS } )
14001404 }
14011405 _ => {
14021406 match ( fragment, extra_fragment. clone ( ) ) {
@@ -1457,7 +1461,8 @@ impl LinkCollector<'_, '_> {
14571461 if let Some ( res) =
14581462 self . check_full_res ( ns, path_str, base_node, extra_fragment)
14591463 {
1460- kind = ResolutionFailure :: WrongNamespace ( res, MacroNS ) ;
1464+ kind =
1465+ ResolutionFailure :: WrongNamespace { res, expected_ns : MacroNS } ;
14611466 break ;
14621467 }
14631468 }
@@ -1889,7 +1894,7 @@ fn resolution_failure(
18891894 let note = match failure {
18901895 ResolutionFailure :: NotResolved { .. } => unreachable ! ( "handled above" ) ,
18911896 ResolutionFailure :: Dummy => continue ,
1892- ResolutionFailure :: WrongNamespace ( res, expected_ns) => {
1897+ ResolutionFailure :: WrongNamespace { res, expected_ns } => {
18931898 if let Res :: Def ( kind, _) = res {
18941899 let disambiguator = Disambiguator :: Kind ( kind) ;
18951900 suggest_disambiguator (
@@ -1910,7 +1915,7 @@ fn resolution_failure(
19101915 }
19111916 ResolutionFailure :: NoParentItem => {
19121917 diag. level = rustc_errors:: Level :: Bug ;
1913- "all intra doc links should have a parent item" . to_owned ( )
1918+ "all intra- doc links should have a parent item" . to_owned ( )
19141919 }
19151920 ResolutionFailure :: MalformedGenerics ( variant) => match variant {
19161921 MalformedGenerics :: UnbalancedAngleBrackets => {
0 commit comments