@@ -128,15 +128,20 @@ impl TryFrom<ResolveRes> for Res {
128
128
}
129
129
}
130
130
131
- #[ derive( Debug ) ]
132
131
/// A link failed to resolve.
132
+ #[ derive( Debug ) ]
133
133
enum ResolutionFailure < ' a > {
134
134
/// 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
140
145
/// a more helpful error that can be given.
141
146
NotResolved {
142
147
/// The scope the link was resolved in.
@@ -151,12 +156,11 @@ enum ResolutionFailure<'a> {
151
156
unresolved : Cow < ' a , str > ,
152
157
} ,
153
158
/// This happens when rustdoc can't determine the parent scope for an item.
154
- ///
155
159
/// It is always a bug in rustdoc.
156
160
NoParentItem ,
157
161
/// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
158
162
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.
160
164
///
161
165
/// This happens when there is no disambiguator and one of the namespaces
162
166
/// failed to resolve.
@@ -210,7 +214,7 @@ impl ResolutionFailure<'a> {
210
214
/// Returns the full resolution of the link, if present.
211
215
fn full_res ( & self ) -> Option < Res > {
212
216
match self {
213
- Self :: WrongNamespace ( res, _ ) => Some ( * res) ,
217
+ Self :: WrongNamespace { res, expected_ns : _ } => Some ( * res) ,
214
218
_ => None ,
215
219
}
216
220
}
@@ -1308,20 +1312,20 @@ impl LinkCollector<'_, '_> {
1308
1312
let extra_fragment = & key. extra_fragment ;
1309
1313
1310
1314
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) {
1313
1317
Ok ( res) => Some ( res) ,
1314
1318
Err ( ErrorKind :: Resolve ( box mut kind) ) => {
1315
1319
// We only looked in one namespace. Try to give a better error if possible.
1316
1320
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 } ;
1318
1322
// FIXME: really it should be `resolution_failure` that does this, not `resolve_with_disambiguator`
1319
1323
// See https://github.com/rust-lang/rust/pull/76955#discussion_r493953382 for a good approach
1320
1324
for & new_ns in & [ other_ns, MacroNS ] {
1321
1325
if let Some ( res) =
1322
1326
self . check_full_res ( new_ns, path_str, base_node, extra_fragment)
1323
1327
{
1324
- kind = ResolutionFailure :: WrongNamespace ( res, ns ) ;
1328
+ kind = ResolutionFailure :: WrongNamespace { res, expected_ns } ;
1325
1329
break ;
1326
1330
}
1327
1331
}
@@ -1396,7 +1400,7 @@ impl LinkCollector<'_, '_> {
1396
1400
// Constructors are picked up in the type namespace.
1397
1401
match res {
1398
1402
Res :: Def ( DefKind :: Ctor ( ..) , _) => {
1399
- Err ( ResolutionFailure :: WrongNamespace ( res, TypeNS ) )
1403
+ Err ( ResolutionFailure :: WrongNamespace { res, expected_ns : TypeNS } )
1400
1404
}
1401
1405
_ => {
1402
1406
match ( fragment, extra_fragment. clone ( ) ) {
@@ -1457,7 +1461,8 @@ impl LinkCollector<'_, '_> {
1457
1461
if let Some ( res) =
1458
1462
self . check_full_res ( ns, path_str, base_node, extra_fragment)
1459
1463
{
1460
- kind = ResolutionFailure :: WrongNamespace ( res, MacroNS ) ;
1464
+ kind =
1465
+ ResolutionFailure :: WrongNamespace { res, expected_ns : MacroNS } ;
1461
1466
break ;
1462
1467
}
1463
1468
}
@@ -1889,7 +1894,7 @@ fn resolution_failure(
1889
1894
let note = match failure {
1890
1895
ResolutionFailure :: NotResolved { .. } => unreachable ! ( "handled above" ) ,
1891
1896
ResolutionFailure :: Dummy => continue ,
1892
- ResolutionFailure :: WrongNamespace ( res, expected_ns) => {
1897
+ ResolutionFailure :: WrongNamespace { res, expected_ns } => {
1893
1898
if let Res :: Def ( kind, _) = res {
1894
1899
let disambiguator = Disambiguator :: Kind ( kind) ;
1895
1900
suggest_disambiguator (
@@ -1910,7 +1915,7 @@ fn resolution_failure(
1910
1915
}
1911
1916
ResolutionFailure :: NoParentItem => {
1912
1917
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 ( )
1914
1919
}
1915
1920
ResolutionFailure :: MalformedGenerics ( variant) => match variant {
1916
1921
MalformedGenerics :: UnbalancedAngleBrackets => {
0 commit comments