about summary refs log tree commit diff
path: root/src/libsyntax/ast_map
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2014-10-09 15:17:22 -0400
committerSteve Klabnik <steve@steveklabnik.com>2014-10-29 11:43:07 -0400
commit7828c3dd2858d8f3a0448484d8093e22719dbda0 (patch)
tree2d2b106b02526219463d877d480782027ffe1f3f /src/libsyntax/ast_map
parent3bc545373df4c81ba223a8bece14cbc27eb85a4d (diff)
downloadrust-7828c3dd2858d8f3a0448484d8093e22719dbda0.tar.gz
rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.zip
Rename fail! to panic!
https://github.com/rust-lang/rfcs/pull/221

The current terminology of "task failure" often causes problems when
writing or speaking about code. You often want to talk about the
possibility of an operation that returns a Result "failing", but cannot
because of the ambiguity with task failure. Instead, you have to speak
of "the failing case" or "when the operation does not succeed" or other
circumlocutions.

Likewise, we use a "Failure" header in rustdoc to describe when
operations may fail the task, but it would often be helpful to separate
out a section describing the "Err-producing" case.

We have been steadily moving away from task failure and toward Result as
an error-handling mechanism, so we should optimize our terminology
accordingly: Result-producing functions should be easy to describe.

To update your code, rename any call to `fail!` to `panic!` instead.
Assuming you have not created your own macro named `panic!`, this
will work on UNIX based systems:

    grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g'

You can of course also do this by hand.

[breaking-change]
Diffstat (limited to 'src/libsyntax/ast_map')
-rw-r--r--src/libsyntax/ast_map/blocks.rs10
-rw-r--r--src/libsyntax/ast_map/mod.rs36
2 files changed, 23 insertions, 23 deletions
diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs
index 8280f34615f..187d94d1fa7 100644
--- a/src/libsyntax/ast_map/blocks.rs
+++ b/src/libsyntax/ast_map/blocks.rs
@@ -198,17 +198,17 @@ impl<'a> FnLikeNode<'a> {
                         ident: i.ident, decl: &**decl, style: style, body: &**block,
                         generics: generics, abi: abi, id: i.id, span: i.span
                     }),
-                _ => fail!("item FnLikeNode that is not fn-like"),
+                _ => panic!("item FnLikeNode that is not fn-like"),
             },
             ast_map::NodeTraitItem(t) => match *t {
                 ast::ProvidedMethod(ref m) => method(&**m),
-                _ => fail!("trait method FnLikeNode that is not fn-like"),
+                _ => panic!("trait method FnLikeNode that is not fn-like"),
             },
             ast_map::NodeImplItem(ii) => {
                 match *ii {
                     ast::MethodImplItem(ref m) => method(&**m),
                     ast::TypeImplItem(_) => {
-                        fail!("impl method FnLikeNode that is not fn-like")
+                        panic!("impl method FnLikeNode that is not fn-like")
                     }
                 }
             }
@@ -217,9 +217,9 @@ impl<'a> FnLikeNode<'a> {
                     closure(ClosureParts::new(&**decl, &**block, e.id, e.span)),
                 ast::ExprProc(ref decl, ref block) =>
                     closure(ClosureParts::new(&**decl, &**block, e.id, e.span)),
-                _ => fail!("expr FnLikeNode that is not fn-like"),
+                _ => panic!("expr FnLikeNode that is not fn-like"),
             },
-            _ => fail!("other FnLikeNode that is not fn-like"),
+            _ => panic!("other FnLikeNode that is not fn-like"),
         }
     }
 }
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index b82a4a0b997..915c2d1b318 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -263,12 +263,12 @@ impl<'ast> Map<'ast> {
         &self.forest.krate
     }
 
-    /// Retrieve the Node corresponding to `id`, failing if it cannot
+    /// Retrieve the Node corresponding to `id`, panicking if it cannot
     /// be found.
     pub fn get(&self, id: NodeId) -> Node<'ast> {
         match self.find(id) {
             Some(node) => node,
-            None => fail!("couldn't find node id {} in the AST map", id)
+            None => panic!("couldn't find node id {} in the AST map", id)
         }
     }
 
@@ -308,7 +308,7 @@ impl<'ast> Map<'ast> {
         };
         match abi {
             Some(abi) => abi,
-            None => fail!("expected foreign mod or inlined parent, found {}",
+            None => panic!("expected foreign mod or inlined parent, found {}",
                           self.node_to_string(parent))
         }
     }
