Skip to content

regression 1.49: problem with autoderef and trait method #80816

Closed
@kodieg

Description

@kodieg

A code attached below used to compile with rustc 1.48 (stable) and stopped to work with 1.49 (stable). Two thing help to make the code compile:

  1. comment out use arc_swap::access::Access;
  2. explicitly deref (*s).load().

To compile code below one need to add arc-swap = "1.2" to Cargo.toml dependencies. Maybe this is due to some conflict between ArcSwap instance method and Access load method?

Code

I tried this code:

use arc_swap;
use std::sync::Arc;
use arc_swap::access::Access;

pub fn foo() {
    let s: Arc<arc_swap::ArcSwap<usize>> = Arc::new(arc_swap::ArcSwap::from_pointee(32))
    let guard: arc_swap::Guard<Arc<usize>> = s.load();
}

I expected to see this happen: It should compile properly (it worked with rustc version 1.48 and earlier versions as well).

Instead, this happened: I got compilation error

error[E0283]: type annotations needed
 --> src/lib.rs:9:50
  |
9 |     let guard: arc_swap::Guard<Arc<usize>> =   s.load();
  |                                                  ^^^^ cannot infer type for type parameter `T`
  |
  = note: cannot satisfy `ArcSwapAny<Arc<usize>>: arc_swap::access::Access<_>`
  = note: required because of the requirements on the impl of `arc_swap::access::Access<_>` for `Arc<ArcSwapAny<Arc<usize>>>`

Version it worked on

It most recently worked on: Rust 1.48

Version with regression

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

Metadata

Metadata

Assignees

Labels

A-inferenceArea: Type inferenceC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions