Skip to content

Commit 9113ca1

Browse files
committed
clippy fixes
1 parent 776e629 commit 9113ca1

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/cargo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use error::*;
1111
///
1212
/// ## Arguments
1313
///
14-
/// - manifest_path: The path containing the `Cargo.toml` of the crate
14+
/// - `manifest_path`: The path containing the `Cargo.toml` of the crate
1515
pub fn generate_analysis(manifest_path: &Path) -> Result<()> {
1616
// FIXME: Here we assume that we are documenting a library. This could be wrong, but it's the
1717
// common case, and it ensures that we are documenting the right target in the case that the
@@ -45,7 +45,7 @@ pub fn generate_analysis(manifest_path: &Path) -> Result<()> {
4545
///
4646
/// ## Arguments
4747
///
48-
/// - manifest_path: The path to the location of `Cargo.toml` of the crate being documented
48+
/// - `manifest_path`: The path to the location of `Cargo.toml` of the crate being documented
4949
pub fn crate_name_from_manifest_path(manifest_path: &Path) -> Result<String> {
5050
let mut command = Command::new("cargo");
5151

@@ -76,7 +76,7 @@ pub fn crate_name_from_manifest_path(manifest_path: &Path) -> Result<String> {
7676
///
7777
/// ## Arguments
7878
///
79-
/// - metadata: The JSON metadata of the crate.
79+
/// - `metadata`: The JSON metadata of the crate.
8080
fn crate_name_from_metadata(metadata: &serde_json::Value) -> Result<String> {
8181
let targets = match metadata["packages"][0]["targets"].as_array() {
8282
Some(targets) => targets,

src/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::HashMap;
55
// Sizes for the HashMaps to avoid reallocation and large HashMap sizes when we know
66
// the upper limit for them
77

8-
/// Number of possible values in the enum item::Metadata
8+
/// Number of possible values in the enum `analysis::DefKind`
99
pub const METADATA_SIZE: usize = 14;
1010

1111
/// Under each item in data.relationships how many fields are there. For now we only have one which
@@ -46,7 +46,7 @@ const DATA_SIZE: usize = 1;
4646
/// ]
4747
/// }
4848
/// ```
49-
#[derive(Serialize, Debug)]
49+
#[derive(Debug, Default, Serialize)]
5050
pub struct Documentation {
5151
/// The top level crate information and documentation
5252
data: Option<Document>,
@@ -57,7 +57,7 @@ pub struct Documentation {
5757

5858
/// A sub type of the `Documentation` struct. It contains the majority of the data. It can be used
5959
/// for both the `data` and `included` field in the serialized JSON.
60-
#[derive(Serialize, Debug)]
60+
#[derive(Debug, Default, Serialize)]
6161
pub struct Document {
6262
#[serde(rename = "type")]
6363
/// The type of the item (e.g. "crate", "function", "enum", etc.)
@@ -75,7 +75,7 @@ pub struct Document {
7575
}
7676

7777
/// Used to populate the `relationships` `data` field in the serialized JSON
78-
#[derive(Serialize, Debug)]
78+
#[derive(Debug, Default, Serialize)]
7979
pub struct Data {
8080
#[serde(rename = "type")]
8181
/// The type of the item (e.g. "crate", "function", "enum", etc.)

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Config {
5454
///
5555
/// ## Arguments
5656
///
57-
/// - manifest_path: The path to the location of `Cargo.toml` of the crate being documented
57+
/// - `manifest_path`: The path to the location of `Cargo.toml` of the crate being documented
5858
pub fn new(manifest_path: PathBuf, assets: Vec<Asset>) -> Result<Config> {
5959
let host = analysis::AnalysisHost::new(analysis::Target::Debug);
6060

@@ -71,8 +71,8 @@ impl Config {
7171
///
7272
/// ## Arguments
7373
///
74-
/// - config: The `Config` struct that contains the data needed to generate the documentation
75-
/// - artifacts: A slice containing what assets should be output at the end
74+
/// - `config`: The `Config` struct that contains the data needed to generate the documentation
75+
/// - `artifacts`: A slice containing what assets should be output at the end
7676
pub fn build(config: &Config, artifacts: &[&str]) -> Result<()> {
7777
generate_and_load_analysis(config)?;
7878

@@ -121,8 +121,8 @@ pub fn build(config: &Config, artifacts: &[&str]) -> Result<()> {
121121
///
122122
/// ## Arguments:
123123
///
124-
/// - config: Contains data for what needs to be output or used. In this case the path to the
125-
/// `Cargo.toml` file
124+
/// - `config`: Contains data for what needs to be output or used. In this case the path to the
125+
/// `Cargo.toml` file
126126
fn generate_and_load_analysis(config: &Config) -> Result<()> {
127127
let manifest_path = &config.manifest_path;
128128

@@ -146,11 +146,11 @@ fn generate_and_load_analysis(config: &Config) -> Result<()> {
146146
Ok(())
147147
}
148148

149-
/// This creates the JSON documentation from the given AnalysisHost.
149+
/// This creates the JSON documentation from the given `AnalysisHost`.
150150
pub fn create_json(host: &AnalysisHost, crate_name: &str) -> Result<String> {
151151
let roots = host.def_roots()?;
152152

153-
let id = roots.iter().find(|&&(_, ref name)| name == &crate_name);
153+
let id = roots.iter().find(|&&(_, ref name)| name == crate_name);
154154
let root_id = match id {
155155
Some(&(id, _)) => id,
156156
_ => return Err(ErrorKind::CrateErr(crate_name.to_string()).into()),
@@ -167,7 +167,7 @@ pub fn create_json(host: &AnalysisHost, crate_name: &str) -> Result<String> {
167167

168168
let child_defs: Vec<analysis::Def> = ids.into_par_iter()
169169
.map(|id: analysis::Id| recur(&id, host))
170-
.reduce(|| Vec::new(), |mut a: Vec<analysis::Def>,
170+
.reduce(Vec::default, |mut a: Vec<analysis::Def>,
171171
b: Vec<analysis::Def>| {
172172
a.extend(b);
173173
a
@@ -208,7 +208,7 @@ pub fn create_json(host: &AnalysisHost, crate_name: &str) -> Result<String> {
208208
.attributes(String::from("docs"), root_def.docs);
209209

210210
// Insert all of the different types of relationships into this `Document` type only
211-
for (ty, data) in relationships.into_iter() {
211+
for (ty, data) in relationships {
212212
data_document.relationships(ty, data);
213213
}
214214

tests/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn generate_analysis(source_file: &Path, tempdir: &Path) -> Result<AnalysisHost>
138138
Ok(())
139139
}
140140

141-
workaround(&tempdir)?;
141+
workaround(tempdir)?;
142142

143143
let host = AnalysisHost::new(Target::Debug);
144144
host.reload(tempdir, tempdir)?;

tests/validation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ mod validation_tests {
3333
panic!("Error: {}", err);
3434
});
3535

36-
match doc.validate() {
37-
Some(errors) => panic!("Error: {:?}", errors),
38-
None => (),
36+
if let Some(errors) = doc.validate() {
37+
panic!("Error: {:?}", errors);
3938
}
4039
}
4140
}

0 commit comments

Comments
 (0)