Skip to content

Commit 3f50dca

Browse files
committed
Auto merge of #27085 - Ryman:gh17546, r=alexcrichton
This also changes how variant values are printed in errors, they are no longer printed in their parent scope. As far as I can tell, this is leftover from pre-namespacing of enums. Closes #17546.
2 parents 81b6b91 + b416762 commit 3f50dca

File tree

6 files changed

+78
-27
lines changed

6 files changed

+78
-27
lines changed

src/librustc/ast_map/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,8 @@ impl<'ast> Map<'ast> {
498498
{
499499
let parent = self.get_parent(id);
500500
let parent = match self.find_entry(id) {
501-
Some(EntryForeignItem(..)) | Some(EntryVariant(..)) => {
502-
// Anonymous extern items, enum variants and struct ctors
503-
// go in the parent scope.
501+
Some(EntryForeignItem(..)) => {
502+
// Anonymous extern items go in the parent scope.
504503
self.get_parent(parent)
505504
}
506505
// But tuple struct ctors don't have names, so use the path of its

src/librustc_typeck/astconv.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,10 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
14761476
prim_ty_to_ty(tcx, base_segments, prim_ty)
14771477
}
14781478
_ => {
1479+
let node = def.def_id().node;
14791480
span_err!(tcx.sess, span, E0248,
1480-
"found value name used as a type: {:?}", *def);
1481+
"found value `{}` used as a type",
1482+
tcx.map.path_to_string(node));
14811483
return this.tcx().types.err;
14821484
}
14831485
}

src/test/compile-fail/enum-variant-type-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 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
//
@@ -14,6 +14,6 @@ enum Foo {
1414
Bar
1515
}
1616

17-
fn foo(x: Foo::Bar) {} //~ERROR found value name used as a type
17+
fn foo(x: Foo::Bar) {} //~ERROR found value `Foo::Bar` used as a type
1818

1919
fn main() {}

src/test/compile-fail/issue-17546.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
use foo::MyEnum::Result;
12+
use foo::NoResult; // Through a re-export
13+
14+
mod foo {
15+
pub use self::MyEnum::NoResult;
16+
17+
enum MyEnum {
18+
Result,
19+
NoResult
20+
}
21+
22+
fn new() -> NoResult<MyEnum, String> {
23+
//~^ ERROR: found value `foo::MyEnum::NoResult` used as a type
24+
unimplemented!()
25+
}
26+
}
27+
28+
mod bar {
29+
use foo::MyEnum::Result;
30+
use foo;
31+
32+
fn new() -> Result<foo::MyEnum, String> {
33+
//~^ ERROR: found value `foo::MyEnum::Result` used as a type
34+
unimplemented!()
35+
}
36+
}
37+
38+
fn new() -> Result<foo::MyEnum, String> {
39+
//~^ ERROR: found value `foo::MyEnum::Result` used as a type
40+
unimplemented!()
41+
}
42+
43+
fn newer() -> NoResult<foo::MyEnum, String> {
44+
//~^ ERROR: found value `foo::MyEnum::NoResult` used as a type
45+
unimplemented!()
46+
}
47+
48+
fn main() {
49+
let _ = new();
50+
}

src/test/compile-fail/move-fragments-2.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 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
//
@@ -30,7 +30,7 @@ pub enum Lonely<X,Y> { Zero, One(X), Two(X, Y) }
3030
#[rustc_move_fragments]
3131
pub fn test_match_partial(p: Lonely<D, D>) {
3232
//~^ ERROR parent_of_fragments: `$(local p)`
33-
//~| ERROR assigned_leaf_path: `($(local p) as Zero)`
33+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
3434
match p {
3535
Zero(..) => {}
3636
_ => {}
@@ -40,9 +40,9 @@ pub fn test_match_partial(p: Lonely<D, D>) {
4040
#[rustc_move_fragments]
4141
pub fn test_match_full(p: Lonely<D, D>) {
4242
//~^ ERROR parent_of_fragments: `$(local p)`
43-
//~| ERROR assigned_leaf_path: `($(local p) as Zero)`
44-
//~| ERROR assigned_leaf_path: `($(local p) as One)`
45-
//~| ERROR assigned_leaf_path: `($(local p) as Two)`
43+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
44+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::One)`
45+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)`
4646
match p {
4747
Zero(..) => {}
4848
One(..) => {}
@@ -53,10 +53,10 @@ pub fn test_match_full(p: Lonely<D, D>) {
5353
#[rustc_move_fragments]
5454
pub fn test_match_bind_one(p: Lonely<D, D>) {
5555
//~^ ERROR parent_of_fragments: `$(local p)`
56-
//~| ERROR assigned_leaf_path: `($(local p) as Zero)`
57-
//~| ERROR parent_of_fragments: `($(local p) as One)`
58-
//~| ERROR moved_leaf_path: `($(local p) as One).#0`
59-
//~| ERROR assigned_leaf_path: `($(local p) as Two)`
56+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
57+
//~| ERROR parent_of_fragments: `($(local p) as Lonely::One)`
58+
//~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0`
59+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)`
6060
//~| ERROR assigned_leaf_path: `$(local data)`
6161
match p {
6262
Zero(..) => {}
@@ -68,13 +68,13 @@ pub fn test_match_bind_one(p: Lonely<D, D>) {
6868
#[rustc_move_fragments]
6969
pub fn test_match_bind_many(p: Lonely<D, D>) {
7070
//~^ ERROR parent_of_fragments: `$(local p)`
71-
//~| ERROR assigned_leaf_path: `($(local p) as Zero)`
72-
//~| ERROR parent_of_fragments: `($(local p) as One)`
73-
//~| ERROR moved_leaf_path: `($(local p) as One).#0`
71+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
72+
//~| ERROR parent_of_fragments: `($(local p) as Lonely::One)`
73+
//~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0`
7474
//~| ERROR assigned_leaf_path: `$(local data)`
75-
//~| ERROR parent_of_fragments: `($(local p) as Two)`
76-
//~| ERROR moved_leaf_path: `($(local p) as Two).#0`
77-
//~| ERROR moved_leaf_path: `($(local p) as Two).#1`
75+
//~| ERROR parent_of_fragments: `($(local p) as Lonely::Two)`
76+
//~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#0`
77+
//~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#1`
7878
//~| ERROR assigned_leaf_path: `$(local left)`
7979
//~| ERROR assigned_leaf_path: `$(local right)`
8080
match p {

src/test/compile-fail/move-fragments-3.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 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
//
@@ -30,11 +30,11 @@ pub enum Lonely<X,Y> { Zero, One(X), Two(X, Y) }
3030
#[rustc_move_fragments]
3131
pub fn test_match_bind_and_underscore(p: Lonely<D, D>) {
3232
//~^ ERROR parent_of_fragments: `$(local p)`
33-
//~| ERROR assigned_leaf_path: `($(local p) as Zero)`
34-
//~| ERROR assigned_leaf_path: `($(local p) as One)`
35-
//~| ERROR parent_of_fragments: `($(local p) as Two)`
36-
//~| ERROR moved_leaf_path: `($(local p) as Two).#0`
37-
//~| ERROR unmoved_fragment: `($(local p) as Two).#1`
33+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
34+
//~| ERROR assigned_leaf_path: `($(local p) as Lonely::One)`
35+
//~| ERROR parent_of_fragments: `($(local p) as Lonely::Two)`
36+
//~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#0`
37+
//~| ERROR unmoved_fragment: `($(local p) as Lonely::Two).#1`
3838
//~| ERROR assigned_leaf_path: `$(local left)`
3939

4040
match p {

0 commit comments

Comments
 (0)