Skip to content

Commit 2878529

Browse files
committed
Eliminate redundant .parse_sess in rustc_attr::builtin errors
1 parent f5429a0 commit 2878529

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

compiler/rustc_attr/src/builtin.rs

+23-34
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ pub fn find_stability(
200200
sym::rustc_allowed_through_unstable_modules => allowed_through_unstable_modules = true,
201201
sym::unstable => {
202202
if stab.is_some() {
203-
sess.parse_sess
204-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
203+
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
205204
break;
206205
}
207206

@@ -211,8 +210,7 @@ pub fn find_stability(
211210
}
212211
sym::stable => {
213212
if stab.is_some() {
214-
sess.parse_sess
215-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
213+
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
216214
break;
217215
}
218216
if let Some((feature, level)) = parse_stability(sess, attr) {
@@ -256,8 +254,7 @@ pub fn find_const_stability(
256254
sym::rustc_promotable => promotable = true,
257255
sym::rustc_const_unstable => {
258256
if const_stab.is_some() {
259-
sess.parse_sess
260-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
257+
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
261258
break;
262259
}
263260

@@ -268,8 +265,7 @@ pub fn find_const_stability(
268265
}
269266
sym::rustc_const_stable => {
270267
if const_stab.is_some() {
271-
sess.parse_sess
272-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
268+
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
273269
break;
274270
}
275271
if let Some((feature, level)) = parse_stability(sess, attr) {
@@ -303,8 +299,7 @@ pub fn find_body_stability(
303299
for attr in attrs {
304300
if attr.has_name(sym::rustc_default_body_unstable) {
305301
if body_stab.is_some() {
306-
sess.parse_sess
307-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
302+
sess.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
308303
break;
309304
}
310305

@@ -319,7 +314,7 @@ pub fn find_body_stability(
319314

320315
fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -> Option<()> {
321316
if item.is_some() {
322-
sess.parse_sess.emit_err(session_diagnostics::MultipleItem {
317+
sess.emit_err(session_diagnostics::MultipleItem {
323318
span: meta.span,
324319
item: pprust::path_to_string(&meta.path),
325320
});
@@ -343,11 +338,11 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
343338
let mut since = None;
344339
for meta in metas {
345340
let Some(mi) = meta.meta_item() else {
346-
sess.parse_sess.emit_err(session_diagnostics::UnsupportedLiteral {
341+
sess.emit_err(session_diagnostics::UnsupportedLiteral {
347342
span: meta.span(),
348343
reason: UnsupportedLiteralReason::Generic,
349344
is_bytestr: false,
350-
start_point_span: sess.parse_sess.source_map().start_point(meta.span()),
345+
start_point_span: sess.source_map().start_point(meta.span()),
351346
});
352347
return None;
353348
};
@@ -356,7 +351,7 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
356351
sym::feature => insert_or_error(sess, mi, &mut feature)?,
357352
sym::since => insert_or_error(sess, mi, &mut since)?,
358353
_ => {
359-
sess.parse_sess.emit_err(session_diagnostics::UnknownMetaItem {
354+
sess.emit_err(session_diagnostics::UnknownMetaItem {
360355
span: meta.span(),
361356
item: pprust::path_to_string(&mi.path),
362357
expected: &["feature", "since"],
@@ -378,11 +373,11 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
378373
Some((feature, level))
379374
}
380375
(None, _) => {
381-
sess.parse_sess.emit_err(session_diagnostics::MissingFeature { span: attr.span });
376+
sess.emit_err(session_diagnostics::MissingFeature { span: attr.span });
382377
None
383378
}
384379
_ => {
385-
sess.parse_sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
380+
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
386381
None
387382
}
388383
}
@@ -402,11 +397,11 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
402397
let mut implied_by = None;
403398
for meta in metas {
404399
let Some(mi) = meta.meta_item() else {
405-
sess.parse_sess.emit_err(session_diagnostics::UnsupportedLiteral {
400+
sess.emit_err(session_diagnostics::UnsupportedLiteral {
406401
span: meta.span(),
407402
reason: UnsupportedLiteralReason::Generic,
408403
is_bytestr: false,
409-
start_point_span: sess.parse_sess.source_map().start_point(meta.span()),
404+
start_point_span: sess.source_map().start_point(meta.span()),
410405
});
411406
return None;
412407
};
@@ -446,7 +441,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
446441
}
447442
sym::implied_by => insert_or_error(sess, mi, &mut implied_by)?,
448443
_ => {
449-
sess.parse_sess.emit_err(session_diagnostics::UnknownMetaItem {
444+
sess.emit_err(session_diagnostics::UnknownMetaItem {
450445
span: meta.span(),
451446
item: pprust::path_to_string(&mi.path),
452447
expected: &["feature", "reason", "issue", "soft", "implied_by"],
@@ -459,7 +454,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
459454
match (feature, reason, issue) {
460455
(Some(feature), reason, Some(_)) => {
461456
if !rustc_lexer::is_ident(feature.as_str()) {
462-
sess.parse_sess.emit_err(session_diagnostics::NonIdentFeature { span: attr.span });
457+
sess.emit_err(session_diagnostics::NonIdentFeature { span: attr.span });
463458
return None;
464459
}
465460
let level = StabilityLevel::Unstable {
@@ -471,7 +466,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
471466
Some((feature, level))
472467
}
473468
(None, _, _) => {
474-
sess.parse_sess.emit_err(session_diagnostics::MissingFeature { span: attr.span });
469+
sess.emit_err(session_diagnostics::MissingFeature { span: attr.span });
475470
return None;
476471
}
477472
_ => {
@@ -753,7 +748,7 @@ pub fn find_deprecation(
753748
MetaItemKind::List(list) => {
754749
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
755750
if item.is_some() {
756-
sess.parse_sess.emit_err(session_diagnostics::MultipleItem {
751+
sess.emit_err(session_diagnostics::MultipleItem {
757752
span: meta.span,
758753
item: pprust::path_to_string(&meta.path),
759754
});
@@ -764,14 +759,11 @@ pub fn find_deprecation(
764759
true
765760
} else {
766761
if let Some(lit) = meta.name_value_literal() {
767-
sess.parse_sess.emit_err(session_diagnostics::UnsupportedLiteral {
762+
sess.emit_err(session_diagnostics::UnsupportedLiteral {
768763
span: lit.span,
769764
reason: UnsupportedLiteralReason::DeprecatedString,
770765
is_bytestr: lit.kind.is_bytestr(),
771-
start_point_span: sess
772-
.parse_sess
773-
.source_map()
774-
.start_point(lit.span),
766+
start_point_span: sess.source_map().start_point(lit.span),
775767
});
776768
} else {
777769
sess.emit_err(session_diagnostics::IncorrectMetaItem {
@@ -810,7 +802,7 @@ pub fn find_deprecation(
810802
}
811803
}
812804
_ => {
813-
sess.parse_sess.emit_err(session_diagnostics::UnknownMetaItem {
805+
sess.emit_err(session_diagnostics::UnknownMetaItem {
814806
span: meta.span(),
815807
item: pprust::path_to_string(&mi.path),
816808
expected: if features.deprecated_suggestion {
@@ -823,14 +815,11 @@ pub fn find_deprecation(
823815
}
824816
},
825817
NestedMetaItem::Lit(lit) => {
826-
sess.parse_sess.emit_err(session_diagnostics::UnsupportedLiteral {
818+
sess.emit_err(session_diagnostics::UnsupportedLiteral {
827819
span: lit.span,
828820
reason: UnsupportedLiteralReason::DeprecatedKvPair,
829821
is_bytestr: false,
830-
start_point_span: sess
831-
.parse_sess
832-
.source_map()
833-
.start_point(lit.span),
822+
start_point_span: sess.source_map().start_point(lit.span),
834823
});
835824
continue 'outer;
836825
}
@@ -841,7 +830,7 @@ pub fn find_deprecation(
841830

842831
if is_rustc {
843832
if since.is_none() {
844-
sess.parse_sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
833+
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
845834
continue;
846835
}
847836

0 commit comments

Comments
 (0)