Skip to content

Static method returning 'self with generics fails cross crate #7178

Closed
@huonw

Description

@huonw
// cross_crate_self.rs
pub struct Foo<'self, A>(&'self A);

impl<'self, A> Foo<'self, A> {
    pub fn new(a: &'self A) -> Foo<'self, A> {
        Foo(a)
    }
}
#[test]
fn test_foo() {
    let _ = Foo::new(&1i);
}
// other.rs
extern mod cross_crate_self;

#[test]
fn test_foo() {
    let _ = cross_crate_self::Foo::new(&1i);
}
$ rustc --test cross_crate_self.rs
$ ./cross_crate_self 

running 1 test
test test_foo ... ok

result: ok. 1 passed; 0 failed; 0 ignored

$ rustc --lib cross_crate_self.rs         
warning: missing crate link meta `name`, using `cross_crate_self` as default
warning: missing crate link meta `vers`, using `0.0` as default
$ rustc --test -L . other.rs
error: internal compiler error: ty::Region#subst(): Reference to self region when given substs with no self region: substs(self_r=None, self_ty=None, tps=[<V1>])

Having a generic A seems to be necessary to exhibit the bug. (Caused #7177.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesA-trait-systemArea: Trait systemA-type-systemArea: Type systemI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions