Use usual lifetime elision rules for foreign functions

This commit is contained in:
Vadim Petrochenkov 2017-08-05 03:13:38 +03:00
parent 5c7add7551
commit 7704762604
2 changed files with 18 additions and 14 deletions

View File

@ -1081,20 +1081,8 @@ fn visit_fn_like_elision(&mut self, inputs: &'tcx [P<hir::Ty>],
Some(body)
}
// `fn(...) -> R` and `Trait(...) -> R` (both types and bounds).
hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None,
// Foreign `fn` decls are terrible because we messed up,
// and their return types get argument type elision.
// And now too much code out there is abusing this rule.
hir::map::NodeForeignItem(_) => {
let arg_scope = Scope::Elision {
elide: arg_elide,
s: self.scope
};
self.with(arg_scope, |_, this| this.visit_ty(output));
return;
}
// Foreign functions, `fn(...) -> R` and `Trait(...) -> R` (both types and bounds).
hir::map::NodeForeignItem(_) | hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None,
// Everything else (only closures?) doesn't
// actually enjoy elision in return types.

View File

@ -0,0 +1,16 @@
// Copyright 2017 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.
extern "C" {
fn g(_: &u8) -> &u8; // OK
fn f() -> &u8; //~ ERROR missing lifetime specifier
}
fn main() {}