Skip to content

Commit e04462f

Browse files
committed
syntax: parse const fn for free functions and inherent methods.
1 parent 9889aae commit e04462f

File tree

36 files changed

+207
-97
lines changed

36 files changed

+207
-97
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10151015
encode_stability(rbml_w, stab);
10161016
rbml_w.end_tag();
10171017
}
1018-
ast::ItemFn(ref decl, _, _, ref generics, _) => {
1018+
ast::ItemFn(ref decl, _, _, _, ref generics, _) => {
10191019
add_to_index(item, rbml_w, index);
10201020
rbml_w.start_tag(tag_items_data_item);
10211021
encode_def_id(rbml_w, def_id);
@@ -1875,7 +1875,7 @@ fn encode_reachable_extern_fns(ecx: &EncodeContext, rbml_w: &mut Encoder) {
18751875

18761876
for id in ecx.reachable {
18771877
if let Some(ast_map::NodeItem(i)) = ecx.tcx.map.find(*id) {
1878-
if let ast::ItemFn(_, _, abi, ref generics, _) = i.node {
1878+
if let ast::ItemFn(_, _, _, abi, ref generics, _) = i.node {
18791879
if abi != abi::Rust && !generics.is_type_parameterized() {
18801880
rbml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id);
18811881
}

src/librustc/middle/effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
8787
block: &'v ast::Block, span: Span, _: ast::NodeId) {
8888

8989
let (is_item_fn, is_unsafe_fn) = match fn_kind {
90-
visit::FkItemFn(_, _, fn_style, _) =>
91-
(true, fn_style == ast::Unsafety::Unsafe),
90+
visit::FkItemFn(_, _, unsafety, _, _) =>
91+
(true, unsafety == ast::Unsafety::Unsafe),
9292
visit::FkMethod(_, sig) =>
9393
(true, sig.unsafety == ast::Unsafety::Unsafe),
9494
_ => (false, false),

src/librustc/middle/infer/error_reporting.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ trait ErrorReportingHelpers<'tcx> {
159159
fn give_expl_lifetime_param(&self,
160160
decl: &ast::FnDecl,
161161
unsafety: ast::Unsafety,
162+
constness: ast::Constness,
162163
ident: ast::Ident,
163164
opt_explicit_self: Option<&ast::ExplicitSelf_>,
164165
generics: &ast::Generics,
@@ -840,8 +841,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
840841
Some(ref node) => match *node {
841842
ast_map::NodeItem(ref item) => {
842843
match item.node {
843-
ast::ItemFn(ref fn_decl, pur, _, ref gen, _) => {
844-
Some((fn_decl, gen, pur, item.ident, None, item.span))
844+
ast::ItemFn(ref fn_decl, unsafety, constness, _, ref gen, _) => {
845+
Some((fn_decl, gen, unsafety, constness,
846+
item.ident, None, item.span))
845847
},
846848
_ => None
847849
}
@@ -852,6 +854,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
852854
Some((&sig.decl,
853855
&sig.generics,
854856
sig.unsafety,
857+
sig.constness,
855858
item.ident,
856859
Some(&sig.explicit_self.node),
857860
item.span))
@@ -866,6 +869,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
866869
Some((&sig.decl,
867870
&sig.generics,
868871
sig.unsafety,
872+
sig.constness,
869873
item.ident,
870874
Some(&sig.explicit_self.node),
871875
item.span))
@@ -877,12 +881,12 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
877881
},
878882
None => None
879883
};
880-
let (fn_decl, generics, unsafety, ident, expl_self, span)
884+
let (fn_decl, generics, unsafety, constness, ident, expl_self, span)
881885
= node_inner.expect("expect item fn");
882886
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
883887
generics, same_regions, &life_giver);
884888
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
885-
self.give_expl_lifetime_param(&fn_decl, unsafety, ident,
889+
self.give_expl_lifetime_param(&fn_decl, unsafety, constness, ident,
886890
expl_self.as_ref(), &generics, span);
887891
}
888892
}
@@ -1437,12 +1441,13 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
14371441
fn give_expl_lifetime_param(&self,
14381442
decl: &ast::FnDecl,
14391443
unsafety: ast::Unsafety,
1444+
constness: ast::Constness,
14401445
ident: ast::Ident,
14411446
opt_explicit_self: Option<&ast::ExplicitSelf_>,
14421447
generics: &ast::Generics,
14431448
span: codemap::Span) {
1444-
let suggested_fn = pprust::fun_to_string(decl, unsafety, ident,
1445-
opt_explicit_self, generics);
1449+
let suggested_fn = pprust::fun_to_string(decl, unsafety, constness, ident,
1450+
opt_explicit_self, generics);
14461451
let msg = format!("consider using an explicit lifetime \
14471452
parameter as shown: {}", suggested_fn);
14481453
self.tcx.sess.span_help(span, &msg[..]);
@@ -1724,7 +1729,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
17241729
let method_id_opt = match tcx.map.find(parent) {
17251730
Some(node) => match node {
17261731
ast_map::NodeItem(item) => match item.node {
1727-
ast::ItemFn(_, _, _, ref gen, _) => {
1732+
ast::ItemFn(_, _, _, _, ref gen, _) => {
17281733
taken.push_all(&gen.lifetimes);
17291734
None
17301735
},

src/librustc/middle/reachable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
4646

4747
match item.node {
4848
ast::ItemImpl(_, _, ref generics, _, _, _) |
49-
ast::ItemFn(_, _, _, ref generics, _) => {
49+
ast::ItemFn(_, _, _, _, ref generics, _) => {
5050
generics_require_inlining(generics)
5151
}
5252
_ => false,
@@ -254,7 +254,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
254254
// but all other rust-only interfaces can be private (they will not
255255
// participate in linkage after this product is produced)
256256
if let ast_map::NodeItem(item) = *node {
257-
if let ast::ItemFn(_, _, abi, _, _) = item.node {
257+
if let ast::ItemFn(_, _, _, abi, _, _) = item.node {
258258
if abi != abi::Rust {
259259
self.reachable_symbols.insert(search_item);
260260
}
@@ -271,7 +271,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
271271
match *node {
272272
ast_map::NodeItem(item) => {
273273
match item.node {
274-
ast::ItemFn(_, _, _, _, ref search_block) => {
274+
ast::ItemFn(_, _, _, _, _, ref search_block) => {
275275
if item_might_be_inlined(&*item) {
276276
visit::walk_block(self, &**search_block)
277277
}

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
142142
fn visit_fn(&mut self, fk: visit::FnKind<'v>, fd: &'v ast::FnDecl,
143143
b: &'v ast::Block, s: Span, _: ast::NodeId) {
144144
match fk {
145-
visit::FkItemFn(_, generics, _, _) => {
145+
visit::FkItemFn(_, generics, _, _, _) =>
146146
self.visit_early_late(subst::FnSpace, generics, |this| {
147147
visit::walk_fn(this, fk, fd, b, s)
148148
})

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use syntax::{attr, visit};
2323
use syntax::ast;
2424
use syntax::ast::{Attribute, Block, Crate, DefId, FnDecl, NodeId, Variant};
2525
use syntax::ast::{Item, Generics, StructField};
26-
use syntax::ast_util::is_local;
26+
use syntax::ast_util::{is_local, PostExpansionMethod};
2727
use syntax::attr::{Stability, AttrMetaMethods};
2828
use syntax::visit::{FnKind, Visitor};
2929
use syntax::feature_gate::emit_feature_warn;

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
23552355
}
23562356
Some(ast_map::NodeItem(item)) => {
23572357
match item.node {
2358-
ast::ItemFn(_, _, _, _, ref body) => {
2358+
ast::ItemFn(_, _, _, _, _, ref body) => {
23592359
// We assume this is a function.
23602360
let fn_def_id = ast_util::local_def(id);
23612361
let fn_scheme = lookup_item_type(cx, fn_def_id);

src/librustc_lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ impl LintPass for NonSnakeCase {
991991
},
992992
_ => (),
993993
},
994-
visit::FkItemFn(ident, _, _, _) => {
994+
visit::FkItemFn(ident, _, _, _, _) => {
995995
self.check_snake_case(cx, "function", ident, span)
996996
},
997997
_ => (),
@@ -1315,7 +1315,7 @@ impl LintPass for UnsafeCode {
13151315
fn check_fn(&mut self, cx: &Context, fk: visit::FnKind, _: &ast::FnDecl,
13161316
_: &ast::Block, span: Span, _: ast::NodeId) {
13171317
match fk {
1318-
visit::FkItemFn(_, _, ast::Unsafety::Unsafe, _) =>
1318+
visit::FkItemFn(_, _, ast::Unsafety::Unsafe, _, _) =>
13191319
cx.span_lint(UNSAFE_CODE, span, "declaration of an `unsafe` function"),
13201320

13211321
visit::FkMethod(_, sig) => {
@@ -1808,7 +1808,7 @@ impl LintPass for UnconditionalRecursion {
18081808
ast::NodeId, ast::NodeId, ast::Ident, ast::NodeId) -> bool;
18091809

18101810
let (name, checker) = match fn_kind {
1811-
visit::FkItemFn(name, _, _, _) => (name, id_refers_to_this_fn as F),
1811+
visit::FkItemFn(name, _, _, _, _) => (name, id_refers_to_this_fn as F),
18121812
visit::FkMethod(name, _) => (name, id_refers_to_this_method as F),
18131813
// closures can't recur, so they don't matter.
18141814
visit::FkFnBlock => return

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
421421
.define_value(DefConst(local_def(item.id)), sp, modifiers);
422422
parent.clone()
423423
}
424-
ItemFn(_, _, _, _, _) => {
424+
ItemFn(_, _, _, _, _, _) => {
425425
let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
426426

427427
let def = DefFn(local_def(item.id), false);

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
238238
_: Span,
239239
node_id: NodeId) {
240240
let rib_kind = match function_kind {
241-
visit::FkItemFn(_, generics, _, _) => {
241+
visit::FkItemFn(_, generics, _, _, _) => {
242242
self.visit_generics(generics);
243243
ItemRibKind
244244
}
@@ -2767,7 +2767,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27672767
ItemRibKind),
27682768
|this| visit::walk_item(this, item));
27692769
}
2770-
ItemFn(_, _, _, ref generics, _) => {
2770+
ItemFn(_, _, _, _, ref generics, _) => {
27712771
self.with_type_parameter_rib(HasTypeParameters(generics,
27722772
FnSpace,
27732773
ItemRibKind),

src/librustc_trans/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11761176
&location[..],
11771177
self.cur_scope);
11781178
}
1179-
ast::ItemFn(ref decl, _, _, ref ty_params, ref body) =>
1179+
ast::ItemFn(ref decl, _, _, _, ref ty_params, ref body) =>
11801180
self.process_fn(item, &**decl, ty_params, &**body),
11811181
ast::ItemStatic(ref typ, mt, ref expr) =>
11821182
self.process_static(item, &**typ, mt, &**expr),

src/librustc_trans/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ fn build_cfg(tcx: &ty::ctxt, id: ast::NodeId) -> (ast::NodeId, Option<cfg::CFG>)
12621262
let blk = match tcx.map.find(id) {
12631263
Some(ast_map::NodeItem(i)) => {
12641264
match i.node {
1265-
ast::ItemFn(_, _, _, _, ref blk) => {
1265+
ast::ItemFn(_, _, _, _, _, ref blk) => {
12661266
blk
12671267
}
12681268
_ => tcx.sess.bug("unexpected item variant in has_nested_returns")
@@ -2230,7 +2230,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
22302230
let from_external = ccx.external_srcs().borrow().contains_key(&item.id);
22312231

22322232
match item.node {
2233-
ast::ItemFn(ref decl, _fn_style, abi, ref generics, ref body) => {
2233+
ast::ItemFn(ref decl, _, _, abi, ref generics, ref body) => {
22342234
if !generics.is_type_parameterized() {
22352235
let trans_everywhere = attr::requests_inline(&item.attrs);
22362236
// Ignore `trans_everywhere` for cross-crate inlined items
@@ -2771,7 +2771,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
27712771
}
27722772
}
27732773

2774-
ast::ItemFn(_, _, abi, _, _) => {
2774+
ast::ItemFn(_, _, _, abi, _, _) => {
27752775
let sym = sym();
27762776
let llfn = if abi == Rust {
27772777
register_fn(ccx, i.span, sym, i.id, ty)

src/librustc_trans/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
12901290
}
12911291

12921292
match item.node {
1293-
ast::ItemFn(ref fn_decl, _, _, ref generics, ref top_level_block) => {
1293+
ast::ItemFn(ref fn_decl, _, _, _, ref generics, ref top_level_block) => {
12941294
(item.ident, fn_decl, generics, top_level_block, item.span, true)
12951295
}
12961296
_ => {

src/librustc_trans/trans/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
5555
trans_item(ccx, &**item);
5656

5757
let linkage = match item.node {
58-
ast::ItemFn(_, _, _, ref generics, _) => {
58+
ast::ItemFn(_, _, _, _, ref generics, _) => {
5959
if generics.is_type_parameterized() {
6060
// Generics have no symbol, so they can't be given any
6161
// linkage.

src/librustc_trans/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
173173
ast_map::NodeItem(i) => {
174174
match *i {
175175
ast::Item {
176-
node: ast::ItemFn(ref decl, _, abi, _, ref body),
176+
node: ast::ItemFn(ref decl, _, _, abi, _, ref body),
177177
..
178178
} => {
179179
let d = mk_lldecl(abi);

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ pub fn check_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx ast::Item) {
718718
&enum_definition.variants,
719719
it.id);
720720
}
721-
ast::ItemFn(ref decl, _, _, _, ref body) => {
721+
ast::ItemFn(ref decl, _, _, _, _, ref body) => {
722722
let fn_pty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
723723
let param_env = ParameterEnvironment::for_item(ccx.tcx, it.id);
724724
check_bare_fn(ccx, &**decl, &**body, it.id, it.span, fn_pty.ty, param_env);

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
13911391
let ty = ccx.icx(&()).to_ty(&ExplicitRscope, &**t);
13921392
ty::TypeScheme { ty: ty, generics: ty::Generics::empty() }
13931393
}
1394-
ast::ItemFn(ref decl, unsafety, abi, ref generics, _) => {
1394+
ast::ItemFn(ref decl, unsafety, _, abi, ref generics, _) => {
13951395
let ty_generics = ty_generics_for_fn(ccx, generics, &ty::Generics::empty());
13961396
let tofd = astconv::ty_of_bare_fn(&ccx.icx(generics), unsafety, abi, &**decl);
13971397
let ty = ty::mk_bare_fn(tcx, Some(local_def(it.id)), tcx.mk_bare_fn(tofd));
@@ -1443,7 +1443,7 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
14431443
ast::ItemStatic(..) | ast::ItemConst(..) => {
14441444
ty::GenericPredicates::empty()
14451445
}
1446-
ast::ItemFn(_, _, _, ref ast_generics, _) => {
1446+
ast::ItemFn(_, _, _, _, ref ast_generics, _) => {
14471447
ty_generic_predicates_for_fn(ccx, ast_generics, &ty::GenericPredicates::empty())
14481448
}
14491449
ast::ItemTy(_, ref generics) => {

src/librustc_typeck/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
218218
match tcx.map.find(main_id) {
219219
Some(ast_map::NodeItem(it)) => {
220220
match it.node {
221-
ast::ItemFn(_, _, _, ref ps, _)
221+
ast::ItemFn(_, _, _, _, ref ps, _)
222222
if ps.is_parameterized() => {
223223
span_err!(ccx.tcx.sess, main_span, E0131,
224224
"main function is not allowed to have type parameters");
@@ -265,7 +265,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
265265
match tcx.map.find(start_id) {
266266
Some(ast_map::NodeItem(it)) => {
267267
match it.node {
268-
ast::ItemFn(_,_,_,ref ps,_)
268+
ast::ItemFn(_,_,_,_,ref ps,_)
269269
if ps.is_parameterized() => {
270270
span_err!(tcx.sess, start_span, E0132,
271271
"start function is not allowed to have type parameters");

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) ->
169169
decl: decl,
170170
generics: (&t.generics, &predicates, subst::FnSpace).clean(cx),
171171
unsafety: style,
172+
constness: ast::Constness::NotConst
172173
}
173174
}
174175

@@ -300,6 +301,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
300301
}) => {
301302
clean::MethodItem(clean::Method {
302303
unsafety: unsafety,
304+
constness: ast::Constness::NotConst,
303305
decl: decl,
304306
self_: self_,
305307
generics: generics,

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ pub struct Method {
944944
pub generics: Generics,
945945
pub self_: SelfTy,
946946
pub unsafety: ast::Unsafety,
947+
pub constness: ast::Constness,
947948
pub decl: FnDecl,
948949
pub abi: abi::Abi
949950
}
@@ -965,7 +966,8 @@ impl Clean<Method> for ast::MethodSig {
965966
Method {
966967
generics: self.generics.clean(cx),
967968
self_: self.explicit_self.node.clean(cx),
968-
unsafety: self.unsafety.clone(),
969+
unsafety: self.unsafety,
970+
constness: self.constness,
969971
decl: decl,
970972
abi: self.abi
971973
}
@@ -1030,6 +1032,7 @@ pub struct Function {
10301032
pub decl: FnDecl,
10311033
pub generics: Generics,
10321034
pub unsafety: ast::Unsafety,
1035+
pub constness: ast::Constness,
10331036
}
10341037

10351038
impl Clean<Item> for doctree::Function {
@@ -1045,6 +1048,7 @@ impl Clean<Item> for doctree::Function {
10451048
decl: self.decl.clean(cx),
10461049
generics: self.generics.clean(cx),
10471050
unsafety: self.unsafety,
1051+
constness: self.constness,
10481052
}),
10491053
}
10501054
}
@@ -2243,6 +2247,7 @@ impl Clean<Item> for ast::ForeignItem {
22432247
decl: decl.clean(cx),
22442248
generics: generics.clean(cx),
22452249
unsafety: ast::Unsafety::Unsafe,
2250+
constness: ast::Constness::NotConst
22462251
})
22472252
}
22482253
ast::ForeignItemStatic(ref ty, mutbl) => {

src/librustdoc/doctree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub struct Function {
132132
pub vis: ast::Visibility,
133133
pub stab: Option<attr::Stability>,
134134
pub unsafety: ast::Unsafety,
135+
pub constness: ast::Constness,
135136
pub whence: Span,
136137
pub generics: ast::Generics,
137138
}

0 commit comments

Comments
 (0)