Skip to content

syntax: Rename P::unwrap into something less alarming #46778

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 1 commit into from
Dec 17, 2017
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
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,9 +2063,9 @@ impl Clean<Type> for hir::Ty {
for (i, ty_param) in generics.ty_params.iter().enumerate() {
let ty_param_def = Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id));
if let Some(ty) = provided_params.types.get(i).cloned() {
ty_substs.insert(ty_param_def, ty.unwrap().clean(cx));
ty_substs.insert(ty_param_def, ty.into_inner().clean(cx));
} else if let Some(default) = ty_param.default.clone() {
ty_substs.insert(ty_param_def, default.unwrap().clean(cx));
ty_substs.insert(ty_param_def, default.into_inner().clean(cx));
}
}
for (i, lt_param) in generics.lifetimes.iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
}

fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
let mut expr = self.configure_expr(expr).unwrap();
let mut expr = self.configure_expr(expr).into_inner();
expr.node = self.configure_expr_kind(expr.node);
P(fold::noop_fold_expr(expr, self))
}

fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
let mut expr = configure!(self, expr).unwrap();
let mut expr = configure!(self, expr).into_inner();
expr.node = self.configure_expr_kind(expr.node);
Some(P(fold::noop_fold_expr(expr, self)))
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ impl Annotatable {

pub fn expect_trait_item(self) -> ast::TraitItem {
match self {
Annotatable::TraitItem(i) => i.unwrap(),
Annotatable::TraitItem(i) => i.into_inner(),
_ => panic!("expected Item")
}
}

pub fn expect_impl_item(self) -> ast::ImplItem {
match self {
Annotatable::ImplItem(i) => i.unwrap(),
Annotatable::ImplItem(i) => i.into_inner(),
_ => panic!("expected Item")
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
tokens: None,
})));

match self.expand(krate_item).make_items().pop().map(P::unwrap) {
match self.expand(krate_item).make_items().pop().map(P::into_inner) {
Some(ast::Item { attrs, node: ast::ItemKind::Mod(module), .. }) => {
krate.attrs = attrs;
krate.module = module;
Expand Down Expand Up @@ -504,8 +504,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
AttrProcMacro(ref mac) => {
let item_tok = TokenTree::Token(DUMMY_SP, Token::interpolated(match item {
Annotatable::Item(item) => token::NtItem(item),
Annotatable::TraitItem(item) => token::NtTraitItem(item.unwrap()),
Annotatable::ImplItem(item) => token::NtImplItem(item.unwrap()),
Annotatable::TraitItem(item) => token::NtTraitItem(item.into_inner()),
Annotatable::ImplItem(item) => token::NtImplItem(item.into_inner()),
})).into();
let tok_result = mac.expand(self.cx, attr.span, attr.tokens, item_tok);
self.parse_expansion(tok_result, kind, &attr.path, attr.span)
Expand Down Expand Up @@ -863,7 +863,7 @@ pub fn find_attr_invoc(attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute

impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
let mut expr = self.cfg.configure_expr(expr).unwrap();
let mut expr = self.cfg.configure_expr(expr).into_inner();
expr.node = self.cfg.configure_expr_kind(expr.node);

if let ast::ExprKind::Mac(mac) = expr.node {
Expand All @@ -875,7 +875,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}

fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
let mut expr = configure!(self, expr).unwrap();
let mut expr = configure!(self, expr).into_inner();
expr.node = self.cfg.configure_expr_kind(expr.node);

if let ast::ExprKind::Mac(mac) = expr.node {
Expand Down Expand Up @@ -906,7 +906,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
};

let (mac, style, attrs) = if let StmtKind::Mac(mac) = stmt.node {
mac.unwrap()
mac.into_inner()
} else {
// The placeholder expander gives ids to statements, so we avoid folding the id here.
let ast::Stmt { id, node, span } = stmt;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {

fn fold_ty(&mut self, ty: P<ast::Ty>) -> P<ast::Ty> {
let ty = match ty.node {
ast::TyKind::Mac(_) => ty.unwrap(),
ast::TyKind::Mac(_) => ty.into_inner(),
_ => return fold::noop_fold_ty(ty, self),
};

Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ impl<'a> Parser<'a> {
self.expect(&token::CloseDelim(token::Paren))?;

if ts.len() == 1 && !last_comma {
let ty = ts.into_iter().nth(0).unwrap().unwrap();
let ty = ts.into_iter().nth(0).unwrap().into_inner();
let maybe_bounds = allow_plus && self.token == token::BinOp(token::Plus);
match ty.node {
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
Expand Down Expand Up @@ -6077,7 +6077,7 @@ impl<'a> Parser<'a> {
fn parse_item_(&mut self, attrs: Vec<Attribute>,
macros_allowed: bool, attributes_allowed: bool) -> PResult<'a, Option<P<Item>>> {
maybe_whole!(self, NtItem, |item| {
let mut item = item.unwrap();
let mut item = item.into_inner();
let mut attrs = attrs;
mem::swap(&mut item.attrs, &mut attrs);
item.attrs.extend(attrs);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<T: 'static> P<T> {
f(*self.ptr)
}
/// Equivalent to and_then(|x| x)
pub fn unwrap(self) -> T {
pub fn into_inner(self) -> T {
*self.ptr
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
}
}

let mut item = i.unwrap();
let mut item = i.into_inner();
// We don't want to recurse into anything other than mods, since
// mods or tests inside of functions will break things
if let ast::ItemKind::Mod(module) = item.node {
Expand Down