Skip to content

Commit 9c96a79

Browse files
committed
auto merge of #19049 : jakub-/rust/roll-up, r=alexcrichton
r? @alexcrichton
2 parents 336349c + 330a1af commit 9c96a79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+744
-367
lines changed

mk/cfg/arm-apple-ios

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CFG_LIB_NAME_arm-apple-ios = lib$(1).a
1313
CFG_LIB_GLOB_arm-apple-ios = lib$(1)-*.a
1414
CFG_STATIC_LIB_NAME_arm-apple-ios=lib$(1).a
1515
CFG_LIB_DSYM_GLOB_arm-apple-ios = lib$(1)-*.a.dSYM
16-
CFG_CFLAGS_arm-apple-ios := -arch armv7 -mfpu=vfp3 $(CFG_IOS_FLAGS)
16+
CFG_JEMALLOC_CFLAGS_arm-apple-ios := -arch armv7 -mfpu=vfp3 $(CFG_IOS_FLAGS)
1717
CFG_GCCISH_CFLAGS_arm-apple-ios := -Wall -Werror -g -fPIC $(CFG_IOS_FLAGS) -mfpu=vfp3 -arch armv7
1818
CFG_GCCISH_CXXFLAGS_arm-apple-ios := -fno-rtti $(CFG_IOS_FLAGS) -I$(CFG_IOS_SDK)/usr/include/c++/4.2.1
1919
CFG_GCCISH_LINK_FLAGS_arm-apple-ios := -lpthread -syslibroot $(CFG_IOS_SDK) -Wl,-no_compact_unwind

mk/cfg/arm-linux-androideabi

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_arm-linux-androideabi=lib$(1).so
77
CFG_STATIC_LIB_NAME_arm-linux-androideabi=lib$(1).a
88
CFG_LIB_GLOB_arm-linux-androideabi=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_arm-linux-androideabi=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_arm-linux-androideabi := -D__arm__ -DANDROID -D__ANDROID__ $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_arm-linux-androideabi := -D__arm__ -DANDROID -D__ANDROID__ $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_arm-linux-androideabi := -Wall -g -fPIC -D__arm__ -DANDROID -D__ANDROID__ $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_arm-linux-androideabi := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_arm-linux-androideabi := -shared -fPIC -ldl -g -lm -lsupc++

mk/cfg/arm-unknown-linux-gnueabi

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CFG_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).so
88
CFG_STATIC_LIB_NAME_arm-unknown-linux-gnueabi=lib$(1).a
99
CFG_LIB_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.so
1010
CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabi=lib$(1)-*.dylib.dSYM
11-
CFG_CFLAGS_arm-unknown-linux-gnueabi := -D__arm__ -mfpu=vfp $(CFLAGS)
11+
CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabi := -D__arm__ -mfpu=vfp $(CFLAGS)
1212
CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabi := -Wall -g -fPIC -D__arm__ -mfpu=vfp $(CFLAGS)
1313
CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabi := -fno-rtti $(CXXFLAGS)
1414
CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabi := -shared -fPIC -g

mk/cfg/arm-unknown-linux-gnueabihf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CFG_LIB_NAME_arm-unknown-linux-gnueabihf=lib$(1).so
88
CFG_STATIC_LIB_NAME_arm-unknown-linux-gnueabihf=lib$(1).a
99
CFG_LIB_GLOB_arm-unknown-linux-gnueabihf=lib$(1)-*.so
1010
CFG_LIB_DSYM_GLOB_arm-unknown-linux-gnueabihf=lib$(1)-*.dylib.dSYM
11-
CFG_CFLAGS_arm-unknown-linux-gnueabihf := -D__arm__ $(CFLAGS)
11+
CFG_JEMALLOC_CFLAGS_arm-unknown-linux-gnueabihf := -D__arm__ $(CFLAGS)
1212
CFG_GCCISH_CFLAGS_arm-unknown-linux-gnueabihf := -Wall -g -fPIC -D__arm__ $(CFLAGS)
1313
CFG_GCCISH_CXXFLAGS_arm-unknown-linux-gnueabihf := -fno-rtti $(CXXFLAGS)
1414
CFG_GCCISH_LINK_FLAGS_arm-unknown-linux-gnueabihf := -shared -fPIC -g

mk/cfg/i386-apple-ios

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ CFG_LIB_NAME_i386-apple-ios = lib$(1).a
1313
CFG_LIB_GLOB_i386-apple-ios = lib$(1)-*.dylib
1414
CFG_STATIC_LIB_NAME_i386-apple-ios=lib$(1).a
1515
CFG_LIB_DSYM_GLOB_i386-apple-ios = lib$(1)-*.dylib.dSYM
16-
CFG_CFLAGS_i386-apple-ios = $(CFG_IOSSIM_FLAGS)
1716
CFG_GCCISH_CFLAGS_i386-apple-ios = -Wall -Werror -g -fPIC -m32 $(CFG_IOSSIM_FLAGS)
1817
CFG_GCCISH_CXXFLAGS_i386-apple-ios = -fno-rtti $(CFG_IOSSIM_FLAGS) -I$(CFG_IOSSIM_SDK)/usr/include/c++/4.2.1
1918
CFG_GCCISH_LINK_FLAGS_i386-apple-ios = -lpthread -Wl,-no_compact_unwind -m32 -Wl,-syslibroot $(CFG_IOSSIM_SDK)
@@ -30,5 +29,5 @@ CFG_PATH_MUNGE_i386-apple-ios = true
3029
CFG_LDPATH_i386-apple-ios =
3130
CFG_RUN_i386-apple-ios = $(2)
3231
CFG_RUN_TARG_i386-apple-ios = $(call CFG_RUN_i386-apple-ios,,$(2))
33-
CFG_JEMALLOC_CFLAGS_i386-apple-ios = -target i386-apple-ios -Wl,-syslibroot $(CFG_IOSSIM_SDK) -Wl,-no_compact_unwind
32+
CFG_JEMALLOC_CFLAGS_i386-apple-ios = $(CFG_IOSSIM_FLAGS) -target i386-apple-ios -Wl,-syslibroot $(CFG_IOSSIM_SDK) -Wl,-no_compact_unwind
3433
CFG_GNU_TRIPLE_i386-apple-ios := i386-apple-ios

mk/cfg/i686-apple-darwin

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_i686-apple-darwin=lib$(1).dylib
77
CFG_STATIC_LIB_NAME_i686-apple-darwin=lib$(1).a
88
CFG_LIB_GLOB_i686-apple-darwin=lib$(1)-*.dylib
99
CFG_LIB_DSYM_GLOB_i686-apple-darwin=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_i686-apple-darwin := -m32 -arch i386 $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_i686-apple-darwin := -m32 -arch i386 $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_i686-apple-darwin := -Wall -Werror -g -fPIC -m32 -arch i386 $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_i686-apple-darwin := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_i686-apple-darwin := -dynamiclib -pthread -framework CoreServices -m32

mk/cfg/i686-pc-windows-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CFG_LIB_NAME_i686-pc-windows-gnu=$(1).dll
88
CFG_STATIC_LIB_NAME_i686-pc-windows-gnu=$(1).lib
99
CFG_LIB_GLOB_i686-pc-windows-gnu=$(1)-*.dll
1010
CFG_LIB_DSYM_GLOB_i686-pc-windows-gnu=$(1)-*.dylib.dSYM
11-
CFG_CFLAGS_i686-pc-windows-gnu := -march=i686 -m32 -D_WIN32_WINNT=0x0600 $(CFLAGS)
11+
CFG_JEMALLOC_CFLAGS_i686-pc-windows-gnu := -march=i686 -m32 -D_WIN32_WINNT=0x0600 $(CFLAGS)
1212
CFG_GCCISH_CFLAGS_i686-pc-windows-gnu := -Wall -Werror -g -m32 -D_WIN32_WINNT=0x0600 $(CFLAGS)
1313
CFG_GCCISH_CXXFLAGS_i686-pc-windows-gnu := -fno-rtti $(CXXFLAGS)
1414
CFG_GCCISH_LINK_FLAGS_i686-pc-windows-gnu := -shared -g -m32

mk/cfg/i686-unknown-linux-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_i686-unknown-linux-gnu=lib$(1).so
77
CFG_STATIC_LIB_NAME_i686-unknown-linux-gnu=lib$(1).a
88
CFG_LIB_GLOB_i686-unknown-linux-gnu=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_i686-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_i686-unknown-linux-gnu := -m32 $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_i686-unknown-linux-gnu := -m32 $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_i686-unknown-linux-gnu := -Wall -Werror -g -fPIC -m32 $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_i686-unknown-linux-gnu := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_i686-unknown-linux-gnu := -shared -fPIC -ldl -pthread -lrt -g -m32

mk/cfg/mips-unknown-linux-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
77
CFG_STATIC_LIB_NAME_mips-unknown-linux-gnu=lib$(1).a
88
CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_mips-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_mips-unknown-linux-gnu := -mips32r2 -msoft-float -mabi=32 -mno-compact-eh $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_mips-unknown-linux-gnu := -mips32r2 -msoft-float -mabi=32 -mno-compact-eh $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_mips-unknown-linux-gnu := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32 -mno-compact-eh $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-gnu := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-gnu := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32

mk/cfg/mipsel-unknown-linux-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).so
77
CFG_STATIC_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).a
88
CFG_LIB_GLOB_mipsel-unknown-linux-gnu=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_mipsel-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_mipsel-unknown-linux-gnu := -mips32 -mabi=32 $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_mipsel-unknown-linux-gnu := -mips32 -mabi=32 $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_mipsel-unknown-linux-gnu := -Wall -g -fPIC -mips32 -mabi=32 $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_mipsel-unknown-linux-gnu := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_mipsel-unknown-linux-gnu := -shared -fPIC -g -mips32

mk/cfg/x86_64-apple-darwin

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_x86_64-apple-darwin=lib$(1).dylib
77
CFG_STATIC_LIB_NAME_x86_64-apple-darwin=lib$(1).a
88
CFG_LIB_GLOB_x86_64-apple-darwin=lib$(1)-*.dylib
99
CFG_LIB_DSYM_GLOB_x86_64-apple-darwin=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_x86_64-apple-darwin := -m64 -arch x86_64 $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_x86_64-apple-darwin := -m64 -arch x86_64 $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_x86_64-apple-darwin := -Wall -Werror -g -fPIC -m64 -arch x86_64 $(CFLAGS)
1212
CFG_GCCISH_CXXFLAGS_x86_64-apple-darwin := -fno-rtti $(CXXFLAGS)
1313
CFG_GCCISH_LINK_FLAGS_x86_64-apple-darwin := -dynamiclib -pthread -framework CoreServices -m64

mk/cfg/x86_64-pc-windows-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CFG_LIB_NAME_x86_64-pc-windows-gnu=$(1).dll
88
CFG_STATIC_LIB_NAME_x86_64-pc-windows-gnu=$(1).lib
99
CFG_LIB_GLOB_x86_64-pc-windows-gnu=$(1)-*.dll
1010
CFG_LIB_DSYM_GLOB_x86_64-pc-windows-gnu=$(1)-*.dylib.dSYM
11-
CFG_CFLAGS_x86_64-pc-windows-gnu := -m64 -D_WIN32_WINNT=0x0600 $(CFLAGS)
11+
CFG_JEMALLOC_CFLAGS_x86_64-pc-windows-gnu := -m64 -D_WIN32_WINNT=0x0600 $(CFLAGS)
1212
CFG_GCCISH_CFLAGS_x86_64-pc-windows-gnu := -Wall -Werror -g -m64 -D_WIN32_WINNT=0x0600 $(CFLAGS)
1313
CFG_GCCISH_CXXFLAGS_x86_64-pc-windows-gnu := -fno-rtti $(CXXFLAGS)
1414
CFG_GCCISH_LINK_FLAGS_x86_64-pc-windows-gnu := -shared -g -m64

mk/cfg/x86_64-unknown-dragonfly

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_x86_64-unknown-dragonfly=lib$(1).so
77
CFG_STATIC_LIB_NAME_x86_64-unknown-dragonfly=lib$(1).a
88
CFG_LIB_GLOB_x86_64-unknown-dragonfly=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_x86_64-unknown-dragonfly=$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_x86_64-unknown-dragonfly := -I/usr/include -I/usr/local/include $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_x86_64-unknown-dragonfly := -I/usr/include -I/usr/local/include $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_x86_64-unknown-dragonfly := -Wall -Werror -g -fPIC -I/usr/include -I/usr/local/include $(CFLAGS)
1212
CFG_GCCISH_LINK_FLAGS_x86_64-unknown-dragonfly := -shared -fPIC -g -pthread -lrt
1313
CFG_GCCISH_DEF_FLAG_x86_64-unknown-dragonfly := -Wl,--export-dynamic,--dynamic-list=

