Migrate some diagnostics
This commit is contained in:
parent
e4f4e58dc3
commit
4226dc2045
@ -296,7 +296,7 @@ resolve_self_in_generic_param_default =
|
||||
generic parameters cannot use `Self` in their defaults
|
||||
.label = `Self` in generic parameter default
|
||||
|
||||
resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$ident}`
|
||||
resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$lifetime}`
|
||||
.label = 'static is a reserved lifetime name
|
||||
|
||||
resolve_tool_module_imported =
|
||||
|
@ -29,8 +29,8 @@
|
||||
use rustc_span::{BytePos, Span, SyntaxContext};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
use crate::errors::{AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion};
|
||||
use crate::errors::{
|
||||
use crate::errors::{self,
|
||||
AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion,
|
||||
ConsiderAddingADerive, ExplicitUnsafeTraits, MacroDefinedLater, MacroSuggMovePosition,
|
||||
MaybeMissingMacroRulesName,
|
||||
};
|
||||
@ -677,18 +677,20 @@ pub(crate) fn into_struct_error(
|
||||
let origin_sp = origin.iter().copied().collect::<Vec<_>>();
|
||||
|
||||
let msp = MultiSpan::from_spans(target_sp.clone());
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
msp,
|
||||
E0408,
|
||||
"variable `{}` is not bound in all patterns",
|
||||
let mut err = self.dcx().create_err(errors::VariableIsNotBoundInAllPatterns {
|
||||
multispan: msp,
|
||||
name,
|
||||
);
|
||||
});
|
||||
for sp in target_sp {
|
||||
err.span_label(sp, format!("pattern doesn't bind `{name}`"));
|
||||
err.subdiagnostic(self.dcx(), errors::PatternDoesntBindName {
|
||||
span: sp,
|
||||
name,
|
||||
});
|
||||
}
|
||||
for sp in origin_sp {
|
||||
err.span_label(sp, "variable not in all patterns");
|
||||
err.subdiagnostic(self.dcx(), errors::VariableNotInAllPatterns {
|
||||
span: sp,
|
||||
});
|
||||
}
|
||||
if could_be_path {
|
||||
let import_suggestions = self.lookup_import_candidates(
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![allow(dead_code)] // TODO : non
|
||||
use rustc_errors::{codes::*, Applicability, MultiSpan};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{
|
||||
|
@ -6,8 +6,7 @@
|
||||
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
|
||||
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
|
||||
|
||||
use crate::errors::ImportsCannotReferTo;
|
||||
use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
||||
use crate::{errors, path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
||||
use crate::{BindingKey, Used};
|
||||
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult};
|
||||
use crate::{ResolutionError, Resolver, Segment, UseError};
|
||||
@ -17,7 +16,7 @@
|
||||
use rustc_ast::*;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_errors::{
|
||||
codes::*, struct_span_code_err, Applicability, DiagArgValue, IntoDiagArg, StashKey,
|
||||
codes::*, Applicability, DiagArgValue, IntoDiagArg, StashKey,
|
||||
};
|
||||
use rustc_hir::def::Namespace::{self, *};
|
||||
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
|
||||
@ -1666,18 +1665,8 @@ fn resolve_anonymous_lifetime(&mut self, lifetime: &Lifetime, elided: bool) {
|
||||
);
|
||||
}
|
||||
LifetimeRibKind::AnonymousReportError => {
|
||||
let (msg, note) = if elided {
|
||||
(
|
||||
"`&` without an explicit lifetime name cannot be used here",
|
||||
"explicit lifetime name needed here",
|
||||
)
|
||||
} else {
|
||||
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
||||
};
|
||||
let mut diag =
|
||||
struct_span_code_err!(self.r.dcx(), lifetime.ident.span, E0637, "{}", msg,);
|
||||
diag.span_label(lifetime.ident.span, note);
|
||||
if elided {
|
||||
let mut suggestion = None;
|
||||
for rib in self.lifetime_ribs[i..].iter().rev() {
|
||||
if let LifetimeRibKind::Generics {
|
||||
span,
|
||||
@ -1685,19 +1674,23 @@ fn resolve_anonymous_lifetime(&mut self, lifetime: &Lifetime, elided: bool) {
|
||||
..
|
||||
} = &rib.kind
|
||||
{
|
||||
diag.multipart_suggestion(
|
||||
"consider introducing a higher-ranked lifetime here",
|
||||
vec![
|
||||
(span.shrink_to_lo(), "for<'a> ".into()),
|
||||
(lifetime.ident.span.shrink_to_hi(), "'a ".into()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
suggestion =
|
||||
Some(errors::ElidedAnonymousLivetimeReportErrorSuggestion {
|
||||
lo: span.shrink_to_lo(),
|
||||
hi: lifetime.ident.span.shrink_to_hi(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
diag.emit();
|
||||
self.r.dcx().emit_err(errors::ElidedAnonymousLivetimeReportError {
|
||||
span: lifetime.ident.span,
|
||||
suggestion,
|
||||
});
|
||||
} else {
|
||||
self.r.dcx().emit_err(errors::ExplicitAnonymousLivetimeReportError {
|
||||
span: lifetime.ident.span,
|
||||
});
|
||||
};
|
||||
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
|
||||
return;
|
||||
}
|
||||
@ -1863,13 +1856,11 @@ fn resolve_elided_lifetimes_in_path(
|
||||
// async fn foo(_: std::cell::Ref<u32>) { ... }
|
||||
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
|
||||
| LifetimeRibKind::AnonymousWarn(_) => {
|
||||
let mut err =
|
||||
self.r.dcx().create_err(errors::ImplicitElidedLifetimeNotAllowedHere {
|
||||
span: path_span,
|
||||
});
|
||||
let sess = self.r.tcx.sess;
|
||||
let mut err = struct_span_code_err!(
|
||||
sess.dcx(),
|
||||
path_span,
|
||||
E0726,
|
||||
"implicit elided lifetime not allowed here"
|
||||
);
|
||||
rustc_errors::add_elided_lifetime_in_path_suggestion(
|
||||
sess.source_map(),
|
||||
&mut err,
|
||||
@ -2313,7 +2304,7 @@ fn future_proof_import(&mut self, use_tree: &UseTree) {
|
||||
let report_error = |this: &Self, ns| {
|
||||
if this.should_report_errs() {
|
||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||
this.r.dcx().emit_err(ImportsCannotReferTo { span: ident.span, what });
|
||||
this.r.dcx().emit_err(errors::ImportsCannotReferTo { span: ident.span, what });
|
||||
}
|
||||
};
|
||||
|
||||
@ -2633,29 +2624,19 @@ fn with_generic_param_rib<'c, F>(
|
||||
}
|
||||
|
||||
if param.ident.name == kw::UnderscoreLifetime {
|
||||
struct_span_code_err!(
|
||||
self.r.dcx(),
|
||||
param.ident.span,
|
||||
E0637,
|
||||
"`'_` cannot be used here"
|
||||
)
|
||||
.with_span_label(param.ident.span, "`'_` is a reserved lifetime name")
|
||||
.emit();
|
||||
self.r
|
||||
.dcx()
|
||||
.emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span });
|
||||
// Record lifetime res, so lowering knows there is something fishy.
|
||||
self.record_lifetime_param(param.id, LifetimeRes::Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
if param.ident.name == kw::StaticLifetime {
|
||||
struct_span_code_err!(
|
||||
self.r.dcx(),
|
||||
param.ident.span,
|
||||
E0262,
|
||||
"invalid lifetime parameter name: `{}`",
|
||||
param.ident,
|
||||
)
|
||||
.with_span_label(param.ident.span, "'static is a reserved lifetime name")
|
||||
.emit();
|
||||
self.r.dcx().emit_err(errors::StaticLifetimeIsReserved {
|
||||
span: param.ident.span,
|
||||
lifetime: param.ident,
|
||||
});
|
||||
// Record lifetime res, so lowering knows there is something fishy.
|
||||
self.record_lifetime_param(param.id, LifetimeRes::Error);
|
||||
continue;
|
||||
|
@ -14,7 +14,7 @@
|
||||
use rustc_attr::StabilityLevel;
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, StashKey};
|
||||
use rustc_errors::{Applicability, StashKey};
|
||||
use rustc_expand::base::{Annotatable, DeriveResolutions, Indeterminate, ResolverExpand};
|
||||
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_expand::compile_declarative_macro;
|
||||
@ -916,14 +916,10 @@ pub(crate) fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> Ma
|
||||
rule_spans = Vec::new();
|
||||
}
|
||||
BuiltinMacroState::AlreadySeen(span) => {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
item.span,
|
||||
E0773,
|
||||
"attempted to define built-in macro more than once"
|
||||
)
|
||||
.with_span_note(span, "previously defined here")
|
||||
.emit();
|
||||
self.dcx().emit_err(errors::AttemptToDefineBuiltinMacroTwice {
|
||||
span: item.span,
|
||||
note_span: span,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user