Skip to content

Commit 918c52e

Browse files
Merge pull request #262 from danieleades/chore/clippy-all-targets
ensure clippy runs on all targets
2 parents 8092fc0 + a880573 commit 918c52e

25 files changed

+82
-70
lines changed

.github/workflows/msrv.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
uses: actions-rs/cargo@v1
137137
with:
138138
command: clippy
139-
args: -- -D warnings
139+
args: --all-targets --all-features -- -D warnings
140140

141141
check-examples:
142142
name: Check examples

examples/glob/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ fn main() {
77
// Option 1
88
// --------
99
// Gather all conf files from conf/ manually
10-
let mut settings = Config::default();
11-
settings
10+
let settings = Config::builder()
1211
// File::with_name(..) is shorthand for File::from(Path::new(..))
13-
.merge(File::with_name("examples/glob/conf/00-default.toml"))
14-
.unwrap()
15-
.merge(File::from(Path::new("examples/glob/conf/05-some.yml")))
16-
.unwrap()
17-
.merge(File::from(Path::new("examples/glob/conf/99-extra.json")))
12+
.add_source(File::with_name("examples/glob/conf/00-default.toml"))
13+
.add_source(File::from(Path::new("examples/glob/conf/05-some.yml")))
14+
.add_source(File::from(Path::new("examples/glob/conf/99-extra.json")))
15+
.build()
1816
.unwrap();
1917

2018
// Print out our settings (as a HashMap)
@@ -28,13 +26,13 @@ fn main() {
2826
// Option 2
2927
// --------
3028
// Gather all conf files from conf/ manually, but put in 1 merge call.
31-
let mut settings = Config::default();
32-
settings
33-
.merge(vec![
29+
let settings = Config::builder()
30+
.add_source(vec![
3431
File::with_name("examples/glob/conf/00-default.toml"),
3532
File::from(Path::new("examples/glob/conf/05-some.yml")),
3633
File::from(Path::new("examples/glob/conf/99-extra.json")),
3734
])
35+
.build()
3836
.unwrap();
3937

4038
// Print out our settings (as a HashMap)
@@ -48,14 +46,14 @@ fn main() {
4846
// Option 3
4947
// --------
5048
// Gather all conf files from conf/ using glob and put in 1 merge call.
51-
let mut settings = Config::default();
52-
settings
53-
.merge(
49+
let settings = Config::builder()
50+
.add_source(
5451
glob("examples/glob/conf/*")
5552
.unwrap()
5653
.map(|path| File::from(path.unwrap()))
5754
.collect::<Vec<_>>(),
5855
)
56+
.build()
5957
.unwrap();
6058

6159
// Print out our settings (as a HashMap)

examples/global/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
use config::Config;
23
use lazy_static::lazy_static;
34
use std::error::Error;

examples/hierarchical-env/settings.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use serde_derive::Deserialize;
33
use std::env;
44

55
#[derive(Debug, Deserialize)]
6+
#[allow(unused)]
67
struct Database {
78
url: String,
89
}
910

1011
#[derive(Debug, Deserialize)]
12+
#[allow(unused)]
1113
struct Sparkpost {
1214
key: String,
1315
token: String,
@@ -16,19 +18,22 @@ struct Sparkpost {
1618
}
1719

1820
#[derive(Debug, Deserialize)]
21+
#[allow(unused)]
1922
struct Twitter {
2023
consumer_token: String,
2124
consumer_secret: String,
2225
}
2326

2427
#[derive(Debug, Deserialize)]
28+
#[allow(unused)]
2529
struct Braintree {
2630
merchant_id: String,
2731
public_key: String,
2832
private_key: String,
2933
}
3034

3135
#[derive(Debug, Deserialize)]
36+
#[allow(unused)]
3237
pub struct Settings {
3338
debug: bool,
3439
database: Database,
@@ -39,29 +44,27 @@ pub struct Settings {
3944

4045
impl Settings {
4146
pub fn new() -> Result<Self, ConfigError> {
42-
let mut s = Config::default();
47+
let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());
4348

44-
// Start off by merging in the "default" configuration file
45-
s.merge(File::with_name("examples/hierarchical-env/config/default"))?;
46-
47-
// Add in the current environment file
48-
// Default to 'development' env
49-
// Note that this file is _optional_
50-
let env = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());
51-
s.merge(
52-
File::with_name(&format!("examples/hierarchical-env/config/{}", env)).required(false),
53-
)?;
54-
55-
// Add in a local configuration file
56-
// This file shouldn't be checked in to git
57-
s.merge(File::with_name("examples/hierarchical-env/config/local").required(false))?;
58-
59-
// Add in settings from the environment (with a prefix of APP)
60-
// Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
61-
s.merge(Environment::with_prefix("app"))?;
62-
63-
// You may also programmatically change settings
64-
s.set("database.url", "postgres://")?;
49+
let s = Config::builder()
50+
// Start off by merging in the "default" configuration file
51+
.add_source(File::with_name("examples/hierarchical-env/config/default"))
52+
// Add in the current environment file
53+
// Default to 'development' env
54+
// Note that this file is _optional_
55+
.add_source(
56+
File::with_name(&format!("examples/hierarchical-env/config/{}", run_mode))
57+
.required(false),
58+
)
59+
// Add in a local configuration file
60+
// This file shouldn't be checked in to git
61+
.add_source(File::with_name("examples/hierarchical-env/config/local").required(false))
62+
// Add in settings from the environment (with a prefix of APP)
63+
// Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
64+
.add_source(Environment::with_prefix("app"))
65+
// You may also programmatically change settings
66+
.set_override("database.url", "postgres://")?
67+
.build()?;
6568

6669
// Now that we're done, let's access our configuration
6770
println!("debug: {:?}", s.get_bool("debug"));

examples/simple/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use config::Config;
12
use std::collections::HashMap;
23

34
fn main() {
4-
let mut settings = config::Config::default();
5-
settings
5+
let settings = Config::builder()
66
// Add in `./Settings.toml`
7-
.merge(config::File::with_name("examples/simple/Settings"))
8-
.unwrap()
7+
.add_source(config::File::with_name("examples/simple/Settings"))
98
// Add in settings from the environment (with a prefix of APP)
109
// Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
11-
.merge(config::Environment::with_prefix("APP"))
10+
.add_source(config::Environment::with_prefix("APP"))
11+
.build()
1212
.unwrap();
1313

1414
// Print out our settings (as a HashMap)

examples/watch/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(deprecated)]
12
use config::{Config, File};
23
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
34
use std::collections::HashMap;

src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl ConfigBuilder<AsyncState> {
272272
///
273273
/// Calling this method does not invoke any I/O. [`Source`] is only saved in internal register for later use.
274274
#[must_use]
275-
pub fn add_source<T>(mut self, source: T) -> ConfigBuilder<AsyncState>
275+
pub fn add_source<T>(mut self, source: T) -> Self
276276
where
277277
T: Source + Send + Sync + 'static,
278278
{
@@ -284,7 +284,7 @@ impl ConfigBuilder<AsyncState> {
284284
///
285285
/// Calling this method does not invoke any I/O. [`AsyncSource`] is only saved in internal register for later use.
286286
#[must_use]
287-
pub fn add_async_source<T>(mut self, source: T) -> ConfigBuilder<AsyncState>
287+
pub fn add_async_source<T>(mut self, source: T) -> Self
288288
where
289289
T: AsyncSource + Send + Sync + 'static,
290290
{

src/file/source/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl FileSourceFile {
7373
}
7474

7575
None => {
76-
for (format, extensions) in ALL_EXTENSIONS.iter() {
76+
for format in ALL_EXTENSIONS.keys() {
7777
for ext in format.extensions() {
7878
filename.set_extension(ext);
7979

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//!
1818
//! See the [examples](https://github.com/mehcode/config-rs/tree/master/examples) for
1919
//! general usage information.
20-
#![allow(unused_variables)]
2120
#![allow(unknown_lints)]
2221
// #![warn(missing_docs)]
2322

src/ser.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer {
231231

232232
fn serialize_tuple_variant(
233233
self,
234-
name: &'static str,
234+
_name: &'static str,
235235
_variant_index: u32,
236236
variant: &'static str,
237237
_len: usize,
@@ -253,7 +253,7 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer {
253253
_name: &'static str,
254254
_variant_index: u32,
255255
variant: &'static str,
256-
len: usize,
256+
_len: usize,
257257
) -> Result<Self::SerializeStructVariant> {
258258
self.push_key(variant);
259259
Ok(self)
@@ -580,7 +580,7 @@ impl ser::SerializeSeq for StringKeySerializer {
580580
type Ok = String;
581581
type Error = ConfigError;
582582

583-
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
583+
fn serialize_element<T>(&mut self, _value: &T) -> Result<()>
584584
where
585585
T: ?Sized + ser::Serialize,
586586
{
@@ -596,7 +596,7 @@ impl ser::SerializeTuple for StringKeySerializer {
596596
type Ok = String;
597597
type Error = ConfigError;
598598

599-
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
599+
fn serialize_element<T>(&mut self, _value: &T) -> Result<()>
600600
where
601601
T: ?Sized + ser::Serialize,
602602
{
@@ -612,7 +612,7 @@ impl ser::SerializeTupleStruct for StringKeySerializer {
612612
type Ok = String;
613613
type Error = ConfigError;
614614

615-
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
615+
fn serialize_field<T>(&mut self, _value: &T) -> Result<()>
616616
where
617617
T: ?Sized + ser::Serialize,
618618
{
@@ -628,7 +628,7 @@ impl ser::SerializeTupleVariant for StringKeySerializer {
628628
type Ok = String;
629629
type Error = ConfigError;
630630

631-
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
631+
fn serialize_field<T>(&mut self, _value: &T) -> Result<()>
632632
where
633633
T: ?Sized + ser::Serialize,
634634
{
@@ -644,14 +644,14 @@ impl ser::SerializeMap for StringKeySerializer {
644644
type Ok = String;
645645
type Error = ConfigError;
646646

647-
fn serialize_key<T>(&mut self, key: &T) -> Result<()>
647+
fn serialize_key<T>(&mut self, _key: &T) -> Result<()>
648648
where
649649
T: ?Sized + ser::Serialize,
650650
{
651651
unreachable!()
652652
}
653653

654-
fn serialize_value<T>(&mut self, value: &T) -> Result<()>
654+
fn serialize_value<T>(&mut self, _value: &T) -> Result<()>
655655
where
656656
T: ?Sized + ser::Serialize,
657657
{
@@ -667,7 +667,7 @@ impl ser::SerializeStruct for StringKeySerializer {
667667
type Ok = String;
668668
type Error = ConfigError;
669669

670-
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
670+
fn serialize_field<T>(&mut self, _key: &'static str, _value: &T) -> Result<()>
671671
where
672672
T: ?Sized + ser::Serialize,
673673
{
@@ -683,7 +683,7 @@ impl ser::SerializeStructVariant for StringKeySerializer {
683683
type Ok = String;
684684
type Error = ConfigError;
685685

686-
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
686+
fn serialize_field<T>(&mut self, _key: &'static str, _value: &T) -> Result<()>
687687
where
688688
T: ?Sized + ser::Serialize,
689689
{

tests/async_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async fn test_single_async_file_source() {
4646
.await
4747
.unwrap();
4848

49-
assert_eq!(true, config.get::<bool>("debug").unwrap());
49+
assert!(config.get::<bool>("debug").unwrap());
5050
}
5151

5252
#[tokio::test]
@@ -65,7 +65,7 @@ async fn test_two_async_file_sources() {
6565
.unwrap();
6666

6767
assert_eq!("Torre di Pisa", config.get::<String>("place.name").unwrap());
68-
assert_eq!(true, config.get::<bool>("debug_json").unwrap());
68+
assert!(config.get::<bool>("debug_json").unwrap());
6969
assert_eq!(1, config.get::<i32>("place.number").unwrap());
7070
}
7171

tests/env.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ fn test_parse_off_int() {
199199

200200
#[derive(Deserialize, Debug)]
201201
struct TestInt {
202+
#[allow(dead_code)]
202203
int_val_1: i32,
203204
}
204205

@@ -230,6 +231,7 @@ fn test_parse_off_float() {
230231

231232
#[derive(Deserialize, Debug)]
232233
struct TestFloat {
234+
#[allow(dead_code)]
233235
float_val_1: f64,
234236
}
235237

@@ -261,6 +263,7 @@ fn test_parse_off_bool() {
261263

262264
#[derive(Deserialize, Debug)]
263265
struct TestBool {
266+
#[allow(dead_code)]
264267
bool_val_1: bool,
265268
}
266269

@@ -292,6 +295,7 @@ fn test_parse_int_fail() {
292295

293296
#[derive(Deserialize, Debug)]
294297
struct TestInt {
298+
#[allow(dead_code)]
295299
int_val_2: i32,
296300
}
297301

@@ -323,6 +327,7 @@ fn test_parse_float_fail() {
323327

324328
#[derive(Deserialize, Debug)]
325329
struct TestFloat {
330+
#[allow(dead_code)]
326331
float_val_2: f64,
327332
}
328333

@@ -354,6 +359,7 @@ fn test_parse_bool_fail() {
354359

355360
#[derive(Deserialize, Debug)]
356361
struct TestBool {
362+
#[allow(dead_code)]
357363
bool_val_2: bool,
358364
}
359365

tests/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ fn test_error_enum_de() {
106106
fn error_with_path() {
107107
#[derive(Debug, Deserialize)]
108108
struct Inner {
109+
#[allow(dead_code)]
109110
test: i32,
110111
}
111112

112113
#[derive(Debug, Deserialize)]
113114
struct Outer {
115+
#[allow(dead_code)]
114116
inner: Inner,
115117
}
116118
const CFG: &str = r#"

tests/file_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn test_file() {
4747
assert_eq!(s.place.name, "Torre di Pisa");
4848
assert!(s.place.longitude.approx_eq_ulps(&43.7224985, 2));
4949
assert!(s.place.latitude.approx_eq_ulps(&10.3970522, 2));
50-
assert_eq!(s.place.favorite, false);
50+
assert!(!s.place.favorite);
5151
assert_eq!(s.place.reviews, 3866);
5252
assert_eq!(s.place.rating, Some(4.5));
5353
assert_eq!(s.place.telephone, None);

0 commit comments

Comments
 (0)