Skip to content

Commit f78ce41

Browse files
committed
astconv: don't use as_local_node_id for ids in a Def
Fixes #30535
1 parent c6ba7fe commit f78ce41

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
15131513
&base_segments[base_segments.len()-2],
15141514
base_segments.last().unwrap())
15151515
}
1516-
Def::Mod(id) => {
1516+
Def::Mod(..) => {
15171517
// Used as sentinel by callers to indicate the `<T>::A::B::C` form.
15181518
// FIXME(#22519) This part of the resolution logic should be
15191519
// avoided entirely for that form, once we stop needed a Def
@@ -1522,15 +1522,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
15221522
// resolve Self::Foo, at the moment we can't resolve the former because
15231523
// we don't have the trait information around, which is just sad.
15241524

1525-
if !base_segments.is_empty() {
1526-
let id_node = tcx.map.as_local_node_id(id).unwrap();
1527-
span_err!(tcx.sess,
1528-
span,
1529-
E0247,
1530-
"found module name used as a type: {}",
1531-
tcx.map.node_to_user_string(id_node));
1532-
return this.tcx().types.err;
1533-
}
1525+
assert!(base_segments.is_empty());
15341526

15351527
opt_self_ty.expect("missing T in <T>::a::b::c")
15361528
}
@@ -1541,10 +1533,9 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
15411533
return this.tcx().types.err;
15421534
}
15431535
_ => {
1544-
let id_node = tcx.map.as_local_node_id(def.def_id()).unwrap();
15451536
span_err!(tcx.sess, span, E0248,
15461537
"found value `{}` used as a type",
1547-
tcx.map.path_to_string(id_node));
1538+
tcx.item_path_str(def.def_id()));
15481539
return this.tcx().types.err;
15491540
}
15501541
}

src/librustc_typeck/diagnostics.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,24 +2565,6 @@ struct Bar<S, T> { x: Foo<S, T> }
25652565
```
25662566
"##,
25672567

2568-
//NB: not currently reachable
2569-
E0247: r##"
2570-
This error indicates an attempt to use a module name where a type is expected.
2571-
For example:
2572-
2573-
```
2574-
mod MyMod {
2575-
mod MySubMod { }
2576-
}
2577-
2578-
fn do_something(x: MyMod::MySubMod) { }
2579-
```
2580-
2581-
In this example, we're attempting to take a parameter of type `MyMod::MySubMod`
2582-
in the do_something function. This is not legal: `MyMod::MySubMod` is a module
2583-
name, not a type.
2584-
"##,
2585-
25862568
E0248: r##"
25872569
This error indicates an attempt to use a value where a type is expected. For
25882570
example:
@@ -3438,6 +3420,7 @@ register_diagnostics! {
34383420
E0242, // internal error looking up a definition
34393421
E0245, // not a trait
34403422
// E0246, // invalid recursive type
3423+
// E0247,
34413424
// E0319, // trait impls for defaulted traits allowed just for structs/enums
34423425
E0320, // recursive overflow during dropck
34433426
E0328, // cannot implement Unsize explicitly

src/test/auxiliary/issue-30535.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 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+
#![crate_type="lib"]
12+
13+
pub enum Foo {
14+
FooV { data: () }
15+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 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+
// aux-build:issue-30535.rs
12+
13+
extern crate issue_30535 as foo;
14+
15+
fn bar(
16+
_: foo::Foo::FooV //~ ERROR value `foo::Foo::FooV` used as a type
17+
) {}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)