@@ -134,15 +134,20 @@ impl TryFrom<ResolveRes> for Res {
134134 }
135135}
136136
137- #[ derive( Debug ) ]
138137/// A link failed to resolve.
138+ #[ derive( Debug ) ]
139139enum ResolutionFailure < ' a > {
140140 /// This resolved, but with the wrong namespace.
141- ///
142- /// `Namespace` is the namespace specified with a disambiguator
143- /// (as opposed to the actual namespace of the `Res`).
144- WrongNamespace ( Res , /* disambiguated */ Namespace ) ,
145- /// The link failed to resolve. `resolution_failure` should look to see if there's
141+ WrongNamespace {
142+ /// What the link resolved to.
143+ res : Res ,
144+ /// The expected namespace for the resolution, determined from the link's disambiguator.
145+ ///
146+ /// E.g., for `[fn@Result]` this is [`Namespace::ValueNS`],
147+ /// even though `Result`'s actual namespace is [`Namespace::TypeNS`].
148+ expected_ns : Namespace ,
149+ } ,
150+ /// The link failed to resolve. [`resolution_failure`] should look to see if there's
146151 /// a more helpful error that can be given.
147152 NotResolved {
148153 /// The scope the link was resolved in.
@@ -157,12 +162,11 @@ enum ResolutionFailure<'a> {
157162 unresolved : Cow < ' a , str > ,
158163 } ,
159164 /// This happens when rustdoc can't determine the parent scope for an item.
160- ///
161165 /// It is always a bug in rustdoc.
162166 NoParentItem ,
163167 /// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
164168 MalformedGenerics ( MalformedGenerics ) ,
165- /// Used to communicate that this should be ignored, but shouldn't be reported to the user
169+ /// Used to communicate that this should be ignored, but shouldn't be reported to the user.
166170 ///
167171 /// This happens when there is no disambiguator and one of the namespaces
168172 /// failed to resolve.
@@ -216,7 +220,7 @@ impl ResolutionFailure<'a> {
216220 /// Returns the full resolution of the link, if present.
217221 fn full_res ( & self ) -> Option < Res > {
218222 match self {
219- Self :: WrongNamespace ( res, _ ) => Some ( * res) ,
223+ Self :: WrongNamespace { res, expected_ns : _ } => Some ( * res) ,
220224 _ => None ,
221225 }
222226 }
@@ -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