Skip to content

Commit a62a690

Browse files
committed
Add checks for self: _ and self: &_
1 parent 766f9b5 commit a62a690

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustc/hir/lowering.rs

+10
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,16 @@ impl<'a> LoweringContext<'a> {
775775
}
776776

777777
fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig {
778+
// Check for `self: _` and `self: &_`
779+
if let SelfKind::Explicit(ref ty, _) = sig.explicit_self.node {
780+
match sig.decl.inputs.get(0).and_then(Arg::to_self).map(|eself| eself.node) {
781+
Some(SelfKind::Value(..)) | Some(SelfKind::Region(..)) => {
782+
self.id_assigner.diagnostic().span_err(ty.span,
783+
"the type placeholder `_` is not allowed within types on item signatures");
784+
}
785+
_ => {}
786+
}
787+
}
778788
hir::MethodSig {
779789
generics: self.lower_generics(&sig.generics),
780790
abi: sig.abi,

src/test/compile-fail/self-infer.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S;
12+
13+
impl S {
14+
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
15+
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)