about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-05 16:47:01 -0700
committerbors <bors@rust-lang.org>2013-08-05 16:47:01 -0700
commitbbda3fa9383dba653b20bd064102caceef91897a (patch)
tree8fa4abc474568ca3a63992b5eea6cf62b7e04259 /src/libsyntax/ext
parent29099e450a912cfcd0a0ccc72f55751bc2e209f2 (diff)
parent0ac7a219f043d3b1c8c239089d9dd6e6c9fa830b (diff)
downloadrust-bbda3fa9383dba653b20bd064102caceef91897a.tar.gz
rust-bbda3fa9383dba653b20bd064102caceef91897a.zip
auto merge of #8288 : Kimundi/rust/opteitres4, r=brson
This is an alternative version to https://github.com/mozilla/rust/pull/8268, where instead of transitioning to `get()` completely, I transitioned to `unwrap()` completely.

My reasoning for also opening this PR is that having two different functions with identical behavior on a common datatype is bad for consistency and confusing for users, and should be solved as soon as possible. The fact that apparently half the code uses `get()`, and the other half `unwrap()` only makes it worse.

If the final naming decision ends up different, there needs to be a big renaming anyway, but until then it should at least be consistent.

---

- Made naming schemes consistent between Option, Result and Either
- Lifted the quality of the either and result module to that of option
- Changed Options Add implementation to work like the maybe Monad (return None if any of the inputs is None)  
  See https://github.com/mozilla/rust/issues/6002, especially my last comment.
- Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead  
  See also https://github.com/mozilla/rust/issues/7887.

Todo: 

Adding testcases for all function in the three modules. Even without the few functions I added, the coverage wasn't complete to begin with. But I'd rather do that as a follow up PR, I've touched to much code here already, need to go through them again later.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/base.rs16
-rw-r--r--src/libsyntax/ext/deriving/generic.rs2
-rw-r--r--src/libsyntax/ext/expand.rs4
-rw-r--r--src/libsyntax/ext/source_util.rs6
4 files changed, 14 insertions, 14 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 1dda2493da2..6ed5ca3e402 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -538,20 +538,20 @@ mod test {
         m.insert (@"def",@16);
         // FIXME: #4492 (ICE)  assert_eq!(m.find(&@"abc"),Some(@15));
         //  ....               assert_eq!(m.find(&@"def"),Some(@16));
-        assert_eq!(*(m.find(&@"abc").get()),15);
-        assert_eq!(*(m.find(&@"def").get()),16);
+        assert_eq!(*(m.find(&@"abc").unwrap()),15);
+        assert_eq!(*(m.find(&@"def").unwrap()),16);
         let n = m.push_frame();
         // old bindings are still present:
-        assert_eq!(*(n.find(&@"abc").get()),15);
-        assert_eq!(*(n.find(&@"def").get()),16);
+        assert_eq!(*(n.find(&@"abc").unwrap()),15);
+        assert_eq!(*(n.find(&@"def").unwrap()),16);
         n.insert (@"def",@17);
         // n shows the new binding
-        assert_eq!(*(n.find(&@"abc").get()),15);
-        assert_eq!(*(n.find(&@"def").get()),17);
+        assert_eq!(*(n.find(&@"abc").unwrap()),15);
+        assert_eq!(*(n.find(&@"def").unwrap()),17);
         // ... but m still has the old ones
         // FIXME: #4492: assert_eq!(m.find(&@"abc"),Some(@15));
         // FIXME: #4492: assert_eq!(m.find(&@"def"),Some(@16));
-        assert_eq!(*(m.find(&@"abc").get()),15);
-        assert_eq!(*(m.find(&@"def").get()),16);
+        assert_eq!(*(m.find(&@"abc").unwrap()),15);
+        assert_eq!(*(m.find(&@"def").unwrap()),16);
     }
 }
diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs
index f5eb57c94b7..fb1e6bf1913 100644
--- a/src/libsyntax/ext/deriving/generic.rs
+++ b/src/libsyntax/ext/deriving/generic.rs
@@ -961,7 +961,7 @@ fn create_struct_pattern(cx: @ExtCtxt,
         let field_pats = do vec::build |push| {
             for (&pat, &(id, _)) in subpats.iter().zip(ident_expr.iter()) {
                 // id is guaranteed to be Some
-                push(ast::field_pat { ident: id.get(), pat: pat })
+                push(ast::field_pat { ident: id.unwrap(), pat: pat })
             }
         };
         cx.pat_struct(span, matching_path, field_pats)
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index a6c5526b5a9..c7020b990bf 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1182,9 +1182,9 @@ mod test {
         let a2_name = intern("a2");
         let renamer = new_ident_renamer(ast::ident{name:a_name,ctxt:empty_ctxt},
                                         a2_name);
-        let renamed_ast = fun_to_ident_folder(renamer).fold_item(item_ast).get();
+        let renamed_ast = fun_to_ident_folder(renamer).fold_item(item_ast).unwrap();
         let resolver = new_ident_resolver();
-        let resolved_ast = fun_to_ident_folder(resolver).fold_item(renamed_ast).get();
+        let resolved_ast = fun_to_ident_folder(resolver).fold_item(renamed_ast).unwrap();
         let resolved_as_str = pprust::item_to_str(resolved_ast,
                                                   get_ident_interner());
         assert_eq!(resolved_as_str,~"fn a2() -> int { let b = 13; b }");
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index 626a562b92c..71903b9aa02 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -31,7 +31,7 @@ pub fn expand_line(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
     -> base::MacResult {
     base::check_zero_tts(cx, sp, tts, "line!");
 
-    let topmost = topmost_expn_info(cx.backtrace().get());
+    let topmost = topmost_expn_info(cx.backtrace().unwrap());
     let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
 
     base::MRExpr(cx.expr_uint(topmost.call_site, loc.line))
@@ -42,7 +42,7 @@ pub fn expand_col(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
     -> base::MacResult {
     base::check_zero_tts(cx, sp, tts, "col!");
 
-    let topmost = topmost_expn_info(cx.backtrace().get());
+    let topmost = topmost_expn_info(cx.backtrace().unwrap());
     let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
     base::MRExpr(cx.expr_uint(topmost.call_site, loc.col.to_uint()))
 }
@@ -54,7 +54,7 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
     -> base::MacResult {
     base::check_zero_tts(cx, sp, tts, "file!");
 
-    let topmost = topmost_expn_info(cx.backtrace().get());
+    let topmost = topmost_expn_info(cx.backtrace().unwrap());
     let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
     let filename = loc.file.name;
     base::MRExpr(cx.expr_str(topmost.call_site, filename))