rust-lang / rust-lang/rust

Broken method resolution for arc-swap + diesel

Open
#127,306 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-bug T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

use arc_swap::ArcSwap; // arc-swap = "1.7.1"
use diesel_async::RunQueryDsl; // diesel-async = "0.4.1"
use std::sync::Arc;

fn issue(arc: ArcSwap<Arc<String>>) {
    let v = arc.load();
}

I expected to see this happen: Code compiles without error as ArcSwap::load() exists

Instead, this happened: Code fails to compile with the following error:

error[E0277]: the trait bound `ArcSwapAny<Arc<Arc<String>>>: diesel::query_builder::Query` is not satisfied
 --> src/main.rs:7:17
  |
7 |     let v = arc.load();
  |                 ^^^^ the trait `diesel::query_builder::Query` is not implemented for `ArcSwapAny<Arc<Arc<String>>>`, which is required by `ArcSwapAny<Arc<Arc<String>>>: LoadQuery<'_, _, _>`
  |
  = help: the following other types implement trait `diesel::query_builder::Query`:
            &'a T
            diesel::expression::sql_literal::SqlLiteral<ST, T>
            diesel::expression::sql_literal::UncheckedBind<Q, Value>
            diesel::query_builder::combination_clause::CombinationClause<Combinator, Rule, Source, Rhs>
            diesel::query_builder::delete_statement::DeleteStatement<T, U, diesel::query_builder::returning_clause::ReturningClause<Ret>>
            diesel::query_builder::insert_statement::InsertStatement<T, U, Op, diesel::query_builder::returning_clause::ReturningClause<Ret>>
            diesel::query_builder::select_statement::SelectStatement<F, S, D, W, O, LOf, G, H, LC>
            diesel::query_builder::select_statement::boxed::BoxedSelectStatement<'a, ST, QS, DB, GB>
          and 6 others
  = note: required for `ArcSwapAny<Arc<Arc<String>>>` to implement `diesel::query_builder::AsQuery`
  = note: required for `ArcSwapAny<Arc<Arc<String>>>` to implement `LoadQuery<'_, _, _>`

error[E0277]: the trait bound `ArcSwapAny<Arc<Arc<String>>>: diesel::query_builder::QueryFragment<_>` is not satisfied
 --> src/main.rs:7:17
  |
7 |     let v = arc.load();
  |                 ^^^^ the trait `diesel::query_builder::QueryFragment<_>` is not implemented for `ArcSwapAny<Arc<Arc<String>>>`, which is required by `ArcSwapAny<Arc<Arc<String>>>: LoadQuery<'_, _, _>`
  |
  = help: the following other types implement trait `diesel::query_builder::QueryFragment<DB, SP>`:
            <&'a T as diesel::query_builder::QueryFragment<DB>>
            <() as diesel::query_builder::QueryFragment<DB>>
            <(T0, T1) as diesel::query_builder::QueryFragment<__DB>>
            <(T0, T1, T2) as diesel::query_builder::QueryFragment<__DB>>
            <(T0, T1, T2, T3) as diesel::query_builder::QueryFragment<__DB>>
            <(T0, T1, T2, T3, T4) as diesel::query_builder::QueryFragment<__DB>>
            <(T0, T1, T2, T3, T4, T5) as diesel::query_builder::QueryFragment<__DB>>
            <(T0, T1, T2, T3, T4, T5, T6) as diesel::query_builder::QueryFragment<__DB>>
          and 160 others
  = note: required for `ArcSwapAny<Arc<Arc<String>>>` to implement `LoadQuery<'_, _, _>`

error[E0277]: the trait bound `ArcSwapAny<Arc<Arc<String>>>: diesel::query_builder::query_id::QueryId` is not satisfied
 --> src/main.rs:7:17
  |
7 |     let v = arc.load();
  |                 ^^^^ the trait `diesel::query_builder::query_id::QueryId` is not implemented for `ArcSwapAny<Arc<Arc<String>>>`, which is required by `ArcSwapAny<Arc<Arc<String>>>: LoadQuery<'_, _, _>`
  |
  = help: the following other types implement trait `diesel::query_builder::query_id::QueryId`:
            &'a T
            ()
            (T0, T1)
            (T0, T1, T2)
            (T0, T1, T2, T3)
            (T0, T1, T2, T3, T4)
            (T0, T1, T2, T3, T4, T5)
            (T0, T1, T2, T3, T4, T5, T6)
          and 148 others
  = note: required for `ArcSwapAny<Arc<Arc<String>>>` to implement `LoadQuery<'_, _, _>`

error[E0277]: the trait bound `ArcSwapAny<Arc<Arc<String>>>: LoadQuery<'_, _, _>` is not satisfied
   --> src/main.rs:7:17
    |
7   |     let v = arc.load();
    |                 ^^^^ the trait `diesel::query_builder::QueryFragment<_>` is not implemented for `ArcSwapAny<Arc<Arc<String>>>`, which is required by `ArcSwapAny<Arc<Arc<String>>>: LoadQuery<'_, _, _>`
    |
    = note: required for `ArcSwapAny<Arc<Arc<String>>>` to implement `LoadQuery<'_, _, _>`
note: required by a bound in `diesel_async::RunQueryDsl::load`
   --> /home/weiznich/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-async-0.4.1/src/run_query_dsl/mod.rs:338:15
    |
331 |     fn load<'query, 'conn, U>(
    |        ---- required by a bound in this associated function
...
338 |         Self: methods::LoadQuery<'query, Conn, U> + 'query,
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0061]: this method takes 1 argument but 0 arguments were supplied
   --> src/main.rs:7:17
    |
7   |     let v = arc.load();
    |                 ^^^^-- an argument of type `&mut _` is missing
    |
note: method defined here
   --> /home/weiznich/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-async-0.4.1/src/run_query_dsl/mod.rs:331:8
    |
331 |     fn load<'query, 'conn, U>(
    |        ^^^^
help: provide the argument
    |
7   |     let v = arc.load(/* conn */);
    |                     ~~~~~~~~~~~~

warning: unused import: `arc_swap::access::Access`
 --> src/main.rs:1:5
  |
1 | use arc_swap::access::Access;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

The method provided by diesel does clearly not apply as:

  • It takes a different number of arguments
  • The trait bounds on the message are not fulfilled.
Meta

rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

(Although the same behavior can be observed with the latest nightly compiler)

Backtrace

<backtrace>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in src/main.rs and run it against the listed arc-swap and diesel-async versions. Read the competing load entry points in diesel-async/src/run_query_dsl/mod.rs and the arc-swap Access API; done means the ArcSwap load call resolves without Diesel-related errors while preserving Diesel's load behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.