Skip to content

Commit b3ff24a

Browse files
committed
auto merge of #10475 : astrieanna/rust/issue8763, r=alexcrichton
Issue #8763 is about improving a particular error message. * added case & better error message for "impl trait for module" * added compile-fail test trait-impl-for-module.rs * updated copyright dates * revised compile-fail test trait-or-new-type-instead (the error message for the modified test is still unclear, but that's a different bug #8767)
2 parents 01b5381 + e1d1ad3 commit b3ff24a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/librustc/middle/typeck/astconv.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -60,10 +60,11 @@ use middle::typeck::lookup_def_tcx;
6060

6161
use std::vec;
6262
use syntax::abi::AbiSet;
63-
use syntax::{ast, ast_util};
63+
use syntax::{ast, ast_map, ast_util};
6464
use syntax::codemap::Span;
6565
use syntax::opt_vec::OptVec;
6666
use syntax::opt_vec;
67+
use syntax::parse::token;
6768
use syntax::print::pprust::{lifetime_to_str, path_to_str};
6869

6970
pub trait AstConv {
@@ -519,6 +520,12 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
519520
let did = ast_util::local_def(id);
520521
ty::mk_self(tcx, did)
521522
}
523+
ast::DefMod(id) => {
524+
tcx.sess.span_fatal(ast_ty.span,
525+
format!("found module name used as a type: {}",
526+
ast_map::node_id_to_str(tcx.items, id.node,
527+
token::get_ident_interner())));
528+
}
522529
_ => {
523530
tcx.sess.span_fatal(ast_ty.span,
524531
format!("found value name used as a type: {:?}", a_def));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
mod a {
12+
}
13+
14+
trait A {
15+
}
16+
17+
impl A for a { //~ERROR found module name used as a type
18+
}
19+
20+
fn main() {
21+
}

src/test/compile-fail/trait-or-new-type-instead.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: found value name used as a type
12-
impl<T> Option<T> {
11+
// FIXME(#8767) bad error message; Option is not a module
12+
impl<T> Option<T> { //~ERROR found module name used as a type
1313
pub fn foo(&self) { }
1414
}
1515

0 commit comments

Comments
 (0)