@@ -48,10 +48,16 @@ pub fn collect_intra_doc_links(krate: Crate, cx: &DocContext<'_>) -> Crate {
48
48
}
49
49
50
50
enum ErrorKind<'a> {
51
- Resolve(ResolutionFailure<'a>),
51
+ Resolve(Box< ResolutionFailure<'a> >),
52
52
AnchorFailure(AnchorFailure),
53
53
}
54
54
55
+ impl<'a> From<ResolutionFailure<'a>> for ErrorKind<'a> {
56
+ fn from(err: ResolutionFailure<'a>) -> Self {
57
+ ErrorKind::Resolve(box err)
58
+ }
59
+ }
60
+
55
61
#[derive(Debug)]
56
62
enum ResolutionFailure<'a> {
57
63
/// This resolved, but with the wrong namespace.
@@ -142,10 +148,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
142
148
.expect("fold_item should ensure link is non-empty");
143
149
let variant_name =
144
150
// we're not sure this is a variant at all, so use the full string
145
- split.next().map(|f| Symbol::intern(f)).ok_or(ErrorKind::Resolve( ResolutionFailure::NotInScope{
151
+ split.next().map(|f| Symbol::intern(f)).ok_or_else(|| ResolutionFailure::NotInScope {
146
152
module_id,
147
153
name: path_str.into(),
148
- })) ?;
154
+ })?;
149
155
let path = split
150
156
.next()
151
157
.map(|f| {
@@ -156,21 +162,18 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
156
162
}
157
163
f.to_owned()
158
164
})
159
- .ok_or(ErrorKind::Resolve( ResolutionFailure::NotInScope {
165
+ .ok_or_else(|| ResolutionFailure::NotInScope {
160
166
module_id,
161
167
name: variant_name.to_string().into(),
162
- })) ?;
168
+ })?;
163
169
let ty_res = cx
164
170
.enter_resolver(|resolver| {
165
171
resolver.resolve_str_path_error(DUMMY_SP, &path, TypeNS, module_id)
166
172
})
167
173
.map(|(_, res)| res)
168
174
.unwrap_or(Res::Err);
169
175
if let Res::Err = ty_res {
170
- return Err(ErrorKind::Resolve(ResolutionFailure::NotInScope {
171
- module_id,
172
- name: path.into(),
173
- }));
176
+ return Err(ResolutionFailure::NotInScope { module_id, name: path.into() }.into());
174
177
}
175
178
let ty_res = ty_res.map_id(|_| panic!("unexpected node_id"));
176
179
match ty_res {
@@ -184,7 +187,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
184
187
{
185
188
// This is just to let `fold_item` know that this shouldn't be considered;
186
189
// it's a bug for the error to make it to the user
187
- return Err(ErrorKind::Resolve( ResolutionFailure::Dummy));
190
+ return Err(ResolutionFailure::Dummy.into( ));
188
191
}
189
192
match cx.tcx.type_of(did).kind() {
190
193
ty::Adt(def, _) if def.is_enum() => {
@@ -197,10 +200,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
197
200
)),
198
201
))
199
202
} else {
200
- Err(ErrorKind::Resolve(ResolutionFailure::NotAVariant(
201
- ty_res,
202
- variant_field_name,
203
- )))
203
+ Err(ResolutionFailure::NotAVariant(ty_res, variant_field_name).into())
204
204
}
205
205
}
206
206
_ => unreachable!(),
@@ -226,7 +226,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
226
226
// Even with the shorter path, it didn't resolve, so say that.
227
227
ResolutionFailure::NoAssocItem(ty_res, variant_name)
228
228
};
229
- Err(ErrorKind::Resolve( kind))
229
+ Err(kind.into( ))
230
230
}
231
231
}
232
232
}
@@ -344,7 +344,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
344
344
};
345
345
346
346
if value != (ns == ValueNS) {
347
- return Err(ErrorKind::Resolve( ResolutionFailure::WrongNamespace(res, ns)));
347
+ return Err(ResolutionFailure::WrongNamespace(res, ns).into( ));
348
348
}
349
349
} else if let Some((path, prim)) = is_primitive(path_str, ns) {
350
350
if extra_fragment.is_some() {
@@ -373,16 +373,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
373
373
// So we can be sure that `rustc_resolve` was accurate when it said it wasn't resolved.
374
374
.ok_or_else(|| {
375
375
debug!("found no `::`, assumming {} was correctly not in scope", item_name);
376
- ErrorKind::Resolve(ResolutionFailure::NotInScope {
377
- module_id,
378
- name: item_name.to_string().into(),
379
- })
376
+ ResolutionFailure::NotInScope { module_id, name: item_name.to_string().into() }
380
377
})?;
381
378
382
379
if let Some((path, prim)) = is_primitive(&path_root, TypeNS) {
383
- let impls = primitive_impl(cx, &path).ok_or_else(|| {
384
- ErrorKind::Resolve(ResolutionFailure::NoPrimitiveImpl(prim, path_root.into()))
385
- })?;
380
+ let impls = primitive_impl(cx, &path)
381
+ .ok_or_else(|| ResolutionFailure::NoPrimitiveImpl(prim, path_root.into()))?;
386
382
for &impl_ in impls {
387
383
let link = cx
388
384
.tcx
@@ -409,11 +405,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
409
405
item_name,
410
406
ns.descr()
411
407
);
412
- return Err(ErrorKind::Resolve( ResolutionFailure::NoPrimitiveAssocItem {
408
+ return Err(ResolutionFailure::NoPrimitiveAssocItem {
413
409
res: prim,
414
410
prim_name: path,
415
411
assoc_item: item_name,
416
- }));
412
+ }
413
+ .into());
417
414
}
418
415
419
416
let ty_res = cx
@@ -445,7 +442,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
445
442
}
446
443
ResolutionFailure::NotInScope { module_id, name: path_root.into() }
447
444
});
448
- Err(ErrorKind::Resolve( kind))
445
+ Err(kind.into( ))
449
446
};
450
447
}
451
448
Ok(res) => res,
@@ -548,9 +545,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
548
545
}
549
546
} else {
550
547
// We already know this isn't in ValueNS, so no need to check variant_field
551
- return Err(ErrorKind::Resolve(ResolutionFailure::NoAssocItem(
552
- ty_res, item_name,
553
- )));
548
+ return Err(ResolutionFailure::NoAssocItem(ty_res, item_name).into());
554
549
}
555
550
}
556
551
Res::Def(DefKind::Trait, did) => cx
@@ -585,12 +580,12 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
585
580
if ns == Namespace::ValueNS {
586
581
self.variant_field(path_str, current_item, module_id, extra_fragment)
587
582
} else {
588
- Err(ErrorKind::Resolve( ResolutionFailure::NoAssocItem(ty_res, item_name)))
583
+ Err(ResolutionFailure::NoAssocItem(ty_res, item_name).into( ))
589
584
}
590
585
})
591
586
} else {
592
587
debug!("attempting to resolve item without parent module: {}", path_str);
593
- Err(ErrorKind::Resolve( ResolutionFailure::NoParentItem))
588
+ Err(ResolutionFailure::NoParentItem.into( ))
594
589
}
595
590
}
596
591
@@ -611,7 +606,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
611
606
let check_full_res_inner = |this: &Self, result: Result<Res, ErrorKind<'_>>| {
612
607
let res = match result {
613
608
Ok(res) => Some(res),
614
- Err(ErrorKind::Resolve(kind)) => kind.full_res(),
609
+ Err(ErrorKind::Resolve(box kind)) => kind.full_res(),
615
610
Err(ErrorKind::AnchorFailure(AnchorFailure::RustdocAnchorConflict(res))) => {
616
611
Some(res)
617
612
}
@@ -626,7 +621,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
626
621
};
627
622
let check_full_res_macro = |this: &Self| {
628
623
let result = this.macro_resolve(path_str, base_node);
629
- check_full_res_inner(this, result.map_err(ErrorKind::Resolve ))
624
+ check_full_res_inner(this, result.map_err(ErrorKind::from ))
630
625
};
631
626
match ns {
632
627
Namespace::MacroNS => check_full_res_macro(self),
@@ -970,7 +965,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
970
965
match self.resolve(path_str, ns, ¤t_item, base_node, &extra_fragment)
971
966
{
972
967
Ok(res) => res,
973
- Err(ErrorKind::Resolve(mut kind)) => {
968
+ Err(ErrorKind::Resolve(box mut kind)) => {
974
969
// We only looked in one namespace. Try to give a better error if possible.
975
970
if kind.full_res().is_none() {
976
971
let other_ns = if ns == ValueNS { TypeNS } else { ValueNS };
@@ -1028,7 +1023,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
1028
1023
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
1029
1024
continue;
1030
1025
}
1031
- Err(ErrorKind::Resolve(kind)) => Err(kind),
1026
+ Err(ErrorKind::Resolve(box kind)) => Err(kind),
1032
1027
},
1033
1028
value_ns: match self.resolve(
1034
1029
path_str,
@@ -1042,7 +1037,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
1042
1037
anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
1043
1038
continue;
1044
1039
}
1045
- Err(ErrorKind::Resolve(kind)) => Err(kind),
1040
+ Err(ErrorKind::Resolve(box kind)) => Err(kind),
1046
1041
}
1047
1042
.and_then(|(res, fragment)| {
1048
1043
// Constructors are picked up in the type namespace.
@@ -1816,7 +1811,7 @@ fn handle_variant(
1816
1811
let parent = if let Some(parent) = cx.tcx.parent(res.def_id()) {
1817
1812
parent
1818
1813
} else {
1819
- return Err(ErrorKind::Resolve( ResolutionFailure::NoParentItem));
1814
+ return Err(ResolutionFailure::NoParentItem.into( ));
1820
1815
};
1821
1816
let parent_def = Res::Def(DefKind::Enum, parent);
1822
1817
let variant = cx.tcx.expect_variant_res(res);
0 commit comments