Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallowed patterns in extern fn declarations. #12715

Merged
merged 1 commit into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Disallowed patterns in extern fn declarations.
Closes #10877
  • Loading branch information
dmski committed Mar 5, 2014
commit 53f3442ef7ee2852e6e59158f47ae7dbefb2f175
11 changes: 11 additions & 0 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,12 +1040,23 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
ast_generics: &ast::Generics,
abis: AbiSet)
-> ty::ty_param_bounds_and_ty {

for i in decl.inputs.iter() {
match (*i).pat.node {
ast::PatIdent(_, _, _) => (),
ast::PatWild => (),
_ => ccx.tcx.sess.span_err((*i).pat.span,
"patterns aren't allowed in foreign function declarations")
}
}

let ty_generics = ty_generics(ccx, ast_generics, 0);
let rb = BindingRscope::new(def_id.node);
let input_tys = decl.inputs
.iter()
.map(|a| ty_of_arg(ccx, &rb, a, None))
.collect();

let output_ty = ast_ty_to_ty(ccx, &rb, decl.output);

let t_fn = ty::mk_bare_fn(
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/issue-10877.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct Foo { x: int }
extern {
fn foo(1: ());
//~^ ERROR: patterns aren't allowed in foreign function declarations
fn bar((): int);
//~^ ERROR: patterns aren't allowed in foreign function declarations
fn baz(Foo { x }: int);
//~^ ERROR: patterns aren't allowed in foreign function declarations
fn qux((x,y): ());
//~^ ERROR: patterns aren't allowed in foreign function declarations
fn this_is_actually_ok(a: uint);
fn and_so_is_this(_: uint);
}
fn main() {}