1
Fork 0

Remove Session methods that duplicate DiagCtxt methods.

Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
This commit is contained in:
Nicholas Nethercote 2023-12-18 22:21:37 +11:00
parent d51db05d7e
commit 99472c7049
298 changed files with 1806 additions and 2064 deletions

View file

@ -797,13 +797,13 @@ impl SyntaxExtension {
let const_stability = attr::find_const_stability(sess, attrs, span);
let body_stability = attr::find_body_stability(sess, attrs);
if let Some((_, sp)) = const_stability {
sess.emit_err(errors::MacroConstStability {
sess.dcx().emit_err(errors::MacroConstStability {
span: sp,
head_span: sess.source_map().guess_head_span(span),
});
}
if let Some((_, sp)) = body_stability {
sess.emit_err(errors::MacroBodyStability {
sess.dcx().emit_err(errors::MacroBodyStability {
span: sp,
head_span: sess.source_map().guess_head_span(span),
});

View file

@ -51,7 +51,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
let name = match mi.ident() {
Some(ident) if mi.is_word() => ident.name,
Some(ident) => {
sess.emit_err(MalformedFeatureAttribute {
sess.dcx().emit_err(MalformedFeatureAttribute {
span: mi.span(),
help: MalformedFeatureAttributeHelp::Suggestion {
span: mi.span(),
@ -61,7 +61,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
continue;
}
None => {
sess.emit_err(MalformedFeatureAttribute {
sess.dcx().emit_err(MalformedFeatureAttribute {
span: mi.span(),
help: MalformedFeatureAttributeHelp::Label { span: mi.span() },
});
@ -71,7 +71,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
// If the declared feature has been removed, issue an error.
if let Some(f) = REMOVED_FEATURES.iter().find(|f| name == f.feature.name) {
sess.emit_err(FeatureRemoved {
sess.dcx().emit_err(FeatureRemoved {
span: mi.span(),
reason: f.reason.map(|reason| FeatureRemovedReason { reason }),
});
@ -90,7 +90,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
// issue an error.
if let Some(allowed) = sess.opts.unstable_opts.allow_features.as_ref() {
if allowed.iter().all(|f| name.as_str() != f) {
sess.emit_err(FeatureNotAllowed { span: mi.span(), name });
sess.dcx().emit_err(FeatureNotAllowed { span: mi.span(), name });
continue;
}
}
@ -415,7 +415,7 @@ impl<'a> StripUnconfigured<'a> {
// N.B., this is intentionally not part of the visit_expr() function
// in order for filter_map_expr() to be able to avoid this check
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a)) {
self.sess.emit_err(RemoveExprNotSupported { span: attr.span });
self.sess.dcx().emit_err(RemoveExprNotSupported { span: attr.span });
}
self.process_cfg_attrs(expr);
@ -427,21 +427,21 @@ pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a Meta
let span = meta_item.span;
match meta_item.meta_item_list() {
None => {
sess.emit_err(InvalidCfg::NotFollowedByParens { span });
sess.dcx().emit_err(InvalidCfg::NotFollowedByParens { span });
None
}
Some([]) => {
sess.emit_err(InvalidCfg::NoPredicate { span });
sess.dcx().emit_err(InvalidCfg::NoPredicate { span });
None
}
Some([_, .., l]) => {
sess.emit_err(InvalidCfg::MultiplePredicates { span: l.span() });
sess.dcx().emit_err(InvalidCfg::MultiplePredicates { span: l.span() });
None
}
Some([single]) => match single.meta_item() {
Some(meta_item) => Some(meta_item),
None => {
sess.emit_err(InvalidCfg::PredicateLiteral { span: single.span() });
sess.dcx().emit_err(InvalidCfg::PredicateLiteral { span: single.span() });
None
}
},

View file

@ -435,7 +435,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
invocations = mem::take(&mut undetermined_invocations);
force = !mem::replace(&mut progress, false);
if force && self.monotonic {
self.cx.sess.span_delayed_bug(
self.cx.dcx().span_delayed_bug(
invocations.last().unwrap().0.span(),
"expansion entered force mode without producing any errors",
);

View file

@ -34,7 +34,10 @@ pub(super) fn failed_to_match_macro<'cx>(
if try_success_result.is_ok() {
// Nonterminal parser recovery might turn failed matches into successful ones,
// but for that it must have emitted an error already
tracker.cx.sess.span_delayed_bug(sp, "Macro matching returned a success on the second try");
tracker
.cx
.dcx()
.span_delayed_bug(sp, "Macro matching returned a success on the second try");
}
if let Some(result) = tracker.result {
@ -151,7 +154,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
Success(_) => {
// Nonterminal parser recovery might turn failed matches into successful ones,
// but for that it must have emitted an error already
self.cx.sess.span_delayed_bug(
self.cx.dcx().span_delayed_bug(
self.root_span,
"should not collect detailed info for successful macro match",
);

View file

@ -260,14 +260,14 @@ impl ModError<'_> {
let modules = paths.join(" -> ");
sess.emit_err(ModuleCircular { span, modules })
sess.dcx().emit_err(ModuleCircular { span, modules })
}
ModError::ModInBlock(ident) => sess.emit_err(ModuleInBlock {
ModError::ModInBlock(ident) => sess.dcx().emit_err(ModuleInBlock {
span,
name: ident.map(|name| ModuleInBlockName { span, name }),
}),
ModError::FileNotFound(name, default_path, secondary_path) => {
sess.emit_err(ModuleFileNotFound {
sess.dcx().emit_err(ModuleFileNotFound {
span,
name,
default_path: default_path.display().to_string(),
@ -275,7 +275,7 @@ impl ModError<'_> {
})
}
ModError::MultipleCandidates(name, default_path, secondary_path) => {
sess.emit_err(ModuleMultipleCandidates {
sess.dcx().emit_err(ModuleMultipleCandidates {
span,
name,
default_path: default_path.display().to_string(),

View file

@ -61,7 +61,7 @@ impl base::BangProcMacro for BangProcMacro {
let strategy = exec_strategy(ecx);
let server = proc_macro_server::Rustc::new(ecx);
self.client.run(&strategy, server, input, proc_macro_backtrace).map_err(|e| {
ecx.sess.emit_err(errors::ProcMacroPanicked {
ecx.dcx().emit_err(errors::ProcMacroPanicked {
span,
message: e
.as_str()
@ -180,7 +180,7 @@ impl MultiItemModifier for DeriveProcMacro {
// fail if there have been errors emitted
if ecx.dcx().err_count() > error_count_before {
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
ecx.dcx().emit_err(errors::ProcMacroDeriveTokens { span });
}
ExpandResult::Ready(items)