Skip to content

Commit

Permalink
Remove the automatic impl of Expression for Column
Browse files Browse the repository at this point in the history
I'm tired of seeing rustc recommend that I implement `Column` whenever
I'm having issues resolving `SelectableExpression`. It's making things
hard to debug, and I don't want to wait for
rust-lang/rust#28894 to be fixed.

The error behavior is awfully peculiar. I have no idea why this changed
causes Rust to not even try and compile the second version of the same
expression.
  • Loading branch information
sgrif committed Nov 23, 2015
1 parent 7d792d3 commit 094dc08
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ macro_rules! table {
pub mod columns {
use super::table;
use $crate::{Table, Column, Expression, SelectableExpression};
use $crate::expression::NonAggregate;
use $crate::query_builder::{QueryBuilder, BuildQueryResult};
use $crate::types::*;

Expand Down Expand Up @@ -111,6 +112,10 @@ macro_rules! table {
}
}

impl SelectableExpression<table> for $column_name {}

impl NonAggregate for $column_name {}

impl Column for $column_name {
type Table = table;

Expand Down
6 changes: 0 additions & 6 deletions src/query_source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ pub trait Column: Expression {
fn name() -> &'static str;
}

impl<C: Column> SelectableExpression<C::Table> for C {
}

impl<C: Column> NonAggregate for C {
}

pub trait Table: QuerySource + AsQuery + Sized {
type PrimaryKey: Column<Table=Self> + Expression + NonAggregate;
type AllColumns: SelectableExpression<Self>;
Expand Down
2 changes: 0 additions & 2 deletions tests/compile-fail/cannot_pass_aggregate_to_where.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ fn main() {

let source = users.filter(count(id).gt(3));
//~^ ERROR NonAggregate
let source = users.filter(count(id).gt(3));
//~^ ERROR E0277
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ table! {
fn main() {
let _ = users::table.filter(posts::id.eq(1));
//~^ ERROR SelectableExpression
let _ = users::table.filter(posts::id.eq(1));
//~^ ERROR E0277
let _ = users::table.filter(users::name.eq(posts::title));
//~^ ERROR SelectableExpression
let _ = users::table.filter(users::name.eq(posts::title));
//~^ ERROR E0277
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ table! {

fn main() {
let source = users::table.order(posts::id);
//~^ ERROR type mismatch
//~^ ERROR E0277
}
23 changes: 20 additions & 3 deletions tests/compile-fail/select_requires_column_from_same_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@ table! {
fn main() {
let connection = Connection::establish("").unwrap();
let select_id = users::table.select(posts::id);
//~^ ERROR type mismatch
// ERROR expected struct `posts::table`,
// ERROR found struct `users::table` [E0271]
//~^ ERROR SelectableExpression
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
//~| ERROR E0277
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ fn main() {
let command = update(users).set(posts::title.eq("Hello"));
//~^ ERROR type mismatch
let command = update(users).set(name.eq(posts::title));
//~^ ERROR type mismatch
//~^ ERROR E0277
}

0 comments on commit 094dc08

Please sign in to comment.