rust/src/test/auxiliary/inner_static.rs
Alex Crichton 36a4af49e0 Remove __extensions__ in names for a "pretty name"
As with the previous commit, this is targeted at removing the possibility of
collisions between statics. The main use case here is when there's a
type-parametric function with an inner static that's compiled as a library.
Before this commit, any impl would generate a path item of "__extensions__".
This changes this identifier to be a "pretty name", which is either the last
element of the path of the trait implemented or the last element of the type's
path that's being implemented.  That doesn't quite cut it though, so the (trait,
type) pair is hashed and again used to append information to the symbol.

Essentially, __extensions__ was removed for something nicer for debugging, and
then some more information was added to symbol name by including a hash of the
trait being implemented and type it's being implemented for. This should prevent
colliding names for inner statics in regular functions with similar names.
2013-09-02 23:12:41 -07:00

62 lines
1.2 KiB
Rust

// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub struct A<T>;
pub struct B<T>;
pub mod test {
pub struct A<T>;
}
impl<T> A<T> {
pub fn foo(&self) -> int {
static a: int = 1;
return a
}
pub fn bar(&self) -> int {
static a: int = 2;
return a;
}
}
impl<T> B<T> {
pub fn foo(&self) -> int {
static a: int = 3;
return a
}
pub fn bar(&self) -> int {
static a: int = 4;
return a;
}
}
impl<T> test::A<T> {
pub fn foo(&self) -> int {
static a: int = 5;
return a
}
pub fn bar(&self) -> int {
static a: int = 6;
return a;
}
}
pub fn foo() -> int {
let a = A::<()>;
let b = B::<()>;
let c = test::A::<()>;
return a.foo() + a.bar() +
b.foo() + b.bar() +
c.foo() + c.bar();
}