diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-05-08 21:19:29 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-05-14 13:42:37 +0300 |
| commit | a62a6903268a68e793407aca05a64e89b8b22f1b (patch) | |
| tree | 76e04ac0e8bdb60a97eeb78861cd81e6bb03d0d3 /src | |
| parent | 766f9b5a2ff2973bc18eddc91b988a2fe476b0a1 (diff) | |
Add checks for `self: _` and `self: &_`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/hir/lowering.rs | 10 | ||||
| -rw-r--r-- | src/test/compile-fail/self-infer.rs | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d6a29b03764..0c3c190064b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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, diff --git a/src/test/compile-fail/self-infer.rs b/src/test/compile-fail/self-infer.rs new file mode 100644 index 00000000000..fd011318a48 --- /dev/null +++ b/src/test/compile-fail/self-infer.rs @@ -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() {} |
