Skip to content

Commit 4d98cbb

Browse files
committed
Forbid associated items in inherent impls
Closes #20359
1 parent 9f1ead8 commit 4d98cbb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc_typeck/collect.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,11 @@ fn convert(ccx: &CollectCtxt, it: &ast::Item) {
607607
methods.push(&**method);
608608
}
609609
ast::TypeImplItem(ref typedef) => {
610+
if opt_trait_ref.is_none() {
611+
tcx.sess.span_err(typedef.span,
612+
"associated items are not allowed in inherent impls");
613+
}
614+
610615
let typ = ccx.to_ty(&ExplicitRscope, &*typedef.typ);
611616
tcx.tcache
612617
.borrow_mut()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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+
// Test associated types are forbidden in inherant impls.
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
type Bar = int; //~ERROR associated items are not allowed in inherent impls
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)