The database feature does not compile without a driver feature (E0004)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start with crates/database/src/db/neutral.rs around line 247, where the issue says driver-gated enum arms cause non-exhaustive match errors, and inspect the related AnyConnection, AnyRow, AnyTransaction, and AnyQueryResult definitions. Check the crate’s feature configuration and reproduce with cargo check using only the database feature. Done means driver-free builds either compile with a clear runtime error or fail with one actionable compile error naming the required driver features.
Written by the indexing model from the issue text.
Description
Problem
A package that uses models or migrations must enable the database feature of laravel-rust. The application selects the database driver, so the package does not enable a driver feature. But database does not compile without one of database-sqlite, database-postgres, or database-mysql.
Steps to reproduce:
-
Create a library crate with this dependency:
[dependencies] laravel-rust = { version = "0.1.6", default-features = false, features = ["database"] } -
Run
cargo check.
error[E0004]: non-exhaustive patterns: type `&AnyConnection` is non-empty
--> laravel-rust-database-0.1.6/src/db/neutral.rs:247:19
|
247 | dispatch!(self, AnyConnection, connection => connection.begin().await.map(Into::into))
| ^^^^
cargo check stops with 57 errors in laravel-rust-database. Most of the errors are E0004 on AnyConnection, AnyRow, AnyTransaction, and AnyQueryResult. All variants of these enums are behind driver features (neutral.rs L247). The problem occurs in 0.1.4 and in 0.1.6.
Who sees the problem
An application does not see the problem, because the application enables a driver and Cargo unifies the features. A package sees the problem each time that Cargo builds the package alone:
cargo publishverifies the package without an application.- docs.rs builds the package alone.
cargo checkandcargo testrun in the workspace of the package.- A check that builds each feature alone fails on each feature set that has no driver.
Workaround
The package adds features that only pass a driver through, for example database-sqlite = ["laravel-rust/database-sqlite"]. An application never uses these features. The package then publishes with --all-features and sets all-features = true for docs.rs. Its feature checks must also skip each feature set that has no driver. Each package that uses the database must repeat this setup.
Laravel
In Laravel for PHP, the models and migrations of a package do not know the driver. The DB_CONNECTION value of the application selects the driver.
Proposal
Make database compile without a driver feature. For example, each Any* enum can get one more arm when no driver feature is enabled. The crate then compiles, and a query fails at runtime with a clear error such as "no database driver is enabled".
If you do not want that behavior, add a compile_error! that names the three driver features. The 57 errors then become one error that tells the user what to do.
- Dominant language
- Rust
- Stars
- 847
- Forks
- 174
- Avg merge
- 5h 40m
- Merged PRs (30d)
- 167
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from laravel/rust-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
laravel/rust-framework#864 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
laravel/rust-framework#876 ·
Maintainers usually reply within 1 day
-
Case-sensitive contains, starts_with and ends_with that match % and _ literally on every databaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#874 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
laravel/rust-framework#873 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#872 ·
Maintainers usually reply within 1 day
All issues in laravel/rust-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neuralmagic/crucible#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
eclipse-score/kyron#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
seanmonstar/reqwest#3157 ·
Maintainers usually reply within 2 days