Skip to content

Commit

Permalink
Merge pull request #2305 from jplatte/lints
Browse files Browse the repository at this point in the history
Some small refactorings
  • Loading branch information
weiznich authored Feb 20, 2020
2 parents dacfcdd + 9d8304b commit 63b404c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion diesel/src/mysql/connection/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ConnectionOptions {
Some(password) => Some(decode_into_cstring(password)?),
None => None,
};
let database = match url.path_segments().and_then(|mut iter| iter.nth(0)) {
let database = match url.path_segments().and_then(|mut iter| iter.next()) {
Some("") | None => None,
Some(segment) => Some(CString::new(segment.as_bytes())?),
};
Expand Down
1 change: 0 additions & 1 deletion diesel_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::error::Error;
use std::fs;
use std::io::Read;
use std::path::PathBuf;
use toml;

use super::find_project_root;
use crate::print_schema;
Expand Down
2 changes: 1 addition & 1 deletion diesel_cli/src/infer_schema_internals/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn load_foreign_key_constraints(
.collect())
})
.collect::<QueryResult<Vec<Vec<_>>>>()?;
Ok(rows.into_iter().flat_map(|x| x).collect())
Ok(rows.into_iter().flatten().collect())
}

pub fn get_table_data(
Expand Down
5 changes: 2 additions & 3 deletions diesel_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ fn migrations_dir(matches: &ArgMatches) -> Result<PathBuf, MigrationError> {
Config::read(matches)
.unwrap_or_else(handle_error)
.migrations_directory?
.dir
.to_owned(),
.dir,
)
});

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

Ok(dir.to_owned())
Ok(dir)
}

fn create_config_file(matches: &ArgMatches) -> DatabaseResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion diesel_derives/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl MetaItem {
}

pub fn ident_value(&self) -> Result<syn::Ident, Diagnostic> {
let maybe_attr = self.nested().ok().and_then(|mut n| n.nth(0));
let maybe_attr = self.nested().ok().and_then(|mut n| n.next());
let maybe_path = maybe_attr.as_ref().and_then(|m| m.path().ok());
match maybe_path {
Some(x) => {
Expand Down
8 changes: 7 additions & 1 deletion diesel_derives/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream {
quote! {
#[allow(unused_imports)]
const _: () = {
// This import is not actually redundant. When using diesel_derives
// inside of diesel, `diesel` doesn't exist as an extern crate, and
// to work around that it contains a private
// `mod diesel { pub use super::*; }` that this import will then
// refer to. In all other cases, this imports refers to the extern
// crate diesel.
use diesel;

#item
Expand Down Expand Up @@ -46,7 +52,7 @@ fn option_ty_arg(ty: &Type) -> Option<&Type> {
pub fn ty_for_foreign_derive(item: &DeriveInput, flags: &MetaItem) -> Result<Type, Diagnostic> {
if flags.has_flag("foreign_derive") {
match item.data {
Data::Struct(ref body) => match body.fields.iter().nth(0) {
Data::Struct(ref body) => match body.fields.iter().next() {
Some(field) => Ok(field.ty.clone()),
None => Err(flags
.span()
Expand Down
2 changes: 1 addition & 1 deletion diesel_migrations/migrations_internals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn version_from_path(path: &Path) -> Result<String, MigrationError> {
.unwrap_or_else(|| panic!("Can't get file name from path `{:?}`", path))
.to_string_lossy()
.split('_')
.nth(0)
.next()
.map(|s| Ok(s.replace('-', "")))
.unwrap_or_else(|| Err(MigrationError::UnknownMigrationFormat(path.to_path_buf())))
}
Expand Down

0 comments on commit 63b404c

Please sign in to comment.