Skip to content

Commit d5f1f70

Browse files
Fix Alias intra doc ICE
1 parent 75af9df commit d5f1f70

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

src/librustdoc/clean/mod.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,8 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
11971197
})?;
11981198
match ty.def {
11991199
Def::Struct(did) | Def::Union(did) | Def::Enum(did) | Def::TyAlias(did) => {
1200-
let item = cx.tcx.inherent_impls(did).iter()
1200+
let item = cx.tcx.inherent_impls(did)
1201+
.iter()
12011202
.flat_map(|imp| cx.tcx.associated_items(*imp))
12021203
.find(|item| item.ident.name == item_name);
12031204
if let Some(item) = item {
@@ -1208,26 +1209,23 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
12081209
};
12091210
Ok((ty.def, Some(format!("{}.{}", out, item_name))))
12101211
} else {
1211-
let is_enum = match ty.def {
1212-
Def::Enum(_) => true,
1213-
_ => false,
1214-
};
1215-
let elem = if is_enum {
1216-
cx.tcx.adt_def(did).all_fields().find(|item| item.ident.name == item_name)
1217-
} else {
1218-
cx.tcx.adt_def(did)
1219-
.non_enum_variant()
1220-
.fields
1221-
.iter()
1222-
.find(|item| item.ident.name == item_name)
1223-
};
1224-
if let Some(item) = elem {
1225-
Ok((ty.def,
1226-
Some(format!("{}.{}",
1227-
if is_enum { "variant" } else { "structfield" },
1228-
item.ident))))
1229-
} else {
1230-
Err(())
1212+
match cx.tcx.type_of(did).sty {
1213+
ty::TyAdt(def, _) => {
1214+
if let Some(item) = def.all_fields()
1215+
.find(|item| item.ident.name == item_name) {
1216+
Ok((ty.def,
1217+
Some(format!("{}.{}",
1218+
if def.is_enum() {
1219+
"variant"
1220+
} else {
1221+
"structfield"
1222+
},
1223+
item.ident))))
1224+
} else {
1225+
Err(())
1226+
}
1227+
}
1228+
_ => Err(()),
12311229
}
12321230
}
12331231
}

src/librustdoc/visit_ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
105105
}
106106

107107
pub fn visit_variant_data(&mut self, item: &hir::Item,
108-
name: ast::Name, sd: &hir::VariantData,
109-
generics: &hir::Generics) -> Struct {
108+
name: ast::Name, sd: &hir::VariantData,
109+
generics: &hir::Generics) -> Struct {
110110
debug!("Visiting struct");
111111
let struct_type = struct_type_from_def(&*sd);
112112
Struct {
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(intra_doc_link_resolution_failure)]
12+
13+
pub type TypeAlias = usize;
14+
15+
/// [broken cross-reference](TypeAlias::hoge) //~ ERROR
16+
pub fn some_public_item() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: `[TypeAlias::hoge]` cannot be resolved, ignoring it...
2+
--> $DIR/intra-doc-alias-ice.rs:15:30
3+
|
4+
15 | /// [broken cross-reference](TypeAlias::hoge) //~ ERROR
5+
| ^^^^^^^^^^^^^^^ cannot be resolved, ignoring
6+
|
7+
note: lint level defined here
8+
--> $DIR/intra-doc-alias-ice.rs:11:9
9+
|
10+
11 | #![deny(intra_doc_link_resolution_failure)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]`
13+

0 commit comments

Comments
 (0)