Skip to content

Commit d191de6

Browse files
committed
Prepare for adding a TyCtxt to Resolver
1 parent 7e253a7 commit d191de6

File tree

9 files changed

+247
-194
lines changed

9 files changed

+247
-194
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
133133
Some(self.new_module(
134134
parent,
135135
ModuleKind::Def(def_kind, def_id, name),
136-
self.cstore().module_expansion_untracked(def_id, &self.session),
137-
self.cstore().get_span_untracked(def_id, &self.session),
136+
self.cstore().module_expansion_untracked(def_id, &self.tcx.sess),
137+
self.cstore().get_span_untracked(def_id, &self.tcx.sess),
138138
// FIXME: Account for `#[no_implicit_prelude]` attributes.
139139
parent.map_or(false, |module| module.no_implicit_prelude),
140140
))
@@ -179,7 +179,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
179179
return macro_data.clone();
180180
}
181181

182-
let (ext, macro_rules) = match self.cstore().load_macro_untracked(def_id, &self.session) {
182+
let (ext, macro_rules) = match self.cstore().load_macro_untracked(def_id, &self.tcx.sess) {
183183
LoadedMacro::MacroDef(item, edition) => (
184184
Lrc::new(self.compile_macro(&item, edition).0),
185185
matches!(item.kind, ItemKind::MacroDef(def) if def.macro_rules),
@@ -205,7 +205,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
205205

206206
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
207207
for child in
208-
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.session))
208+
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess))
209209
{
210210
let parent_scope = ParentScope::module(module, self);
211211
BuildReducedGraphVisitor { r: self, parent_scope }
@@ -346,7 +346,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
346346

347347
fn insert_field_names_extern(&mut self, def_id: DefId) {
348348
let field_names =
349-
self.r.cstore().struct_field_names_untracked(def_id, self.r.session).collect();
349+
self.r.cstore().struct_field_names_untracked(def_id, self.r.tcx.sess).collect();
350350
self.r.field_names.insert(def_id, field_names);
351351
}
352352

@@ -539,14 +539,15 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
539539
}
540540

541541
self.r
542-
.session
542+
.tcx
543+
.sess
543544
.struct_span_err(item.span, "`$crate` may not be imported")
544545
.emit();
545546
}
546547
}
547548

