Skip to content

Commit 336f5d2

Browse files
committed
---
yaml --- r: 194538 b: refs/heads/snap-stage3 c: 1c35953 h: refs/heads/master v: v3
1 parent 7735d39 commit 336f5d2

File tree

7 files changed

+104
-44
lines changed

7 files changed

+104
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 242ed0b7c0f6a21096f2cc3e1ad1bdb176d02545
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 53a183f0274316596bf9405944d4f0468d8c93e4
4+
refs/heads/snap-stage3: 1c35953cf8baa2e721401ba6354f0bd9a9f2abaf
55
refs/heads/try: 961e0358e1a5c0faaef606e31e9965742c1643bf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcollections/btree/map.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,15 +1143,39 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
11431143
}
11441144

11451145
impl<'a, K: Ord, V> Entry<'a, K, V> {
1146-
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11471146
#[unstable(feature = "std_misc",
11481147
reason = "will soon be replaced by or_insert")]
1148+
#[deprecated(since = "1.0",
1149+
reason = "replaced with more ergonomic `default` and `default_with`")]
1150+
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11491151
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
11501152
match self {
11511153
Occupied(entry) => Ok(entry.into_mut()),
11521154
Vacant(entry) => Err(entry),
11531155
}
11541156
}
1157+
1158+
#[unstable(feature = "collections",
1159+
reason = "matches entry v3 specification, waiting for dust to settle")]
1160+
/// Ensures a value is in the entry by inserting the default if empty, and returns
1161+
/// a mutable reference to the value in the entry.
1162+
pub fn default(self, default: V) -> &'a mut V {
1163+
match self {
1164+
Occupied(entry) => entry.into_mut(),
1165+
Vacant(entry) => entry.insert(default),
1166+
}
1167+
}
1168+
1169+
#[unstable(feature = "collections",
1170+
reason = "matches entry v3 specification, waiting for dust to settle")]
1171+
/// Ensures a value is in the entry by inserting the result of the default function if empty,
1172+
/// and returns a mutable reference to the value in the entry.
1173+
pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
1174+
match self {
1175+
Occupied(entry) => entry.into_mut(),
1176+
Vacant(entry) => entry.insert(default()),
1177+
}
1178+
}
11551179
}
11561180

11571181
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {

branches/snap-stage3/src/libcollections/vec_map.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,37 @@ impl<V> VecMap<V> {
675675
impl<'a, V> Entry<'a, V> {
676676
#[unstable(feature = "collections",
677677
reason = "will soon be replaced by or_insert")]
678+
#[deprecated(since = "1.0",
679+
reason = "replaced with more ergonomic `default` and `default_with`")]
678680
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
679681
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
680682
match self {
681683
Occupied(entry) => Ok(entry.into_mut()),
682684
Vacant(entry) => Err(entry),
683685
}
684686
}
687+
688+
#[unstable(feature = "collections",
689+
reason = "matches entry v3 specification, waiting for dust to settle")]
690+
/// Ensures a value is in the entry by inserting the default if empty, and returns
691+
/// a mutable reference to the value in the entry.
692+
pub fn default(self, default: V) -> &'a mut V {
693+
match self {
694+
Occupied(entry) => entry.into_mut(),
695+
Vacant(entry) => entry.insert(default),
696+
}
697+
}
698+
699+
#[unstable(feature = "collections",
700+
reason = "matches entry v3 specification, waiting for dust to settle")]
701+
/// Ensures a value is in the entry by inserting the result of the default function if empty,
702+
/// and returns a mutable reference to the value in the entry.
703+
pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
704+
match self {
705+
Occupied(entry) => entry.into_mut(),
706+
Vacant(entry) => entry.insert(default()),
707+
}
708+
}
685709
}
686710

687711
impl<'a, V> VacantEntry<'a, V> {

branches/snap-stage3/src/libstd/collections/hash/map.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hash::{Hash, SipHasher};
2323
use iter::{self, Iterator, ExactSizeIterator, IntoIterator, IteratorExt, FromIterator, Extend, Map};
2424
use marker::Sized;
2525
use mem::{self, replace};
26-
use ops::{Deref, FnMut, Index};
26+
use ops::{Deref, FnMut, FnOnce, Index};
2727
use option::Option::{self, Some, None};
2828
use rand::{self, Rng};
2929
use result::Result::{self, Ok, Err};
@@ -1488,12 +1488,36 @@ impl<'a, K, V> Entry<'a, K, V> {
14881488
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant.
14891489
#[unstable(feature = "std_misc",
14901490
reason = "will soon be replaced by or_insert")]
1491+
#[deprecated(since = "1.0",
1492+
reason = "replaced with more ergonomic `default` and `default_with`")]
14911493
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
14921494
match self {
14931495
Occupied(entry) => Ok(entry.into_mut()),
14941496
Vacant(entry) => Err(entry),
14951497
}
14961498
}
1499+
1500+
#[unstable(feature = "collections",
1501+
reason = "matches entry v3 specification, waiting for dust to settle")]
1502+
/// Ensures a value is in the entry by inserting the default if empty, and returns
1503+
/// a mutable reference to the value in the entry.
1504+
pub fn default(self, default: V) -> &'a mut V {
1505+
match self {
1506+
Occupied(entry) => entry.into_mut(),
1507+
Vacant(entry) => entry.insert(default),
1508+
}
1509+
}
1510+
1511+
#[unstable(feature = "collections",
1512+
reason = "matches entry v3 specification, waiting for dust to settle")]
1513+
/// Ensures a value is in the entry by inserting the result of the default function if empty,
1514+
/// and returns a mutable reference to the value in the entry.
1515+
pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
1516+
match self {
1517+
Occupied(entry) => entry.into_mut(),
1518+
Vacant(entry) => entry.insert(default()),
1519+
}
1520+
}
14971521
}
14981522