mk/cfg/x86_64-unknown-freebsd

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_x86_64-unknown-freebsd=lib$(1).so
77
CFG_STATIC_LIB_NAME_x86_64-unknown-freebsd=lib$(1).a
88
CFG_LIB_GLOB_x86_64-unknown-freebsd=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_x86_64-unknown-freebsd=$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_x86_64-unknown-freebsd := -I/usr/local/include $(CFLAGS)
10+
CFG_JEMALLOC_CFLAGS_x86_64-unknown-freebsd := -I/usr/local/include $(CFLAGS)
1111
CFG_GCCISH_CFLAGS_x86_64-unknown-freebsd := -Wall -Werror -g -fPIC -I/usr/local/include $(CFLAGS)
1212
CFG_GCCISH_LINK_FLAGS_x86_64-unknown-freebsd := -shared -fPIC -g -pthread -lrt
1313
CFG_GCCISH_DEF_FLAG_x86_64-unknown-freebsd := -Wl,--export-dynamic,--dynamic-list=

mk/cfg/x86_64-unknown-linux-gnu

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFG_LIB_NAME_x86_64-unknown-linux-gnu=lib$(1).so
77
CFG_STATIC_LIB_NAME_x86_64-unknown-linux-gnu=lib$(1).a
88
CFG_LIB_GLOB_x86_64-unknown-linux-gnu=lib$(1)-*.so
99
CFG_LIB_DSYM_GLOB_x86_64-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
10-
CFG_CFLAGS_x86_64-unknown-linux-gnu := -m64
10+
CFG_JEMALLOC_CFLAGS_x86_64-unknown-linux-gnu := -m64
1111
CFG_GCCISH_CFLAGS_x86_64-unknown-linux-gnu := -Wall -Werror -g -fPIC -m64
1212
CFG_GCCISH_CXXFLAGS_x86_64-unknown-linux-gnu := -fno-rtti
1313
CFG_GCCISH_LINK_FLAGS_x86_64-unknown-linux-gnu := -shared -fPIC -ldl -pthread -lrt -g -m64

