Manually fix remaining compile warnings.

This commit is contained in:
Magnus Hovland Hoff 2022-04-03 14:19:56 +02:00
parent e0f52cd031
commit 9320d14d89
5 changed files with 8 additions and 28 deletions

View file

@ -40,11 +40,9 @@ fn main() {
)); ));
// Integer is a dummy placeholder. Compiling fails when passing (). // Integer is a dummy placeholder. Compiling fails when passing ().
diesel::expression::sql_literal::sql::<(diesel::sql_types::Integer)>( diesel::expression::sql_literal::sql::<diesel::sql_types::Integer>("PRAGMA foreign_keys = ON")
"PRAGMA foreign_keys = ON", .execute(&connection)
) .expect("Should be able to enable foreign keys");
.execute(&connection)
.expect("Should be able to enable foreign keys");
sqlfunc::markdown_to_fts::register_impl(&connection, |_: String| -> String { unreachable!() }) sqlfunc::markdown_to_fts::register_impl(&connection, |_: String| -> String { unreachable!() })
.unwrap(); .unwrap();

View file

@ -21,7 +21,7 @@ pub mod sqlfunc {
impl CustomizeConnection<SqliteConnection, r2d2_diesel::Error> for SqliteInitializer { impl CustomizeConnection<SqliteConnection, r2d2_diesel::Error> for SqliteInitializer {
fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), r2d2_diesel::Error> { fn on_acquire(&self, conn: &mut SqliteConnection) -> Result<(), r2d2_diesel::Error> {
sql::<(Integer)>("PRAGMA foreign_keys = ON") sql::<Integer>("PRAGMA foreign_keys = ON")
.execute(conn) .execute(conn)
.map_err(|x| r2d2_diesel::Error::QueryError(x))?; .map_err(|x| r2d2_diesel::Error::QueryError(x))?;

View file

@ -352,8 +352,6 @@ impl Resource for ChangesResource {
let head = self.head(); let head = self.head();
Box::new(data.join(head).and_then(move |(mut data, head)| { Box::new(data.join(head).and_then(move |(mut data, head)| {
use std::iter::Iterator;
let extra_element = if data.len() > self.limit as usize { let extra_element = if data.len() > self.limit as usize {
data.pop() data.pop()
} else { } else {

View file

@ -8,15 +8,11 @@ pub struct Error;
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", (self as &dyn error::Error).description()) write!(f, "`after` and `before` are mutually exclusive")
} }
} }
impl error::Error for Error { impl error::Error for Error {}
fn description(&self) -> &str {
"`after` and `before` are mutually exclusive"
}
}
#[derive(Deserialize)] #[derive(Deserialize)]
struct PaginationStruct<T> { struct PaginationStruct<T> {

View file

@ -92,8 +92,6 @@ fn decide_slug(
&base_slug &base_slug
}; };
use crate::schema::article_revisions;
let mut slug = base_slug.to_owned(); let mut slug = base_slug.to_owned();
let mut disambiguator = 1; let mut disambiguator = 1;
@ -125,8 +123,6 @@ impl<'a> SyncState<'a> {
} }
pub fn get_article_slug(&self, article_id: i32) -> Result<Option<String>, Error> { pub fn get_article_slug(&self, article_id: i32) -> Result<Option<String>, Error> {
use crate::schema::article_revisions;
Ok(article_revisions::table Ok(article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.filter(article_revisions::latest.eq(true)) .filter(article_revisions::latest.eq(true))
@ -140,8 +136,6 @@ impl<'a> SyncState<'a> {
article_id: i32, article_id: i32,
revision: i32, revision: i32,
) -> Result<Option<models::ArticleRevision>, Error> { ) -> Result<Option<models::ArticleRevision>, Error> {
use crate::schema::article_revisions;
Ok(article_revisions::table Ok(article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.filter(article_revisions::revision.eq(revision)) .filter(article_revisions::revision.eq(revision))
@ -181,8 +175,6 @@ impl<'a> SyncState<'a> {
article_id: i32, article_id: i32,
revision: i32, revision: i32,
) -> Result<Option<models::ArticleRevisionStub>, Error> { ) -> Result<Option<models::ArticleRevisionStub>, Error> {
use crate::schema::article_revisions;
Ok(self Ok(self
.query_article_revision_stubs(move |query| { .query_article_revision_stubs(move |query| {
query query
@ -202,8 +194,6 @@ impl<'a> SyncState<'a> {
} }
self.db_connection.transaction(|| { self.db_connection.transaction(|| {
use crate::schema::article_revisions;
Ok( Ok(
match article_revisions::table match article_revisions::table
.filter(article_revisions::slug.eq(slug)) .filter(article_revisions::slug.eq(slug))
@ -327,8 +317,6 @@ impl<'a> SyncState<'a> {
} }
self.db_connection.transaction(|| { self.db_connection.transaction(|| {
use crate::schema::article_revisions;
let (latest_revision, prev_title, prev_slug, prev_theme) = article_revisions::table let (latest_revision, prev_title, prev_slug, prev_theme) = article_revisions::table
.filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::article_id.eq(article_id))
.order(article_revisions::revision.desc()) .order(article_revisions::revision.desc())
@ -424,9 +412,9 @@ impl<'a> SyncState<'a> {
let article_id = { let article_id = {
use diesel::expression::sql_literal::sql; use diesel::expression::sql_literal::sql;
// Diesel and SQLite are a bit in disagreement for how this should look: // Diesel and SQLite are a bit in disagreement for how this should look:
sql::<(diesel::sql_types::Integer)>("INSERT INTO articles VALUES (null)") sql::<diesel::sql_types::Integer>("INSERT INTO articles VALUES (null)")
.execute(self.db_connection)?; .execute(self.db_connection)?;
sql::<(diesel::sql_types::Integer)>("SELECT LAST_INSERT_ROWID()") sql::<diesel::sql_types::Integer>("SELECT LAST_INSERT_ROWID()")
.load::<i32>(self.db_connection)? .load::<i32>(self.db_connection)?
.pop() .pop()
.expect("Statement must evaluate to an integer") .expect("Statement must evaluate to an integer")