Skip to content

Commit 5a32da5

Browse files
committed
rebasing and reviewer changes
Primarily refactoring `(Ident, Option<NodeId>)` to `Segment`
1 parent edb0831 commit 5a32da5

File tree

7 files changed

+157
-134
lines changed

7 files changed

+157
-134
lines changed

src/librustc/hir/lowering.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,6 @@ impl<'a> LoweringContext<'a> {
13811381
// does not actually exist in the AST.
13821382
lctx.items.insert(exist_ty_id.node_id, exist_ty_item);
13831383

1384-
let def = Def::Existential(DefId::local(exist_ty_def_index));
13851384
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`
13861385
hir::TyKind::Def(hir::ItemId { id: exist_ty_id.node_id }, lifetimes)
13871386
})

src/librustc_resolve/build_reduced_graph.rs

+34-39
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use macros::{InvocationData, ParentScope, LegacyScope};
1717
use resolve_imports::ImportDirective;
1818
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
19-
use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, ToNameBinding};
19+
use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segment, ToNameBinding};
2020
use {ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas};
2121
use Namespace::{self, TypeNS, ValueNS, MacroNS};
2222
use {resolve_error, resolve_struct_error, ResolutionError};
@@ -121,7 +121,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
121121
use_tree: &ast::UseTree,
122122
id: NodeId,
123123
vis: ty::Visibility,
124-
parent_prefix: &[Ident],
124+
parent_prefix: &[Segment],
125125
mut uniform_paths_canary_emitted: bool,
126126
nested: bool,
127127
item: &Item,
@@ -138,10 +138,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
138138
self.session.features_untracked().uniform_paths;
139139

140140
let prefix_iter = || parent_prefix.iter().cloned()
141-
.chain(use_tree.prefix.segments.iter().map(|seg| seg.ident));
141+
.chain(use_tree.prefix.segments.iter().map(|seg| seg.into()));
142142
let prefix_start = prefix_iter().nth(0);
143-
let starts_with_non_keyword = prefix_start.map_or(false, |(ident, _)| {
144-
!ident.is_path_segment_keyword()
143+
let starts_with_non_keyword = prefix_start.map_or(false, |seg| {
144+
!seg.ident.is_path_segment_keyword()
145145
});
146146

147147
// Imports are resolved as global by default, prepend `CrateRoot`,
@@ -155,7 +155,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
155155
};
156156
let root = if inject_crate_root {
157157
let span = use_tree.prefix.span.shrink_to_lo();
158-
Some(Ident::new(keywords::CrateRoot.name(), span))
158+
Some(Segment::from_ident(Ident::new(keywords::CrateRoot.name(), span)))
159159
} else {
160160
None
161161
};
@@ -201,13 +201,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
201201
let source = prefix_start.unwrap();
202202

203203
// Helper closure to emit a canary with the given base path.
204-
let emit = |this: &mut Self, base: Option<(Ident, Option<NodeId>)>| {
204+
let emit = |this: &mut Self, base: Option<Segment>| {
205205
let subclass = SingleImport {
206206
target: Ident {
207207
name: keywords::Underscore.name().gensymed(),
208-
span: source.0.span,
208+
span: source.ident.span,
209209
},
210-
source: source.0,
210+
source: source.ident,
211211
result: PerNS {
212212
type_ns: Cell::new(Err(Undetermined)),
213213
value_ns: Cell::new(Err(Undetermined)),
@@ -218,7 +218,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
218218
this.add_import_directive(
219219
base.into_iter().collect(),
220220
subclass.clone(),
221-
source.0.span,
221+
source.ident.span,
222222
id,
223223
root_use_tree.span,
224224
root_id,
@@ -229,15 +229,18 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
229229
};
230230

231231
// A single simple `self::x` canary.
232-
emit(self, Some((Ident {
233-
name: keywords::SelfValue.name(),
234-
span: source.0.span,
235-
}, source.1)));
232+
emit(self, Some(Segment {
233+
ident: Ident {
234+
name: keywords::SelfValue.name(),
235+
span: source.ident.span,
236+
},
237+
id: source.id
238+
}));
236239

237240
// One special unprefixed canary per block scope around
238241
// the import, to detect items unreachable by `self::x`.
239242
let orig_current_module = self.current_module;
240-
let mut span = source.0.span.modern();
243+
let mut span = source.ident.span.modern();
241244
loop {
242245
match self.current_module.kind {
243246
ModuleKind::Block(..) => emit(self, None),
@@ -264,11 +267,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
264267

265268
if nested {
266269
// Correctly handle `self`
267-
if source.0.name == keywords::SelfValue.name() {
270+
if source.ident.name == keywords::SelfValue.name() {
268271
type_ns_only = true;
269272

270-
let empty_prefix = module_path.last().map_or(true, |(ident, _)| {
271-
ident.name == keywords::CrateRoot.name()
273+
let empty_prefix = module_path.last().map_or(true, |seg| {
274+
seg.ident.name == keywords::CrateRoot.name()
272275
});
273276
if empty_prefix {
274277
resolve_error(
@@ -283,20 +286,20 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
283286
// Replace `use foo::self;` with `use foo;`
284287
source = module_path.pop().unwrap();
285288
if rename.is_none() {
286-
ident = source.0;
289+
ident = source.ident;
287290
}
288291
}
289292
} else {
290293
// Disallow `self`
291-
if source.0.name == keywords::SelfValue.name() {
294+
if source.ident.name == keywords::SelfValue.name() {
292295
resolve_error(self,
293296
use_tree.span,
294297
ResolutionError::SelfImportsOnlyAllowedWithin);
295298
}
296299

297300
// Disallow `use $crate;`
298-
if source.0.name == keywords::DollarCrate.name() && module_path.is_empty() {
299-
let crate_root = self.resolve_crate_root(source.0);
301+
if source.ident.name == keywords::DollarCrate.name() && module_path.is_empty() {
302+
let crate_root = self.resolve_crate_root(source.ident);
300303
let crate_name = match crate_root.kind {
301304
ModuleKind::Def(_, name) => name,
302305
ModuleKind::Block(..) => unreachable!(),
@@ -306,11 +309,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
306309
// while the current crate doesn't have a valid `crate_name`.
307310
if crate_name != keywords::Invalid.name() {
308311
// `crate_name` should not be interpreted as relative.
309-
module_path.push((Ident {
310-
name: keywords::CrateRoot.name(),
311-
span: source.0.span,
312-
}, Some(self.session.next_node_id())));
313-
source.0.name = crate_name;
312+
module_path.push(Segment {
313+
ident: Ident {
314+
name: keywords::CrateRoot.name(),
315+
span: source.ident.span,
316+
},
317+
id: Some(self.session.next_node_id()),
318+
});
319+
source.ident.name = crate_name;
314320
}
315321
if rename.is_none() {
316322
ident.name = crate_name;
@@ -331,7 +337,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
331337

332338
let subclass = SingleImport {
333339
target: ident,
334-
source: source.0,
340+
source: source.ident,
335341
result: PerNS {
336342
type_ns: Cell::new(Err(Undetermined)),
337343
value_ns: Cell::new(Err(Undetermined)),
@@ -391,17 +397,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
391397
e.emit();
392398
}
393399

394-
let prefix = ast::Path {
395-
segments: module_path.into_iter()
396-
.map(|(ident, id)| {
397-
let mut seg = ast::PathSegment::from_ident(ident);
398-
seg.id = id.expect("Missing node id");
399-
seg
400-
})
401-
.collect(),
402-
span: path.span,
403-
};
404-
405400
for &(ref tree, id) in items {
406401
self.build_reduced_graph_for_use_tree(
407402
root_use_tree,

src/librustc_resolve/error_reporting.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use {CrateLint, PathResult};
11+
use {CrateLint, PathResult, Segment};
1212

1313
use std::collections::BTreeSet;
1414

@@ -23,8 +23,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
2323
pub(crate) fn make_path_suggestion(
2424
&mut self,
2525
span: Span,
26-
path: Vec<Ident>
27-
) -> Option<Vec<Ident>> {
26+
path: Vec<Segment>
27+
) -> Option<Vec<Segment>> {
2828
debug!("make_path_suggestion: span={:?} path={:?}", span, path);
2929
// If we don't have a path to suggest changes to, then return.
3030
if path.is_empty() {
@@ -37,13 +37,13 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
3737

3838
match (path.get(0), path.get(1)) {
3939
// Make suggestions that require at least two non-special path segments.
40-
(Some(fst), Some(snd)) if !is_special(*fst) && !is_special(*snd) => {
40+
(Some(fst), Some(snd)) if !is_special(fst.ident) && !is_special(snd.ident) => {
4141
debug!("make_path_suggestion: fst={:?} snd={:?}", fst, snd);
4242

4343
self.make_missing_self_suggestion(span, path.clone())
4444
.or_else(|| self.make_missing_crate_suggestion(span, path.clone()))
4545
.or_else(|| self.make_missing_super_suggestion(span, path.clone()))
46-
.or_else(|| self.make_external_crate_suggestion(span, path.clone()))
46+
.or_else(|| self.make_external_crate_suggestion(span, path))
4747
},
4848
_ => None,
4949
}
@@ -59,10 +59,10 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
5959
fn make_missing_self_suggestion(
6060
&mut self,
6161
span: Span,
62-
mut path: Vec<Ident>
63-
) -> Option<Vec<Ident>> {
62+
mut path: Vec<Segment>
63+
) -> Option<Vec<Segment>> {
6464
// Replace first ident with `self` and check if that is valid.
65-
path[0].name = keywords::SelfValue.name();
65+
path[0].ident.name = keywords::SelfValue.name();
6666
let result = self.resolve_path(None, &path, None, false, span, CrateLint::No);
6767
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
6868
if let PathResult::Module(..) = result {
@@ -82,10 +82,10 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
8282
fn make_missing_crate_suggestion(
8383
&mut self,
8484
span: Span,
85-
mut path: Vec<Ident>
86-
) -> Option<Vec<Ident>> {
85+
mut path: Vec<Segment>
86+
) -> Option<Vec<Segment>> {
8787
// Replace first ident with `crate` and check if that is valid.
88-
path[0].name = keywords::Crate.name();
88+
path[0].ident.name = keywords::Crate.name();
8989
let result = self.resolve_path(None, &path, None, false, span, CrateLint::No);
9090
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
9191
if let PathResult::Module(..) = result {
@@ -105,10 +105,10 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
105105
fn make_missing_super_suggestion(
106106
&mut self,
107107
span: Span,
108-
mut path: Vec<Ident>
109-
) -> Option<Vec<Ident>> {
108+
mut path: Vec<Segment>
109+
) -> Option<Vec<Segment>> {
110110
// Replace first ident with `crate` and check if that is valid.
111-
path[0].name = keywords::Super.name();
111+
path[0].ident.name = keywords::Super.name();
112112
let result = self.resolve_path(None, &path, None, false, span, CrateLint::No);
113113
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
114114
if let PathResult::Module(..) = result {
@@ -131,8 +131,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
131131
fn make_external_crate_suggestion(
132132
&mut self,
133133
span: Span,
134-
mut path: Vec<Ident>
135-
) -> Option<Vec<Ident>> {
134+
mut path: Vec<Segment>
135+
) -> Option<Vec<Segment>> {
136136
// Need to clone else we can't call `resolve_path` without a borrow error. We also store
137137
// into a `BTreeMap` so we can get consistent ordering (and therefore the same diagnostic)
138138
// each time.
@@ -152,7 +152,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
152152
if let Some(_) = self.crate_loader.maybe_process_path_extern(*name, ident.span) {
153153
// Replace the first after root (a placeholder we inserted) with a crate name
154154
// and check if that is valid.
155-
path[1].name = *name;
155+
path[1].ident.name = *name;
156156
let result = self.resolve_path(None, &path, None, false, span, CrateLint::No);
157157
debug!("make_external_crate_suggestion: name={:?} path={:?} result={:?}",
158158
name, path, result);
@@ -162,8 +162,6 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
162162
}
163163
}
164164

165-
// Remove our placeholder segment.
166-
path.remove(1);
167165
None
168166
}
169167
}

0 commit comments

Comments
 (0)