Use usual lifetime elision rules for foreign functions
This commit is contained in:
parent
5c7add7551
commit
7704762604
@ -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.
|
||||
|
16
src/test/compile-fail/foreign-fn-return-lifetime.rs
Normal file
16
src/test/compile-fail/foreign-fn-return-lifetime.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user