14991523
impl<'a, K, V> OccupiedEntry<'a, K, V> {

branches/snap-stage3/src/libsyntax/ext/quote.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,10 @@ pub mod rt {
171171
}
172172
}
173173

174-
impl_to_source! { ast::Path, path_to_string }
175174
impl_to_source! { ast::Ty, ty_to_string }
176175
impl_to_source! { ast::Block, block_to_string }
177176
impl_to_source! { ast::Arg, arg_to_string }
178177
impl_to_source! { Generics, generics_to_string }
179-
impl_to_source! { ast::WhereClause, where_clause_to_string }
180178
impl_to_source! { P<ast::Item>, item_to_string }
181179
impl_to_source! { P<ast::ImplItem>, impl_item_to_string }
182180
impl_to_source! { P<ast::TraitItem>, trait_item_to_string }
@@ -312,7 +310,6 @@ pub mod rt {
312310
}
313311

314312
impl_to_tokens! { ast::Ident }
315-
impl_to_tokens! { ast::Path }
316313
impl_to_tokens! { P<ast::Item> }
317314
impl_to_tokens! { P<ast::ImplItem> }
318315
impl_to_tokens! { P<ast::TraitItem> }
@@ -322,7 +319,6 @@ pub mod rt {
322319
impl_to_tokens! { ast::Ty }
323320
impl_to_tokens_lifetime! { &'a [ast::Ty] }
324321
impl_to_tokens! { Generics }
325-
impl_to_tokens! { ast::WhereClause }
326322
impl_to_tokens! { P<ast::Stmt> }
327323
impl_to_tokens! { P<ast::Expr> }
328324
impl_to_tokens! { ast::Block }

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ impl<'a> Parser<'a> {
11261126
p.parse_arg_general(false)
11271127
});
11281128

1129-
generics.where_clause = p.parse_where_clause();
1129+
p.parse_where_clause(&mut generics);
11301130
let sig = ast::MethodSig {
11311131
unsafety: style,
11321132
decl: d,
@@ -3932,14 +3932,9 @@ impl<'a> Parser<'a> {
39323932
/// ```
39333933
/// where T : Trait<U, V> + 'b, 'a : 'b
39343934
/// ```
3935-
fn parse_where_clause(&mut self) -> ast::WhereClause {
3936-
let mut where_clause = WhereClause {
3937-
id: ast::DUMMY_NODE_ID,
3938-
predicates: Vec::new(),
3939-
};
3940-
3935+
fn parse_where_clause(&mut self, generics: &mut ast::Generics) {
39413936
if !self.eat_keyword(keywords::Where) {
3942-
return where_clause;
3937+
return
39433938
}
39443939

39453940
let mut parsed_something = false;
@@ -3962,7 +3957,7 @@ impl<'a> Parser<'a> {
39623957
let hi = self.span.hi;
39633958
let span = mk_sp(lo, hi);
39643959

3965-
where_clause.predicates.push(ast::WherePredicate::RegionPredicate(
3960+
generics.where_clause.predicates.push(ast::WherePredicate::RegionPredicate(
39663961
ast::WhereRegionPredicate {
39673962
span: span,
39683963
lifetime: bounded_lifetime,
@@ -3997,7 +3992,7 @@ impl<'a> Parser<'a> {
39973992
at least one bound in it");
39983993
}
39993994

4000-
where_clause.predicates.push(ast::WherePredicate::BoundPredicate(
3995+
generics.where_clause.predicates.push(ast::WherePredicate::BoundPredicate(
40013996
ast::WhereBoundPredicate {
40023997
span: span,
40033998
bound_lifetimes: bound_lifetimes,
@@ -4010,7 +4005,7 @@ impl<'a> Parser<'a> {
40104005
// let ty = self.parse_ty();
40114006
let hi = self.span.hi;
40124007
let span = mk_sp(lo, hi);
4013-
// where_clause.predicates.push(
4008+
// generics.where_clause.predicates.push(
40144009
// ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
40154010
// id: ast::DUMMY_NODE_ID,
40164011
// span: span,
@@ -4041,8 +4036,6 @@ impl<'a> Parser<'a> {
40414036
"a `where` clause must have at least one predicate \
40424037
in it");
40434038
}
4044-
4045-
where_clause
40464039
}
40474040

40484041
fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
@@ -4361,7 +4354,7 @@ impl<'a> Parser<'a> {
43614354
fn parse_item_fn(&mut self, unsafety: Unsafety, abi: abi::Abi) -> ItemInfo {
43624355
let (ident, mut generics) = self.parse_fn_header();
43634356
let decl = self.parse_fn_decl(false);
4364-
generics.where_clause = self.parse_where_clause();
4357+
self.parse_where_clause(&mut generics);
43654358
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
43664359
(ident, ItemFn(decl, unsafety, abi, generics, body), Some(inner_attrs))
43674360
}
@@ -4446,7 +4439,7 @@ impl<'a> Parser<'a> {
44464439
let (explicit_self, decl) = self.parse_fn_decl_with_self(|p| {
44474440
p.parse_arg()
44484441
});
4449-
generics.where_clause = self.parse_where_clause();
4442+
self.parse_where_clause(&mut generics);
44504443
let (inner_attrs, body) = self.parse_inner_attrs_and_block();
44514444
(ident, inner_attrs, MethodImplItem(ast::MethodSig {
44524445
generics: generics,
@@ -4467,7 +4460,7 @@ impl<'a> Parser<'a> {
44674460
// Parse supertrait bounds.
44684461
let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare);
44694462

4470-
tps.where_clause = self.parse_where_clause();
4463+
self.parse_where_clause(&mut tps);
44714464

44724465
let meths = self.parse_trait_items();
44734466
(ident, ItemTrait(unsafety, tps, bounds, meths), None)
@@ -4538,7 +4531,7 @@ impl<'a> Parser<'a> {
45384531
if opt_trait.is_some() {
45394532
ty = self.parse_ty_sum();
45404533
}
4541-
generics.where_clause = self.parse_where_clause();
4534+
self.parse_where_clause(&mut generics);
45424535

45434536
self.expect(&token::OpenDelim(token::Brace));
45444537
let attrs = self.parse_inner_attributes();
@@ -4610,7 +4603,7 @@ impl<'a> Parser<'a> {
46104603
// struct.
46114604

46124605
let (fields, ctor_id) = if self.token.is_keyword(keywords::Where) {
4613-
generics.where_clause = self.parse_where_clause();
4606+
self.parse_where_clause(&mut generics);
46144607
if self.eat(&token::Semi) {
46154608
// If we see a: `struct Foo<T> where T: Copy;` style decl.
46164609
(Vec::new(), Some(ast::DUMMY_NODE_ID))
@@ -4691,12 +4684,12 @@ impl<'a> Parser<'a> {
46914684
token::get_ident(class_name.clone())));
46924685
}
46934686

4694-
generics.where_clause = self.parse_where_clause();
4687+
self.parse_where_clause(generics);
46954688
self.expect(&token::Semi);
46964689
fields
46974690
// This is the case where we just see struct Foo<T> where T: Copy;
46984691
} else if self.token.is_keyword(keywords::Where) {
4699-
generics.where_clause = self.parse_where_clause();
4692+
self.parse_where_clause(generics);
47004693
self.expect(&token::Semi);
47014694
Vec::new()
47024695
// This case is where we see: `struct Foo<T>;`
@@ -4944,7 +4937,7 @@ impl<'a> Parser<'a> {
49444937

49454938
let (ident, mut generics) = self.parse_fn_header();
49464939
let decl = self.parse_fn_decl(true);
4947-
generics.where_clause = self.parse_where_clause();
4940+
self.parse_where_clause(&mut generics);
49484941
let hi = self.span.hi;
49494942
self.expect(&token::Semi);
49504943
P(ast::ForeignItem {
@@ -5081,7 +5074,7 @@ impl<'a> Parser<'a> {
50815074
fn parse_item_type(&mut self) -> ItemInfo {
50825075
let ident = self.parse_ident();
50835076
let mut tps = self.parse_generics();
5084-
tps.where_clause = self.parse_where_clause();
5077+
self.parse_where_clause(&mut tps);
50855078
self.expect(&token::Eq);
50865079
let ty = self.parse_ty_sum();
50875080
self.expect(&token::Semi);
@@ -5181,7 +5174,7 @@ impl<'a> Parser<'a> {
51815174
fn parse_item_enum(&mut self) -> ItemInfo {
51825175
let id = self.parse_ident();
51835176
let mut generics = self.parse_generics();
5184-
generics.where_clause = self.parse_where_clause();
5177+
self.parse_where_clause(&mut generics);
51855178
self.expect(&token::OpenDelim(token::Brace));
51865179

51875180
let enum_definition = self.parse_enum_def(&generics);

0 commit comments

Comments
 (0)