Skip to content

Commit bc721a1

Browse files
Rollup merge of rust-lang#52835 - GuillaumeGomez:ice-rustdoc-links, r=eddyb
Fix Alias intra doc ICE Fixes rust-lang#52611. cc @QuietMisdreavus r? @varkor
2 parents a5e993d + d94bdf8 commit bc721a1

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

src/librustdoc/clean/mod.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,8 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
11941194
})?;
11951195
match ty.def {
11961196
Def::Struct(did) | Def::Union(did) | Def::Enum(did) | Def::TyAlias(did) => {
1197-
let item = cx.tcx.inherent_impls(did).iter()
1197+
let item = cx.tcx.inherent_impls(did)
1198+
.iter()
11981199
.flat_map(|imp| cx.tcx.associated_items(*imp))
11991200
.find(|item| item.ident.name == item_name);
12001201
if let Some(item) = item {
@@ -1205,26 +1206,29 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
12051206
};
12061207
Ok((ty.def, Some(format!("{}.{}", out, item_name))))
12071208
} else {
1208-
let is_enum = match ty.def {
1209-
Def::Enum(_) => true,
1210-
_ => false,
1211-
};
1212-
let elem = if is_enum {
1213-
cx.tcx.adt_def(did).all_fields().find(|item| item.ident.name == item_name)
1214-
} else {
1215-
cx.tcx.adt_def(did)
1216-
.non_enum_variant()
1217-
.fields
1218-
.iter()
1219-
.find(|item| item.ident.name == item_name)
1220-
};
1221-
if let Some(item) = elem {
1222-
Ok((ty.def,
1223-
Some(format!("{}.{}",
1224-
if is_enum { "variant" } else { "structfield" },
1225-
item.ident))))
1226-
} else {
1227-
Err(())
1209+
match cx.tcx.type_of(did).sty {
1210+
ty::TyAdt(def, _) => {
1211+
if let Some(item) = if def.is_enum() {
1212+
def.all_fields().find(|item| item.ident.name == item_name)
1213+
} else {
1214+
def.non_enum_variant()
1215+
.fields
1216+
.iter()
1217+
.find(|item| item.ident.name == item_name)
1218+
} {
1219+
Ok((ty.def,
1220+
Some(format!("{}.{}",
1221+
if def.is_enum() {
1222+
"variant"
1223+
} else {
1224+
"structfield"
1225+
},
1226+
item.ident))))
1227+
} else {
1228+
Err(())
1229+
}
1230+
}
1231+
_ => Err(()),
12281232
}
12291233
}
12301234
}

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)