Skip to content

Commit

Permalink
Rename FunctionRetTy to FnRetTy
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Feb 15, 2020
1 parent 19288dd commit 5c962c7
Show file tree
Hide file tree
Showing 42 changed files with 111 additions and 118 deletions.
6 changes: 3 additions & 3 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Body, Expr, ExprKind, FunctionRetTy, HirId, Local, Pat};
use rustc_hir::{Body, Expr, ExprKind, FnRetTy, HirId, Local, Pat};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::kw;
use rustc_span::Span;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
fn closure_return_type_suggestion(
span: Span,
err: &mut DiagnosticBuilder<'_>,
output: &FunctionRetTy<'_>,
output: &FnRetTy<'_>,
body: &Body<'_>,
descr: &str,
name: &str,
Expand All @@ -117,7 +117,7 @@ fn closure_return_type_suggestion(
parent_descr: Option<&str>,
) {
let (arrow, post) = match output {
FunctionRetTy::DefaultReturn(_) => ("-> ", " "),
FnRetTy::DefaultReturn(_) => ("-> ", " "),
_ => ("", ""),
};
let suggestion = match body.value.kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::ty;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir::{FunctionRetTy, TyKind};
use rustc_hir::{FnRetTy, TyKind};

impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
return None;
}
if let FunctionRetTy::Return(ty) = &fndecl.output {
if let FnRetTy::Return(ty) = &fndecl.output {
if let (TyKind::Def(_, _), ty::ReStatic) = (&ty.kind, sub) {
// This is an impl Trait return that evaluates de need of 'static.
// We handle this case better in `static_impl_trait`.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
_ => return false,
};

let ret_ty = if let hir::FunctionRetTy::Return(ret_ty) = sig.decl.output {
let ret_ty = if let hir::FnRetTy::Return(ret_ty) = sig.decl.output {
ret_ty
} else {
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::ExprKind<'hir> {
let output = match ret_ty {
Some(ty) => FunctionRetTy::Ty(ty),
None => FunctionRetTy::Default(span),
Some(ty) => FnRetTy::Ty(ty),
None => FnRetTy::Default(span),
};
let ast_decl = FnDecl { inputs: vec![], output };
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
Expand Down Expand Up @@ -721,7 +721,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: Span,
) -> hir::ExprKind<'hir> {
let outer_decl =
FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span) };
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the
// closure argument types.
Expand All @@ -747,7 +747,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `|x: u8| future_from_generator(|| -> X { ... })`.
let body_id = this.lower_fn_body(&outer_decl, |this| {
let async_ret_ty =
if let FunctionRetTy::Ty(ty) = &decl.output { Some(ty.clone()) } else { None };
if let FnRetTy::Ty(ty) = &decl.output { Some(ty.clone()) } else { None };
let async_body = this.make_async_expr(
capture_clause,
closure_id,
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,16 +1723,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
} else {
match decl.output {
FunctionRetTy::Ty(ref ty) => {
FnRetTy::Ty(ref ty) => {
let context = match in_band_ty_params {
Some((def_id, _)) if impl_trait_return_allow => {
ImplTraitContext::OpaqueTy(Some(def_id), hir::OpaqueTyOrigin::FnReturn)
}
_ => ImplTraitContext::disallowed(),
};
hir::FunctionRetTy::Return(self.lower_ty(ty, context))
hir::FnRetTy::Return(self.lower_ty(ty, context))
}
FunctionRetTy::Default(span) => hir::FunctionRetTy::DefaultReturn(span),
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(span),
}
};

Expand Down Expand Up @@ -1779,10 +1779,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// `elided_lt_replacement`: replacement for elided lifetimes in the return type
fn lower_async_fn_ret_ty(
&mut self,
output: &FunctionRetTy,
output: &FnRetTy,
fn_def_id: DefId,
opaque_ty_node_id: NodeId,
) -> hir::FunctionRetTy<'hir> {
) -> hir::FnRetTy<'hir> {
debug!(
"lower_async_fn_ret_ty(\
output={:?}, \
Expand Down Expand Up @@ -1947,27 +1947,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// only the lifetime parameters that we must supply.
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args);
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FunctionRetTy::Return(self.arena.alloc(opaque_ty))
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}

/// Transforms `-> T` into `Future<Output = T>`
fn lower_async_fn_output_type_to_future_bound(
&mut self,
output: &FunctionRetTy,
output: &FnRetTy,
fn_def_id: DefId,
span: Span,
) -> hir::GenericBound<'hir> {
// Compute the `T` in `Future<Output = T>` from the return type.
let output_ty = match output {
FunctionRetTy::Ty(ty) => {
FnRetTy::Ty(ty) => {
// Not `OpaqueTyOrigin::AsyncFn`: that's only used for the
// `impl Future` opaque type that `async fn` implicitly
// generates.
let context =
ImplTraitContext::OpaqueTy(Some(fn_def_id), hir::OpaqueTyOrigin::FnReturn);
self.lower_ty(ty, context)
}
FunctionRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
};

// "<Output = T>"
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_lowering/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
inputs.iter().map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())),
);
let output_ty = match output {
FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
FnRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
FnRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
};
let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))];
let binding = this.output_ty_binding(output_ty.span, output_ty);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
GenericArgs::Parenthesized(ref data) => {
walk_list!(self, visit_ty, &data.inputs);
if let FunctionRetTy::Ty(ty) = &data.output {
if let FnRetTy::Ty(ty) = &data.output {
// `-> Foo` syntax is essentially an associated type binding,
// so it is also allowed to contain nested `impl Trait`.
self.with_impl_trait(None, |this| this.visit_ty(ty));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_ty(self, ty)
}

fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
if let ast::FnRetTy::Ty(ref output_ty) = *ret_ty {
if let ast::TyKind::Never = output_ty.kind {
// Do nothing.
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2673,8 +2673,8 @@ impl<'a> State<'a> {
self.end();
}

crate fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FunctionRetTy) {
if let ast::FunctionRetTy::Ty(ty) = fn_ret_ty {
crate fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FnRetTy) {
if let ast::FnRetTy::Ty(ty) = fn_ret_ty {
self.space_if_not_bol();
self.ibox(INDENT_UNIT);
self.word_space("->");
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_ast_pretty/pprust/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ fn test_fun_to_string() {
with_default_globals(|| {
let abba_ident = ast::Ident::from_str("abba");

let decl = ast::FnDecl {
inputs: Vec::new(),
output: ast::FunctionRetTy::Default(rustc_span::DUMMY_SP),
};
let decl =
ast::FnDecl { inputs: Vec::new(), output: ast::FnRetTy::Default(rustc_span::DUMMY_SP) };
let generics = ast::Generics::default();
assert_eq!(
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ impl<'a> MethodDef<'a> {
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);

let method_ident = cx.ident_of(self.name, trait_.span);
let fn_decl = cx.fn_decl(args, ast::FunctionRetTy::Ty(ret_type));
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
let body_block = cx.block_expr(body);

let unsafety = if self.is_unsafe { ast::Unsafe::Yes(trait_.span) } else { ast::Unsafe::No };
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl AllocFnFactory<'_, '_> {
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, mk)).collect();
let result = self.call_allocator(method.name, args);
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
let decl = self.cx.fn_decl(abi_args, ast::FunctionRetTy::Ty(output_ty));
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() };
let sig = FnSig { decl, header };
let kind = ItemKind::Fn(sig, Generics::default(), Some(self.cx.block_expr(output_expr)));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
// If the termination trait is active, the compiler will check that the output
// type implements the `Termination` trait as `libtest` enforces that.
let has_output = match sig.decl.output {
ast::FunctionRetTy::Default(..) => false,
ast::FunctionRetTy::Ty(ref t) if t.kind.is_unit() => false,
ast::FnRetTy::Default(..) => false,
ast::FnRetTy::Ty(ref t) if t.kind.is_unit() => false,
_ => true,
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
ecx.block(sp, vec![call_test_main])
};

let decl = ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty));
let decl = ecx.fn_decl(vec![], ast::FnRetTy::Ty(main_ret_ty));
let sig = ast::FnSig { decl, header: ast::FnHeader::default() };
let main = ast::ItemKind::Fn(sig, ast::Generics::default(), Some(main_body));

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_expand/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'a> ExtCtxt<'a> {
pub fn lambda(&self, span: Span, ids: Vec<ast::Ident>, body: P<ast::Expr>) -> P<ast::Expr> {
let fn_decl = self.fn_decl(
ids.iter().map(|id| self.param(span, *id, self.ty(span, ast::TyKind::Infer))).collect(),
ast::FunctionRetTy::Default(span),
ast::FnRetTy::Default(span),
);

// FIXME -- We are using `span` as the span of the `|...|`
Expand Down Expand Up @@ -569,7 +569,7 @@ impl<'a> ExtCtxt<'a> {
}

// FIXME: unused `self`
pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FunctionRetTy) -> P<ast::FnDecl> {
pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> {
P(ast::FnDecl { inputs, output })
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::itemlikevisit;
use crate::print;

crate use BlockCheckMode::*;
crate use FunctionRetTy::*;
crate use FnRetTy::*;
crate use UnsafeSource::*;

use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -2079,7 +2079,7 @@ pub struct FnDecl<'hir> {
///
/// Additional argument data is stored in the function's [body](Body::parameters).
pub inputs: &'hir [Ty<'hir>],
pub output: FunctionRetTy<'hir>,
pub output: FnRetTy<'hir>,
pub c_variadic: bool,
/// Does the function have an implicit self?
pub implicit_self: ImplicitSelfKind,
Expand Down Expand Up @@ -2145,7 +2145,7 @@ impl Defaultness {
}

#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum FunctionRetTy<'hir> {
pub enum FnRetTy<'hir> {
/// Return type is not specified.
///
/// Functions default to `()` and
Expand All @@ -2156,7 +2156,7 @@ pub enum FunctionRetTy<'hir> {
Return(&'hir Ty<'hir>),
}

impl fmt::Display for FunctionRetTy<'_> {
impl fmt::Display for FnRetTy<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Return(ref ty) => print::to_string(print::NO_ANN, |s| s.print_type(ty)).fmt(f),
Expand All @@ -2165,7 +2165,7 @@ impl fmt::Display for FunctionRetTy<'_> {
}
}

impl FunctionRetTy<'_> {
impl FnRetTy<'_> {
pub fn span(&self) -> Span {
match *self {
Self::DefaultReturn(span) => span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
}
}

pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy<'v>) {
if let FunctionRetTy::Return(ref output_ty) = *ret_ty {
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) {
if let FnRetTy::Return(ref output_ty) = *ret_ty {
visitor.visit_ty(output_ty)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
ret
}

fn should_ignore_fn(ret_ty: &ast::FunctionRetTy) -> bool {
if let ast::FunctionRetTy::Ty(ref ty) = ret_ty {
fn should_ignore_fn(ret_ty: &ast::FnRetTy) -> bool {
if let ast::FnRetTy::Ty(ref ty) = ret_ty {
fn involves_impl_trait(ty: &ast::Ty) -> bool {
match ty.kind {
ast::TyKind::ImplTrait(..) => true,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false);
}

if let hir::FunctionRetTy::Return(ref ret_hir) = decl.output {
if let hir::FnRetTy::Return(ref ret_hir) = decl.output {
let ret_ty = sig.output();
if !ret_ty.is_unit() {
self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// as the HIR doesn't have full types for closure arguments.
let return_ty = *sig.output().skip_binder();
let mut return_span = fn_decl.output.span();
if let hir::FunctionRetTy::Return(ty) = &fn_decl.output {
if let hir::FnRetTy::Return(ty) = &fn_decl.output {
if let hir::TyKind::Rptr(lifetime, _) = ty.kind {
return_span = lifetime.span;
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
..
}) => (
match return_ty.output {
hir::FunctionRetTy::DefaultReturn(_) => tcx.sess.source_map().end_point(*span),
hir::FunctionRetTy::Return(_) => return_ty.output.span(),
hir::FnRetTy::DefaultReturn(_) => tcx.sess.source_map().end_point(*span),
hir::FnRetTy::Return(_) => return_ty.output.span(),
},
if gen_move.is_some() { " of generator" } else { " of closure" },
),
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use rustc_span::source_map::{self, Span, Spanned};
use rustc_span::symbol::{kw, sym, Symbol};
use std::mem;
use syntax::ast::{self, AttrStyle, AttrVec, CaptureBy, Field, Ident, Lit, DUMMY_NODE_ID};
use syntax::ast::{
AnonConst, BinOp, BinOpKind, FnDecl, FunctionRetTy, Mac, Param, Ty, TyKind, UnOp,
};
use syntax::ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, Mac, Param, Ty, TyKind, UnOp};
use syntax::ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
use syntax::ptr::P;
use syntax::token::{self, Token, TokenKind};
Expand Down Expand Up @@ -1358,7 +1356,7 @@ impl<'a> Parser<'a> {
let decl = self.parse_fn_block_decl()?;
let decl_hi = self.prev_span;
let body = match decl.output {
FunctionRetTy::Default(_) => {
FnRetTy::Default(_) => {
let restrictions = self.restrictions - Restrictions::STMT_EXPR;
self.parse_expr_res(restrictions, None)?
}
Expand Down
Loading

0 comments on commit 5c962c7

Please sign in to comment.