diff options
| author | Leah Hanson <astrieanna@gmail.com> | 2013-11-13 21:29:37 -0600 |
|---|---|---|
| committer | Leah Hanson <leah.a.hanson@gmail.com> | 2013-11-24 11:14:27 -0600 |
| commit | e1d1ad34f7d28eeb2af2e17097615b74498a1511 (patch) | |
| tree | f7bf4802880a2071f0ed76115e36bc00cef6e422 | |
| parent | 314d6f693f9442ab40879b58f34c6d0afb76f447 (diff) | |
| download | rust-e1d1ad34f7d28eeb2af2e17097615b74498a1511.tar.gz rust-e1d1ad34f7d28eeb2af2e17097615b74498a1511.zip | |
Fix issue #8763
* added case & better error message for "impl trait for module"
* used better way to print the module
* switched from //error-pattern to //~ ERROR
* added compile-fail test trait-impl-for-module.rs
* 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)
* added FIXME to trait-or-new-type-instead
| -rw-r--r-- | src/librustc/middle/typeck/astconv.rs | 11 | ||||
| -rw-r--r-- | src/test/compile-fail/trait-impl-for-module.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/trait-or-new-type-instead.rs | 6 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 57581306b5d..2ab3fc3502e 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -60,10 +60,11 @@ use middle::typeck::lookup_def_tcx; use std::vec; use syntax::abi::AbiSet; -use syntax::{ast, ast_util}; +use syntax::{ast, ast_map, ast_util}; use syntax::codemap::Span; use syntax::opt_vec::OptVec; use syntax::opt_vec; +use syntax::parse::token; use syntax::print::pprust::{lifetime_to_str, path_to_str}; pub trait AstConv { @@ -518,6 +519,12 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>( let did = ast_util::local_def(id); ty::mk_self(tcx, did) } + ast::DefMod(id) => { + tcx.sess.span_fatal(ast_ty.span, + format!("found module name used as a type: {}", + ast_map::node_id_to_str(tcx.items, id.node, + token::get_ident_interner()))); + } _ => { tcx.sess.span_fatal(ast_ty.span, format!("found value name used as a type: {:?}", a_def)); diff --git a/src/test/compile-fail/trait-impl-for-module.rs b/src/test/compile-fail/trait-impl-for-module.rs new file mode 100644 index 00000000000..28d20483c7e --- /dev/null +++ b/src/test/compile-fail/trait-impl-for-module.rs @@ -0,0 +1,21 @@ +// Copyright 2013 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. + +mod a { +} + +trait A { +} + +impl A for a { //~ERROR found module name used as a type +} + +fn main() { +} diff --git a/src/test/compile-fail/trait-or-new-type-instead.rs b/src/test/compile-fail/trait-or-new-type-instead.rs index c44887593ab..1a394aa8c9b 100644 --- a/src/test/compile-fail/trait-or-new-type-instead.rs +++ b/src/test/compile-fail/trait-or-new-type-instead.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: found value name used as a type -impl<T> Option<T> { +// FIXME(#8767) bad error message; Option is not a module +impl<T> Option<T> { //~ERROR found module name used as a type pub fn foo(&self) { } } |
