Skip to content

Recent nightly causes [E0308]: mismatched types #117598

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
nyurik opened this issue Nov 5, 2023 · 3 comments · Fixed by #117542
Closed

Recent nightly causes [E0308]: mismatched types #117598

nyurik opened this issue Nov 5, 2023 · 3 comments · Fixed by #117542
Assignees
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@nyurik
Copy link
Contributor

nyurik commented Nov 5, 2023

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;
   |                    ^^^^^^^^

@nyurik nyurik added the C-bug Category: This is a bug. label Nov 5, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 5, 2023
@HTGAzureX1212
Copy link
Contributor

I ran a rustc bisection and came to the following conclusion:

searched nightlies: from nightly-2023-11-03 to nightly-2023-11-05
regressed nightly: nightly-2023-11-04
searched commit range: a2f5f96...1bb6553
regressed commit: 2520ca8

bisected with cargo-bisect-rustc v0.6.7

Host triple: x86_64-pc-windows-msvc
Reproduce with:

cargo bisect-rustc --end=2023-11-05

@HTGAzureX1212
Copy link
Contributor

HTGAzureX1212 commented Nov 5, 2023

The commit corresponds to the merging this PR: #117131
cc @compiler-errors

nyurik added a commit to maplibre/martin that referenced this issue Nov 5, 2023
@compiler-errors compiler-errors self-assigned this Nov 5, 2023
@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 5, 2023
@Noratrieb Noratrieb added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Nov 7, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 7, 2023
@apiraino
Copy link
Contributor

apiraino commented Nov 7, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants