Skip to content

Methods with &mut Trait and polymorphic objects can't get encoded #8401

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

Closed
alexcrichton opened this issue Aug 8, 2013 · 3 comments
Closed
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@alexcrichton
Copy link
Member

This code

#[crate_type = "lib"];
#[link(name = "foo", vers = "0.1")];

use std::cast;

trait A {}
struct B;
impl A for B {}

fn bar<T>(_: &mut A, _: &T) {}

fn foo<T>(t: &T) {
    let b = B;
    bar(unsafe { cast::transmute(&b as &A) }, t)
}

Dies with

error: internal compiler error: Cannot encode region variables

The transmute is in place to get around #8248, but I think that this may be uncovering a separate issue. Even with the transmute, I think this should compile anyway (although it's still unsafe code).

cc @msullivan

@alexcrichton
Copy link
Member Author

Also cc @nikomatsakis

@alexcrichton
Copy link
Member Author

Some similar code giving the same error, but with less stuff going on:

#[crate_type = "lib"];
#[link(name = "foo", vers = "0.1")];

use std::cast;

trait A {}
struct B;
impl A for B {}

pub fn bar<T>(_: &A) {}

fn foo<T>(b: &A) {
    let b: &A = unsafe { cast::transmute(b) };
    bar::<T>(b)
}

@alexcrichton
Copy link
Member Author

Yay, this works now!

Flagging as needstest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

1 participant