Skip to content

Commit 3da5a5c

Browse files
committed
auto merge of #14253 : alexcrichton/rust/issue-14221, r=pcwalton
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
2 parents 20b502b + 7cbec55 commit 3da5a5c

File tree

10 files changed

+52
-42
lines changed

10 files changed

+52
-42
lines changed

src/compiletest/runtest.rs

+2-1
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

+1-1
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

+1-1
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

+2-1
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

+16-32
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)
@@ -2849,9 +2844,7 @@ impl<'a> Resolver<'a> {
28492844
fn resolve_item_in_lexical_scope(&mut self,
28502845
module_: Rc<Module>,
28512846
name: Ident,
2852-
namespace: Namespace,
2853-
search_through_modules:
2854-
SearchThroughModulesFlag)
2847+
namespace: Namespace)
28552848
-> ResolveResult<(Target, bool)> {
28562849
debug!("(resolving item in lexical scope) resolving `{}` in \
28572850
namespace {:?} in `{}`",
@@ -2924,26 +2917,19 @@ impl<'a> Resolver<'a> {
29242917
return Failed;
29252918
}
29262919
ModuleParentLink(parent_module_node, _) => {
2927-
match search_through_modules {
2928-
DontSearchThroughModules => {
2929-
match search_module.kind.get() {
2930-
NormalModuleKind => {
2931-
// We stop the search here.
2932-
debug!("(resolving item in lexical \
2933-
scope) unresolved module: not \
2934-
searching through module \
2935-
parents");
2936-
return Failed;
2937-
}
2938-
ExternModuleKind |
2939-
TraitModuleKind |
2940-
ImplModuleKind |
2941-
AnonymousModuleKind => {
2942-
search_module = parent_module_node.upgrade().unwrap();
2943-
}
2944-
}
2920+
match search_module.kind.get() {
2921+
NormalModuleKind => {
2922+
// We stop the search here.
2923+
debug!("(resolving item in lexical \
2924+
scope) unresolved module: not \
2925+
searching through module \
2926+
parents");
2927+
return Failed;
29452928
}
2946-
SearchThroughModules => {
2929+
ExternModuleKind |
2930+
TraitModuleKind |
2931+
ImplModuleKind |
2932+
AnonymousModuleKind => {
29472933
search_module = parent_module_node.upgrade().unwrap();
29482934
}
29492935
}
@@ -2988,7 +2974,7 @@ impl<'a> Resolver<'a> {
29882974
// If this module is an anonymous module, resolve the item in the
29892975
// lexical scope. Otherwise, resolve the item from the crate root.
29902976
let resolve_result = self.resolve_item_in_lexical_scope(
2991-
module_, name, TypeNS, DontSearchThroughModules);
2977+
module_, name, TypeNS);
29922978
match resolve_result {
29932979
Success((target, _)) => {
29942980
let bindings = &*target.bindings;
@@ -4517,8 +4503,7 @@ impl<'a> Resolver<'a> {
45174503
let module = self.current_module.clone();
45184504
match self.resolve_item_in_lexical_scope(module,
45194505
name,
4520-
ValueNS,
4521-
SearchThroughModules) {
4506+
ValueNS) {
45224507
Success((target, _)) => {
45234508
debug!("(resolve bare identifier pattern) succeeded in \
45244509
finding {} at {:?}",
@@ -4859,8 +4844,7 @@ impl<'a> Resolver<'a> {
48594844
let module = self.current_module.clone();
48604845
match self.resolve_item_in_lexical_scope(module,
48614846
ident,
4862-
namespace,
4863-
DontSearchThroughModules) {
4847+
namespace) {
48644848
Success((target, _)) => {
48654849
match (*target.bindings).def_for_namespace(namespace) {
48664850
None => {

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

+1-1
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

-1
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

+1-1
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

+3-3
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

+25
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)