Skip to content

Commit 7cbec55

Browse files
committed
rustc: Stop leaking enum variants into children
This plugs a leak where resolve was treating enums defined in parent modules as in-scope for all children modules when resolving a pattern identifier. This eliminates the code path in resolve entirely. If this breaks any existing code, then it indicates that the variants need to be explicitly imported into the module. Closes #14221 [breaking-change]
1 parent 25c5422 commit 7cbec55

File tree

10 files changed

+52
-42
lines changed

10 files changed

+52
-42
lines changed

src/compiletest/runtest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// except according to those terms.
1010

1111
use common::Config;
12-
use common::{CompileFail, Pretty, RunFail, RunPass, DebugInfoGdb, DebugInfoLldb};
12+
use common::{CompileFail, Pretty, RunFail, RunPass, DebugInfoGdb};
13+
use common::{Codegen, DebugInfoLldb};
1314
use errors;
1415
use header::TestProps;
1516
use header;

src/libcollections/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl<'a> Iterator<uint> for SetItems<'a> {
634634

635635
#[cfg(test)]
636636
mod test_map {
637-
use super::{TrieMap, TrieNode, Internal, External};
637+
use super::{TrieMap, TrieNode, Internal, External, Nothing};
638638
use std::iter::range_step;
639639
use std::uint;
640640

src/libgreen/sched.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ mod test {
10281028
use {TaskState, PoolConfig, SchedPool};
10291029
use basic;
10301030
use sched::{TaskFromFriend, PinnedTask};
1031-
use task::{GreenTask, HomeSched};
1031+
use task::{GreenTask, HomeSched, AnySched};
10321032

10331033
fn pool() -> SchedPool {
10341034
SchedPool::new(PoolConfig {

src/librustc/driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use back::link;
1313
use driver::session::Session;
1414
use driver::{config, PpMode};
15-
use driver::PpmFlowGraph; // FIXME (#14221).
15+
use driver::{PpmFlowGraph, PpmExpanded, PpmExpandedIdentified, PpmTyped};
16+
use driver::{PpmIdentified};
1617
use front;
1718
use lib::llvm::{ContextRef, ModuleRef};
1819
use metadata::common::LinkMeta;

src/librustc/middle/resolve.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ enum UseLexicalScopeFlag {
283283
UseLexicalScope
284284
}
285285

286-
enum SearchThroughModulesFlag {
287-
DontSearchThroughModules,
288-
SearchThroughModules
289-
}
290-
291286
enum ModulePrefixResult {
292287
NoPrefixFound,
293288
PrefixFound(Rc<Module>, uint)
@@ -2846,9 +2841,7 @@ impl<'a> Resolver<'a> {
28462841
fn resolve_item_in_lexical_scope(&mut self,
28472842
module_: Rc<Module>,
28482843
name: Ident,
2849-
namespace: Namespace,
2850-
search_through_modules:
2851-
SearchThroughModulesFlag)
2844+
namespace: Namespace)
28522845
-> ResolveResult<(Target, bool)> {
28532846
debug!("(resolving item in lexical scope) resolving `{}` in \
28542847
namespace {:?} in `{}`",
@@ -2921,26 +2914,19 @@ impl<'a> Resolver<'a> {
29212914
return Failed;
29222915
}
29232916
ModuleParentLink(parent_module_node, _) => {
2924-
match search_through_modules {
2925-
DontSearchThroughModules => {
2926-
match search_module.kind.get() {
2927-
NormalModuleKind => {
2928-
// We stop the search here.
2929-
debug!("(resolving item in lexical \
2930-
scope) unresolved module: not \
2931-
searching through module \
2932-
parents");
2933-
return Failed;
2934-
}
2935-
ExternModuleKind |
2936-
TraitModuleKind |
2937-
ImplModuleKind |
2938-
AnonymousModuleKind => {
2939-
search_module = parent_module_node.upgrade().unwrap();
2940-
}
2941-
}
2917+
match search_module.kind.get() {
2918+
NormalModuleKind => {
2919+
// We stop the search here.
2920+
debug!("(resolving item in lexical \
2921+
scope) unresolved module: not \
2922+
searching through module \
2923+
parents");
2924+
return Failed;
29422925
}
2943-
SearchThroughModules => {
2926+
ExternModuleKind |
2927+
TraitModuleKind |
2928+
ImplModuleKind |
2929+
AnonymousModuleKind => {
29442930
search_module = parent_module_node.upgrade().unwrap();
29452931
}
29462932
}
@@ -2985,7 +2971,7 @@ impl<'a> Resolver<'a> {
29852971
// If this module is an anonymous module, resolve the item in the
29862972
// lexical scope. Otherwise, resolve the item from the crate root.
29872973
let resolve_result = self.resolve_item_in_lexical_scope(
2988-
module_, name, TypeNS, DontSearchThroughModules);
2974+
module_, name, TypeNS);
29892975
match resolve_result {
29902976
Success((target, _)) => {
29912977
let bindings = &*target.bindings;
@@ -4514,8 +4500,7 @@ impl<'a> Resolver<'a> {
45144500
let module = self.current_module.clone();
45154501
match self.resolve_item_in_lexical_scope(module,
45164502
name,
4517-
ValueNS,
4518-
SearchThroughModules) {
4503+
ValueNS) {
45194504
Success((target, _)) => {
45204505
debug!("(resolve bare identifier pattern) succeeded in \
45214506
finding {} at {:?}",
@@ -4856,8 +4841,7 @@ impl<'a> Resolver<'a> {
48564841
let module = self.current_module.clone();
48574842
match self.resolve_item_in_lexical_scope(module,
48584843
ident,
4859-
namespace,
4860-
DontSearchThroughModules) {
4844+
namespace) {
48614845
Success((target, _)) => {
48624846
match (*target.bindings).def_for_namespace(namespace) {
48634847
None => {

src/librustc/middle/typeck/infer/lub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
use middle::ty::{BuiltinBounds};
1312
use middle::ty::RegionVid;
1413
use middle::ty;
@@ -25,6 +24,7 @@ use collections::HashMap;
2524
use syntax::ast::{Many, Once, NodeId};
2625
use syntax::ast::{NormalFn, UnsafeFn};
2726
use syntax::ast::{Onceness, FnStyle};
27+
use syntax::ast::{MutMutable, MutImmutable};
2828
use util::ppaux::mt_to_str;
2929

3030
pub struct Lub<'f>(pub CombineFields<'f>); // least-upper-bound: common supertype

src/librustc/middle/typeck/infer/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use middle::typeck::infer::unify::{ValsAndBindings, Root};
3939
use middle::typeck::infer::error_reporting::ErrorReporting;
4040
use std::cell::{Cell, RefCell};
4141
use std::rc::Rc;
42-
use syntax::ast::{MutImmutable, MutMutable};
4342
use syntax::ast;
4443
use syntax::codemap;
4544
use syntax::codemap::Span;

src/librustc/middle/typeck/infer/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use middle::typeck::infer::{TypeTrace, Subtype};
2525
use util::common::{indenter};
2626
use util::ppaux::bound_region_to_str;
2727

28-
use syntax::ast::{Onceness, FnStyle};
28+
use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable};
2929

3030
pub struct Sub<'f>(pub CombineFields<'f>); // "subtype", "subregion" etc
3131

src/libstd/io/mem.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use vec::Vec;
2323
fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> {
2424
// compute offset as signed and clamp to prevent overflow
2525
let pos = match seek {
26-
SeekSet => 0,
27-
SeekEnd => end,
28-
SeekCur => cur,
26+
io::SeekSet => 0,
27+
io::SeekEnd => end,
28+
io::SeekCur => cur,
2929
} as i64;
3030

3131
if offset + pos < 0 {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 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+
pub enum E {
12+
A,
13+
B,
14+
}
15+
16+
pub mod b {
17+
pub fn key(e: ::E) -> &'static str {
18+
match e {
19+
A => "A",
20+
B => "B", //~ ERROR: unreachable pattern
21+
}
22+
}
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)