Skip to content

Implied bounds compat mode does not deduce sufficient outlives bounds #137767

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
compiler-errors opened this issue Feb 28, 2025 · 1 comment · Fixed by #137633
Closed

Implied bounds compat mode does not deduce sufficient outlives bounds #137767

compiler-errors opened this issue Feb 28, 2025 · 1 comment · Fixed by #137633
Assignees
Labels
C-bug Category: This is a bug.

Comments

@compiler-errors
Copy link
Member

I tried this code:

pub trait Iter {
    type Item;
}

impl<'x, I> Iter for I
where
    I: IntoIterator<Item = &'x ()>,
{
    type Item = &'x ();
}

pub struct Map<I>(I)
where
    I: Iter,
    I::Item: 'static;

pub fn test_borrowck<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
    s
}

fn main() {}

I expected to see it work.

Instead, it did not.

Meta

1.85 + beta + nightly for Feb 27, 2025

@compiler-errors compiler-errors added the C-bug Category: This is a bug. label Feb 28, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 28, 2025
@compiler-errors
Copy link
Member Author

The reason this fails is because of this if statement:

if obligation.predicate.has_non_region_infer() {

Combined w/ the fact that we use this function during borrowck for implied bounds means that we don't end up being able to assume that 'x: 'static during wfcheck:

pub fn wf<'x>(_: Map<Vec<&'x ()>>, s: &'x str)
where
    &'static &'x ():,
{
}

(which wouldn't be WF if we didn't know that 'x: 'static, so #137633 is strictly a fix.)

@compiler-errors compiler-errors self-assigned this Feb 28, 2025
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 1, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 5, 2025
…hack-unless-bevy, r=lcnr

Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack

Consolidates the implied bounds computation mode into a single function, which deeply normalizes, and if it's in **compat** mode (for bevy), it extracts outlives bounds from the infcx.

Previously, we were using the implied bounds compat mode in two cases:
1. During WF, if it detects `ParamSet`
2. EVERYWHERE ELSE (lol) -- e.g. borrowck, predicate entailment, etc.

While I think this is fine, and the net effect was just that we emitted fewer diagnostics, it makes me uncomfortable that all crates were using the supposed "compat" code.

Fixes rust-lang#137767
@bors bors closed this as completed in 6c60abf Mar 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 5, 2025
Rollup merge of rust-lang#137633 - compiler-errors:no-implied-bounds-hack-unless-bevy, r=lcnr

Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack

Consolidates the implied bounds computation mode into a single function, which deeply normalizes, and if it's in **compat** mode (for bevy), it extracts outlives bounds from the infcx.

Previously, we were using the implied bounds compat mode in two cases:
1. During WF, if it detects `ParamSet`
2. EVERYWHERE ELSE (lol) -- e.g. borrowck, predicate entailment, etc.

While I think this is fine, and the net effect was just that we emitted fewer diagnostics, it makes me uncomfortable that all crates were using the supposed "compat" code.

Fixes rust-lang#137767
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
3 participants