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