mk/rt.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ $$(JEMALLOC_LOCAL_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
177177
cd "$$(JEMALLOC_BUILD_DIR_$(1))"; "$(S)src/jemalloc/configure" \
178178
$$(JEMALLOC_ARGS_$(1)) --with-jemalloc-prefix=je_ $(CFG_JEMALLOC_FLAGS) \
179179
--build=$$(CFG_GNU_TRIPLE_$(CFG_BUILD)) --host=$$(CFG_GNU_TRIPLE_$(1)) \
180-
CC="$$(CC_$(1))" \
180+
CC="$$(CC_$(1)) $$(CFG_JEMALLOC_CFLAGS_$(1))" \
181181
AR="$$(AR_$(1))" \
182182
RANLIB="$$(AR_$(1)) s" \
183183
CPPFLAGS="-I $(S)src/rt/" \
184-
EXTRA_CFLAGS="$$(CFG_CFLAGS_$(1)) $$(CFG_JEMALLOC_CFLAGS_$(1)) -g1"
184+
EXTRA_CFLAGS="-g1"
185185
$$(Q)$$(MAKE) -C "$$(JEMALLOC_BUILD_DIR_$(1))" build_lib_static
186186

187187
ifeq ($$(CFG_DISABLE_JEMALLOC),)

src/doc/reference.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ r##"foo #"# bar"##; // foo #"# bar
304304
#### Byte and byte string literals
305305

306306
```{.ebnf .gram}
307-
byte_lit : 'b' '\x27' byte_body '\x27' ;
308-
byte_string_lit : 'b' '"' string_body * '"' | 'b' 'r' raw_byte_string ;
307+
byte_lit : "b\x27" byte_body '\x27' ;
308+
byte_string_lit : "b\x22" string_body * '\x22' | "br" raw_byte_string ;
309309
310310
byte_body : ascii_non_single_quote
311311
| '\x5c' [ '\x27' | common_escape ] ;
@@ -381,10 +381,10 @@ num_suffix : int_suffix | float_suffix ;
381381
382382
int_suffix : 'u' int_suffix_size ?
383383
| 'i' int_suffix_size ? ;
384-
int_suffix_size : [ '8' | '1' '6' | '3' '2' | '6' '4' ] ;
384+
int_suffix_size : [ '8' | "16" | "32" | "64" ] ;
385385
386386
float_suffix : [ exponent | '.' dec_lit exponent ? ] ? float_suffix_ty ? ;
387-
float_suffix_ty : 'f' [ '3' '2' | '6' '4' ] ;
387+
float_suffix_ty : 'f' [ "32" | "64" ] ;
388388
exponent : ['E' | 'e'] ['-' | '+' ] ? dec_lit ;
389389
dec_lit : [ dec_digit | '_' ] + ;
390390
```
@@ -1862,7 +1862,7 @@ the namespace hierarchy as it normally would.
18621862
## Attributes
18631863

18641864
```{.ebnf .gram}
1865-
attribute : '#' '!' ? '[' meta_item ']' ;
1865+
attribute : "#!" ? '[' meta_item ']' ;
18661866
meta_item : ident [ '=' literal
18671867
| '(' meta_seq ')' ] ? ;
18681868
meta_seq : meta_item [ ',' meta_seq ] ? ;

src/grammar/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
178178
let toknum = m.name("toknum");
179179
let content = m.name("content");
180180

181-
let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map",
181+
let proto_tok = tokens.get(&toknum).expect(format!("didn't find token {} in the map",
182182
toknum).as_slice());
183183

184184
let nm = parse::token::intern(content);

src/libcollections/bit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Bitv {
283283
x != 0
284284
}
285285

286-
/// Sets the value of a bit at a index `i`.
286+
/// Sets the value of a bit at an index `i`.
287287
///
288288
/// # Panics
289289
///
@@ -582,7 +582,7 @@ impl Bitv {
582582
///
583583
/// # Panics
584584
///
585-
/// Panics if the the `Bitv` and slice are of different length.
585+
/// Panics if the `Bitv` and slice are of different length.
586586
///
587587
/// # Example
588588
///

src/libcollections/btree/map.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core::prelude::*;
2121

2222
use self::StackOp::*;
2323
use super::node::*;
24+
use core::borrow::BorrowFrom;
2425
use std::hash::{Writer, Hash};
2526
use core::default::Default;
2627
use core::{iter, fmt, mem};
@@ -56,7 +57,7 @@ use ring_buf::RingBuf;
5657
/// and possibly other factors. Using linear search, searching for a random element is expected
5758
/// to take O(B log<sub>B</sub>n) comparisons, which is generally worse than a BST. In practice,
5859
/// however, performance is excellent. `BTreeMap` is able to readily outperform `TreeMap` under
59-
/// many workloads, and is competetive where it doesn't. BTreeMap also generally *scales* better
60+
/// many workloads, and is competitive where it doesn't. BTreeMap also generally *scales* better
6061
/// than TreeMap, making it more appropriate for large datasets.
6162
///
6263
/// However, `TreeMap` may still be more appropriate to use in many contexts. If elements are very
@@ -184,6 +185,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
184185

185186
/// Returns a reference to the value corresponding to the key.
186187
///
188+
/// The key may be any borrowed form of the map's key type, but the ordering
189+
/// on the borrowed form *must* match the ordering on the key type.
190+
///
187191
/// # Example
188192
///
189193
/// ```
@@ -195,7 +199,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
195199
/// assert_eq!(map.get(&2), None);
196200
/// ```
197201
#[unstable = "matches collection reform specification, waiting for dust to settle"]
198-
pub fn get(&self, key: &K) -> Option<&V> {
202+
pub fn get<Sized? Q>(&self, key: &Q) -> Option<&V> where Q: BorrowFrom<K> + Ord {
199203
let mut cur_node = &self.root;
200204
loop {
201205
match cur_node.search(key) {
@@ -213,6 +217,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
213217

214218
/// Returns true if the map contains a value for the specified key.
215219
///
220+
/// The key may be any borrowed form of the map's key type, but the ordering
221+
/// on the borrowed form *must* match the ordering on the key type.
222+
///
216223
/// # Example
217224
///
218225
/// ```
@@ -224,7 +231,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
224231
/// assert_eq!(map.contains_key(&2), false);
225232
/// ```
226233
#[unstable = "matches collection reform specification, waiting for dust to settle"]
227-
pub fn contains_key(&self, key: &K) -> bool {
234+
pub fn contains_key<Sized? Q>(&self, key: &Q) -> bool where Q: BorrowFrom<K> + Ord {
228235
self.get(key).is_some()
229236
}
230237

@@ -236,6 +243,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
236243

237244
/// Returns a mutable reference to the value corresponding to the key.
238245
///
246+
/// The key may be any borrowed form of the map's key type, but the ordering
247+
/// on the borrowed form *must* match the ordering on the key type.
248+
///
239249
/// # Example
240250
///
241251
/// ```
@@ -251,7 +261,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
251261
/// ```
252262
// See `get` for implementation notes, this is basically a copy-paste with mut's added
253263
#[unstable = "matches collection reform specification, waiting for dust to settle"]
254-
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
264+
pub fn get_mut<Sized? Q>(&mut self, key: &Q) -> Option<&mut V> where Q: BorrowFrom<K> + Ord {
255265
// temp_node is a Borrowck hack for having a mutable value outlive a loop iteration
256266
let mut temp_node = &mut self.root;
257267
loop {
@@ -410,6 +420,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
410420
/// Removes a key from the map, returning the value at the key if the key
411421
/// was previously in the map.
412422
///
423+
/// The key may be any borrowed form of the map's key type, but the ordering
424+
/// on the borrowed form *must* match the ordering on the key type.
425+
///
413426
/// # Example
414427
///
415428
/// ```
@@ -421,7 +434,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
421434
/// assert_eq!(map.remove(&1), None);
422435
/// ```
423436
#[unstable = "matches collection reform specification, waiting for dust to settle"]
424-
pub fn remove(&mut self, key: &K) -> Option<V> {
437+
pub fn remove<Sized? Q>(&mut self, key: &Q) -> Option<V> where Q: BorrowFrom<K> + Ord {
425438
// See `swap` for a more thorough description of the stuff going on in here
426439
let mut stack = stack::PartialSearchStack::new(self);
427440
loop {
@@ -790,14 +803,18 @@ impl<K: Show, V: Show> Show for BTreeMap<K, V> {
790803
}
791804
}
792805

793-
impl<K: Ord, V> Index<K, V> for BTreeMap<K, V> {
794-
fn index(&self, key: &K) -> &V {
806+
impl<K: Ord, Sized? Q, V> Index<Q, V> for BTreeMap<K, V>
807+
where Q: BorrowFrom<K> + Ord
808+
{
809+
fn index(&self, key: &Q) -> &V {
795810
self.get(key).expect("no entry found for key")
796811
}
797812
}
798813

799-
impl<K: Ord, V> IndexMut<K, V> for BTreeMap<K, V> {
800-
fn index_mut(&mut self, key: &K) -> &mut V {
814+
impl<K: Ord, Sized? Q, V> IndexMut<Q, V> for BTreeMap<K, V>
815+
where Q: BorrowFrom<K> + Ord
816+
{
817+
fn index_mut(&mut self, key: &Q) -> &mut V {
801818
self.get_mut(key).expect("no entry found for key")
802819
}
803820
}

src/libcollections/btree/node.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::prelude::*;
1919

2020
use core::{slice, mem, ptr};
2121
use core::iter::Zip;
22+
use core::borrow::BorrowFrom;
2223

2324
use vec;
2425
use vec::Vec;
@@ -47,7 +48,7 @@ pub struct Node<K, V> {
4748
// theory, if we take full control of allocation like HashMap's RawTable does,
4849
// and restrict leaves to max size 256 (not unreasonable for a btree node) we can cut
4950
// this down to just (ptr, cap: u8, size: u8, is_leaf: bool). With generic
50-
// integer arguments, cap can even move into the the type, reducing this just to
51+
// integer arguments, cap can even move into the type, reducing this just to
5152
// (ptr, size, is_leaf). This could also have cache benefits for very small nodes, as keys
5253
// could bleed into edges and vals.
5354
//
@@ -73,19 +74,19 @@ impl<K: Ord, V> Node<K, V> {
7374
/// Searches for the given key in the node. If it finds an exact match,
7475
/// `Found` will be yielded with the matching index. If it doesn't find an exact match,
7576
/// `GoDown` will be yielded with the index of the subtree the key must lie in.
76-
pub fn search(&self, key: &K) -> SearchResult {
77+
pub fn search<Sized? Q>(&self, key: &Q) -> SearchResult where Q: BorrowFrom<K> + Ord {
7778
// FIXME(Gankro): Tune when to search linear or binary based on B (and maybe K/V).
7879
// For the B configured as of this writing (B = 6), binary search was *significantly*
7980
// worse for uints.
8081
self.search_linear(key)
8182
}
8283

83-
fn search_linear(&self, key: &K) -> SearchResult {
84+
fn search_linear<Sized? Q>(&self, key: &Q) -> SearchResult where Q: BorrowFrom<K> + Ord {
8485
for (i, k) in self.keys.iter().enumerate() {
85-
match k.cmp(key) {
86-
Less => {},
86+
match key.cmp(BorrowFrom::borrow_from(k)) {
87+
Greater => {},
8788
Equal => return Found(i),
88-
Greater => return GoDown(i),
89+
Less => return GoDown(i),
8990
}
9091
}
9192
GoDown(self.len())

0 commit comments

Comments
 (0)