Skip to content

Commit 1154374

Browse files
committed
syntax: don't keep a redundant c_variadic flag in the AST.
1 parent 590ae0e commit 1154374

File tree

12 files changed

+22
-19
lines changed

12 files changed

+22
-19
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ impl<'a> LoweringContext<'a> {
21682168
P(hir::FnDecl {
21692169
inputs,
21702170
output,
2171-
c_variadic: decl.c_variadic,
2171+
c_variadic: decl.c_variadic(),
21722172
implicit_self: decl.inputs.get(0).map_or(
21732173
hir::ImplicitSelfKind::None,
21742174
|arg| {

src/librustc/hir/lowering/expr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ impl LoweringContext<'_> {
450450
let ast_decl = FnDecl {
451451
inputs: vec![],
452452
output,
453-
c_variadic: false
454453
};
455454
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
456455
let body_id = self.lower_fn_body(&ast_decl, |this| {
@@ -740,7 +739,6 @@ impl LoweringContext<'_> {
740739
let outer_decl = FnDecl {
741740
inputs: decl.inputs.clone(),
742741
output: FunctionRetTy::Default(fn_decl_span),
743-
c_variadic: false,
744742
};
745743
// We need to lower the declaration outside the new scope, because we
746744
// have to conserve the state of being inside a loop condition for the

src/libsyntax/ast.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,6 @@ impl Param {
18931893
pub struct FnDecl {
18941894
pub inputs: Vec<Param>,
18951895
pub output: FunctionRetTy,
1896-
pub c_variadic: bool,
18971896
}
18981897

18991898
impl FnDecl {
@@ -1903,6 +1902,12 @@ impl FnDecl {
19031902
pub fn has_self(&self) -> bool {
19041903
self.inputs.get(0).map(Param::is_self).unwrap_or(false)
19051904
}
1905+
pub fn c_variadic(&self) -> bool {
1906+
self.inputs.last().map(|arg| match arg.ty.kind {
1907+
TyKind::CVarArgs => true,
1908+
_ => false,
1909+
}).unwrap_or(false)
1910+
}
19061911
}
19071912

19081913
/// Is the trait definition an auto trait?

src/libsyntax/ext/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ impl<'a> ExtCtxt<'a> {
562562
P(ast::FnDecl {
563563
inputs,
564564
output,
565-
c_variadic: false
566565
})
567566
}
568567

src/libsyntax/feature_gate/check.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
531531
self.check_abi(header.abi, span);
532532
}
533533

534-
if fn_decl.c_variadic {
534+
if fn_decl.c_variadic() {
535535
gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable");
536536
}
537537

@@ -564,7 +564,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
564564
if block.is_none() {
565565
self.check_abi(sig.header.abi, ti.span);
566566
}
567-
if sig.decl.c_variadic {
567+
if sig.decl.c_variadic() {
568568
gate_feature_post!(&self, c_variadic, ti.span,
569569
"C-variadic functions are unstable");
570570
}
@@ -601,7 +601,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
601601
}
602602

603603
match ii.kind {
604-
ast::ImplItemKind::Method(..) => {}
604+
ast::ImplItemKind::Method(ref sig, _) => {
605+
if sig.decl.c_variadic() {
606+
gate_feature_post!(&self, c_variadic, ii.span,
607+
"C-variadic functions are unstable");
608+
}
609+
}
605610
ast::ImplItemKind::OpaqueTy(..) => {
606611
gate_feature_post!(
607612
&self,

src/libsyntax/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut IsAsync, vis: &mut T)
717717
}
718718

719719
pub fn noop_visit_fn_decl<T: MutVisitor>(decl: &mut P<FnDecl>, vis: &mut T) {
720-
let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut();
720+
let FnDecl { inputs, output } = decl.deref_mut();
721721
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
722722
match output {
723723
FunctionRetTy::Default(span) => vis.visit_span(span),

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ impl<'a> Parser<'a> {
11941194
}
11951195

11961196
fn parse_fn_params(&mut self, named_params: bool, allow_c_variadic: bool)
1197-
-> PResult<'a, (Vec<Param> , bool)> {
1197+
-> PResult<'a, Vec<Param>> {
11981198
let sp = self.token.span;
11991199
let mut c_variadic = false;
12001200
let (params, _): (Vec<Option<Param>>, _) = self.parse_paren_comma_seq(|p| {
@@ -1218,6 +1218,8 @@ impl<'a> Parser<'a> {
12181218
let span = p.token.span;
12191219
p.span_err(span,
12201220
"`...` must be the last argument of a C-variadic function");
1221+
// FIXME(eddyb) this should probably still push `CVarArgs`.
1222+
// Maybe AST validation/HIR lowering should emit the above error?
12211223
Ok(None)
12221224
} else {
12231225
Ok(Some(param))
@@ -1245,7 +1247,7 @@ impl<'a> Parser<'a> {
12451247
"C-variadic function must be declared with at least one named argument");
12461248
}
12471249

1248-
Ok((params, c_variadic))
1250+
Ok(params)
12491251
}
12501252

12511253
/// Returns the parsed optional self parameter and whether a self shortcut was used.
@@ -1414,7 +1416,6 @@ impl<'a> Parser<'a> {
14141416
Ok(P(FnDecl {
14151417
inputs: fn_inputs,
14161418
output: self.parse_ret_ty(true)?,
1417-
c_variadic: false
14181419
}))
14191420
}
14201421

src/libsyntax/parse/parser/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,6 @@ impl<'a> Parser<'a> {
11761176
Ok(P(FnDecl {
11771177
inputs: inputs_captures,
11781178
output,
1179-
c_variadic: false
11801179
}))
11811180
}
11821181

src/libsyntax/parse/parser/item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,12 @@ impl<'a> Parser<'a> {
12921292

12931293
/// Parses the argument list and result type of a function declaration.
12941294
fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P<FnDecl>> {
1295-
let (args, c_variadic) = self.parse_fn_params(true, allow_c_variadic)?;
1295+
let args = self.parse_fn_params(true, allow_c_variadic)?;
12961296
let ret_ty = self.parse_ret_ty(true)?;
12971297

12981298
Ok(P(FnDecl {
12991299
inputs: args,
13001300
output: ret_ty,
1301-
c_variadic,
13021301
}))
13031302
}
13041303

src/libsyntax/parse/parser/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ impl<'a> Parser<'a> {
292292
};
293293

294294
self.expect_keyword(kw::Fn)?;
295-
let (inputs, c_variadic) = self.parse_fn_params(false, true)?;
295+
let inputs = self.parse_fn_params(false, true)?;
296296
let ret_ty = self.parse_ret_ty(false)?;
297297
let decl = P(FnDecl {
298298
inputs,
299299
output: ret_ty,
300-
c_variadic,
301300
});
302301
Ok(TyKind::BareFn(P(BareFnTy {
303302
abi,

src/libsyntax/print/pprust/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fn test_fun_to_string() {
2929
let decl = ast::FnDecl {
3030
inputs: Vec::new(),
3131
output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP),
32-
c_variadic: false
3332
};
3433
let generics = ast::Generics::default();
3534
assert_eq!(

src/test/ui-fulldeps/pprust-expr-roundtrip.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
114114
let decl = P(FnDecl {
115115
inputs: vec![],
116116
output: FunctionRetTy::Default(DUMMY_SP),
117-
c_variadic: false,
118117
});
119118
iter_exprs(depth - 1, &mut |e| g(
120119
ExprKind::Closure(CaptureBy::Value,

0 commit comments

Comments
 (0)