From 0a91daeaa33e4ae71e0be405cdddba741b72aa7f Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Mon, 8 Feb 2021 16:04:14 -0500 Subject: [PATCH] Vec -> HashSet --- src/librustdoc/json/conversions.rs | 17 ++++++++++------- src/rustdoc-json-types/lib.rs | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index af44ab9868e..de0240f28f7 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -14,6 +14,7 @@ use rustdoc_json_types::*; use crate::clean; use crate::formats::item_type::ItemType; use crate::json::JsonRenderer; +use std::collections::HashSet; impl JsonRenderer<'_> { pub(super) fn convert_item(&self, item: clean::Item) -> Option { @@ -225,19 +226,19 @@ crate fn from_ctor_kind(struct_type: CtorKind) -> StructType { } } -crate fn from_fn_header(header: &rustc_hir::FnHeader) -> Vec { - let mut v = Vec::new(); +crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet { + let mut v = HashSet::new(); if let rustc_hir::Unsafety::Unsafe = header.unsafety { - v.push(Modifiers::Unsafe); + v.insert(Modifiers::Unsafe); } if let rustc_hir::IsAsync::Async = header.asyncness { - v.push(Modifiers::Async); + v.insert(Modifiers::Async); } if let rustc_hir::Constness::Const = header.constness { - v.push(Modifiers::Const); + v.insert(Modifiers::Const); } v @@ -372,9 +373,11 @@ impl From for FunctionPointer { let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl; FunctionPointer { header: if let rustc_hir::Unsafety::Unsafe = unsafety { - vec![Modifiers::Unsafe] + let mut hs = HashSet::new(); + hs.insert(Modifiers::Unsafe); + hs } else { - vec![] + HashSet::new() }, generic_params: generic_params.into_iter().map(Into::into).collect(), decl: decl.into(), diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 20bae0f14a2..a2f323699c1 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -3,7 +3,7 @@ //! These types are the public API exposed through the `--output-format json` flag. The [`Crate`] //! struct is the root of the JSON blob and all other items are contained within. -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::path::PathBuf; use serde::{Deserialize, Serialize}; @@ -282,7 +282,7 @@ pub enum StructType { } #[non_exhaustive] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "snake_case")] pub enum Modifiers { Const, @@ -294,7 +294,7 @@ pub enum Modifiers { pub struct Function { pub decl: FnDecl, pub generics: Generics, - pub header: Vec, + pub header: HashSet, pub abi: String, } @@ -302,7 +302,7 @@ pub struct Function { pub struct Method { pub decl: FnDecl, pub generics: Generics, - pub header: Vec, + pub header: HashSet, pub abi: String, pub has_body: bool, } @@ -415,7 +415,7 @@ pub enum Type { pub struct FunctionPointer { pub decl: FnDecl, pub generic_params: Vec, - pub header: Vec, + pub header: HashSet, pub abi: String, }