@@ -324,7 +324,7 @@ impl<'ast> Map<'ast> {
     pub fn expect_item(&self, id: NodeId) -> &'ast Item {
         match self.find(id) {
             Some(NodeItem(item)) => item,
-            _ => fail!("expected item, found {}", self.node_to_string(id))
+            _ => panic!("expected item, found {}", self.node_to_string(id))
         }
     }
 
@@ -333,37 +333,37 @@ impl<'ast> Map<'ast> {
             Some(NodeItem(i)) => {
                 match i.node {
                     ItemStruct(ref struct_def, _) => &**struct_def,
-                    _ => fail!("struct ID bound to non-struct")
+                    _ => panic!("struct ID bound to non-struct")
                 }
             }
             Some(NodeVariant(variant)) => {
                 match variant.node.kind {
                     StructVariantKind(ref struct_def) => &**struct_def,
-                    _ => fail!("struct ID bound to enum variant that isn't struct-like"),
+                    _ => panic!("struct ID bound to enum variant that isn't struct-like"),
                 }
             }
-            _ => fail!(format!("expected struct, found {}", self.node_to_string(id))),
+            _ => panic!(format!("expected struct, found {}", self.node_to_string(id))),
         }
     }
 
     pub fn expect_variant(&self, id: NodeId) -> &'ast Variant {
         match self.find(id) {
             Some(NodeVariant(variant)) => variant,
-            _ => fail!(format!("expected variant, found {}", self.node_to_string(id))),
+            _ => panic!(format!("expected variant, found {}", self.node_to_string(id))),
         }
     }
 
     pub fn expect_foreign_item(&self, id: NodeId) -> &'ast ForeignItem {
         match self.find(id) {
             Some(NodeForeignItem(item)) => item,
-            _ => fail!("expected foreign item, found {}", self.node_to_string(id))
+            _ => panic!("expected foreign item, found {}", self.node_to_string(id))
         }
     }
 
     pub fn expect_expr(&self, id: NodeId) -> &'ast Expr {
         match self.find(id) {
             Some(NodeExpr(expr)) => expr,
-            _ => fail!("expected expr, found {}", self.node_to_string(id))
+            _ => panic!("expected expr, found {}", self.node_to_string(id))
         }
     }
 
@@ -388,7 +388,7 @@ impl<'ast> Map<'ast> {
                                 PathName(ident.name)
                             }
                             MethMac(_) => {
-                                fail!("no path elem for {}", node)
+                                panic!("no path elem for {}", node)
                             }
                         }
                     }
@@ -402,13 +402,13 @@ impl<'ast> Map<'ast> {
                         MethDecl(ident, _, _, _, _, _, _, _) => {
                             PathName(ident.name)
                         }
-                        MethMac(_) => fail!("no path elem for {}", node),
+                        MethMac(_) => panic!("no path elem for {}", node),
                     }
                 }
                 TypeTraitItem(ref m) => PathName(m.ident.name),
             },
             NodeVariant(v) => PathName(v.node.name.name),
-            _ => fail!("no path elem for {}", node)
+            _ => panic!("no path elem for {}", node)
         }
     }
 
@@ -533,7 +533,7 @@ impl<'ast> Map<'ast> {
 
     pub fn span(&self, id: NodeId) -> Span {
         self.opt_span(id)
-            .unwrap_or_else(|| fail!("AstMap.span: could not find span for id {}", id))
+            .unwrap_or_else(|| panic!("AstMap.span: could not find span for id {}", id))
     }
 
     pub fn def_id_span(&self, def_id: DefId, fallback: Span) -> Span {
@@ -666,7 +666,7 @@ impl Named for Method {
     fn name(&self) -> Name {
         match self.node {
             MethDecl(i, _, _, _, _, _, _, _) => i.name,
-            MethMac(_) => fail!("encountered unexpanded method macro."),
+            MethMac(_) => panic!("encountered unexpanded method macro."),
         }
     }
 }
@@ -1018,9 +1018,9 @@ impl<'a> NodePrinter for pprust::State<'a> {
             // these cases do not carry enough information in the
             // ast_map to reconstruct their full structure for pretty
             // printing.
-            NodeLocal(_)       => fail!("cannot print isolated Local"),
-            NodeArg(_)         => fail!("cannot print isolated Arg"),
-            NodeStructCtor(_)  => fail!("cannot print isolated StructCtor"),
+            NodeLocal(_)       => panic!("cannot print isolated Local"),
+            NodeArg(_)         => panic!("cannot print isolated Arg"),
+            NodeStructCtor(_)  => panic!("cannot print isolated StructCtor"),
         }
     }
 }