Skip to content

Commit e5cc046

Browse files
committed
Move the E0130 check to AST validation pass
1 parent 32e462e commit e5cc046

File tree

4 files changed

+53
-47
lines changed

4 files changed

+53
-47
lines changed

src/librustc_passes/ast_validation.rs

+17
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ impl<'a> Visitor for AstValidator<'a> {
135135
visit::walk_item(self, item)
136136
}
137137

138+
fn visit_foreign_item(&mut self, fi: &ForeignItem) {
139+
match fi.node {
140+
ForeignItemKind::Fn(ref decl, _) => {
141+
for arg in &decl.inputs {
142+
match arg.pat.node {
143+
PatKind::Ident(..) | PatKind::Wild => {}
144+
_ => span_err!(self.session, arg.pat.span, E0130,
145+
"patterns aren't allowed in foreign function declarations")
146+
}
147+
}
148+
}
149+
ForeignItemKind::Static(..) => {}
150+
}
151+
152+
visit::walk_foreign_item(self, fi)
153+
}
154+
138155
fn visit_variant_data(&mut self, vdata: &VariantData, _: Ident,
139156
_: &Generics, _: NodeId, span: Span) {
140157
if vdata.fields().is_empty() {

src/librustc_passes/diagnostics.rs

+33
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,39 @@ match 5u32 {
4949
```
5050
"##,
5151

52+
E0130: r##"
53+
You declared a pattern as an argument in a foreign function declaration.
54+
Erroneous code example:
55+
56+
```compile_fail
57+
extern {
58+
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
59+
// function declarations
60+
}
61+
```
62+
63+
Please replace the pattern argument with a regular one. Example:
64+
65+
```
66+
struct SomeStruct {
67+
a: u32,
68+
b: u32,
69+
}
70+
71+
extern {
72+
fn foo(s: SomeStruct); // ok!
73+
}
74+
```
75+
76+
Or:
77+
78+
```
79+
extern {
80+
fn foo(a: (u32, u32)); // ok!
81+
}
82+
```
83+
"##,
84+
5285
E0161: r##"
5386
A value was moved. However, its size was not known at compile time, and only
5487
values of a known size can be moved.

src/librustc_typeck/collect.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ There are some shortcomings in this design:
6060

6161
use astconv::{AstConv, ast_region_to_region, Bounds, PartitionedBounds, partition_bounds};
6262
use lint;
63-
use hir::def::Def;
64-
use hir::def_id::DefId;
6563
use constrained_type_params as ctp;
6664
use middle::lang_items::SizedTraitLangItem;
6765
use middle::const_val::ConstVal;
@@ -74,7 +72,6 @@ use rustc::ty::{VariantKind};
7472
use rustc::ty::util::IntTypeExt;
7573
use rscope::*;
7674
use rustc::dep_graph::DepNode;
77-
use rustc::hir::map as hir_map;
7875
use util::common::{ErrorReported, MemoizationMap};
7976
use util::nodemap::{NodeMap, FnvHashMap};
8077
use {CrateCtxt, write_ty_to_tcx};
@@ -91,9 +88,9 @@ use syntax::parse::token::keywords;
9188
use syntax::ptr::P;
9289
use syntax_pos::Span;
9390

94-
use rustc::hir::{self, PatKind};
95-
use rustc::hir::intravisit;
96-
use rustc::hir::print as pprust;
91+
use rustc::hir::{self, intravisit, map as hir_map, print as pprust};
92+
use rustc::hir::def::Def;
93+
use rustc::hir::def_id::DefId;
9794

9895
///////////////////////////////////////////////////////////////////////////
9996
// Main entry point
@@ -2144,14 +2141,6 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
21442141
abi: abi::Abi)
21452142
-> ty::TypeScheme<'tcx>
21462143
{
2147-
for i in &decl.inputs {
2148-
match i.pat.node {
2149-
PatKind::Binding(..) | PatKind::Wild => {}
2150-
_ => span_err!(ccx.tcx.sess, i.pat.span, E0130,
2151-
"patterns aren't allowed in foreign function declarations")
2152-
}
2153-
}
2154-
21552144
let ty_generics = ty_generics_for_fn(ccx, ast_generics, &ty::Generics::empty());
21562145

21572146
let rb = BindingRscope::new();

src/librustc_typeck/diagnostics.rs

-33
Original file line numberDiff line numberDiff line change
@@ -1800,39 +1800,6 @@ Please also verify that this wasn't because of a name-clash and rename the type
18001800
parameter if so.
18011801
"##,
18021802

1803-
E0130: r##"
1804-
You declared a pattern as an argument in a foreign function declaration.
1805-
Erroneous code example:
1806-
1807-
```compile_fail
1808-
extern {
1809-
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
1810-
// function declarations
1811-
}
1812-
```
1813-
1814-
Please replace the pattern argument with a regular one. Example:
1815-
1816-
```
1817-
struct SomeStruct {
1818-
a: u32,
1819-
b: u32,
1820-
}
1821-
1822-
extern {
1823-
fn foo(s: SomeStruct); // ok!
1824-
}
1825-
```
1826-
1827-
Or:
1828-
1829-
```
1830-
extern {
1831-
fn foo(a: (u32, u32)); // ok!
1832-
}
1833-
```
1834-
"##,
1835-
18361803
E0131: r##"
18371804
It is not possible to define `main` with type parameters, or even with function
18381805
parameters. When `main` is present, it must take no arguments and return `()`.

0 commit comments

Comments
 (0)