Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

normalizing opaques while proving implied bounds #159

Open
lcnr opened this issue Jan 31, 2025 · 2 comments
Open

normalizing opaques while proving implied bounds #159

lcnr opened this issue Jan 31, 2025 · 2 comments

Comments

@lcnr
Copy link
Contributor

lcnr commented Jan 31, 2025

This is unsound with the new solver with rust-lang/rust#136074.

I am using a OutlivesComponent::Alias as these use equality on the computed region constraints graph. When computing the implied bounds, the hidden type of impl Sized still has unconstrained regions, so region outlive bounds don't get added to the free_region_relations.

use std::any::Any;

struct Outlives<'a, T>(Option<&'a T>);
trait Trait {
    type Assoc;
}

impl<T> Trait for T {
    type Assoc = T;
}

// Computing the implied bounds for `foo` normalizes `impl Sized` to
// `Outlives::<'static, <T as Trait>::Assoc>`, adding the implied bound
// `<T as Trait>::Assoc: 'static`.
//
// The caller does not have to prove that bound.
fn foo<T: Trait>(x: <T as Trait>::Assoc) -> (Box<dyn Any>, impl Sized) {
    (Box::new(x), Outlives::<'static, <T as Trait>::Assoc>(None))
}

fn main() {
    let string = String::from("temporary");
    let (any, _proof) = foo::<&str>(string.as_str());
    drop(_proof);
    drop(string);
    println!("{}", any.downcast_ref::<&str>().unwrap());
}
@compiler-errors
Copy link
Member

Not sure how we're gonna do this, especially b/c now with TypingEnv being associated with an inference context it's not so easy to just swap out the reveal mode to something that keeps the opaques opaque.

@compiler-errors
Copy link
Member

Actually this is doable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants