Skip to content

Recent nightly causes [E0308]: mismatched types #117598

Closed
@nyurik

Description

@nyurik

This code is a subset of the sqlx crate code that is no longer compiling on the nightly (nightly change was very recent, it was working fine a few versions ago). Matching bug in sqlx crate - launchbadge/sqlx#2855

trait Database: for<'r> HasValueRef<'r, Database = Self> {}

trait HasValueRef<'r> {
    type Database: Database;
}

struct Any;

impl Database for Any {}

impl<'r> HasValueRef<'r> for Any {
    type Database = Any;
}

I expected to see this happen: code compiles

Instead, this happened: code fails to compile using +nightly

Meta

Version that compiles fine: rustc --version:

rustc 1.73.0

Version that fails to compile: rustc +nightly --version --verbose

rustc 1.75.0-nightly (4b85902b4 2023-11-04)
binary: rustc
commit-hash: 4b85902b438f791c5bfcb6b1c5b476d5b88e2bef
commit-date: 2023-11-04
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4
`cargo +nightly build` results

✦ ❯ cargo +nightly build
   Compiling mydemo v0.1.0 (...)
error[E0308]: mismatched types
  --> src/bin/main.rs:12:21
   |
12 |     type Database = Any;
   |                     ^^^ lifetime mismatch
   |
   = note: expected associated type `<Any as HasValueRef<'r>>::Database`
              found associated type `<Any as HasValueRef<'r>>::Database`
note: the required lifetime does not necessarily outlive the lifetime `'r` as defined here
  --> src/bin/main.rs:11:6
   |
11 | impl<'r> HasValueRef<'r> for Any {
   |      ^^
note: the lifetime requirement is introduced here
  --> src/bin/main.rs:4:20
   |
4  |     type Database: Database;
   |                    ^^^^^^^^

error[E0308]: mismatched types
  --> src/bin/main.rs:12:21
   |
12 |     type Database = Any;
   |                     ^^^ lifetime mismatch
   |
   = note: expected associated type `<Any as HasValueRef<'r>>::Database`
              found associated type `<Any as HasValueRef<'r>>::Database`
note: the lifetime `'r` as defined here doesn't meet the lifetime requirements
  --> src/bin/main.rs:11:6
   |
11 | impl<'r> HasValueRef<'r> for Any {
   |      ^^
note: the lifetime requirement is introduced here
  --> src/bin/main.rs:4:20
   |
4  |     type Database: Database;
   |                    ^^^^^^^^

Metadata

Metadata

Labels

C-bugCategory: This is a bug.P-criticalCritical 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-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions