Diesel: error: cannot find macro `infer_schema!` in this scope

Created on 27 Aug 2017  Â·  16Comments  Â·  Source: diesel-rs/diesel

I'm following the tutorial step by step. In "src/schema.rs" I have only this single line:

 infer_schema!("dotenv:DATABASE_URL");

And:

% cargo build
[................]
error: cannot find macro `infer_schema!` in this scope
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^

question

Most helpful comment

I asked help on the diesel-rs/diesel and @weiznich came to the rescue.

@weiznich quickly found out that I was missing a macro_use annotation on the extern crate diesel import. In fact, I was missing the entire import. Adding it in, made my problems go away, even without the altered recursion limit.

All 16 comments

with 0.16 the exception becomes this:

error: recursion limit reached while expanding the macro `table_body`
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: this error originates in a macro outside of the current crate

Yeah, it's a known issue that the recursion limit is reached quite quickly
by that macro. Just do what the compiler says and increase it to 128 or
more until it works :) There was another issue here with a bit more
information if you want to know more details.

(This default will actually change in rustc soon IIRC.)

yyolf117 notifications@github.com schrieb am So. 27. Aug. 2017 um 10:12:

with 0.16 the exception becomes this:

error: recursion limit reached while expanding the macro table_body
--> src/schema.rs:1:1
|
1 | infer_schema!("dotenv:DATABASE_URL");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a #![recursion_limit="128"] attribute to your crate
= note: this error originates in a macro outside of the current crate

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/diesel-rs/diesel/issues/1132#issuecomment-325183869,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX4GkyJxC7rinI7GMGnM1vVfGmzeVks5scSTUgaJpZM4PDuu7
.

I've put #![recursion_limit="128"] to the main file of my crate - src/main.rs - but the error remained.

Did you try a higher limit or putting it in the schema.rs file?

yyolf117 notifications@github.com schrieb am So. 27. Aug. 2017 um 12:38:

I've put #![recursion_limit="128"] to my main file of my crate - main.rs

  • but the error remained.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/diesel-rs/diesel/issues/1132#issuecomment-325190413,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX2-_TIyB9uxqtsVZnT2wRaYM6rWeks5scUcmgaJpZM4PDuu7
.

yes, yes.
is it possible to use diesel without infer_schema!("dotenv:DATABASE_URL") by writing code manually?

Yes, diesel print-schema will show you the calls to table! that
infer_schema! creates. You can copy those to the file instead of calling
infer_schema!.
yyolf117 notifications@github.com schrieb am So. 27. Aug. 2017 um 13:08:

yes, yes.
is it possible to use diesel without infer_schema!("dotenv:DATABASE_URL")
by writing code manually?

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/diesel-rs/diesel/issues/1132#issuecomment-325191721,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX_sjeIAB7Bz-VyFacZH1yObmdZvkks5scU4UgaJpZM4PDuu7
.

Now there're several errors:

the trait bound `(......)` is not satisfied

^ the trait `diesel::Expression` is not implemented for .....
= note: required by `diesel::query_builder::AsQuery`
= note: this error originates in a macro outside of the current crate


^ the trait `diesel::SelectableExpression<schema .....` is not implemented for .....
^ the trait `diesel::expression::NonAggregate` is not implemented for .....

Can you quote the full error? And give more details on what your schema is?
It's really hard to guess :)

yyolf117 notifications@github.com schrieb am So. 27. Aug. 2017 um 13:33:

Now there're several errors:

the trait bound (......) is not satisfied

^ the trait diesel::Expression is not implemented for .....

= note: required by diesel::query_builder::AsQuery

= note: this error originates in a macro outside of the current crate

^ the trait diesel::SelectableExpression<schema ..... is not implemented for .....
^ the trait diesel::expression::NonAggregate is not implemented for .....

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/diesel-rs/diesel/issues/1132#issuecomment-325192797,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX5ahdLNdyBDqKK1niZm-7JYPoLF4ks5scVQYgaJpZM4PDuu7
.

I'm following the tutorial step by step.

Maybe it'll help looking at the finished code that you can download and run? You can find it here.

@killercup
I got a error

error: recursion limit reached while expanding the macro `numeric_expr`
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
  = note: this error originates in a macro outside of the current crate

See above: just do what the compiler suggests and increase the recursion
limit :)

Lisq notifications@github.com schrieb am Mo. 28. Aug. 2017 um 05:39:

@killercup https://github.com/killercup
I got a error

error: recursion limit reached while expanding the macro numeric_expr
--> src/schema.rs:1:1
|
1 | infer_schema!("dotenv:DATABASE_URL");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a #![recursion_limit="128"] attribute to your crate
= note: this error originates in a macro outside of the current crate

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/diesel-rs/diesel/issues/1132#issuecomment-325252791,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABOX922jNiIMVwB5A1H9t5lhpD_2bX3ks5scjZbgaJpZM4PDuu7
.

I have a model with many fields:

# models.rs
pub struct Table123<'a> {
    pub id: i32,
    pub var1: &'a str,
    pub var2: &'a str,
    pub var3: &'a str,
    pub var4: &'a str,
    pub var5: &'a str,
    pub var6: &'a str,
    pub var7: &'a str,
    pub var8: &'a str,
    pub var9: &'a str,
    pub var10: &'a str,
    pub var11: &'a str,
    pub var12: &'a str,
    pub var13: &'a str,
    pub var14: &'a str,
    pub var15: &'a str,
    pub var16: &'a str,
    pub var17: &'a str,
    pub var18: &'a str,
    pub var19: &'a str,
    pub var20: &'a str,
}


# schema.rs
table! {
    table123 (id) {
        id -> Int4,
        var1 -> Nullable<Varchar>,
        var2 -> Nullable<Text>,
        var3 -> Nullable<Varchar>,
        var4 -> Nullable<Varchar>,
        var5 -> Nullable<Varchar>,
        var6 -> Nullable<Varchar>,
        var7 -> Nullable<Varchar>,
        var8 -> Nullable<Varchar>,
        var9 -> Nullable<Varchar>,
        var10 -> Nullable<Varchar>,
        var11 -> Nullable<Varchar>,
        var12 -> Nullable<Varchar>,
        var13 -> Nullable<Varchar>,
        var14 -> Nullable<Varchar>,
        var15 -> Nullable<Varchar>,
        var16 -> Nullable<Varchar>,
        var17 -> Nullable<Varchar>,
        var18 -> Nullable<Varchar>,
        var19 -> Nullable<Varchar>,
        var20 -> Nullable<Varchar>,
    }
}

Exceptions:

  error[E0277]: the trait bound `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20): diesel::Expression` is not satisfied
    --> src/schema.rs:30:1
     |
  30 | / table! {
  31 | |     table123 (id) {
  32 | |         id -> Int4,
  33 | |         var1 -> Nullable<Varchar>,
  ...  |
  53 | |     }
  54 | | }
     | |_^ the trait `diesel::Expression` is not implemented for `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20)`
     |
     = note: required by `diesel::query_builder::AsQuery`
     = note: this error originates in a macro outside of the current crate

  error[E0277]: the trait bound `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20): diesel::SelectableExpression<schema::table123::table>` is not satisfied
    --> src/schema.rs:30:1
     |
  30 | / table! {
  31 | |     table123 (id) {
  32 | |         id -> Int4,
  33 | |         var1 -> Nullable<Varchar>,
  ...  |
  53 | |     }
  54 | | }
     | |_^ the trait `diesel::SelectableExpression<schema::table123::table>` is not implemented for `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20)`
     |
     = note: required by `diesel::Table`
     = note: this error originates in a macro outside of the current crate

  error[E0277]: the trait bound `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20): diesel::expression::NonAggregate` is not satisfied
    --> src/schema.rs:30:1
     |
  30 | / table! {
  31 | |     table123 (id) {
  32 | |         id -> Int4,
  33 | |         var1 -> Nullable<Varchar>,
  ...  |
  53 | |     }
  54 | | }
     | |_^ the trait `diesel::expression::NonAggregate` is not implemented for `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20)`
     |
     = note: required by `diesel::Table`
     = note: this error originates in a macro outside of the current crate

  error[E0277]: the trait bound `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20): diesel::SelectableExpression<schema::table123::table>` is not satisfied
    --> src/schema.rs:30:1
     |
  30 | / table! {
  31 | |     table123 (id) {
  32 | |         id -> Int4,
  33 | |         var1 -> Nullable<Varchar>,
  ...  |
  53 | |     }
  54 | | }
     | |_^ the trait `diesel::SelectableExpression<schema::table123::table>` is not implemented for `(schema::table123::columns::id, schema::table123::columns::var1, schema::table123::columns::var2, schema::table123::columns::var3, schema::table123::columns::var4, schema::table123::columns::var5, schema::table123::columns::var6, schema::table123::columns::var7, schema::table123::columns::var8, schema::table123::columns::var9, schema::table123::columns::var10, schema::table123::columns::var11, schema::table123::columns::var12, schema::table123::columns::var13, schema::table123::columns::var14, schema::table123::columns::var15, schema::table123::columns::var16, schema::table123::columns::var17, schema::table123::columns::var18, schema::table123::columns::var19, schema::table123::columns::var20)`
     |
     = note: required by `diesel::QuerySource`
     = note: this error originates in a macro outside of the current crate

  error: aborting due to 4 previous errors

Ah, I see. You'll to enable the large-tables (or huge-tables) feature for diesel in your Cargo.toml. (It's off by default to make diesel compile faster.)

I assume this solved the issue for you?

If you have any more questions, don't hesitate to ask here or on gitter!

I experienced the same problem while walking through the tutorial. I cranked the recursion limit up all the way to 4096 to no avail. My model is small:

#[derive(Serialize, Deserialize, Debug, PartialEq, Queryable)]
pub struct Event {
    id: i32,
    origin: String,
    message: String,
}

but it doesn't residue in models.rs. When I use diesel print-schema it returns

table! {
    events (id) {
        id -> Int4,
        origin -> Varchar,
        message -> Varchar,
    }
}

Putting this in schema.rs results in a similar error: cannot find macro 'table!' in this scope.

Does anyone have a clue?

I asked help on the diesel-rs/diesel and @weiznich came to the rescue.

@weiznich quickly found out that I was missing a macro_use annotation on the extern crate diesel import. In fact, I was missing the entire import. Adding it in, made my problems go away, even without the altered recursion limit.

Was this page helpful?
0 / 5 - 0 ratings