Use identifiers in diagnostics more often
This commit is contained in:
parent
f85c6de552
commit
ac1c6c50f4
21 changed files with 83 additions and 72 deletions
|
@ -2362,7 +2362,7 @@ fn try_report_async_mismatch<'tcx>(
|
||||||
// the right span is a bit difficult.
|
// the right span is a bit difficult.
|
||||||
return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
|
return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
|
||||||
span: tcx.def_span(impl_m.def_id),
|
span: tcx.def_span(impl_m.def_id),
|
||||||
method_name: trait_m.name,
|
method_name: tcx.item_ident(impl_m.def_id),
|
||||||
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
|
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
|
||||||
|
|
||||||
fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_impl: DefId) {
|
fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_impl: DefId) {
|
||||||
let span = tcx.def_span(impl_item);
|
let span = tcx.def_span(impl_item);
|
||||||
let ident = tcx.item_name(impl_item);
|
let ident = tcx.item_ident(impl_item);
|
||||||
|
|
||||||
let err = match tcx.span_of_impl(parent_impl) {
|
let err = match tcx.span_of_impl(parent_impl) {
|
||||||
Ok(sp) => errors::ImplNotMarkedDefault::Ok { span, ident, ok_label: sp },
|
Ok(sp) => errors::ImplNotMarkedDefault::Ok { span, ident, ok_label: sp },
|
||||||
|
@ -297,7 +297,7 @@ fn default_body_is_unstable(
|
||||||
reason: Option<Symbol>,
|
reason: Option<Symbol>,
|
||||||
issue: Option<NonZero<u32>>,
|
issue: Option<NonZero<u32>>,
|
||||||
) {
|
) {
|
||||||
let missing_item_name = tcx.associated_item(item_did).name;
|
let missing_item_name = tcx.item_ident(item_did);
|
||||||
let (mut some_note, mut none_note, mut reason_str) = (false, false, String::new());
|
let (mut some_note, mut none_note, mut reason_str) = (false, false, String::new());
|
||||||
match reason {
|
match reason {
|
||||||
Some(r) => {
|
Some(r) => {
|
||||||
|
|
|
@ -292,7 +292,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
|
||||||
|
|
||||||
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
|
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
|
||||||
span,
|
span,
|
||||||
name: field.name,
|
name: field.ident(tcx),
|
||||||
ty: ty_a,
|
ty: ty_a,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -465,8 +465,8 @@ fn emit_orphan_check_error<'tcx>(
|
||||||
traits::OrphanCheckErr::UncoveredTyParams(UncoveredTyParams { uncovered, local_ty }) => {
|
traits::OrphanCheckErr::UncoveredTyParams(UncoveredTyParams { uncovered, local_ty }) => {
|
||||||
let mut reported = None;
|
let mut reported = None;
|
||||||
for param_def_id in uncovered {
|
for param_def_id in uncovered {
|
||||||
let span = tcx.def_ident_span(param_def_id).unwrap();
|
let name = tcx.item_ident(param_def_id);
|
||||||
let name = tcx.item_name(param_def_id);
|
let span = name.span;
|
||||||
|
|
||||||
reported.get_or_insert(match local_ty {
|
reported.get_or_insert(match local_ty {
|
||||||
Some(local_type) => tcx.dcx().emit_err(errors::TyParamFirstLocal {
|
Some(local_type) => tcx.dcx().emit_err(errors::TyParamFirstLocal {
|
||||||
|
@ -492,7 +492,7 @@ fn lint_uncovered_ty_params<'tcx>(
|
||||||
|
|
||||||
for param_def_id in uncovered {
|
for param_def_id in uncovered {
|
||||||
let span = tcx.def_ident_span(param_def_id).unwrap();
|
let span = tcx.def_ident_span(param_def_id).unwrap();
|
||||||
let name = tcx.item_name(param_def_id);
|
let name = tcx.item_ident(param_def_id);
|
||||||
|
|
||||||
match local_ty {
|
match local_ty {
|
||||||
Some(local_type) => tcx.emit_node_span_lint(
|
Some(local_type) => tcx.emit_node_span_lint(
|
||||||
|
|
|
@ -928,7 +928,7 @@ fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||||
tcx.dcx().emit_err(errors::EnumDiscriminantOverflowed {
|
tcx.dcx().emit_err(errors::EnumDiscriminantOverflowed {
|
||||||
span,
|
span,
|
||||||
discr: prev_discr.unwrap().to_string(),
|
discr: prev_discr.unwrap().to_string(),
|
||||||
item_name: tcx.item_name(variant.def_id),
|
item_name: tcx.item_ident(variant.def_id),
|
||||||
wrapped_discr: wrapped_discr.to_string(),
|
wrapped_discr: wrapped_discr.to_string(),
|
||||||
});
|
});
|
||||||
None
|
None
|
||||||
|
@ -990,11 +990,10 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a given field `ident` declared at `field_decl` has been declared elsewhere before.
|
/// Check if a given field `ident` declared at `field_decl` has been declared elsewhere before.
|
||||||
fn check_field_decl(&mut self, ident: Ident, field_decl: FieldDeclSpan) {
|
fn check_field_decl(&mut self, field_name: Ident, field_decl: FieldDeclSpan) {
|
||||||
use FieldDeclSpan::*;
|
use FieldDeclSpan::*;
|
||||||
let field_name = ident.name;
|
let field_name = field_name.normalize_to_macros_2_0();
|
||||||
let ident = ident.normalize_to_macros_2_0();
|
match (field_decl, self.seen_fields.get(&field_name).copied()) {
|
||||||
match (field_decl, self.seen_fields.get(&ident).copied()) {
|
|
||||||
(NotNested(span), Some(NotNested(prev_span))) => {
|
(NotNested(span), Some(NotNested(prev_span))) => {
|
||||||
self.tcx.dcx().emit_err(errors::FieldAlreadyDeclared::NotNested {
|
self.tcx.dcx().emit_err(errors::FieldAlreadyDeclared::NotNested {
|
||||||
field_name,
|
field_name,
|
||||||
|
@ -1035,7 +1034,7 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(field_decl, None) => {
|
(field_decl, None) => {
|
||||||
self.seen_fields.insert(ident, field_decl);
|
self.seen_fields.insert(field_name, field_decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
|
||||||
} else {
|
} else {
|
||||||
let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType {
|
let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType {
|
||||||
span: tcx.def_span(def_id),
|
span: tcx.def_span(def_id),
|
||||||
name: tcx.item_name(parent_def_id.to_def_id()),
|
name: tcx.item_ident(parent_def_id.to_def_id()),
|
||||||
what: "impl",
|
what: "impl",
|
||||||
});
|
});
|
||||||
Ty::new_error(tcx, reported)
|
Ty::new_error(tcx, reported)
|
||||||
|
@ -136,7 +136,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
|
||||||
}
|
}
|
||||||
let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType {
|
let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType {
|
||||||
span: tcx.def_span(def_id),
|
span: tcx.def_span(def_id),
|
||||||
name: tcx.item_name(parent_def_id.to_def_id()),
|
name: tcx.item_ident(parent_def_id.to_def_id()),
|
||||||
what: match tcx.hir_node(scope) {
|
what: match tcx.hir_node(scope) {
|
||||||
_ if scope == hir::CRATE_HIR_ID => "module",
|
_ if scope == hir::CRATE_HIR_ID => "module",
|
||||||
Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module",
|
Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module",
|
||||||
|
|
|
@ -217,7 +217,7 @@ pub(crate) struct DropImplOnWrongItem {
|
||||||
pub(crate) enum FieldAlreadyDeclared {
|
pub(crate) enum FieldAlreadyDeclared {
|
||||||
#[diag(hir_analysis_field_already_declared, code = E0124)]
|
#[diag(hir_analysis_field_already_declared, code = E0124)]
|
||||||
NotNested {
|
NotNested {
|
||||||
field_name: Symbol,
|
field_name: Ident,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -226,7 +226,7 @@ pub(crate) enum FieldAlreadyDeclared {
|
||||||
},
|
},
|
||||||
#[diag(hir_analysis_field_already_declared_current_nested)]
|
#[diag(hir_analysis_field_already_declared_current_nested)]
|
||||||
CurrentNested {
|
CurrentNested {
|
||||||
field_name: Symbol,
|
field_name: Ident,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -239,7 +239,7 @@ pub(crate) enum FieldAlreadyDeclared {
|
||||||
},
|
},
|
||||||
#[diag(hir_analysis_field_already_declared_previous_nested)]
|
#[diag(hir_analysis_field_already_declared_previous_nested)]
|
||||||
PreviousNested {
|
PreviousNested {
|
||||||
field_name: Symbol,
|
field_name: Ident,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -252,7 +252,7 @@ pub(crate) enum FieldAlreadyDeclared {
|
||||||
},
|
},
|
||||||
#[diag(hir_analysis_field_already_declared_both_nested)]
|
#[diag(hir_analysis_field_already_declared_both_nested)]
|
||||||
BothNested {
|
BothNested {
|
||||||
field_name: Symbol,
|
field_name: Ident,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -418,7 +418,7 @@ pub(crate) struct ValueOfAssociatedStructAlreadySpecified {
|
||||||
pub(crate) struct UnconstrainedOpaqueType {
|
pub(crate) struct UnconstrainedOpaqueType {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Symbol,
|
pub name: Ident,
|
||||||
pub what: &'static str,
|
pub what: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,7 +802,7 @@ pub(crate) struct EnumDiscriminantOverflowed {
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub discr: String,
|
pub discr: String,
|
||||||
pub item_name: Symbol,
|
pub item_name: Ident,
|
||||||
pub wrapped_discr: String,
|
pub wrapped_discr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +893,7 @@ pub(crate) enum ImplNotMarkedDefault {
|
||||||
span: Span,
|
span: Span,
|
||||||
#[label(hir_analysis_ok_label)]
|
#[label(hir_analysis_ok_label)]
|
||||||
ok_label: Span,
|
ok_label: Span,
|
||||||
ident: Symbol,
|
ident: Ident,
|
||||||
},
|
},
|
||||||
#[diag(hir_analysis_impl_not_marked_default_err, code = E0520)]
|
#[diag(hir_analysis_impl_not_marked_default_err, code = E0520)]
|
||||||
#[note]
|
#[note]
|
||||||
|
@ -901,7 +901,7 @@ pub(crate) enum ImplNotMarkedDefault {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
cname: Symbol,
|
cname: Symbol,
|
||||||
ident: Symbol,
|
ident: Ident,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -977,7 +977,7 @@ pub(crate) struct MissingTraitItemUnstable {
|
||||||
pub some_note: bool,
|
pub some_note: bool,
|
||||||
#[note(hir_analysis_none_note)]
|
#[note(hir_analysis_none_note)]
|
||||||
pub none_note: bool,
|
pub none_note: bool,
|
||||||
pub missing_item_name: Symbol,
|
pub missing_item_name: Ident,
|
||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
pub reason: String,
|
pub reason: String,
|
||||||
}
|
}
|
||||||
|
@ -1249,7 +1249,7 @@ pub(crate) struct InherentNominal {
|
||||||
pub(crate) struct DispatchFromDynZST<'a> {
|
pub(crate) struct DispatchFromDynZST<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Symbol,
|
pub name: Ident,
|
||||||
pub ty: Ty<'a>,
|
pub ty: Ty<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,7 +1389,7 @@ pub(crate) struct TyParamFirstLocal<'tcx> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[note(hir_analysis_case_note)]
|
#[note(hir_analysis_case_note)]
|
||||||
pub note: (),
|
pub note: (),
|
||||||
pub param: Symbol,
|
pub param: Ident,
|
||||||
pub local_type: Ty<'tcx>,
|
pub local_type: Ty<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1401,7 +1401,7 @@ pub(crate) struct TyParamFirstLocalLint<'tcx> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[note(hir_analysis_case_note)]
|
#[note(hir_analysis_case_note)]
|
||||||
pub note: (),
|
pub note: (),
|
||||||
pub param: Symbol,
|
pub param: Ident,
|
||||||
pub local_type: Ty<'tcx>,
|
pub local_type: Ty<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,7 +1414,7 @@ pub(crate) struct TyParamSome {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[note(hir_analysis_only_note)]
|
#[note(hir_analysis_only_note)]
|
||||||
pub note: (),
|
pub note: (),
|
||||||
pub param: Symbol,
|
pub param: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
@ -1425,7 +1425,7 @@ pub(crate) struct TyParamSomeLint {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[note(hir_analysis_only_note)]
|
#[note(hir_analysis_only_note)]
|
||||||
pub note: (),
|
pub note: (),
|
||||||
pub param: Symbol,
|
pub param: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -1533,7 +1533,7 @@ pub(crate) struct UnsupportedDelegation<'a> {
|
||||||
pub(crate) struct MethodShouldReturnFuture {
|
pub(crate) struct MethodShouldReturnFuture {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub method_name: Symbol,
|
pub method_name: Ident,
|
||||||
#[note]
|
#[note]
|
||||||
pub trait_item_span: Option<Span>,
|
pub trait_item_span: Option<Span>,
|
||||||
}
|
}
|
||||||
|
@ -1585,7 +1585,7 @@ pub(crate) struct UnconstrainedGenericParameter {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub param_name: Symbol,
|
pub param_name: Ident,
|
||||||
pub param_def_kind: &'static str,
|
pub param_def_kind: &'static str,
|
||||||
#[note(hir_analysis_const_param_note)]
|
#[note(hir_analysis_const_param_note)]
|
||||||
pub const_param_note: bool,
|
pub const_param_note: bool,
|
||||||
|
|
|
@ -152,7 +152,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
|
||||||
{
|
{
|
||||||
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
|
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
|
||||||
span: tcx.def_span(param.def_id),
|
span: tcx.def_span(param.def_id),
|
||||||
param_name: param.name,
|
param_name: tcx.item_ident(param.def_id),
|
||||||
param_def_kind: tcx.def_descr(param.def_id),
|
param_def_kind: tcx.def_descr(param.def_id),
|
||||||
const_param_note: false,
|
const_param_note: false,
|
||||||
const_param_note2: false,
|
const_param_note2: false,
|
||||||
|
@ -223,7 +223,7 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
|
||||||
let const_param_note = matches!(param.kind, ty::GenericParamDefKind::Const { .. });
|
let const_param_note = matches!(param.kind, ty::GenericParamDefKind::Const { .. });
|
||||||
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
|
let mut diag = tcx.dcx().create_err(UnconstrainedGenericParameter {
|
||||||
span: tcx.def_span(param.def_id),
|
span: tcx.def_span(param.def_id),
|
||||||
param_name: param.name,
|
param_name: tcx.item_ident(param.def_id),
|
||||||
param_def_kind: tcx.def_descr(param.def_id),
|
param_def_kind: tcx.def_descr(param.def_id),
|
||||||
const_param_note,
|
const_param_note,
|
||||||
const_param_note2: const_param_note,
|
const_param_note2: const_param_note,
|
||||||
|
|
|
@ -141,7 +141,7 @@ fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||||
expr.hir_id,
|
expr.hir_id,
|
||||||
method.ident.span,
|
method.ident.span,
|
||||||
DanglingPointersFromTemporaries {
|
DanglingPointersFromTemporaries {
|
||||||
callee: method.ident.name,
|
callee: method.ident,
|
||||||
ty,
|
ty,
|
||||||
ptr_span: method.ident.span,
|
ptr_span: method.ident.span,
|
||||||
temporary_span: receiver.span,
|
temporary_span: receiver.span,
|
||||||
|
|
|
@ -1132,7 +1132,7 @@ pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
|
||||||
#[help(lint_help_visit)]
|
#[help(lint_help_visit)]
|
||||||
// FIXME: put #[primary_span] on `ptr_span` once it does not cause conflicts
|
// FIXME: put #[primary_span] on `ptr_span` once it does not cause conflicts
|
||||||
pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
|
pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
|
||||||
pub callee: Symbol,
|
pub callee: Ident,
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
#[label(lint_label_ptr)]
|
#[label(lint_label_ptr)]
|
||||||
pub ptr_span: Span,
|
pub ptr_span: Span,
|
||||||
|
@ -1333,7 +1333,7 @@ pub(crate) enum NonUpperCaseGlobalSub {
|
||||||
#[diag(lint_noop_method_call)]
|
#[diag(lint_noop_method_call)]
|
||||||
#[note]
|
#[note]
|
||||||
pub(crate) struct NoopMethodCallDiag<'a> {
|
pub(crate) struct NoopMethodCallDiag<'a> {
|
||||||
pub method: Symbol,
|
pub method: Ident,
|
||||||
pub orig_ty: Ty<'a>,
|
pub orig_ty: Ty<'a>,
|
||||||
pub trait_: Symbol,
|
pub trait_: Symbol,
|
||||||
#[suggestion(code = "", applicability = "machine-applicable")]
|
#[suggestion(code = "", applicability = "machine-applicable")]
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
cx.emit_span_lint(NOOP_METHOD_CALL, span, NoopMethodCallDiag {
|
cx.emit_span_lint(NOOP_METHOD_CALL, span, NoopMethodCallDiag {
|
||||||
method: call.ident.name,
|
method: call.ident,
|
||||||
orig_ty,
|
orig_ty,
|
||||||
trait_,
|
trait_,
|
||||||
label: span,
|
label: span,
|
||||||
|
|
|
@ -1596,6 +1596,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
Some(Ident::new(def, span))
|
Some(Ident::new(def, span))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Look up the name and span of a definition.
|
||||||
|
///
|
||||||
|
/// See [`item_name`][Self::item_name] for more information.
|
||||||
|
pub fn item_ident(self, def_id: DefId) -> Ident {
|
||||||
|
self.opt_item_ident(def_id).unwrap_or_else(|| {
|
||||||
|
bug!("item_ident: no name for {:?}", self.def_path(def_id));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
|
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
|
||||||
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
|
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
|
||||||
Some(self.associated_item(def_id))
|
Some(self.associated_item(def_id))
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_pattern_analysis::errors::Uncovered;
|
use rustc_pattern_analysis::errors::Uncovered;
|
||||||
use rustc_pattern_analysis::rustc::RustcPatCtxt;
|
use rustc_pattern_analysis::rustc::RustcPatCtxt;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Ident, Span, Symbol};
|
||||||
|
|
||||||
use crate::fluent_generated as fluent;
|
use crate::fluent_generated as fluent;
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ pub(crate) struct BindingsWithVariantName {
|
||||||
#[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
|
#[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
|
||||||
pub(crate) suggestion: Option<Span>,
|
pub(crate) suggestion: Option<Span>,
|
||||||
pub(crate) ty_path: String,
|
pub(crate) ty_path: String,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
@ -797,7 +797,7 @@ pub(crate) struct BorrowOfMovedValue {
|
||||||
pub(crate) binding_span: Span,
|
pub(crate) binding_span: Span,
|
||||||
#[label(mir_build_value_borrowed_label)]
|
#[label(mir_build_value_borrowed_label)]
|
||||||
pub(crate) conflicts_ref: Vec<Span>,
|
pub(crate) conflicts_ref: Vec<Span>,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
pub(crate) ty: String,
|
pub(crate) ty: String,
|
||||||
#[suggestion(code = "ref ", applicability = "machine-applicable")]
|
#[suggestion(code = "ref ", applicability = "machine-applicable")]
|
||||||
pub(crate) suggest_borrowing: Option<Span>,
|
pub(crate) suggest_borrowing: Option<Span>,
|
||||||
|
|
|
@ -25,7 +25,7 @@ use rustc_session::lint::builtin::{
|
||||||
};
|
};
|
||||||
use rustc_span::edit_distance::find_best_match_for_name;
|
use rustc_span::edit_distance::find_best_match_for_name;
|
||||||
use rustc_span::hygiene::DesugaringKind;
|
use rustc_span::hygiene::DesugaringKind;
|
||||||
use rustc_span::{Span, sym};
|
use rustc_span::{Ident, Span, sym};
|
||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
@ -800,7 +800,7 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat:
|
||||||
sess.dcx().emit_err(BorrowOfMovedValue {
|
sess.dcx().emit_err(BorrowOfMovedValue {
|
||||||
binding_span: pat.span,
|
binding_span: pat.span,
|
||||||
conflicts_ref,
|
conflicts_ref,
|
||||||
name,
|
name: Ident::new(name, pat.span),
|
||||||
ty,
|
ty,
|
||||||
suggest_borrowing: Some(pat.span.shrink_to_lo()),
|
suggest_borrowing: Some(pat.span.shrink_to_lo()),
|
||||||
has_path: path.is_some(),
|
has_path: path.is_some(),
|
||||||
|
@ -908,7 +908,7 @@ fn check_for_bindings_named_same_as_variants(
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
ty_path,
|
ty_path,
|
||||||
name,
|
name: Ident::new(name, pat.span),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3233,7 +3233,7 @@ pub(crate) struct MalformedCfgAttr {
|
||||||
pub(crate) struct UnknownBuiltinConstruct {
|
pub(crate) struct UnknownBuiltinConstruct {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Symbol,
|
pub name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
|
@ -1958,7 +1958,7 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
let err = self.dcx().create_err(errors::UnknownBuiltinConstruct {
|
let err = self.dcx().create_err(errors::UnknownBuiltinConstruct {
|
||||||
span: lo.to(ident.span),
|
span: lo.to(ident.span),
|
||||||
name: ident.name,
|
name: ident,
|
||||||
});
|
});
|
||||||
return Err(err);
|
return Err(err);
|
||||||
};
|
};
|
||||||
|
|
|
@ -677,7 +677,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
if could_be_path {
|
if could_be_path {
|
||||||
let import_suggestions = self.lookup_import_candidates(
|
let import_suggestions = self.lookup_import_candidates(
|
||||||
Ident::with_dummy_span(name),
|
name,
|
||||||
Namespace::ValueNS,
|
Namespace::ValueNS,
|
||||||
&parent_scope,
|
&parent_scope,
|
||||||
&|res: Res| {
|
&|res: Res| {
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub(crate) struct NameAlreadyUsedInParameterList {
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
#[label(resolve_first_use_of_name)]
|
#[label(resolve_first_use_of_name)]
|
||||||
pub(crate) first_use_span: Span,
|
pub(crate) first_use_span: Span,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -142,7 +142,7 @@ pub(crate) struct VariableBoundWithDifferentMode {
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
#[label(resolve_first_binding_span)]
|
#[label(resolve_first_binding_span)]
|
||||||
pub(crate) first_binding_span: Span,
|
pub(crate) first_binding_span: Span,
|
||||||
pub(crate) variable_name: Symbol,
|
pub(crate) variable_name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -151,7 +151,7 @@ pub(crate) struct IdentifierBoundMoreThanOnceInParameterList {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) identifier: Symbol,
|
pub(crate) identifier: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -160,7 +160,7 @@ pub(crate) struct IdentifierBoundMoreThanOnceInSamePattern {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) identifier: Symbol,
|
pub(crate) identifier: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -478,7 +478,7 @@ pub(crate) struct TraitImplDuplicate {
|
||||||
pub(crate) old_span: Span,
|
pub(crate) old_span: Span,
|
||||||
#[label(resolve_trait_item_span)]
|
#[label(resolve_trait_item_span)]
|
||||||
pub(crate) trait_item_span: Span,
|
pub(crate) trait_item_span: Span,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -976,7 +976,7 @@ pub(crate) struct AttemptToDefineBuiltinMacroTwice {
|
||||||
pub(crate) struct VariableIsNotBoundInAllPatterns {
|
pub(crate) struct VariableIsNotBoundInAllPatterns {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub(crate) multispan: MultiSpan,
|
pub(crate) multispan: MultiSpan,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic, Debug, Clone)]
|
#[derive(Subdiagnostic, Debug, Clone)]
|
||||||
|
@ -984,7 +984,7 @@ pub(crate) struct VariableIsNotBoundInAllPatterns {
|
||||||
pub(crate) struct PatternDoesntBindName {
|
pub(crate) struct PatternDoesntBindName {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic, Debug, Clone)]
|
#[derive(Subdiagnostic, Debug, Clone)]
|
||||||
|
@ -1260,7 +1260,7 @@ pub(crate) struct TraitImplMismatch {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) name: Symbol,
|
pub(crate) name: Ident,
|
||||||
pub(crate) kind: &'static str,
|
pub(crate) kind: &'static str,
|
||||||
pub(crate) trait_path: String,
|
pub(crate) trait_path: String,
|
||||||
#[label(resolve_trait_impl_mismatch_label_item)]
|
#[label(resolve_trait_impl_mismatch_label_item)]
|
||||||
|
|
|
@ -2835,7 +2835,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
match seen_bindings.entry(ident) {
|
match seen_bindings.entry(ident) {
|
||||||
Entry::Occupied(entry) => {
|
Entry::Occupied(entry) => {
|
||||||
let span = *entry.get();
|
let span = *entry.get();
|
||||||
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
|
let err = ResolutionError::NameAlreadyUsedInParameterList(ident, span);
|
||||||
self.report_error(param.ident.span, err);
|
self.report_error(param.ident.span, err);
|
||||||
let rib = match param.kind {
|
let rib = match param.kind {
|
||||||
GenericParamKind::Lifetime => {
|
GenericParamKind::Lifetime => {
|
||||||
|
@ -3422,7 +3422,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
match seen_trait_items.entry(id_in_trait) {
|
match seen_trait_items.entry(id_in_trait) {
|
||||||
Entry::Occupied(entry) => {
|
Entry::Occupied(entry) => {
|
||||||
self.report_error(span, ResolutionError::TraitImplDuplicate {
|
self.report_error(span, ResolutionError::TraitImplDuplicate {
|
||||||
name: ident.name,
|
name: ident,
|
||||||
old_span: *entry.get(),
|
old_span: *entry.get(),
|
||||||
trait_item_span: binding.span,
|
trait_item_span: binding.span,
|
||||||
});
|
});
|
||||||
|
@ -3457,7 +3457,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
};
|
};
|
||||||
let trait_path = path_names_to_string(path);
|
let trait_path = path_names_to_string(path);
|
||||||
self.report_error(span, ResolutionError::TraitImplMismatch {
|
self.report_error(span, ResolutionError::TraitImplMismatch {
|
||||||
name: ident.name,
|
name: ident,
|
||||||
kind,
|
kind,
|
||||||
code,
|
code,
|
||||||
trait_path,
|
trait_path,
|
||||||
|
@ -3640,9 +3640,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
.filter(|(_, pat)| pat.id != pat_outer.id)
|
.filter(|(_, pat)| pat.id != pat_outer.id)
|
||||||
.flat_map(|(map, _)| map);
|
.flat_map(|(map, _)| map);
|
||||||
|
|
||||||
for (key, binding_inner) in inners {
|
for (&name, binding_inner) in inners {
|
||||||
let name = key.name;
|
match map_outer.get(&name) {
|
||||||
match map_outer.get(key) {
|
|
||||||
None => {
|
None => {
|
||||||
// The inner binding is missing in the outer.
|
// The inner binding is missing in the outer.
|
||||||
let binding_error =
|
let binding_error =
|
||||||
|
@ -3880,7 +3879,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
// `Variant(a, a)`:
|
// `Variant(a, a)`:
|
||||||
_ => IdentifierBoundMoreThanOnceInSamePattern,
|
_ => IdentifierBoundMoreThanOnceInSamePattern,
|
||||||
};
|
};
|
||||||
self.report_error(ident.span, error(ident.name));
|
self.report_error(ident.span, error(ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record as bound if it's valid:
|
// Record as bound if it's valid:
|
||||||
|
|
|
@ -214,7 +214,7 @@ enum Used {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct BindingError {
|
struct BindingError {
|
||||||
name: Symbol,
|
name: Ident,
|
||||||
origin: BTreeSet<Span>,
|
origin: BTreeSet<Span>,
|
||||||
target: BTreeSet<Span>,
|
target: BTreeSet<Span>,
|
||||||
could_be_path: bool,
|
could_be_path: bool,
|
||||||
|
@ -226,7 +226,7 @@ enum ResolutionError<'ra> {
|
||||||
GenericParamsFromOuterItem(Res, HasGenericParams, DefKind),
|
GenericParamsFromOuterItem(Res, HasGenericParams, DefKind),
|
||||||
/// Error E0403: the name is already used for a type or const parameter in this generic
|
/// Error E0403: the name is already used for a type or const parameter in this generic
|
||||||
/// parameter list.
|
/// parameter list.
|
||||||
NameAlreadyUsedInParameterList(Symbol, Span),
|
NameAlreadyUsedInParameterList(Ident, Span),
|
||||||
/// Error E0407: method is not a member of trait.
|
/// Error E0407: method is not a member of trait.
|
||||||
MethodNotMemberOfTrait(Ident, String, Option<Symbol>),
|
MethodNotMemberOfTrait(Ident, String, Option<Symbol>),
|
||||||
/// Error E0437: type is not a member of trait.
|
/// Error E0437: type is not a member of trait.
|
||||||
|
@ -236,11 +236,11 @@ enum ResolutionError<'ra> {
|
||||||
/// Error E0408: variable `{}` is not bound in all patterns.
|
/// Error E0408: variable `{}` is not bound in all patterns.
|
||||||
VariableNotBoundInPattern(BindingError, ParentScope<'ra>),
|
VariableNotBoundInPattern(BindingError, ParentScope<'ra>),
|
||||||
/// Error E0409: variable `{}` is bound in inconsistent ways within the same match arm.
|
/// Error E0409: variable `{}` is bound in inconsistent ways within the same match arm.
|
||||||
VariableBoundWithDifferentMode(Symbol, Span),
|
VariableBoundWithDifferentMode(Ident, Span),
|
||||||
/// Error E0415: identifier is bound more than once in this parameter list.
|
/// Error E0415: identifier is bound more than once in this parameter list.
|
||||||
IdentifierBoundMoreThanOnceInParameterList(Symbol),
|
IdentifierBoundMoreThanOnceInParameterList(Ident),
|
||||||
/// Error E0416: identifier is bound more than once in the same pattern.
|
/// Error E0416: identifier is bound more than once in the same pattern.
|
||||||
IdentifierBoundMoreThanOnceInSamePattern(Symbol),
|
IdentifierBoundMoreThanOnceInSamePattern(Ident),
|
||||||
/// Error E0426: use of undeclared label.
|
/// Error E0426: use of undeclared label.
|
||||||
UndeclaredLabel { name: Symbol, suggestion: Option<LabelSuggestion> },
|
UndeclaredLabel { name: Symbol, suggestion: Option<LabelSuggestion> },
|
||||||
/// Error E0429: `self` imports are only allowed within a `{ }` list.
|
/// Error E0429: `self` imports are only allowed within a `{ }` list.
|
||||||
|
@ -292,14 +292,14 @@ enum ResolutionError<'ra> {
|
||||||
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
||||||
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
||||||
TraitImplMismatch {
|
TraitImplMismatch {
|
||||||
name: Symbol,
|
name: Ident,
|
||||||
kind: &'static str,
|
kind: &'static str,
|
||||||
trait_path: String,
|
trait_path: String,
|
||||||
trait_item_span: Span,
|
trait_item_span: Span,
|
||||||
code: ErrCode,
|
code: ErrCode,
|
||||||
},
|
},
|
||||||
/// Error E0201: multiple impl items for the same trait item.
|
/// Error E0201: multiple impl items for the same trait item.
|
||||||
TraitImplDuplicate { name: Symbol, trait_item_span: Span, old_span: Span },
|
TraitImplDuplicate { name: Ident, trait_item_span: Span, old_span: Span },
|
||||||
/// Inline asm `sym` operand must refer to a `fn` or `static`.
|
/// Inline asm `sym` operand must refer to a `fn` or `static`.
|
||||||
InvalidAsmSym,
|
InvalidAsmSym,
|
||||||
/// `self` used instead of `Self` in a generic parameter
|
/// `self` used instead of `Self` in a generic parameter
|
||||||
|
|
|
@ -13,7 +13,7 @@ use rustc_middle::ty::print::PrintTraitRefExt as _;
|
||||||
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt};
|
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt};
|
||||||
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
|
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
|
||||||
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
|
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
|
||||||
use rustc_span::{Span, Symbol, kw, sym};
|
use rustc_span::{Ident, Span, Symbol, kw, sym};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
use {rustc_attr_parsing as attr, rustc_hir as hir};
|
use {rustc_attr_parsing as attr, rustc_hir as hir};
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ impl IgnoredDiagnosticOption {
|
||||||
#[help]
|
#[help]
|
||||||
pub struct UnknownFormatParameterForOnUnimplementedAttr {
|
pub struct UnknownFormatParameterForOnUnimplementedAttr {
|
||||||
argument_name: Symbol,
|
argument_name: Symbol,
|
||||||
trait_name: Symbol,
|
trait_name: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
@ -792,7 +792,7 @@ impl<'tcx> OnUnimplementedFormatString {
|
||||||
tcx.trait_id_of_impl(item_def_id)
|
tcx.trait_id_of_impl(item_def_id)
|
||||||
.expect("expected `on_unimplemented` to correspond to a trait")
|
.expect("expected `on_unimplemented` to correspond to a trait")
|
||||||
};
|
};
|
||||||
let trait_name = tcx.item_name(trait_def_id);
|
let trait_name = tcx.item_ident(trait_def_id);
|
||||||
let generics = tcx.generics_of(item_def_id);
|
let generics = tcx.generics_of(item_def_id);
|
||||||
let s = self.symbol.as_str();
|
let s = self.symbol.as_str();
|
||||||
let mut parser = Parser::new(s, None, None, false, ParseMode::Format);
|
let mut parser = Parser::new(s, None, None, false, ParseMode::Format);
|
||||||
|
@ -821,7 +821,11 @@ impl<'tcx> OnUnimplementedFormatString {
|
||||||
Position::ArgumentNamed(s) => {
|
Position::ArgumentNamed(s) => {
|
||||||
match Symbol::intern(s) {
|
match Symbol::intern(s) {
|
||||||
// `{ThisTraitsName}` is allowed
|
// `{ThisTraitsName}` is allowed
|
||||||
s if s == trait_name && !self.is_diagnostic_namespace_variant => (),
|
s if s == trait_name.name
|
||||||
|
&& !self.is_diagnostic_namespace_variant =>
|
||||||
|
{
|
||||||
|
()
|
||||||
|
}
|
||||||
s if ALLOWED_FORMAT_SYMBOLS.contains(&s)
|
s if ALLOWED_FORMAT_SYMBOLS.contains(&s)
|
||||||
&& !self.is_diagnostic_namespace_variant =>
|
&& !self.is_diagnostic_namespace_variant =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue