mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Add checks for self: _
and self: &_
This commit is contained in:
parent
766f9b5a2f
commit
a62a690326
@ -775,6 +775,16 @@ impl<'a> LoweringContext<'a> {
|
||||
}
|
||||
|
||||
fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig {
|
||||
// Check for `self: _` and `self: &_`
|
||||
if let SelfKind::Explicit(ref ty, _) = sig.explicit_self.node {
|
||||
match sig.decl.inputs.get(0).and_then(Arg::to_self).map(|eself| eself.node) {
|
||||
Some(SelfKind::Value(..)) | Some(SelfKind::Region(..)) => {
|
||||
self.id_assigner.diagnostic().span_err(ty.span,
|
||||
"the type placeholder `_` is not allowed within types on item signatures");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
hir::MethodSig {
|
||||
generics: self.lower_generics(&sig.generics),
|
||||
abi: sig.abi,
|
||||
|
18
src/test/compile-fail/self-infer.rs
Normal file
18
src/test/compile-fail/self-infer.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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 S;
|
||||
|
||||
impl S {
|
||||
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
|
||||
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user