548549
if ident.name == kw::Crate {
549-
self.r.session.span_err(
550+
self.r.tcx.sess.span_err(
550551
ident.span,
551552
"crate root imports need to be explicitly named: \
552553
`use crate as name;`",
@@ -575,7 +576,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
575576
}
576577
ast::UseTreeKind::Glob => {
577578
let kind = ImportKind::Glob {
578-
is_prelude: self.r.session.contains_name(&item.attrs, sym::prelude_import),
579+
is_prelude: self.r.tcx.sess.contains_name(&item.attrs, sym::prelude_import),
579580
max_vis: Cell::new(None),
580581
id,
581582
};
@@ -690,7 +691,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
690691
expansion.to_expn_id(),
691692
item.span,
692693
parent.no_implicit_prelude
693-
|| self.r.session.contains_name(&item.attrs, sym::no_implicit_prelude),
694+
|| self.r.tcx.sess.contains_name(&item.attrs, sym::no_implicit_prelude),
694695
);
695696
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
696697

@@ -755,7 +756,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
755756
// If the structure is marked as non_exhaustive then lower the visibility
756757
// to within the crate.
757758
let mut ctor_vis = if vis.is_public()
758-
&& self.r.session.contains_name(&item.attrs, sym::non_exhaustive)
759+
&& self.r.tcx.sess.contains_name(&item.attrs, sym::non_exhaustive)
759760
{
760761
ty::Visibility::Restricted(CRATE_DEF_ID)
761762
} else {
@@ -837,7 +838,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
837838

838839
let (used, module, binding) = if orig_name.is_none() && ident.name == kw::SelfLower {
839840
self.r
840-
.session
841+
.tcx
842+
.sess
841843
.struct_span_err(item.span, "`extern crate self;` requires renaming")
842844
.span_suggestion(
843845
item.span,
@@ -887,7 +889,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
887889
{
888890
let msg = "macro-expanded `extern crate` items cannot \
889891
shadow names passed with `--extern`";
890-
self.r.session.span_err(item.span, msg);
892+
self.r.tcx.sess.span_err(item.span, msg);
891893
}
892894
}
893895
let entry = self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(
@@ -1014,7 +1016,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10141016
}
10151017
Res::Def(DefKind::Union, def_id) => self.insert_field_names_extern(def_id),
10161018
Res::Def(DefKind::AssocFn, def_id) => {
1017-
if cstore.fn_has_self_parameter_untracked(def_id, self.r.session) {
1019+
if cstore.fn_has_self_parameter_untracked(def_id, self.r.tcx.sess) {
10181020
self.r.has_self.insert(def_id);
10191021
}
10201022
}
@@ -1033,7 +1035,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10331035
let msg = format!("`{}` is already in scope", name);
10341036
let note =
10351037
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
1036-
self.r.session.struct_span_err(span, &msg).note(note).emit();
1038+
self.r.tcx.sess.struct_span_err(span, &msg).note(note).emit();
10371039
}
10381040
}
10391041

@@ -1045,7 +1047,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10451047
if attr.has_name(sym::macro_use) {
10461048
if self.parent_scope.module.parent.is_some() {
10471049
struct_span_err!(
1048-
self.r.session,
1050+
self.r.tcx.sess,
10491051
item.span,
10501052
E0468,
10511053
"an `extern crate` loading macros must be at the crate root"
@@ -1055,7 +1057,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10551057
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
10561058
if orig_name == kw::SelfLower {
10571059
self.r
1058-
.session
1060+
.tcx
1061+
.sess
10591062
.struct_span_err(
10601063
attr.span,
10611064
"`#[macro_use]` is not supported on `extern crate self`",
@@ -1064,7 +1067,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10641067
}
10651068
}
10661069
let ill_formed = |span| {
1067-
struct_span_err!(self.r.session, span, E0466, "bad macro import").emit();
1070+
struct_span_err!(self.r.tcx.sess, span, E0466, "bad macro import").emit();
10681071
};
10691072
match attr.meta() {
10701073
Some(meta) => match meta.kind {
@@ -1135,8 +1138,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11351138
allow_shadowing,
11361139
);
11371140
} else {
1138-
struct_span_err!(self.r.session, ident.span, E0469, "imported macro not found")
1139-
.emit();
1141+
struct_span_err!(
1142+
self.r.tcx.sess,
1143+
ident.span,
1144+
E0469,
1145+
"imported macro not found"
1146+
)
1147+
.emit();
11401148
}
11411149
}
11421150
}
@@ -1148,7 +1156,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11481156
for attr in attrs {
11491157
if attr.has_name(sym::macro_escape) {
11501158
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
1151-
let mut err = self.r.session.struct_span_warn(attr.span, msg);
1159+
let mut err = self.r.tcx.sess.struct_span_warn(attr.span, msg);
11521160
if let ast::AttrStyle::Inner = attr.style {
11531161
err.help("try an outer attribute: `#[macro_use]`").emit();
11541162
} else {
@@ -1159,7 +1167,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11591167
}
11601168

11611169
if !attr.is_word() {
1162-
self.r.session.span_err(attr.span, "arguments to `macro_use` are not allowed here");
1170+
self.r
1171+
.tcx
1172+
.sess
1173+
.span_err(attr.span, "arguments to `macro_use` are not allowed here");
11631174
}
11641175
return true;
11651176
}
@@ -1183,11 +1194,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11831194
}
11841195

11851196
fn proc_macro_stub(&self, item: &ast::Item) -> Option<(MacroKind, Ident, Span)> {
1186-
if self.r.session.contains_name(&item.attrs, sym::proc_macro) {
1197+
if self.r.tcx.sess.contains_name(&item.attrs, sym::proc_macro) {
11871198
return Some((MacroKind::Bang, item.ident, item.span));
1188-
} else if self.r.session.contains_name(&item.attrs, sym::proc_macro_attribute) {
1199+
} else if self.r.tcx.sess.contains_name(&item.attrs, sym::proc_macro_attribute) {
11891200
return Some((MacroKind::Attr, item.ident, item.span));
1190-
} else if let Some(attr) = self.r.session.find_by_name(&item.attrs, sym::proc_macro_derive)
1201+
} else if let Some(attr) = self.r.tcx.sess.find_by_name(&item.attrs, sym::proc_macro_derive)
11911202
{
11921203
if let Some(nested_meta) = attr.meta_item_list().and_then(|list| list.get(0).cloned()) {
11931204
if let Some(ident) = nested_meta.ident() {
@@ -1222,7 +1233,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12221233
let def_id = self.r.local_def_id(item.id);
12231234
let (ext, ident, span, macro_rules, rule_spans) = match &item.kind {
12241235
ItemKind::MacroDef(def) => {
1225-
let (ext, rule_spans) = self.r.compile_macro(item, self.r.session.edition());
1236+
let (ext, rule_spans) = self.r.compile_macro(item, self.r.tcx.sess.edition());
12261237
let ext = Lrc::new(ext);
12271238
(ext, item.ident, item.span, def.macro_rules, rule_spans)
12281239
}
@@ -1243,7 +1254,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12431254
if macro_rules {
12441255
let ident = ident.normalize_to_macros_2_0();
12451256
self.r.macro_names.insert(ident);
1246-
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
1257+
let is_macro_export = self.r.tcx.sess.contains_name(&item.attrs, sym::macro_export);
12471258
let vis = if is_macro_export {
12481259
ty::Visibility::Public
12491260
} else {
@@ -1507,7 +1518,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
15071518

15081519
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
15091520
let ctor_vis = if vis.is_public()
1510-
&& self.r.session.contains_name(&variant.attrs, sym::non_exhaustive)
1521+
&& self.r.tcx.sess.contains_name(&variant.attrs, sym::non_exhaustive)
15111522
{
15121523
ty::Visibility::Restricted(CRATE_DEF_ID)
15131524
} else {

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl Resolver<'_, '_> {
290290
let ms = MultiSpan::from_spans(spans.clone());
291291
let mut span_snippets = spans
292292
.iter()
293-
.filter_map(|s| match visitor.r.session.source_map().span_to_snippet(*s) {
293+
.filter_map(|s| match visitor.r.tcx.sess.source_map().span_to_snippet(*s) {
294294
Ok(s) => Some(format!("`{}`", s)),
295295
_ => None,
296296
})
@@ -317,7 +317,7 @@ impl Resolver<'_, '_> {
317317
// If we are in the `--test` mode, suppress a help that adds the `#[cfg(test)]`
318318
// attribute; however, if not, suggest adding the attribute. There is no way to
319319
// retrieve attributes here because we do not have a `TyCtxt` yet.
320-
let test_module_span = if visitor.r.session.opts.test {
320+
let test_module_span = if visitor.r.tcx.sess.opts.test {
321321
None
322322
} else {
323323
let parent_module = visitor.r.get_nearest_non_block_module(

0 commit comments

Comments
 (0)