Skip to content

normalizing opaques while proving implied bounds #159

Open
@lcnr

Description

@lcnr

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());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions