From f78ce412ef7b5137f91976dd93fb18865118ebae Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Fri, 22 Jan 2016 21:23:51 +0200 Subject: [PATCH] astconv: don't use as_local_node_id for ids in a Def Fixes #30535 --- src/librustc_typeck/astconv.rs | 15 +++------------ src/librustc_typeck/diagnostics.rs | 19 +------------------ src/test/auxiliary/issue-30535.rs | 15 +++++++++++++++ src/test/compile-fail/issue-30535.rs | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 src/test/auxiliary/issue-30535.rs create mode 100644 src/test/compile-fail/issue-30535.rs diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index da4265dda54d7..d67f5f9db5ee4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1513,7 +1513,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>, &base_segments[base_segments.len()-2], base_segments.last().unwrap()) } - Def::Mod(id) => { + Def::Mod(..) => { // Used as sentinel by callers to indicate the `::A::B::C` form. // FIXME(#22519) This part of the resolution logic should be // avoided entirely for that form, once we stop needed a Def @@ -1522,15 +1522,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>, // resolve Self::Foo, at the moment we can't resolve the former because // we don't have the trait information around, which is just sad. - if !base_segments.is_empty() { - let id_node = tcx.map.as_local_node_id(id).unwrap(); - span_err!(tcx.sess, - span, - E0247, - "found module name used as a type: {}", - tcx.map.node_to_user_string(id_node)); - return this.tcx().types.err; - } + assert!(base_segments.is_empty()); opt_self_ty.expect("missing T in ::a::b::c") } @@ -1541,10 +1533,9 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>, return this.tcx().types.err; } _ => { - let id_node = tcx.map.as_local_node_id(def.def_id()).unwrap(); span_err!(tcx.sess, span, E0248, "found value `{}` used as a type", - tcx.map.path_to_string(id_node)); + tcx.item_path_str(def.def_id())); return this.tcx().types.err; } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 55a1021f0fb94..fdc23f89de237 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2565,24 +2565,6 @@ struct Bar { x: Foo } ``` "##, -//NB: not currently reachable -E0247: r##" -This error indicates an attempt to use a module name where a type is expected. -For example: - -``` -mod MyMod { - mod MySubMod { } -} - -fn do_something(x: MyMod::MySubMod) { } -``` - -In this example, we're attempting to take a parameter of type `MyMod::MySubMod` -in the do_something function. This is not legal: `MyMod::MySubMod` is a module -name, not a type. -"##, - E0248: r##" This error indicates an attempt to use a value where a type is expected. For example: @@ -3438,6 +3420,7 @@ register_diagnostics! { E0242, // internal error looking up a definition E0245, // not a trait // E0246, // invalid recursive type +// E0247, // E0319, // trait impls for defaulted traits allowed just for structs/enums E0320, // recursive overflow during dropck E0328, // cannot implement Unsize explicitly diff --git a/src/test/auxiliary/issue-30535.rs b/src/test/auxiliary/issue-30535.rs new file mode 100644 index 0000000000000..8d44e8d101616 --- /dev/null +++ b/src/test/auxiliary/issue-30535.rs @@ -0,0 +1,15 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type="lib"] + +pub enum Foo { + FooV { data: () } +} diff --git a/src/test/compile-fail/issue-30535.rs b/src/test/compile-fail/issue-30535.rs new file mode 100644 index 0000000000000..93f3086d05771 --- /dev/null +++ b/src/test/compile-fail/issue-30535.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-30535.rs + +extern crate issue_30535 as foo; + +fn bar( + _: foo::Foo::FooV //~ ERROR value `foo::Foo::FooV` used as a type +) {} + +fn main() {}