Skip to content

Commit

Permalink
Rollup merge of #106260 - chenyukang:yukang/fix-106213-doc, r=Guillau…
Browse files Browse the repository at this point in the history
…meGomez

Fix index out of bounds issues in rustdoc

Fixes #106213
r? `@matthiaskrgr`
  • Loading branch information
matthiaskrgr committed Dec 29, 2022
2 parents b75b0a8 + c6b90d2 commit caa33bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ impl Type {
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
let t: PrimitiveType = match *self {
Type::Path { ref path } => return Some(path.def_id()),
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
DynTrait(ref bounds, _) => return bounds.get(0).map(|b| b.trait_.def_id()),
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
BorrowedRef { ref type_, .. } => return type_.inner_def_id(cache),
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ fn get_index_type_id(clean_type: &clean::Type) -> Option<RenderTypeId> {
match *clean_type {
clean::Type::Path { ref path, .. } => Some(RenderTypeId::DefId(path.def_id())),
clean::DynTrait(ref bounds, _) => {
let path = &bounds[0].trait_;
Some(RenderTypeId::DefId(path.def_id()))
bounds.get(0).map(|b| RenderTypeId::DefId(b.trait_.def_id()))
}
clean::Primitive(p) => Some(RenderTypeId::Primitive(p)),
clean::BorrowedRef { ref type_, .. } | clean::RawPointer(_, ref type_) => {
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-ui/issue-106213.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-flags: --document-private-items
// edition:2021

fn use_avx() -> dyn {
//~^ ERROR at least one trait is required for an object type
!( ident_error )
}
9 changes: 9 additions & 0 deletions src/test/rustdoc-ui/issue-106213.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0224]: at least one trait is required for an object type
--> $DIR/issue-106213.rs:4:17
|
LL | fn use_avx() -> dyn {
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0224`.

0 comments on commit caa33bf

Please sign in to comment.