Skip to content

Commit b59ebaf

Browse files
committed
Add missing dyn Trait in diesel_cli
1 parent 267f847 commit b59ebaf

8 files changed

Lines changed: 27 additions & 27 deletions

File tree

diesel_cli/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Config {
2525
.unwrap_or_else(|| find_project_root().unwrap_or_default().join("diesel.toml"))
2626
}
2727

28-
pub fn read(matches: &ArgMatches) -> Result<Self, Box<Error>> {
28+
pub fn read(matches: &ArgMatches) -> Result<Self, Box<dyn Error>> {
2929
let path = Self::file_path(matches);
3030

3131
if path.exists() {

diesel_cli/src/infer_schema_internals/inference.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static RESERVED_NAMES: &[&str] = &[
1717
pub fn load_table_names(
1818
database_url: &str,
1919
schema_name: Option<&str>,
20-
) -> Result<Vec<TableName>, Box<Error>> {
20+
) -> Result<Vec<TableName>, Box<dyn Error>> {
2121
let connection = InferConnection::establish(database_url)?;
2222

2323
match connection {
@@ -33,7 +33,7 @@ pub fn load_table_names(
3333
fn get_column_information(
3434
conn: &InferConnection,
3535
table: &TableName,
36-
) -> Result<Vec<ColumnInformation>, Box<Error>> {
36+
) -> Result<Vec<ColumnInformation>, Box<dyn Error>> {
3737
let column_info = match *conn {
3838
#[cfg(feature = "sqlite")]
3939
InferConnection::Sqlite(ref c) => super::sqlite::get_table_data(c, table),
@@ -52,7 +52,7 @@ fn get_column_information(
5252
fn determine_column_type(
5353
attr: &ColumnInformation,
5454
conn: &InferConnection,
55-
) -> Result<ColumnType, Box<Error>> {
55+
) -> Result<ColumnType, Box<dyn Error>> {
5656
match *conn {
5757
#[cfg(feature = "sqlite")]
5858
InferConnection::Sqlite(_) => super::sqlite::determine_column_type(attr),
@@ -66,7 +66,7 @@ fn determine_column_type(
6666
pub(crate) fn get_primary_keys(
6767
conn: &InferConnection,
6868
table: &TableName,
69-
) -> Result<Vec<String>, Box<Error>> {
69+
) -> Result<Vec<String>, Box<dyn Error>> {
7070
let primary_keys: Vec<String> = match *conn {
7171
#[cfg(feature = "sqlite")]
7272
InferConnection::Sqlite(ref c) => super::sqlite::get_primary_keys(c, table),
@@ -90,7 +90,7 @@ pub(crate) fn get_primary_keys(
9090
pub fn load_foreign_key_constraints(
9191
database_url: &str,
9292
schema_name: Option<&str>,
93-
) -> Result<Vec<ForeignKeyConstraint>, Box<Error>> {
93+
) -> Result<Vec<ForeignKeyConstraint>, Box<dyn Error>> {
9494
let connection = InferConnection::establish(database_url)?;
9595

9696
let constraints = match connection {
@@ -129,7 +129,7 @@ macro_rules! doc_comment {
129129
};
130130
}
131131

132-
pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData, Box<Error>> {
132+
pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData, Box<dyn Error>> {
133133
let connection = InferConnection::establish(database_url)?;
134134
let docs = doc_comment!(
135135
"Representation of the `{}` table.
@@ -175,7 +175,7 @@ pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData,
175175
rust_name,
176176
})
177177
})
178-
.collect::<Result<_, Box<Error>>>()?;
178+
.collect::<Result<_, Box<dyn Error>>>()?;
179179

180180
Ok(TableData {
181181
name,

diesel_cli/src/infer_schema_internals/information_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ where
167167
pub fn load_table_names<Conn>(
168168
connection: &Conn,
169169
schema_name: Option<&str>,
170-
) -> Result<Vec<TableName>, Box<Error>>
170+
) -> Result<Vec<TableName>, Box<dyn Error>>
171171
where
172172
Conn: Connection,
173173
Conn::Backend: UsesInformationSchema,

diesel_cli/src/infer_schema_internals/mysql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn load_foreign_key_constraints(
8282
Ok(constraints)
8383
}
8484

85-
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<Error>> {
85+
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<dyn Error>> {
8686
let tpe = determine_type_name(&attr.type_name)?;
8787
let unsigned = determine_unsigned(&attr.type_name);
8888

@@ -94,7 +94,7 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
9494
})
9595
}
9696

97-
fn determine_type_name(sql_type_name: &str) -> Result<String, Box<Error>> {
97+
fn determine_type_name(sql_type_name: &str) -> Result<String, Box<dyn Error>> {
9898
let result = if sql_type_name == "tinyint(1)" {
9999
"bool"
100100
} else if sql_type_name.starts_with("int") {

diesel_cli/src/infer_schema_internals/pg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use heck::CamelCase;
33
use std::error::Error;
44
use std::io::{stderr, Write};
55

6-
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<Error>> {
6+
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<dyn Error>> {
77
let is_array = attr.type_name.starts_with('_');
88
let tpe = if is_array {
99
&attr.type_name[1..]

diesel_cli/src/infer_schema_internals/sqlite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ table! {
3939
pub fn load_table_names(
4040
connection: &SqliteConnection,
4141
schema_name: Option<&str>,
42-
) -> Result<Vec<TableName>, Box<Error>> {
42+
) -> Result<Vec<TableName>, Box<dyn Error>> {
4343
use self::sqlite_master::dsl::*;
4444

4545
if schema_name.is_some() {
@@ -63,7 +63,7 @@ pub fn load_table_names(
6363
pub fn load_foreign_key_constraints(
6464
connection: &SqliteConnection,
6565
schema_name: Option<&str>,
66-
) -> Result<Vec<ForeignKeyConstraint>, Box<Error>> {
66+
) -> Result<Vec<ForeignKeyConstraint>, Box<dyn Error>> {
6767
let tables = load_table_names(connection, schema_name)?;
6868
let rows = tables
6969
.into_iter()
@@ -127,7 +127,7 @@ pub fn get_primary_keys(conn: &SqliteConnection, table: &TableName) -> QueryResu
127127
.collect())
128128
}
129129

130-
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<Error>> {
130+
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<dyn Error>> {
131131
let type_name = attr.type_name.to_lowercase();
132132
let path = if is_bool(&type_name) {
133133
String::from("Bool")

diesel_cli/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use clap::{ArgMatches, Shell};
4848
use migrations_internals::{self as migrations, MigrationConnection};
4949
use std::any::Any;
5050
use std::error::Error;
51+
use std::fmt::Display;
5152
use std::io::stdout;
5253
use std::path::{Path, PathBuf};
5354
use std::{env, fs};
@@ -75,7 +76,7 @@ fn main() {
7576

7677
// https://github.com/rust-lang-nursery/rust-clippy/issues/2927#issuecomment-405705595
7778
#[allow(clippy::similar_names)]
78-
fn run_migration_command(matches: &ArgMatches) -> Result<(), Box<Error>> {
79+
fn run_migration_command(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
7980
match matches.subcommand() {
8081
("run", Some(_)) => {
8182
let database_url = database::database_url(matches);
@@ -171,11 +172,10 @@ fn generate_sql_migration(path: &PathBuf) {
171172
.unwrap();
172173
}
173174

174-
use std::fmt::Display;
175-
fn migration_version<'a>(matches: &'a ArgMatches) -> Box<Display + 'a> {
175+
fn migration_version<'a>(matches: &'a ArgMatches) -> Box<dyn Display + 'a> {
176176
matches
177177
.value_of("MIGRATION_VERSION")
178-
.map(|s| Box::new(s) as Box<Display>)
178+
.map(|s| Box::new(s) as Box<dyn Display>)
179179
.unwrap_or_else(|| Box::new(Utc::now().format(TIMESTAMP_FORMAT)))
180180
}
181181

@@ -233,7 +233,7 @@ fn create_config_file(matches: &ArgMatches) -> DatabaseResult<()> {
233233
Ok(())
234234
}
235235

236-
fn run_database_command(matches: &ArgMatches) -> Result<(), Box<Error>> {
236+
fn run_database_command(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
237237
match matches.subcommand() {
238238
("setup", Some(args)) => {
239239
let migrations_dir = migrations_dir(args);
@@ -315,12 +315,12 @@ where
315315
}
316316

317317
#[cfg(feature = "mysql")]
318-
fn should_redo_migration_in_transaction(t: &Any) -> bool {
318+
fn should_redo_migration_in_transaction(t: &dyn Any) -> bool {
319319
!t.is::<::diesel::mysql::MysqlConnection>()
320320
}
321321

322322
#[cfg(not(feature = "mysql"))]
323-
fn should_redo_migration_in_transaction(_t: &Any) -> bool {
323+
fn should_redo_migration_in_transaction(_t: &dyn Any) -> bool {
324324
true
325325
}
326326

@@ -346,7 +346,7 @@ fn convert_absolute_path_to_relative(target_path: &Path, mut current_path: &Path
346346
result.join(target_path.strip_prefix(current_path).unwrap())
347347
}
348348

349-
fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<Error>> {
349+
fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
350350
use infer_schema_internals::TableName;
351351
use print_schema::*;
352352

@@ -400,7 +400,7 @@ fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<Error>> {
400400
Ok(())
401401
}
402402

403-
fn regenerate_schema_if_file_specified(matches: &ArgMatches) -> Result<(), Box<Error>> {
403+
fn regenerate_schema_if_file_specified(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
404404
use std::io::Read;
405405

406406
let config = Config::read(matches)?;

diesel_cli/src/print_schema.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn run_print_schema<W: IoWrite>(
3939
database_url: &str,
4040
config: &config::PrintSchema,
4141
output: &mut W,
42-
) -> Result<(), Box<Error>> {
42+
) -> Result<(), Box<dyn Error>> {
4343
let tempfile = NamedTempFile::new()?;
4444
let file = tempfile.reopen()?;
4545
output_schema(database_url, config, file, tempfile.path())?;
@@ -56,7 +56,7 @@ pub fn output_schema(
5656
config: &config::PrintSchema,
5757
mut out: File,
5858
out_path: &Path,
59-
) -> Result<(), Box<Error>> {
59+
) -> Result<(), Box<dyn Error>> {
6060
let table_names = load_table_names(database_url, config.schema_name())?
6161
.into_iter()
6262
.filter(|t| !config.filter.should_ignore_table(t))
@@ -67,7 +67,7 @@ pub fn output_schema(
6767
let table_data = table_names
6868
.into_iter()
6969
.map(|t| load_table_data(database_url, t))
70-
.collect::<Result<_, Box<Error>>>()?;
70+
.collect::<Result<_, Box<dyn Error>>>()?;
7171
let definitions = TableDefinitions {
7272
tables: table_data,
7373
fk_constraints: foreign_keys,

0 commit comments

Comments
 (0)