Skip to content

Hygiene for methods #15537

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

Merged
merged 17 commits into from
Jul 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ impl<K: Ord, V> TreeMap<K, V> {

macro_rules! bound_setup {
// initialiser of the iterator to manipulate
($iter:expr,
($iter:expr, $k:expr,
// whether we are looking for the lower or upper bound.
$is_lower_bound:expr) => {
{
let mut iter = $iter;
loop {
if !iter.node.is_null() {
let node_k = unsafe {&(*iter.node).key};
match k.cmp(node_k) {
match $k.cmp(node_k) {
Less => iter.traverse_left(),
Greater => iter.traverse_right(),
Equal => {
Expand Down Expand Up @@ -230,13 +230,13 @@ impl<K: Ord, V> TreeMap<K, V> {
/// Return a lazy iterator to the first key-value pair whose key is not less than `k`
/// If all keys in map are less than `k` an empty iterator is returned.
pub fn lower_bound<'a>(&'a self, k: &K) -> Entries<'a, K, V> {
bound_setup!(self.iter_for_traversal(), true)
bound_setup!(self.iter_for_traversal(), k, true)
}

/// Return a lazy iterator to the first key-value pair whose key is greater than `k`
/// If all keys in map are not greater than `k` an empty iterator is returned.
pub fn upper_bound<'a>(&'a self, k: &K) -> Entries<'a, K, V> {
bound_setup!(self.iter_for_traversal(), false)
bound_setup!(self.iter_for_traversal(), k, false)
}

/// Get a lazy iterator that should be initialized using
Expand All @@ -256,7 +256,7 @@ impl<K: Ord, V> TreeMap<K, V> {
/// If all keys in map are less than `k` an empty iterator is
/// returned.
pub fn mut_lower_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
bound_setup!(self.mut_iter_for_traversal(), true)
bound_setup!(self.mut_iter_for_traversal(), k, true)
}

/// Return a lazy iterator to the first key-value pair (with the
Expand All @@ -265,7 +265,7 @@ impl<K: Ord, V> TreeMap<K, V> {
/// If all keys in map are not greater than `k` an empty iterator
/// is returned.
pub fn mut_upper_bound<'a>(&'a mut self, k: &K) -> MutEntries<'a, K, V> {
bound_setup!(self.mut_iter_for_traversal(), false)
bound_setup!(self.mut_iter_for_traversal(), k, false)
}
}

Expand Down
134 changes: 67 additions & 67 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,16 @@ pub trait ToPrimitive {
}

macro_rules! impl_to_primitive_int_to_int(
($SrcT:ty, $DstT:ty) => (
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some(*self as $DstT)
Some($slf as $DstT)
} else {
let n = *self as i64;
let n = $slf as i64;
let min_value: $DstT = Bounded::min_value();
let max_value: $DstT = Bounded::max_value();
if min_value as i64 <= n && n <= max_value as i64 {
Some(*self as $DstT)
Some($slf as $DstT)
} else {
None
}
Expand All @@ -788,12 +788,12 @@ macro_rules! impl_to_primitive_int_to_int(
)

macro_rules! impl_to_primitive_int_to_uint(
($SrcT:ty, $DstT:ty) => (
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
let zero: $SrcT = Zero::zero();
let max_value: $DstT = Bounded::max_value();
if zero <= *self && *self as u64 <= max_value as u64 {
Some(*self as $DstT)
if zero <= $slf && $slf as u64 <= max_value as u64 {
Some($slf as $DstT)
} else {
None
}
Expand All @@ -805,26 +805,26 @@ macro_rules! impl_to_primitive_int(
($T:ty) => (
impl ToPrimitive for $T {
#[inline]
fn to_int(&self) -> Option<int> { impl_to_primitive_int_to_int!($T, int) }
fn to_int(&self) -> Option<int> { impl_to_primitive_int_to_int!($T, int, *self) }
#[inline]
fn to_i8(&self) -> Option<i8> { impl_to_primitive_int_to_int!($T, i8) }
fn to_i8(&self) -> Option<i8> { impl_to_primitive_int_to_int!($T, i8, *self) }
#[inline]
fn to_i16(&self) -> Option<i16> { impl_to_primitive_int_to_int!($T, i16) }
fn to_i16(&self) -> Option<i16> { impl_to_primitive_int_to_int!($T, i16, *self) }
#[inline]
fn to_i32(&self) -> Option<i32> { impl_to_primitive_int_to_int!($T, i32) }
fn to_i32(&self) -> Option<i32> { impl_to_primitive_int_to_int!($T, i32, *self) }
#[inline]
fn to_i64(&self) -> Option<i64> { impl_to_primitive_int_to_int!($T, i64) }
fn to_i64(&self) -> Option<i64> { impl_to_primitive_int_to_int!($T, i64, *self) }

#[inline]
fn to_uint(&self) -> Option<uint> { impl_to_primitive_int_to_uint!($T, uint) }
fn to_uint(&self) -> Option<uint> { impl_to_primitive_int_to_uint!($T, uint, *self) }
#[inline]
fn to_u8(&self) -> Option<u8> { impl_to_primitive_int_to_uint!($T, u8) }
fn to_u8(&self) -> Option<u8> { impl_to_primitive_int_to_uint!($T, u8, *self) }
#[inline]
fn to_u16(&self) -> Option<u16> { impl_to_primitive_int_to_uint!($T, u16) }
fn to_u16(&self) -> Option<u16> { impl_to_primitive_int_to_uint!($T, u16, *self) }
#[inline]
fn to_u32(&self) -> Option<u32> { impl_to_primitive_int_to_uint!($T, u32) }
fn to_u32(&self) -> Option<u32> { impl_to_primitive_int_to_uint!($T, u32, *self) }
#[inline]
fn to_u64(&self) -> Option<u64> { impl_to_primitive_int_to_uint!($T, u64) }
fn to_u64(&self) -> Option<u64> { impl_to_primitive_int_to_uint!($T, u64, *self) }

#[inline]
fn to_f32(&self) -> Option<f32> { Some(*self as f32) }
Expand All @@ -841,11 +841,11 @@ impl_to_primitive_int!(i32)
impl_to_primitive_int!(i64)

macro_rules! impl_to_primitive_uint_to_int(
($DstT:ty) => (
($DstT:ty, $slf:expr) => (
{
let max_value: $DstT = Bounded::max_value();
if *self as u64 <= max_value as u64 {
Some(*self as $DstT)
if $slf as u64 <= max_value as u64 {
Some($slf as $DstT)
} else {
None
}
Expand All @@ -854,15 +854,15 @@ macro_rules! impl_to_primitive_uint_to_int(
)

macro_rules! impl_to_primitive_uint_to_uint(
($SrcT:ty, $DstT:ty) => (
($SrcT:ty, $DstT:ty, $slf:expr) => (
{
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some(*self as $DstT)
Some($slf as $DstT)
} else {
let zero: $SrcT = Zero::zero();
let max_value: $DstT = Bounded::max_value();
if zero <= *self && *self as u64 <= max_value as u64 {
Some(*self as $DstT)
if zero <= $slf && $slf as u64 <= max_value as u64 {
Some($slf as $DstT)
} else {
None
}
Expand All @@ -875,26 +875,26 @@ macro_rules! impl_to_primitive_uint(
($T:ty) => (
impl ToPrimitive for $T {
#[inline]
fn to_int(&self) -> Option<int> { impl_to_primitive_uint_to_int!(int) }
fn to_int(&self) -> Option<int> { impl_to_primitive_uint_to_int!(int, *self) }
#[inline]
fn to_i8(&self) -> Option<i8> { impl_to_primitive_uint_to_int!(i8) }
fn to_i8(&self) -> Option<i8> { impl_to_primitive_uint_to_int!(i8, *self) }
#[inline]
fn to_i16(&self) -> Option<i16> { impl_to_primitive_uint_to_int!(i16) }
fn to_i16(&self) -> Option<i16> { impl_to_primitive_uint_to_int!(i16, *self) }
#[inline]
fn to_i32(&self) -> Option<i32> { impl_to_primitive_uint_to_int!(i32) }
fn to_i32(&self) -> Option<i32> { impl_to_primitive_uint_to_int!(i32, *self) }
#[inline]
fn to_i64(&self) -> Option<i64> { impl_to_primitive_uint_to_int!(i64) }
fn to_i64(&self) -> Option<i64> { impl_to_primitive_uint_to_int!(i64, *self) }

#[inline]
fn to_uint(&self) -> Option<uint> { impl_to_primitive_uint_to_uint!($T, uint) }
fn to_uint(&self) -> Option<uint> { impl_to_primitive_uint_to_uint!($T, uint, *self) }
#[inline]
fn to_u8(&self) -> Option<u8> { impl_to_primitive_uint_to_uint!($T, u8) }
fn to_u8(&self) -> Option<u8> { impl_to_primitive_uint_to_uint!($T, u8, *self) }
#[inline]
fn to_u16(&self) -> Option<u16> { impl_to_primitive_uint_to_uint!($T, u16) }
fn to_u16(&self) -> Option<u16> { impl_to_primitive_uint_to_uint!($T, u16, *self) }
#[inline]
fn to_u32(&self) -> Option<u32> { impl_to_primitive_uint_to_uint!($T, u32) }
fn to_u32(&self) -> Option<u32> { impl_to_primitive_uint_to_uint!($T, u32, *self) }
#[inline]
fn to_u64(&self) -> Option<u64> { impl_to_primitive_uint_to_uint!($T, u64) }
fn to_u64(&self) -> Option<u64> { impl_to_primitive_uint_to_uint!($T, u64, *self) }

#[inline]
fn to_f32(&self) -> Option<f32> { Some(*self as f32) }
Expand All @@ -911,14 +911,14 @@ impl_to_primitive_uint!(u32)
impl_to_primitive_uint!(u64)

macro_rules! impl_to_primitive_float_to_float(
($SrcT:ty, $DstT:ty) => (
($SrcT:ty, $DstT:ty, $slf:expr) => (
if size_of::<$SrcT>() <= size_of::<$DstT>() {
Some(*self as $DstT)
Some($slf as $DstT)
} else {
let n = *self as f64;
let n = $slf as f64;
let max_value: $SrcT = Bounded::max_value();
if -max_value as f64 <= n && n <= max_value as f64 {
Some(*self as $DstT)
Some($slf as $DstT)
} else {
None
}
Expand Down Expand Up @@ -952,9 +952,9 @@ macro_rules! impl_to_primitive_float(
fn to_u64(&self) -> Option<u64> { Some(*self as u64) }

#[inline]
fn to_f32(&self) -> Option<f32> { impl_to_primitive_float_to_float!($T, f32) }
fn to_f32(&self) -> Option<f32> { impl_to_primitive_float_to_float!($T, f32, *self) }
#[inline]
fn to_f64(&self) -> Option<f64> { impl_to_primitive_float_to_float!($T, f64) }
fn to_f64(&self) -> Option<f64> { impl_to_primitive_float_to_float!($T, f64, *self) }
}
)
)
Expand Down Expand Up @@ -1104,38 +1104,38 @@ pub fn from_f64<A: FromPrimitive>(n: f64) -> Option<A> {
}

macro_rules! impl_from_primitive(
($T:ty, $to_ty:expr) => (
($T:ty, $to_ty:ident) => (
impl FromPrimitive for $T {
#[inline] fn from_int(n: int) -> Option<$T> { $to_ty }
#[inline] fn from_i8(n: i8) -> Option<$T> { $to_ty }
#[inline] fn from_i16(n: i16) -> Option<$T> { $to_ty }
#[inline] fn from_i32(n: i32) -> Option<$T> { $to_ty }
#[inline] fn from_i64(n: i64) -> Option<$T> { $to_ty }

#[inline] fn from_uint(n: uint) -> Option<$T> { $to_ty }
#[inline] fn from_u8(n: u8) -> Option<$T> { $to_ty }
#[inline] fn from_u16(n: u16) -> Option<$T> { $to_ty }
#[inline] fn from_u32(n: u32) -> Option<$T> { $to_ty }
#[inline] fn from_u64(n: u64) -> Option<$T> { $to_ty }

#[inline] fn from_f32(n: f32) -> Option<$T> { $to_ty }
#[inline] fn from_f64(n: f64) -> Option<$T> { $to_ty }
#[inline] fn from_int(n: int) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i8(n: i8) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i16(n: i16) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i32(n: i32) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i64(n: i64) -> Option<$T> { n.$to_ty() }

#[inline] fn from_uint(n: uint) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u8(n: u8) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u16(n: u16) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u32(n: u32) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u64(n: u64) -> Option<$T> { n.$to_ty() }

#[inline] fn from_f32(n: f32) -> Option<$T> { n.$to_ty() }
#[inline] fn from_f64(n: f64) -> Option<$T> { n.$to_ty() }
}
)
)

impl_from_primitive!(int, n.to_int())
impl_from_primitive!(i8, n.to_i8())
impl_from_primitive!(i16, n.to_i16())
impl_from_primitive!(i32, n.to_i32())
impl_from_primitive!(i64, n.to_i64())
impl_from_primitive!(uint, n.to_uint())
impl_from_primitive!(u8, n.to_u8())
impl_from_primitive!(u16, n.to_u16())
impl_from_primitive!(u32, n.to_u32())
impl_from_primitive!(u64, n.to_u64())
impl_from_primitive!(f32, n.to_f32())
impl_from_primitive!(f64, n.to_f64())
impl_from_primitive!(int, to_int)
impl_from_primitive!(i8, to_i8)
impl_from_primitive!(i16, to_i16)
impl_from_primitive!(i32, to_i32)
impl_from_primitive!(i64, to_i64)
impl_from_primitive!(uint, to_uint)
impl_from_primitive!(u8, to_u8)
impl_from_primitive!(u16, to_u16)
impl_from_primitive!(u32, to_u32)
impl_from_primitive!(u64, to_u64)
impl_from_primitive!(f32, to_f32)
impl_from_primitive!(f64, to_f64)

/// Cast from one machine scalar to another.
///
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,11 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
let explicit_self_kind = string.as_bytes()[0];
match explicit_self_kind as char {
's' => ast::SelfStatic,
'v' => ast::SelfValue,
'~' => ast::SelfUniq,
'v' => ast::SelfValue(special_idents::self_),
'~' => ast::SelfUniq(special_idents::self_),
// FIXME(#4846) expl. region
'&' => ast::SelfRegion(None, get_mutability(string.as_bytes()[1])),
'&' => ast::SelfRegion(None, get_mutability(string.as_bytes()[1]),
special_idents::self_),
_ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ fn encode_explicit_self(ebml_w: &mut Encoder, explicit_self: ast::ExplicitSelf_)

// Encode the base self type.
match explicit_self {
SelfStatic => { ebml_w.writer.write(&[ 's' as u8 ]); }
SelfValue => { ebml_w.writer.write(&[ 'v' as u8 ]); }
SelfUniq => { ebml_w.writer.write(&[ '~' as u8 ]); }
SelfRegion(_, m) => {
SelfStatic => { ebml_w.writer.write(&[ 's' as u8 ]); }
SelfValue(_) => { ebml_w.writer.write(&[ 'v' as u8 ]); }
SelfUniq(_) => { ebml_w.writer.write(&[ '~' as u8 ]); }
SelfRegion(_, m, _) => {
// FIXME(#4846) encode custom lifetime
ebml_w.writer.write(&['&' as u8]);
encode_mutability(ebml_w, m);
Expand Down
18 changes: 10 additions & 8 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use syntax::ast;
use syntax::ast_util::{local_def};
use syntax::ast_util::{walk_pat, trait_method_to_ty_method};
use syntax::ext::mtwt;
use syntax::parse::token::special_names;
use syntax::parse::token::special_idents;
use syntax::parse::token;
use syntax::codemap::{Span, DUMMY_SP, Pos};
Expand Down Expand Up @@ -830,9 +831,9 @@ struct Resolver<'a> {
current_self_type: Option<Ty>,

// The ident for the keyword "self".
self_ident: Ident,
self_name: Name,
// The ident for the non-keyword "Self".
type_self_ident: Ident,
type_self_name: Name,

// The idents for the primitive types.
primitive_type_table: PrimitiveTypeTable,
Expand Down Expand Up @@ -926,8 +927,8 @@ impl<'a> Resolver<'a> {
current_trait_ref: None,
current_self_type: None,

self_ident: special_idents::self_,
type_self_ident: special_idents::type_self,
self_name: special_names::self_,
type_self_name: special_names::type_self,

primitive_type_table: PrimitiveTypeTable::new(),

Expand Down Expand Up @@ -3628,8 +3629,8 @@ impl<'a> Resolver<'a> {
// Create a new rib for the self type.
let self_type_rib = Rib::new(ItemRibKind);

// plain insert (no renaming)
let name = self.type_self_ident.name;
// plain insert (no renaming, types are not currently hygienic....)
let name = self.type_self_name;
self_type_rib.bindings.borrow_mut()
.insert(name, DlDef(DefSelfTy(item.id)));
self.type_ribs.borrow_mut().push(self_type_rib);
Expand Down Expand Up @@ -5159,8 +5160,8 @@ impl<'a> Resolver<'a> {
false // Stop advancing
});

if method_scope && token::get_name(self.self_ident.name).get()
== wrong_name.as_slice() {
if method_scope && token::get_name(self.self_name).get()
== wrong_name.as_slice() {
self.resolve_error(
expr.span,
"`self` is not available \
Expand Down Expand Up @@ -5532,6 +5533,7 @@ impl<'a> Resolver<'a> {
collect_mod(idents, &*module.upgrade().unwrap());
}
BlockParentLink(ref module, _) => {
// danger, shouldn't be ident?
idents.push(special_idents::opaque);
collect_mod(idents, &*module.upgrade().unwrap());
}
Expand Down
Loading