diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-12-29 18:24:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-29 18:24:33 +0100 |
| commit | caa33bfc75e51ba412db6b9b415336aecd8e6c66 (patch) | |
| tree | d6c1106ba38ec6061f0a0598779a2ef1e426cc61 /src | |
| parent | b75b0a8f94fcabf6e4e81d15f7486bf749132cff (diff) | |
| parent | c6b90d28009320dfa823136921242b5c0e02ae97 (diff) | |
| download | rust-caa33bfc75e51ba412db6b9b415336aecd8e6c66.tar.gz rust-caa33bfc75e51ba412db6b9b415336aecd8e6c66.zip | |
Rollup merge of #106260 - chenyukang:yukang/fix-106213-doc, r=GuillaumeGomez
Fix index out of bounds issues in rustdoc Fixes #106213 r? `@matthiaskrgr`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/types.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render/search_index.rs | 3 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/issue-106213.rs | 7 | ||||
| -rw-r--r-- | src/test/rustdoc-ui/issue-106213.stderr | 9 |
4 files changed, 18 insertions, 3 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 7a13e7e36d1..62217df8de7 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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), diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 8eb9c07f8a7..2d61519d6c9 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -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_) => { diff --git a/src/test/rustdoc-ui/issue-106213.rs b/src/test/rustdoc-ui/issue-106213.rs new file mode 100644 index 00000000000..6d51846b7d0 --- /dev/null +++ b/src/test/rustdoc-ui/issue-106213.rs @@ -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 ) +} diff --git a/src/test/rustdoc-ui/issue-106213.stderr b/src/test/rustdoc-ui/issue-106213.stderr new file mode 100644 index 00000000000..0a4ff69bafb --- /dev/null +++ b/src/test/rustdoc-ui/issue-106213.stderr @@ -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`. |
