rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.13k stars 12.8k forks source link

Irrelevant error caused by illegal blanket impl #67427

Open Ploppz opened 4 years ago

Ploppz commented 4 years ago

I have a minimal example, using stable rustc 1.39.0:

Cargo.toml:

[package]
name = "minimal"
version = "0.1.0"
authors = ["Erlend Langseth <3rlend@gmail.com>"]
edition = "2018"

[dependencies]
# Actix
actix = "0.9.0-alpha.2"
actix-web = "2.0.0-alpha.6"
actix-rt = "1.0.0"
actix-http = "1.0.0"

# Redis
redis-async = "0.6.1"
actix-redis = "0.8.0-alpha.1"

# Serde
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

main.rs:

use actix::prelude::*;
use actix_web::{
    get,
    web::{Json, Data},
    App, HttpServer,
};
use serde::{Deserialize};

use redis_async::{
    resp_array,
    resp::{RespValue, FromResp},
    client::paired::PairedConnection as RedisConn
};
use std::str::FromStr;
use std::net::SocketAddr;

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    let redis = redis_async::client::paired::paired_connect(&SocketAddr::from_str("127.0.0.1:6379").unwrap()).await.unwrap();

    HttpServer::new(move || {
        App::new()
            .wrap(actix_web::middleware::Logger::new(
                "%a \"%r\" Response: %s %b",
            ))
            .data(redis.clone())
            .service(get_health)
    })
    .bind("127.0.0.1:8088")?
    .start()
    .await
}

impl<'a, T: Deserialize<'a>> FromResp for T {
    fn from_resp_int(resp: RespValue) -> Result<T, redis_async::error::Error> {
        unimplemented!()
    }
}

#[get("/admin/v1/health")]
async fn get_health(redis: Data<RedisConn>) -> Json<usize> {
    let res = redis.send::<String>(resp_array!["PING"]).await;
    Json(0)
}

It yields this weird error:

error[E0283]: type annotations required: cannot resolve `std::string::String: redis_async::resp::FromResp`
  --> src/main.rs:43:21
   |
43 |     let res = redis.send::<String>(resp_array!["PING"]).await;
   |                     ^^^^

error: aborting due to previous error

Whereas the real error is impl<'a, T: Deserialize<'a>> FromResp for T. If I remove that impl block, it's all fine.

Enselic commented 1 year ago

Triage: I can't reproduce this any longer? Can you? If yes, can you update the reproducer please?