Skip to content

Commit 63b404c

Browse files
authored
Merge pull request diesel-rs#2305 from jplatte/lints
Some small refactorings
2 parents dacfcdd + 9d8304b commit 63b404c

7 files changed

Lines changed: 13 additions & 9 deletions

File tree

diesel/src/mysql/connection/url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ConnectionOptions {
4040
Some(password) => Some(decode_into_cstring(password)?),
4141
None => None,
4242
};
43-
let database = match url.path_segments().and_then(|mut iter| iter.nth(0)) {
43+
let database = match url.path_segments().and_then(|mut iter| iter.next()) {
4444
Some("") | None => None,
4545
Some(segment) => Some(CString::new(segment.as_bytes())?),
4646
};

diesel_cli/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::error::Error;
44
use std::fs;
55
use std::io::Read;
66
use std::path::PathBuf;
7-
use toml;
87

98
use super::find_project_root;
109
use crate::print_schema;

diesel_cli/src/infer_schema_internals/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn load_foreign_key_constraints(
8585
.collect())
8686
})
8787
.collect::<QueryResult<Vec<Vec<_>>>>()?;
88-
Ok(rows.into_iter().flat_map(|x| x).collect())
88+
Ok(rows.into_iter().flatten().collect())
8989
}
9090

9191
pub fn get_table_data(

diesel_cli/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ fn migrations_dir(matches: &ArgMatches) -> Result<PathBuf, MigrationError> {
216216
Config::read(matches)
217217
.unwrap_or_else(handle_error)
218218
.migrations_directory?
219-
.dir
220-
.to_owned(),
219+
.dir,
221220
)
222221
});
223222

@@ -248,7 +247,7 @@ fn create_migrations_dir(matches: &ArgMatches) -> DatabaseResult<PathBuf> {
248247
create_migrations_directory(&dir)?;
249248
}
250249

251-
Ok(dir.to_owned())
250+
Ok(dir)
252251
}
253252

254253
fn create_config_file(matches: &ArgMatches) -> DatabaseResult<()> {

diesel_derives/src/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl MetaItem {
8282
}
8383

8484
pub fn ident_value(&self) -> Result<syn::Ident, Diagnostic> {
85-
let maybe_attr = self.nested().ok().and_then(|mut n| n.nth(0));
85+
let maybe_attr = self.nested().ok().and_then(|mut n| n.next());
8686
let maybe_path = maybe_attr.as_ref().and_then(|m| m.path().ok());
8787
match maybe_path {
8888
Some(x) => {

diesel_derives/src/util.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream {
88
quote! {
99
#[allow(unused_imports)]
1010
const _: () = {
11+
// This import is not actually redundant. When using diesel_derives
12+
// inside of diesel, `diesel` doesn't exist as an extern crate, and
13+
// to work around that it contains a private
14+
// `mod diesel { pub use super::*; }` that this import will then
15+
// refer to. In all other cases, this imports refers to the extern
16+
// crate diesel.
1117
use diesel;
1218

1319
#item
@@ -46,7 +52,7 @@ fn option_ty_arg(ty: &Type) -> Option<&Type> {
4652
pub fn ty_for_foreign_derive(item: &DeriveInput, flags: &MetaItem) -> Result<Type, Diagnostic> {
4753
if flags.has_flag("foreign_derive") {
4854
match item.data {
49-
Data::Struct(ref body) => match body.fields.iter().nth(0) {
55+
Data::Struct(ref body) => match body.fields.iter().next() {
5056
Some(field) => Ok(field.ty.clone()),
5157
None => Err(flags
5258
.span()

diesel_migrations/migrations_internals/src/migration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn version_from_path(path: &Path) -> Result<String, MigrationError> {
102102
.unwrap_or_else(|| panic!("Can't get file name from path `{:?}`", path))
103103
.to_string_lossy()
104104
.split('_')
105-
.nth(0)
105+
.next()
106106
.map(|s| Ok(s.replace('-', "")))
107107
.unwrap_or_else(|| Err(MigrationError::UnknownMigrationFormat(path.to_path_buf())))
108108
}

0 commit comments

Comments
 (0)