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:
parent
d51db05d7e
commit
99472c7049
298 changed files with 1806 additions and 2064 deletions
|
@ -524,12 +524,12 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
ident.name = crate_name;
|
||||
}
|
||||
|
||||
self.r.tcx.sess.emit_err(errors::CrateImported { span: item.span });
|
||||
self.r.dcx().emit_err(errors::CrateImported { span: item.span });
|
||||
}
|
||||
}
|
||||
|
||||
if ident.name == kw::Crate {
|
||||
self.r.tcx.sess.span_err(
|
||||
self.r.dcx().span_err(
|
||||
ident.span,
|
||||
"crate root imports need to be explicitly named: \
|
||||
`use crate as name;`",
|
||||
|
@ -816,8 +816,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
|
||||
let (used, module, binding) = if orig_name.is_none() && ident.name == kw::SelfLower {
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
||||
.span_suggestion(
|
||||
item.span,
|
||||
|
@ -867,7 +866,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
if expansion != LocalExpnId::ROOT && orig_name.is_some() && !entry.is_import() {
|
||||
let msg = "macro-expanded `extern crate` items cannot \
|
||||
shadow names passed with `--extern`";
|
||||
self.r.tcx.sess.span_err(item.span, msg);
|
||||
self.r.dcx().span_err(item.span, msg);
|
||||
// `return` is intended to discard this binding because it's an
|
||||
// unregistered ambiguity error which would result in a panic
|
||||
// caused by inconsistency `path_res`
|
||||
|
@ -1000,7 +999,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
let msg = format!("`{name}` is already in scope");
|
||||
let note =
|
||||
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
|
||||
self.r.tcx.sess.struct_span_err(span, msg).note(note).emit();
|
||||
self.r.dcx().struct_span_err(span, msg).note(note).emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1012,7 +1011,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
if attr.has_name(sym::macro_use) {
|
||||
if self.parent_scope.module.parent.is_some() {
|
||||
struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
item.span,
|
||||
E0468,
|
||||
"an `extern crate` loading macros must be at the crate root"
|
||||
|
@ -1021,14 +1020,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
}
|
||||
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
|
||||
if orig_name == kw::SelfLower {
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
|
||||
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
|
||||
}
|
||||
}
|
||||
let ill_formed = |span| {
|
||||
struct_span_err!(self.r.tcx.sess, span, E0466, "bad macro import").emit();
|
||||
struct_span_err!(self.r.dcx(), span, E0466, "bad macro import").emit();
|
||||
};
|
||||
match attr.meta() {
|
||||
Some(meta) => match meta.kind {
|
||||
|
@ -1099,13 +1095,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
allow_shadowing,
|
||||
);
|
||||
} else {
|
||||
struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
ident.span,
|
||||
E0469,
|
||||
"imported macro not found"
|
||||
)
|
||||
.emit();
|
||||
struct_span_err!(self.r.dcx(), ident.span, E0469, "imported macro not found")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1117,7 +1108,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
for attr in attrs {
|
||||
if attr.has_name(sym::macro_escape) {
|
||||
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
|
||||
let mut err = self.r.tcx.sess.struct_span_warn(attr.span, msg);
|
||||
let mut err = self.r.dcx().struct_span_warn(attr.span, msg);
|
||||
if let ast::AttrStyle::Inner = attr.style {
|
||||
err.help("try an outer attribute: `#[macro_use]`").emit();
|
||||
} else {
|
||||
|
@ -1128,10 +1119,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
}
|
||||
|
||||
if !attr.is_word() {
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.span_err(attr.span, "arguments to `macro_use` are not allowed here");
|
||||
self.r.dcx().span_err(attr.span, "arguments to `macro_use` are not allowed here");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@ use rustc_ast::{self as ast, Crate, ItemKind, ModKind, NodeId, Path, CRATE_NODE_
|
|||
use rustc_ast::{MetaItemKind, NestedMetaItem};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{pluralize, report_ambiguity_error, struct_span_err, SuggestionStyle};
|
||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{
|
||||
pluralize, report_ambiguity_error, struct_span_err, Applicability, DiagCtxt, Diagnostic,
|
||||
DiagnosticBuilder, ErrorGuaranteed, MultiSpan, SuggestionStyle,
|
||||
};
|
||||
use rustc_feature::BUILTIN_ATTRIBUTES;
|
||||
use rustc_hir::def::Namespace::{self, *};
|
||||
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
|
||||
|
@ -116,6 +118,10 @@ fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
pub(crate) fn dcx(&self) -> &'tcx DiagCtxt {
|
||||
self.tcx.dcx()
|
||||
}
|
||||
|
||||
pub(crate) fn report_errors(&mut self, krate: &Crate) {
|
||||
self.report_with_use_injections(krate);
|
||||
|
||||
|
@ -145,7 +151,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
BuiltinLintDiagnostics::AmbiguousGlobImports { diag },
|
||||
);
|
||||
} else {
|
||||
let mut err = struct_span_err!(self.tcx.sess, diag.span, E0659, "{}", &diag.msg);
|
||||
let mut err = struct_span_err!(self.dcx(), diag.span, E0659, "{}", &diag.msg);
|
||||
report_ambiguity_error(&mut err, diag);
|
||||
err.emit();
|
||||
}
|
||||
|
@ -246,15 +252,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let msg = format!("the name `{name}` is defined multiple times");
|
||||
|
||||
let mut err = match (old_binding.is_extern_crate(), new_binding.is_extern_crate()) {
|
||||
(true, true) => struct_span_err!(self.tcx.sess, span, E0259, "{}", msg),
|
||||
(true, true) => struct_span_err!(self.dcx(), span, E0259, "{}", msg),
|
||||
(true, _) | (_, true) => match new_binding.is_import() && old_binding.is_import() {
|
||||
true => struct_span_err!(self.tcx.sess, span, E0254, "{}", msg),
|
||||
false => struct_span_err!(self.tcx.sess, span, E0260, "{}", msg),
|
||||
true => struct_span_err!(self.dcx(), span, E0254, "{}", msg),
|
||||
false => struct_span_err!(self.dcx(), span, E0260, "{}", msg),
|
||||
},
|
||||
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
|
||||
(false, false) => struct_span_err!(self.tcx.sess, span, E0428, "{}", msg),
|
||||
(true, true) => struct_span_err!(self.tcx.sess, span, E0252, "{}", msg),
|
||||
_ => struct_span_err!(self.tcx.sess, span, E0255, "{}", msg),
|
||||
(false, false) => struct_span_err!(self.dcx(), span, E0428, "{}", msg),
|
||||
(true, true) => struct_span_err!(self.dcx(), span, E0252, "{}", msg),
|
||||
_ => struct_span_err!(self.dcx(), span, E0255, "{}", msg),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -566,7 +572,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let def_id = match outer_res {
|
||||
Res::SelfTyParam { .. } => {
|
||||
err.label = Some(Label::SelfTyParam(span));
|
||||
return self.tcx.sess.create_err(err);
|
||||
return self.dcx().create_err(err);
|
||||
}
|
||||
Res::SelfTyAlias { alias_to: def_id, .. } => {
|
||||
err.label = Some(Label::SelfTyAlias(reduce_impl_span_to_impl_keyword(
|
||||
|
@ -574,7 +580,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.def_span(def_id),
|
||||
)));
|
||||
err.refer_to_type_directly = Some(span);
|
||||
return self.tcx.sess.create_err(err);
|
||||
return self.dcx().create_err(err);
|
||||
}
|
||||
Res::Def(DefKind::TyParam, def_id) => {
|
||||
err.label = Some(Label::TyParam(self.def_span(def_id)));
|
||||
|
@ -606,14 +612,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
err.sugg = Some(errs::GenericParamsFromOuterItemSugg { span, snippet });
|
||||
}
|
||||
|
||||
self.tcx.sess.create_err(err)
|
||||
self.dcx().create_err(err)
|
||||
}
|
||||
ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::NameAlreadyUsedInParameterList { span, first_use_span, name }),
|
||||
ResolutionError::MethodNotMemberOfTrait(method, trait_, candidate) => {
|
||||
self.tcx.sess.create_err(errs::MethodNotMemberOfTrait {
|
||||
self.dcx().create_err(errs::MethodNotMemberOfTrait {
|
||||
span,
|
||||
method,
|
||||
trait_,
|
||||
|
@ -624,7 +629,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
ResolutionError::TypeNotMemberOfTrait(type_, trait_, candidate) => {
|
||||
self.tcx.sess.create_err(errs::TypeNotMemberOfTrait {
|
||||
self.dcx().create_err(errs::TypeNotMemberOfTrait {
|
||||
span,
|
||||
type_,
|
||||
trait_,
|
||||
|
@ -635,7 +640,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
ResolutionError::ConstNotMemberOfTrait(const_, trait_, candidate) => {
|
||||
self.tcx.sess.create_err(errs::ConstNotMemberOfTrait {
|
||||
self.dcx().create_err(errs::ConstNotMemberOfTrait {
|
||||
span,
|
||||
const_,
|
||||
trait_,
|
||||
|
@ -653,7 +658,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
let msp = MultiSpan::from_spans(target_sp.clone());
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
self.dcx(),
|
||||
msp,
|
||||
E0408,
|
||||
"variable `{}` is not bound in all patterns",
|
||||
|
@ -706,19 +711,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
err
|
||||
}
|
||||
ResolutionError::VariableBoundWithDifferentMode(variable_name, first_binding_span) => {
|
||||
self.tcx.sess.create_err(errs::VariableBoundWithDifferentMode {
|
||||
self.dcx().create_err(errs::VariableBoundWithDifferentMode {
|
||||
span,
|
||||
first_binding_span,
|
||||
variable_name,
|
||||
})
|
||||
}
|
||||
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::IdentifierBoundMoreThanOnceInParameterList { span, identifier }),
|
||||
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::IdentifierBoundMoreThanOnceInSamePattern { span, identifier }),
|
||||
ResolutionError::UndeclaredLabel { name, suggestion } => {
|
||||
let ((sub_reachable, sub_reachable_suggestion), sub_unreachable) = match suggestion
|
||||
|
@ -744,7 +747,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// No similarly-named labels exist.
|
||||
None => ((None, None), None),
|
||||
};
|
||||
self.tcx.sess.create_err(errs::UndeclaredLabel {
|
||||
self.dcx().create_err(errs::UndeclaredLabel {
|
||||
span,
|
||||
name,
|
||||
sub_reachable,
|
||||
|
@ -769,22 +772,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
};
|
||||
(Some(suggestion), Some(mpart_suggestion))
|
||||
};
|
||||
self.tcx.sess.create_err(errs::SelfImportsOnlyAllowedWithin {
|
||||
self.dcx().create_err(errs::SelfImportsOnlyAllowedWithin {
|
||||
span,
|
||||
suggestion,
|
||||
mpart_suggestion,
|
||||
})
|
||||
}
|
||||
ResolutionError::SelfImportCanOnlyAppearOnceInTheList => {
|
||||
self.tcx.sess.create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span })
|
||||
self.dcx().create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span })
|
||||
}
|
||||
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => {
|
||||
self.dcx().create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span })
|
||||
}
|
||||
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => self
|
||||
.tcx
|
||||
.sess
|
||||
.create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }),
|
||||
ResolutionError::FailedToResolve { last_segment, label, suggestion, module } => {
|
||||
let mut err =
|
||||
struct_span_err!(self.tcx.sess, span, E0433, "failed to resolve: {}", &label);
|
||||
struct_span_err!(self.dcx(), span, E0433, "failed to resolve: {}", &label);
|
||||
err.span_label(span, label);
|
||||
|
||||
if let Some((suggestions, msg, applicability)) = suggestion {
|
||||
|
@ -805,7 +807,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
err
|
||||
}
|
||||
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
|
||||
self.tcx.sess.create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
||||
self.dcx().create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
||||
}
|
||||
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, suggestion, current) => {
|
||||
// let foo =...
|
||||
|
@ -844,7 +846,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
),
|
||||
};
|
||||
|
||||
self.tcx.sess.create_err(errs::AttemptToUseNonConstantValueInConstant {
|
||||
self.dcx().create_err(errs::AttemptToUseNonConstantValueInConstant {
|
||||
span,
|
||||
with,
|
||||
with_label,
|
||||
|
@ -858,7 +860,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
article,
|
||||
shadowed_binding,
|
||||
shadowed_binding_span,
|
||||
} => self.tcx.sess.create_err(errs::BindingShadowsSomethingUnacceptable {
|
||||
} => self.dcx().create_err(errs::BindingShadowsSomethingUnacceptable {
|
||||
span,
|
||||
shadowing_binding,
|
||||
shadowed_binding,
|
||||
|
@ -875,14 +877,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
name,
|
||||
}),
|
||||
ResolutionError::ForwardDeclaredGenericParam => {
|
||||
self.tcx.sess.create_err(errs::ForwardDeclaredGenericParam { span })
|
||||
self.dcx().create_err(errs::ForwardDeclaredGenericParam { span })
|
||||
}
|
||||
ResolutionError::ParamInTyOfConstParam { name, param_kind: is_type } => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::ParamInTyOfConstParam { span, name, param_kind: is_type }),
|
||||
ResolutionError::ParamInNonTrivialAnonConst { name, param_kind: is_type } => {
|
||||
self.tcx.sess.create_err(errs::ParamInNonTrivialAnonConst {
|
||||
self.dcx().create_err(errs::ParamInNonTrivialAnonConst {
|
||||
span,
|
||||
name,
|
||||
param_kind: is_type,
|
||||
|
@ -894,11 +895,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::ParamInEnumDiscriminant { span, name, param_kind: is_type }),
|
||||
ResolutionError::SelfInGenericParamDefault => {
|
||||
self.tcx.sess.create_err(errs::SelfInGenericParamDefault { span })
|
||||
self.dcx().create_err(errs::SelfInGenericParamDefault { span })
|
||||
}
|
||||
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
||||
let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) =
|
||||
|
@ -926,7 +926,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// No similarly-named labels exist.
|
||||
None => ((None, None), None),
|
||||
};
|
||||
self.tcx.sess.create_err(errs::UnreachableLabel {
|
||||
self.dcx().create_err(errs::UnreachableLabel {
|
||||
span,
|
||||
name,
|
||||
definition_span,
|
||||
|
@ -942,7 +942,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
trait_item_span,
|
||||
trait_path,
|
||||
} => {
|
||||
let mut err = self.tcx.sess.struct_span_err_with_code(
|
||||
let mut err = self.dcx().struct_span_err_with_code(
|
||||
span,
|
||||
format!(
|
||||
"item `{name}` is an associated {kind}, which doesn't match its trait `{trait_path}`",
|
||||
|
@ -954,15 +954,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
err
|
||||
}
|
||||
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errs::TraitImplDuplicate { span, name, trait_item_span, old_span }),
|
||||
ResolutionError::InvalidAsmSym => {
|
||||
self.tcx.sess.create_err(errs::InvalidAsmSym { span })
|
||||
}
|
||||
ResolutionError::LowercaseSelf => {
|
||||
self.tcx.sess.create_err(errs::LowercaseSelf { span })
|
||||
}
|
||||
ResolutionError::InvalidAsmSym => self.dcx().create_err(errs::InvalidAsmSym { span }),
|
||||
ResolutionError::LowercaseSelf => self.dcx().create_err(errs::LowercaseSelf { span }),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -972,7 +967,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
) -> ErrorGuaranteed {
|
||||
match vis_resolution_error {
|
||||
VisResolutionError::Relative2018(span, path) => {
|
||||
self.tcx.sess.create_err(errs::Relative2018 {
|
||||
self.dcx().create_err(errs::Relative2018 {
|
||||
span,
|
||||
path_span: path.span,
|
||||
// intentionally converting to String, as the text would also be used as
|
||||
|
@ -981,7 +976,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
VisResolutionError::AncestorOnly(span) => {
|
||||
self.tcx.sess.create_err(errs::AncestorOnly(span))
|
||||
self.dcx().create_err(errs::AncestorOnly(span))
|
||||
}
|
||||
VisResolutionError::FailedToResolve(span, label, suggestion) => self.into_struct_error(
|
||||
span,
|
||||
|
@ -993,14 +988,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
},
|
||||
),
|
||||
VisResolutionError::ExpectedFound(span, path_str, res) => {
|
||||
self.tcx.sess.create_err(errs::ExpectedFound { span, res, path_str })
|
||||
self.dcx().create_err(errs::ExpectedFound { span, res, path_str })
|
||||
}
|
||||
VisResolutionError::Indeterminate(span) => {
|
||||
self.tcx.sess.create_err(errs::Indeterminate(span))
|
||||
}
|
||||
VisResolutionError::ModuleOnly(span) => {
|
||||
self.tcx.sess.create_err(errs::ModuleOnly(span))
|
||||
self.dcx().create_err(errs::Indeterminate(span))
|
||||
}
|
||||
VisResolutionError::ModuleOnly(span) => self.dcx().create_err(errs::ModuleOnly(span)),
|
||||
}
|
||||
.emit()
|
||||
}
|
||||
|
@ -1699,7 +1692,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Print the primary message.
|
||||
let descr = get_descr(binding);
|
||||
let mut err =
|
||||
struct_span_err!(self.tcx.sess, ident.span, E0603, "{} `{}` is private", descr, ident);
|
||||
struct_span_err!(self.dcx(), ident.span, E0603, "{} `{}` is private", descr, ident);
|
||||
err.span_label(ident.span, format!("private {descr}"));
|
||||
|
||||
let mut not_publicly_reexported = false;
|
||||
|
|
|
@ -1201,7 +1201,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
self.report_error(span, error);
|
||||
self.tcx.sess.span_delayed_bug(span, CG_BUG_STR);
|
||||
self.dcx().span_delayed_bug(span, CG_BUG_STR);
|
||||
}
|
||||
|
||||
return Res::Err;
|
||||
|
@ -1496,7 +1496,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
record_segment_res(self, res);
|
||||
} else if res == Res::ToolMod && !is_last && opt_ns.is_some() {
|
||||
if binding.is_import() {
|
||||
self.tcx.sess.emit_err(errors::ToolModuleImported {
|
||||
self.dcx().emit_err(errors::ToolModuleImported {
|
||||
span: ident.span,
|
||||
import: binding.span,
|
||||
});
|
||||
|
|
|
@ -686,7 +686,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
.collect::<Vec<_>>();
|
||||
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);
|
||||
|
||||
let mut diag = struct_span_err!(self.tcx.sess, span, E0432, "{}", &msg);
|
||||
let mut diag = struct_span_err!(self.dcx(), span, E0432, "{}", &msg);
|
||||
|
||||
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
|
||||
diag.note(note.clone());
|
||||
|
@ -826,8 +826,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
source_binding @ (Ok(..) | Err(Determined)) => {
|
||||
if source_binding.is_ok() {
|
||||
this.tcx
|
||||
.sess
|
||||
this.dcx()
|
||||
.create_err(IsNotDirectlyImportable { span: import.span, target })
|
||||
.emit();
|
||||
}
|
||||
|
@ -877,8 +876,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
span_bug!(import.span, "inconsistent resolution for an import");
|
||||
}
|
||||
} else if self.privacy_errors.is_empty() {
|
||||
self.tcx
|
||||
.sess
|
||||
self.dcx()
|
||||
.create_err(CannotDetermineImportResolution { span: import.span })
|
||||
.emit();
|
||||
}
|
||||
|
@ -1066,8 +1064,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let has_ambiguity_error =
|
||||
this.ambiguity_errors.iter().any(|error| !error.warning);
|
||||
if res == Res::Err || has_ambiguity_error {
|
||||
this.tcx
|
||||
.sess
|
||||
this.dcx()
|
||||
.span_delayed_bug(import.span, "some error happened for an import");
|
||||
return;
|
||||
}
|
||||
|
@ -1076,8 +1073,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
span_bug!(import.span, "inconsistent resolution for an import");
|
||||
}
|
||||
} else if this.privacy_errors.is_empty() {
|
||||
this.tcx
|
||||
.sess
|
||||
this.dcx()
|
||||
.create_err(CannotDetermineImportResolution { span: import.span })
|
||||
.emit();
|
||||
}
|
||||
|
@ -1238,24 +1234,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
} else {
|
||||
if ns == TypeNS {
|
||||
let mut err = if crate_private_reexport {
|
||||
self.tcx.sess.create_err(CannotBeReexportedCratePublicNS {
|
||||
self.dcx().create_err(CannotBeReexportedCratePublicNS {
|
||||
span: import.span,
|
||||
ident,
|
||||
})
|
||||
} else {
|
||||
self.tcx
|
||||
.sess
|
||||
self.dcx()
|
||||
.create_err(CannotBeReexportedPrivateNS { span: import.span, ident })
|
||||
};
|
||||
err.emit();
|
||||
} else {
|
||||
let mut err = if crate_private_reexport {
|
||||
self.tcx
|
||||
.sess
|
||||
self.dcx()
|
||||
.create_err(CannotBeReexportedCratePublic { span: import.span, ident })
|
||||
} else {
|
||||
self.tcx
|
||||
.sess
|
||||
self.dcx()
|
||||
.create_err(CannotBeReexportedPrivate { span: import.span, ident })
|
||||
};
|
||||
|
||||
|
@ -1378,12 +1371,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
|
||||
|
||||
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
|
||||
self.tcx.sess.create_err(CannotGlobImportAllCrates { span: import.span }).emit();
|
||||
self.dcx().create_err(CannotGlobImportAllCrates { span: import.span }).emit();
|
||||
return;
|
||||
};
|
||||
|
||||
if module.is_trait() {
|
||||
self.tcx.sess.create_err(ItemsInTraitsAreNotImportable { span: import.span }).emit();
|
||||
self.dcx().create_err(ItemsInTraitsAreNotImportable { span: import.span }).emit();
|
||||
return;
|
||||
} else if module == import.parent_scope.module {
|
||||
return;
|
||||
|
|
|
@ -1665,7 +1665,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
||||
};
|
||||
let mut diag = rustc_errors::struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
lifetime.ident.span,
|
||||
E0637,
|
||||
"{}",
|
||||
|
@ -1854,7 +1854,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
| LifetimeRibKind::AnonymousWarn(_) => {
|
||||
let sess = self.r.tcx.sess;
|
||||
let mut err = rustc_errors::struct_span_err!(
|
||||
sess,
|
||||
sess.dcx(),
|
||||
path_span,
|
||||
E0726,
|
||||
"implicit elided lifetime not allowed here"
|
||||
|
@ -2301,11 +2301,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
let report_error = |this: &Self, ns| {
|
||||
if this.should_report_errs() {
|
||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||
this.r
|
||||
.tcx
|
||||
.sess
|
||||
.create_err(ImportsCannotReferTo { span: ident.span, what })
|
||||
.emit();
|
||||
this.r.dcx().create_err(ImportsCannotReferTo { span: ident.span, what }).emit();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2599,7 +2595,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
|
||||
if param.ident.name == kw::UnderscoreLifetime {
|
||||
rustc_errors::struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
param.ident.span,
|
||||
E0637,
|
||||
"`'_` cannot be used here"
|
||||
|
@ -2613,7 +2609,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
|
||||
if param.ident.name == kw::StaticLifetime {
|
||||
rustc_errors::struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
param.ident.span,
|
||||
E0262,
|
||||
"invalid lifetime parameter name: `{}`",
|
||||
|
@ -3559,7 +3555,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||
Res::SelfCtor(_) => {
|
||||
// We resolve `Self` in pattern position as an ident sometimes during recovery,
|
||||
// so delay a bug instead of ICEing.
|
||||
self.r.tcx.sess.span_delayed_bug(
|
||||
self.r.dcx().span_delayed_bug(
|
||||
ident.span,
|
||||
"unexpected `SelfCtor` in pattern, expected identifier"
|
||||
);
|
||||
|
|
|
@ -429,11 +429,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
let base_error = self.make_base_error(path, span, source, res);
|
||||
|
||||
let code = source.error_code(res.is_some());
|
||||
let mut err = self.r.tcx.sess.struct_span_err_with_code(
|
||||
base_error.span,
|
||||
base_error.msg.clone(),
|
||||
code,
|
||||
);
|
||||
let mut err =
|
||||
self.r.dcx().struct_span_err_with_code(base_error.span, base_error.msg.clone(), code);
|
||||
|
||||
self.suggest_at_operator_in_slice_pat_with_range(&mut err, path);
|
||||
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);
|
||||
|
@ -2602,7 +2599,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
|
||||
let mut err = if let Some(outer) = outer_lifetime_ref {
|
||||
let mut err = struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
lifetime_ref.ident.span,
|
||||
E0401,
|
||||
"can't use generic parameters from outer item",
|
||||
|
@ -2612,7 +2609,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
err
|
||||
} else {
|
||||
let mut err = struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
lifetime_ref.ident.span,
|
||||
E0261,
|
||||
"use of undeclared lifetime name `{}`",
|
||||
|
@ -2721,8 +2718,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
|
||||
pub(crate) fn emit_non_static_lt_in_const_param_ty_error(&self, lifetime_ref: &ast::Lifetime) {
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errors::ParamInTyOfConstParam {
|
||||
span: lifetime_ref.ident.span,
|
||||
name: lifetime_ref.ident.name,
|
||||
|
@ -2742,8 +2738,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
match cause {
|
||||
NoConstantGenericsReason::IsEnumDiscriminant => {
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errors::ParamInEnumDiscriminant {
|
||||
span: lifetime_ref.ident.span,
|
||||
name: lifetime_ref.ident.name,
|
||||
|
@ -2754,8 +2749,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
NoConstantGenericsReason::NonTrivialConstArg => {
|
||||
assert!(!self.r.tcx.features().generic_const_exprs);
|
||||
self.r
|
||||
.tcx
|
||||
.sess
|
||||
.dcx()
|
||||
.create_err(errors::ParamInNonTrivialAnonConst {
|
||||
span: lifetime_ref.ident.span,
|
||||
name: lifetime_ref.ident.name,
|
||||
|
@ -2781,7 +2775,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||
let spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
self.r.tcx.sess,
|
||||
self.r.dcx(),
|
||||
spans,
|
||||
E0106,
|
||||
"missing lifetime specifier{}",
|
||||
|
@ -3286,7 +3280,7 @@ fn mk_where_bound_predicate(
|
|||
/// Report lifetime/lifetime shadowing as an error.
|
||||
pub(super) fn signal_lifetime_shadowing(sess: &Session, orig: Ident, shadower: Ident) {
|
||||
let mut err = struct_span_err!(
|
||||
sess,
|
||||
sess.dcx(),
|
||||
shadower.span,
|
||||
E0496,
|
||||
"lifetime name `{}` shadows a lifetime name that is already in scope",
|
||||
|
@ -3320,7 +3314,7 @@ impl<'ast> Visitor<'ast> for LifetimeFinder<'ast> {
|
|||
pub(super) fn signal_label_shadowing(sess: &Session, orig: Span, shadower: Ident) {
|
||||
let name = shadower.name;
|
||||
let shadower = shadower.span;
|
||||
let mut err = sess.struct_span_warn(
|
||||
let mut err = sess.dcx().struct_span_warn(
|
||||
shadower,
|
||||
format!("label name `{name}` shadows a label name that is already in scope"),
|
||||
);
|
||||
|
|
|
@ -126,7 +126,7 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
|
|||
Some(ident) => {
|
||||
if let Some(old_ident) = registered_tools.replace(ident) {
|
||||
let msg = format!("{} `{}` was already registered", "tool", ident);
|
||||
tcx.sess
|
||||
tcx.dcx()
|
||||
.struct_span_err(ident.span, msg)
|
||||
.span_label(old_ident.span, "already registered here")
|
||||
.emit();
|
||||
|
@ -135,7 +135,7 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
|
|||
None => {
|
||||
let msg = format!("`{}` only accepts identifiers", sym::register_tool);
|
||||
let span = nested_meta.span();
|
||||
tcx.sess
|
||||
tcx.dcx()
|
||||
.struct_span_err(span, msg)
|
||||
.span_label(span, "not an identifier")
|
||||
.emit();
|
||||
|
@ -205,7 +205,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
|||
|
||||
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
|
||||
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
|
||||
self.tcx.sess.dcx().bug(format!("built-in macro `{name}` was already registered"));
|
||||
self.dcx().bug(format!("built-in macro `{name}` was already registered"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
|||
PathResult::NonModule(..) |
|
||||
// HACK(Urgau): This shouldn't be necessary
|
||||
PathResult::Failed { is_error_from_last_segment: false, .. } => {
|
||||
self.tcx.sess
|
||||
self.dcx()
|
||||
.emit_err(errors::CfgAccessibleUnsure { span });
|
||||
|
||||
// If we get a partially resolved NonModule in one namespace, we should get the
|
||||
|
@ -512,10 +512,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Report errors for the resolved macro.
|
||||
for segment in &path.segments {
|
||||
if let Some(args) = &segment.args {
|
||||
self.tcx.sess.span_err(args.span(), "generic arguments in macro path");
|
||||
self.dcx().span_err(args.span(), "generic arguments in macro path");
|
||||
}
|
||||
if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
|
||||
self.tcx.sess.span_err(
|
||||
self.dcx().span_err(
|
||||
segment.ident.span,
|
||||
"attributes starting with `rustc` are reserved for use by the `rustc` compiler",
|
||||
);
|
||||
|
@ -527,7 +527,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
if let Some(def_id) = def_id.as_local() {
|
||||
self.unused_macros.remove(&def_id);
|
||||
if self.proc_macro_stubs.contains(&def_id) {
|
||||
self.tcx.sess.emit_err(errors::ProcMacroSameCrate {
|
||||
self.dcx().emit_err(errors::ProcMacroSameCrate {
|
||||
span: path.span,
|
||||
is_test: self.tcx.sess.is_test_crate(),
|
||||
});
|
||||
|
@ -576,7 +576,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
err.add_as_non_derive = Some(AddAsNonDerive { macro_path: &path_str });
|
||||
}
|
||||
|
||||
let mut err = self.tcx.sess.create_err(err);
|
||||
let mut err = self.dcx().create_err(err);
|
||||
err.span_label(path.span, format!("not {article} {expected}"));
|
||||
|
||||
err.emit();
|
||||
|
@ -707,7 +707,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Make sure compilation does not succeed if preferred macro resolution
|
||||
// has changed after the macro had been expanded. In theory all such
|
||||
// situations should be reported as errors, so this is a bug.
|
||||
this.tcx.sess.span_delayed_bug(span, "inconsistent resolution for a macro");
|
||||
this.dcx().span_delayed_bug(span, "inconsistent resolution for a macro");
|
||||
}
|
||||
} else {
|
||||
// It's possible that the macro was unresolved (indeterminate) and silently
|
||||
|
@ -718,7 +718,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// even if speculative `resolve_path` returned nothing previously, so we skip this
|
||||
// less informative error if the privacy error is reported elsewhere.
|
||||
if this.privacy_errors.is_empty() {
|
||||
this.tcx.sess.emit_err(CannotDetermineMacroResolution {
|
||||
this.dcx().emit_err(CannotDetermineMacroResolution {
|
||||
span,
|
||||
kind: kind.descr(),
|
||||
path: Segment::names_to_string(path),
|
||||
|
@ -825,7 +825,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
Err(..) => {
|
||||
let expected = kind.descr_expected();
|
||||
|
||||
let mut err = self.tcx.sess.create_err(CannotFindIdentInThisScope {
|
||||
let mut err = self.dcx().create_err(CannotFindIdentInThisScope {
|
||||
span: ident.span,
|
||||
expected,
|
||||
ident,
|
||||
|
@ -907,7 +907,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
if kind != NonMacroAttrKind::Tool && binding.map_or(true, |b| b.is_import()) {
|
||||
let msg =
|
||||
format!("cannot use {} {} through an import", kind.article(), kind.descr());
|
||||
let mut err = self.tcx.sess.struct_span_err(span, msg);
|
||||
let mut err = self.dcx().struct_span_err(span, msg);
|
||||
if let Some(binding) = binding {
|
||||
err.span_note(binding.span, format!("the {} imported here", kind.descr()));
|
||||
}
|
||||
|
@ -922,7 +922,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
if ident.name == sym::cfg || ident.name == sym::cfg_attr {
|
||||
let macro_kind = self.get_macro(res).map(|macro_data| macro_data.ext.macro_kind());
|
||||
if macro_kind.is_some() && sub_namespace_match(macro_kind, Some(MacroKind::Attr)) {
|
||||
self.tcx.sess.span_err(
|
||||
self.dcx().span_err(
|
||||
ident.span,
|
||||
format!("name `{ident}` is reserved in attribute namespace"),
|
||||
);
|
||||
|
@ -950,7 +950,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
BuiltinMacroState::AlreadySeen(span) => {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
self.dcx(),
|
||||
item.span,
|
||||
E0773,
|
||||
"attempted to define built-in macro more than once"
|
||||
|
@ -961,7 +961,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
} else {
|
||||
let msg = format!("cannot find a built-in macro with name `{}`", item.ident);
|
||||
self.tcx.sess.span_err(item.span, msg);
|
||||
self.dcx().span_err(item.span, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue