Skip to content

Commit caa33bf

Browse files
authoredDec 29, 2022
Rollup merge of #106260 - chenyukang:yukang/fix-106213-doc, r=GuillaumeGomez
Fix index out of bounds issues in rustdoc Fixes #106213 r? `@matthiaskrgr`
2 parents b75b0a8 + c6b90d2 commit caa33bf

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed
 

‎src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ impl Type {
17401740
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
17411741
let t: PrimitiveType = match *self {
17421742
Type::Path { ref path } => return Some(path.def_id()),
1743-
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
1743+
DynTrait(ref bounds, _) => return bounds.get(0).map(|b| b.trait_.def_id()),
17441744
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
17451745
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
17461746
BorrowedRef { ref type_, .. } => return type_.inner_def_id(cache),

‎src/librustdoc/html/render/search_index.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ fn get_index_type_id(clean_type: &clean::Type) -> Option<RenderTypeId> {
322322
match *clean_type {
323323
clean::Type::Path { ref path, .. } => Some(RenderTypeId::DefId(path.def_id())),
324324
clean::DynTrait(ref bounds, _) => {
325-
let path = &bounds[0].trait_;
326-
Some(RenderTypeId::DefId(path.def_id()))
325+
bounds.get(0).map(|b| RenderTypeId::DefId(b.trait_.def_id()))
327326
}
328327
clean::Primitive(p) => Some(RenderTypeId::Primitive(p)),
329328
clean::BorrowedRef { ref type_, .. } | clean::RawPointer(_, ref type_) => {

‎src/test/rustdoc-ui/issue-106213.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: --document-private-items
2+
// edition:2021
3+
4+
fn use_avx() -> dyn {
5+
//~^ ERROR at least one trait is required for an object type
6+
!( ident_error )
7+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0224]: at least one trait is required for an object type
2+
--> $DIR/issue-106213.rs:4:17
3+
|
4+
LL | fn use_avx() -> dyn {
5+
| ^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0224`.

0 commit comments

Comments
 (0)
Please sign in to comment.