Skip to content

Commit 8fc3deb

Browse files
committed
Remove sess field from LoweringContext.
1 parent 74be945 commit 8fc3deb

File tree

6 files changed

+69
-57
lines changed

6 files changed

+69
-57
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2424
) -> &'hir hir::InlineAsm<'hir> {
2525
// Rustdoc needs to support asm! from foreign architectures: don't try
2626
// lowering the register constraints in this case.
27-
let asm_arch = if self.sess.opts.actually_rustdoc { None } else { self.sess.asm_arch };
28-
if asm_arch.is_none() && !self.sess.opts.actually_rustdoc {
29-
struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target")
30-
.emit();
27+
let asm_arch =
28+
if self.tcx.sess.opts.actually_rustdoc { None } else { self.tcx.sess.asm_arch };
29+
if asm_arch.is_none() && !self.tcx.sess.opts.actually_rustdoc {
30+
struct_span_err!(
31+
self.tcx.sess,
32+
sp,
33+
E0472,
34+
"inline assembly is unsupported on this target"
35+
)
36+
.emit();
3137
}
3238
if let Some(asm_arch) = asm_arch {
3339
// Inline assembly is currently only stable for these architectures.
@@ -40,9 +46,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4046
| asm::InlineAsmArch::RiscV32
4147
| asm::InlineAsmArch::RiscV64
4248
);
43-
if !is_stable && !self.sess.features_untracked().asm_experimental_arch {
49+
if !is_stable && !self.tcx.features().asm_experimental_arch {
4450
feature_err(
45-
&self.sess.parse_sess,
51+
&self.tcx.sess.parse_sess,
4652
sym::asm_experimental_arch,
4753
sp,
4854
"inline assembly is not stable yet on this architecture",
@@ -52,17 +58,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5258
}
5359
if asm.options.contains(InlineAsmOptions::ATT_SYNTAX)
5460
&& !matches!(asm_arch, Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64))
55-
&& !self.sess.opts.actually_rustdoc
61+
&& !self.tcx.sess.opts.actually_rustdoc
5662
{
57-
self.sess
63+
self.tcx
64+
.sess
5865
.struct_span_err(sp, "the `att_syntax` option is only supported on x86")
5966
.emit();
6067
}
61-
if asm.options.contains(InlineAsmOptions::MAY_UNWIND)
62-
&& !self.sess.features_untracked().asm_unwind
63-
{
68+
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind {
6469
feature_err(
65-
&self.sess.parse_sess,
70+
&self.tcx.sess.parse_sess,
6671
sym::asm_unwind,
6772
sp,
6873
"the `may_unwind` option is unstable",
@@ -73,20 +78,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7378
let mut clobber_abis = FxHashMap::default();
7479
if let Some(asm_arch) = asm_arch {
7580
for (abi_name, abi_span) in &asm.clobber_abis {
76-
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.sess.target, *abi_name) {
81+
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {
7782
Ok(abi) => {
7883
// If the abi was already in the list, emit an error
7984
match clobber_abis.get(&abi) {
8085
Some((prev_name, prev_sp)) => {
81-
let mut err = self.sess.struct_span_err(
86+
let mut err = self.tcx.sess.struct_span_err(
8287
*abi_span,
8388
&format!("`{}` ABI specified multiple times", prev_name),
8489
);
8590
err.span_label(*prev_sp, "previously specified here");
8691

8792
// Multiple different abi names may actually be the same ABI
8893
// If the specified ABIs are not the same name, alert the user that they resolve to the same ABI
89-
let source_map = self.sess.source_map();
94+
let source_map = self.tcx.sess.source_map();
9095
if source_map.span_to_snippet(*prev_sp)
9196
!= source_map.span_to_snippet(*abi_span)
9297
{
@@ -101,16 +106,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
101106
}
102107
}
103108
Err(&[]) => {
104-
self.sess
109+
self.tcx
110+
.sess
105111
.struct_span_err(
106112
*abi_span,
107113
"`clobber_abi` is not supported on this target",
108114
)
109115
.emit();
110116
}
111117
Err(supported_abis) => {
112-
let mut err =
113-
self.sess.struct_span_err(*abi_span, "invalid ABI for `clobber_abi`");
118+
let mut err = self
119+
.tcx
120+
.sess
121+
.struct_span_err(*abi_span, "invalid ABI for `clobber_abi`");
114122
let mut abis = format!("`{}`", supported_abis[0]);
115123
for m in &supported_abis[1..] {
116124
let _ = write!(abis, ", `{}`", m);
@@ -128,7 +136,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
128136
// Lower operands to HIR. We use dummy register classes if an error
129137
// occurs during lowering because we still need to be able to produce a
130138
// valid HIR.
131-
let sess = self.sess;
139+
let sess = self.tcx.sess;
132140
let mut operands: Vec<_> = asm
133141
.operands
134142
.iter()
@@ -184,9 +192,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
184192
}
185193
}
186194
InlineAsmOperand::Const { ref anon_const } => {
187-
if !self.sess.features_untracked().asm_const {
195+
if !self.tcx.features().asm_const {
188196
feature_err(
189-
&self.sess.parse_sess,
197+
&sess.parse_sess,
190198
sym::asm_const,
191199
*op_sp,
192200
"const operands for inline assembly are unstable",
@@ -198,9 +206,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
198206
}
199207
}
200208
InlineAsmOperand::Sym { ref sym } => {
201-
if !self.sess.features_untracked().asm_sym {
209+
if !self.tcx.features().asm_sym {
202210
feature_err(
203-
&self.sess.parse_sess,
211+
&sess.parse_sess,
204212
sym::asm_sym,
205213
*op_sp,
206214
"sym operands for inline assembly are unstable",

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
159159
span,
160160
kind: hir::ExprKind::If(let_expr, then_expr, Some(else_expr)),
161161
});
162-
if !self.sess.features_untracked().let_else {
162+
if !self.tcx.features().let_else {
163163
feature_err(
164-
&self.sess.parse_sess,
164+
&self.tcx.sess.parse_sess,
165165
sym::let_else,
166166
local.span,
167167
"`let...else` statements are unstable",

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4646
let hir_id = self.lower_node_id(e.id);
4747
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
4848
} else {
49-
self.sess
49+
self.tcx.sess
5050
.struct_span_err(
5151
e.span,
5252
"#[rustc_box] requires precisely one argument \
@@ -207,8 +207,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
207207
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), lims)
208208
}
209209
ExprKind::Underscore => {
210-
self.sess
211-
.struct_span_err(
210+
self.tcx
211+
.sess.struct_span_err(
212212
e.span,
213213
"in expressions, `_` can only be used on the left-hand side of an assignment",
214214
)
@@ -245,7 +245,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
245245
let rest = match &se.rest {
246246
StructRest::Base(e) => Some(self.lower_expr(e)),
247247
StructRest::Rest(sp) => {
248-
self.sess
248+
self.tcx
249+
.sess
249250
.struct_span_err(*sp, "base expression required after `..`")
250251
.span_label(*sp, "add a base expression here")
251252
.emit();
@@ -474,7 +475,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
474475
} else {
475476
let try_span = this.mark_span_with_reason(
476477
DesugaringKind::TryBlock,
477-
this.sess.source_map().end_point(body.span),
478+
this.tcx.sess.source_map().end_point(body.span),
478479
this.allow_try_trait.clone(),
479480
);
480481

@@ -653,7 +654,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
653654
Some(hir::GeneratorKind::Async(_)) => {}
654655
Some(hir::GeneratorKind::Gen) | None => {
655656
let mut err = struct_span_err!(
656-
self.sess,
657+
self.tcx.sess,
657658
dot_await_span,
658659
E0728,
659660
"`await` is only allowed inside `async` functions and blocks"
@@ -878,7 +879,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
878879
Some(hir::GeneratorKind::Gen) => {
879880
if decl.inputs.len() > 1 {
880881
struct_span_err!(
881-
self.sess,
882+
self.tcx.sess,
882883
fn_decl_span,
883884
E0628,
884885
"too many parameters for a generator (expected 0 or 1 parameters)"
@@ -892,8 +893,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
892893
}
893894
None => {
894895
if movability == Movability::Static {
895-
struct_span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static")
896-
.emit();
896+
struct_span_err!(
897+
self.tcx.sess,
898+
fn_decl_span,
899+
E0697,
900+
"closures cannot be static"
901+
)
902+
.emit();
897903
}
898904
None
899905
}
@@ -916,7 +922,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
916922
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
917923
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
918924
struct_span_err!(
919-
this.sess,
925+
this.tcx.sess,
920926
fn_decl_span,
921927
E0708,
922928
"`async` non-`move` closures with parameters are not currently supported",
@@ -1163,7 +1169,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11631169
);
11641170
let fields_omitted = match &se.rest {
11651171
StructRest::Base(e) => {
1166-
self.sess
1172+
self.tcx
1173+
.sess
11671174
.struct_span_err(
11681175
e.span,
11691176
"functional record updates are not allowed in destructuring \
@@ -1371,7 +1378,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13711378
Some(hir::GeneratorKind::Gen) => {}
13721379
Some(hir::GeneratorKind::Async(_)) => {
13731380
struct_span_err!(
1374-
self.sess,
1381+
self.tcx.sess,
13751382
span,
13761383
E0727,
13771384
"`async` generators are not yet supported"
@@ -1516,7 +1523,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15161523
span,
15171524
self.allow_try_trait.clone(),
15181525
);
1519-
let try_span = self.sess.source_map().end_point(span);
1526+
let try_span = self.tcx.sess.source_map().end_point(span);
15201527
let try_span = self.mark_span_with_reason(
15211528
DesugaringKind::QuestionMark,
15221529
try_span,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5858
let mut lctx = LoweringContext {
5959
// Pseudo-globals.
6060
tcx: self.tcx,
61-
sess: &self.tcx.sess,
6261
resolver: self.resolver,
6362
arena: self.tcx.hir_arena,
6463

@@ -1268,7 +1267,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12681267
}
12691268

12701269
fn error_on_invalid_abi(&self, abi: StrLit) {
1271-
struct_span_err!(self.sess, abi.span, E0703, "invalid ABI: found `{}`", abi.symbol)
1270+
struct_span_err!(self.tcx.sess, abi.span, E0703, "invalid ABI: found `{}`", abi.symbol)
12721271
.span_label(abi.span, "invalid ABI")
12731272
.help(&format!("valid ABIs: {}", abi::all_names().join(", ")))
12741273
.emit();

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4949
use rustc_data_structures::sorted_map::SortedMap;
5050
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5151
use rustc_data_structures::sync::Lrc;
52-
use rustc_errors::{struct_span_err, Applicability};
52+
use rustc_errors::{struct_span_err, Applicability, Handler};
5353
use rustc_hir as hir;
5454
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5555
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
@@ -58,7 +58,6 @@ use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
5858
use rustc_index::vec::{Idx, IndexVec};
5959
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6060
use rustc_session::parse::feature_err;
61-
use rustc_session::Session;
6261
use rustc_span::hygiene::MacroKind;
6362
use rustc_span::source_map::DesugaringKind;
6463
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -83,7 +82,6 @@ mod path;
8382

8483
struct LoweringContext<'a, 'hir> {
8584
tcx: TyCtxt<'hir>,
86-
sess: &'hir Session,
8785
resolver: &'a mut ResolverAstLowering,
8886

8987
/// Used to allocate HIR nodes.
@@ -681,8 +679,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
681679
self.resolver.get_import_res(id).present_items()
682680
}
683681

684-
fn diagnostic(&self) -> &rustc_errors::Handler {
685-
self.sess.diagnostic()
682+
fn diagnostic(&self) -> &Handler {
683+
self.tcx.sess.diagnostic()
686684
}
687685

688686
/// Reuses the span but adds information like the kind of the desugaring and features that are
@@ -694,14 +692,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
694692
allow_internal_unstable: Option<Lrc<[Symbol]>>,
695693
) -> Span {
696694
self.tcx.with_stable_hashing_context(|hcx| {
697-
span.mark_with_reason(allow_internal_unstable, reason, self.sess.edition(), hcx)
695+
span.mark_with_reason(allow_internal_unstable, reason, self.tcx.sess.edition(), hcx)
698696
})
699697
}
700698

701699
/// Intercept all spans entering HIR.
702700
/// Mark a span as relative to the current owning item.
703701
fn lower_span(&self, span: Span) -> Span {
704-
if self.sess.opts.debugging_opts.incremental_relative_spans {
702+
if self.tcx.sess.opts.debugging_opts.incremental_relative_spans {
705703
span.with_parent(Some(self.current_hir_id_owner))
706704
} else {
707705
// Do not make spans relative when not using incremental compilation.
@@ -1048,7 +1046,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10481046
}
10491047

10501048
fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1051-
let mut err = self.sess.struct_span_err(
1049+
let mut err = self.tcx.sess.struct_span_err(
10521050
data.span,
10531051
"parenthesized generic arguments cannot be used in associated type constraints",
10541052
);
@@ -1093,7 +1091,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10931091
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
10941092
ast::GenericArg::Type(ty) => {
10951093
match ty.kind {
1096-
TyKind::Infer if self.sess.features_untracked().generic_arg_infer => {
1094+
TyKind::Infer if self.tcx.features().generic_arg_infer => {
10971095
return GenericArg::Infer(hir::InferArg {
10981096
hir_id: self.lower_node_id(ty.id),
10991097
span: self.lower_span(ty.span),
@@ -1190,7 +1188,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11901188
} else {
11911189
self.next_node_id()
11921190
};
1193-
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
1191+
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
11941192
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
11951193
});
11961194
let lifetime = self.lower_lifetime(&region);
@@ -1294,7 +1292,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12941292
}
12951293
ImplTraitContext::Disallowed(position) => {
12961294
let mut err = struct_span_err!(
1297-
self.sess,
1295+
self.tcx.sess,
12981296
t.span,
12991297
E0562,
13001298
"`impl Trait` only allowed in function and inherent method return types, not in {}",
@@ -1307,7 +1305,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13071305
}
13081306
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
13091307
TyKind::CVarArgs => {
1310-
self.sess.delay_span_bug(
1308+
self.tcx.sess.delay_span_bug(
13111309
t.span,
13121310
"`TyKind::CVarArgs` should have been handled elsewhere",
13131311
);
@@ -1912,7 +1910,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19121910
hir_id,
19131911
name,
19141912
span: self.lower_span(param.span()),
1915-
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
1913+
pure_wrt_drop: self.tcx.sess.contains_name(&param.attrs, sym::may_dangle),
19161914
kind,
19171915
colon_span: param.colon_span.map(|s| self.lower_span(s)),
19181916
}
@@ -2054,11 +2052,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20542052
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen {
20552053
match c.value.kind {
20562054
ExprKind::Underscore => {
2057-
if self.sess.features_untracked().generic_arg_infer {
2055+
if self.tcx.features().generic_arg_infer {
20582056
hir::ArrayLen::Infer(self.lower_node_id(c.id), c.value.span)
20592057
} else {
20602058
feature_err(
2061-
&self.sess.parse_sess,
2059+
&self.tcx.sess.parse_sess,
20622060
sym::generic_arg_infer,
20632061
c.value.span,
20642062
"using `_` for array lengths is unstable",

0 commit comments

Comments
 (0)