@@ -134,15 +134,20 @@ impl TryFrom<ResolveRes> for Res {
134
134
}
135
135
}
136
136
137
- #[ derive( Debug ) ]
138
137
/// A link failed to resolve.
138
+ #[ derive( Debug ) ]
139
139
enum ResolutionFailure < ' a > {
140
140
/// 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
146
151
/// a more helpful error that can be given.
147
152
NotResolved {
148
153
/// The scope the link was resolved in.
@@ -157,12 +162,11 @@ enum ResolutionFailure<'a> {
157
162
unresolved : Cow < ' a , str > ,
158
163
} ,
159
164
/// This happens when rustdoc can't determine the parent scope for an item.
160
- ///
161
165
/// It is always a bug in rustdoc.
162
166
NoParentItem ,
163
167
/// This link has malformed generic parameters; e.g., the angle brackets are unbalanced.
164
168
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.
166
170
///
167
171
/// This happens when there is no disambiguator and one of the namespaces
168
172
/// failed to resolve.
@@ -216,7 +220,7 @@ impl ResolutionFailure<'a> {
216
220
/// Returns the full resolution of the link, if present.
217
221
fn full_res ( & self ) -> Option < Res > {
218
222
match self {
219
- Self :: WrongNamespace ( res, _ ) => Some ( * res) ,
223
+ Self :: WrongNamespace { res, expected_ns : _ } => Some ( * res) ,
220
224
_ => None ,
221
225
}
222
226
}
@@ -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