syntax: don't keep a redundant c_variadic flag in the AST.
This commit is contained in:
parent
f3c8eba643
commit
8a9d775888
@ -2168,7 +2168,7 @@ impl<'a> LoweringContext<'a> {
|
||||
P(hir::FnDecl {
|
||||
inputs,
|
||||
output,
|
||||
c_variadic: decl.c_variadic,
|
||||
c_variadic: decl.c_variadic(),
|
||||
implicit_self: decl.inputs.get(0).map_or(
|
||||
hir::ImplicitSelfKind::None,
|
||||
|arg| {
|
||||
|
@ -450,7 +450,6 @@ impl LoweringContext<'_> {
|
||||
let ast_decl = FnDecl {
|
||||
inputs: vec![],
|
||||
output,
|
||||
c_variadic: false
|
||||
};
|
||||
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
|
||||
let body_id = self.lower_fn_body(&ast_decl, |this| {
|
||||
@ -739,7 +738,6 @@ impl LoweringContext<'_> {
|
||||
let outer_decl = FnDecl {
|
||||
inputs: decl.inputs.clone(),
|
||||
output: FunctionRetTy::Default(fn_decl_span),
|
||||
c_variadic: false,
|
||||
};
|
||||
// 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
|
||||
|
@ -1893,7 +1893,6 @@ impl Param {
|
||||
pub struct FnDecl {
|
||||
pub inputs: Vec<Param>,
|
||||
pub output: FunctionRetTy,
|
||||
pub c_variadic: bool,
|
||||
}
|
||||
|
||||
impl FnDecl {
|
||||
@ -1903,6 +1902,12 @@ impl FnDecl {
|
||||
pub fn has_self(&self) -> bool {
|
||||
self.inputs.get(0).map(Param::is_self).unwrap_or(false)
|
||||
}
|
||||
pub fn c_variadic(&self) -> bool {
|
||||
self.inputs.last().map(|arg| match arg.ty.kind {
|
||||
TyKind::CVarArgs => true,
|
||||
_ => false,
|
||||
}).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the trait definition an auto trait?
|
||||
|
@ -562,7 +562,6 @@ impl<'a> ExtCtxt<'a> {
|
||||
P(ast::FnDecl {
|
||||
inputs,
|
||||
output,
|
||||
c_variadic: false
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -531,7 +531,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
self.check_abi(header.abi, span);
|
||||
}
|
||||
|
||||
if fn_decl.c_variadic {
|
||||
if fn_decl.c_variadic() {
|
||||
gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable");
|
||||
}
|
||||
|
||||
@ -564,7 +564,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
if block.is_none() {
|
||||
self.check_abi(sig.header.abi, ti.span);
|
||||
}
|
||||
if sig.decl.c_variadic {
|
||||
if sig.decl.c_variadic() {
|
||||
gate_feature_post!(&self, c_variadic, ti.span,
|
||||
"C-variadic functions are unstable");
|
||||
}
|
||||
@ -601,7 +601,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
|
||||
match ii.kind {
|
||||
ast::ImplItemKind::Method(..) => {}
|
||||
ast::ImplItemKind::Method(ref sig, _) => {
|
||||
if sig.decl.c_variadic() {
|
||||
gate_feature_post!(&self, c_variadic, ii.span,
|
||||
"C-variadic functions are unstable");
|
||||
}
|
||||
}
|
||||
ast::ImplItemKind::OpaqueTy(..) => {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
|
@ -717,7 +717,7 @@ pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut IsAsync, vis: &mut T)
|
||||
}
|
||||
|
||||
pub fn noop_visit_fn_decl<T: MutVisitor>(decl: &mut P<FnDecl>, vis: &mut T) {
|
||||
let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut();
|
||||
let FnDecl { inputs, output } = decl.deref_mut();
|
||||
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
|
||||
match output {
|
||||
FunctionRetTy::Default(span) => vis.visit_span(span),
|
||||
|
@ -1194,7 +1194,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn parse_fn_params(&mut self, named_params: bool, allow_c_variadic: bool)
|
||||
-> PResult<'a, (Vec<Param> , bool)> {
|
||||
-> PResult<'a, Vec<Param>> {
|
||||
let sp = self.token.span;
|
||||
let mut c_variadic = false;
|
||||
let (params, _): (Vec<Option<Param>>, _) = self.parse_paren_comma_seq(|p| {
|
||||
@ -1218,6 +1218,8 @@ impl<'a> Parser<'a> {
|
||||
let span = p.token.span;
|
||||
p.span_err(span,
|
||||
"`...` must be the last argument of a C-variadic function");
|
||||
// FIXME(eddyb) this should probably still push `CVarArgs`.
|
||||
// Maybe AST validation/HIR lowering should emit the above error?
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(param))
|
||||
@ -1245,7 +1247,7 @@ impl<'a> Parser<'a> {
|
||||
"C-variadic function must be declared with at least one named argument");
|
||||
}
|
||||
|
||||
Ok((params, c_variadic))
|
||||
Ok(params)
|
||||
}
|
||||
|
||||
/// Returns the parsed optional self parameter and whether a self shortcut was used.
|
||||
@ -1414,7 +1416,6 @@ impl<'a> Parser<'a> {
|
||||
Ok(P(FnDecl {
|
||||
inputs: fn_inputs,
|
||||
output: self.parse_ret_ty(true)?,
|
||||
c_variadic: false
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -1176,7 +1176,6 @@ impl<'a> Parser<'a> {
|
||||
Ok(P(FnDecl {
|
||||
inputs: inputs_captures,
|
||||
output,
|
||||
c_variadic: false
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -1292,13 +1292,12 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// Parses the argument list and result type of a function declaration.
|
||||
fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P<FnDecl>> {
|
||||
let (args, c_variadic) = self.parse_fn_params(true, allow_c_variadic)?;
|
||||
let args = self.parse_fn_params(true, allow_c_variadic)?;
|
||||
let ret_ty = self.parse_ret_ty(true)?;
|
||||
|
||||
Ok(P(FnDecl {
|
||||
inputs: args,
|
||||
output: ret_ty,
|
||||
c_variadic,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -292,12 +292,11 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
self.expect_keyword(kw::Fn)?;
|
||||
let (inputs, c_variadic) = self.parse_fn_params(false, true)?;
|
||||
let inputs = self.parse_fn_params(false, true)?;
|
||||
let ret_ty = self.parse_ret_ty(false)?;
|
||||
let decl = P(FnDecl {
|
||||
inputs,
|
||||
output: ret_ty,
|
||||
c_variadic,
|
||||
});
|
||||
Ok(TyKind::BareFn(P(BareFnTy {
|
||||
abi,
|
||||
|
@ -29,7 +29,6 @@ fn test_fun_to_string() {
|
||||
let decl = ast::FnDecl {
|
||||
inputs: Vec::new(),
|
||||
output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP),
|
||||
c_variadic: false
|
||||
};
|
||||
let generics = ast::Generics::default();
|
||||
assert_eq!(
|
||||
|
@ -114,7 +114,6 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
||||
let decl = P(FnDecl {
|
||||
inputs: vec![],
|
||||
output: FunctionRetTy::Default(DUMMY_SP),
|
||||
c_variadic: false,
|
||||
});
|
||||
iter_exprs(depth - 1, &mut |e| g(
|
||||
ExprKind::Closure(CaptureBy::Value,
|
||||
|
Loading…
x
Reference in New Issue
Block a user