Skip to content

Commit 0a91dae

Browse files
committed
Vec -> HashSet
1 parent ce02b7f commit 0a91dae

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustdoc_json_types::*;
1414
use crate::clean;
1515
use crate::formats::item_type::ItemType;
1616
use crate::json::JsonRenderer;
17+
use std::collections::HashSet;
1718

1819
impl JsonRenderer<'_> {
1920
pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
@@ -225,19 +226,19 @@ crate fn from_ctor_kind(struct_type: CtorKind) -> StructType {
225226
}
226227
}
227228

228-
crate fn from_fn_header(header: &rustc_hir::FnHeader) -> Vec<Modifiers> {
229-
let mut v = Vec::new();
229+
crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet<Modifiers> {
230+
let mut v = HashSet::new();
230231

231232
if let rustc_hir::Unsafety::Unsafe = header.unsafety {
232-
v.push(Modifiers::Unsafe);
233+
v.insert(Modifiers::Unsafe);
233234
}
234235

235236
if let rustc_hir::IsAsync::Async = header.asyncness {
236-
v.push(Modifiers::Async);
237+
v.insert(Modifiers::Async);
237238
}
238239

239240
if let rustc_hir::Constness::Const = header.constness {
240-
v.push(Modifiers::Const);
241+
v.insert(Modifiers::Const);
241242
}
242243

243244
v
@@ -372,9 +373,11 @@ impl From<clean::BareFunctionDecl> for FunctionPointer {
372373
let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
373374
FunctionPointer {
374375
header: if let rustc_hir::Unsafety::Unsafe = unsafety {
375-
vec![Modifiers::Unsafe]
376+
let mut hs = HashSet::new();
377+
hs.insert(Modifiers::Unsafe);
378+
hs
376379
} else {
377-
vec![]
380+
HashSet::new()
378381
},
379382
generic_params: generic_params.into_iter().map(Into::into).collect(),
380383
decl: decl.into(),

src/rustdoc-json-types/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
44
//! struct is the root of the JSON blob and all other items are contained within.
55
6-
use std::collections::HashMap;
6+
use std::collections::{HashMap, HashSet};
77
use std::path::PathBuf;
88

99
use serde::{Deserialize, Serialize};
@@ -282,7 +282,7 @@ pub enum StructType {
282282
}
283283

284284
#[non_exhaustive]
285-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
285+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
286286
#[serde(rename_all = "snake_case")]
287287
pub enum Modifiers {
288288
Const,
@@ -294,15 +294,15 @@ pub enum Modifiers {
294294
pub struct Function {
295295
pub decl: FnDecl,
296296
pub generics: Generics,
297-
pub header: Vec<Modifiers>,
297+
pub header: HashSet<Modifiers>,
298298
pub abi: String,
299299
}
300300

301301
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
302302
pub struct Method {
303303
pub decl: FnDecl,
304304
pub generics: Generics,
305-
pub header: Vec<Modifiers>,
305+
pub header: HashSet<Modifiers>,
306306
pub abi: String,
307307
pub has_body: bool,
308308
}
@@ -415,7 +415,7 @@ pub enum Type {
415415
pub struct FunctionPointer {
416416
pub decl: FnDecl,
417417
pub generic_params: Vec<GenericParamDef>,
418-
pub header: Vec<Modifiers>,
418+
pub header: HashSet<Modifiers>,
419419
pub abi: String,
420420
}
421421

0 commit comments

Comments
 (0)