Skip to content

Commit 4226dc2

Browse files
committed
Migrate some diagnostics
1 parent e4f4e58 commit 4226dc2

5 files changed

Lines changed: 48 additions & 70 deletions

File tree

‎compiler/rustc_resolve/messages.ftl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ resolve_self_in_generic_param_default =
296296
generic parameters cannot use `Self` in their defaults
297297
.label = `Self` in generic parameter default
298298
299-
resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$ident}`
299+
resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$lifetime}`
300300
.label = 'static is a reserved lifetime name
301301
302302
resolve_tool_module_imported =

‎compiler/rustc_resolve/src/diagnostics.rs‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
2929
use rustc_span::{BytePos,Span,SyntaxContext};
3030
use thin_vec::{thin_vec,ThinVec};
3131

32-
usecrate::errors::{AddedMacroUse,ChangeImportBinding,ChangeImportBindingSuggestion};
33-
usecrate::errors::{
32+
usecrate::errors::{self,
33+
AddedMacroUse,ChangeImportBinding,ChangeImportBindingSuggestion,
3434
ConsiderAddingADerive,ExplicitUnsafeTraits,MacroDefinedLater,MacroSuggMovePosition,
3535
MaybeMissingMacroRulesName,
3636
};
@@ -677,18 +677,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
677677
let origin_sp = origin.iter().copied().collect::<Vec<_>>();
678678

679679
let msp = MultiSpan::from_spans(target_sp.clone());
680-
letmut err = struct_span_code_err!(
681-
self.dcx(),
682-
msp,
683-
E0408,
684-
"variable `{}` is not bound in all patterns",
680+
letmut err = self.dcx().create_err(errors::VariableIsNotBoundInAllPatterns{
681+
multispan: msp,
685682
name,
686-
);
683+
});
687684
for sp in target_sp {
688-
err.span_label(sp,format!("pattern doesn't bind `{name}`"));
685+
err.subdiagnostic(self.dcx(), errors::PatternDoesntBindName{
686+
span: sp,
687+
name,
688+
});
689689
}
690690
for sp in origin_sp {
691-
err.span_label(sp,"variable not in all patterns");
691+
err.subdiagnostic(self.dcx(), errors::VariableNotInAllPatterns{
692+
span: sp,
693+
});
692694
}
693695
if could_be_path {
694696
let import_suggestions = self.lookup_import_candidates(

‎compiler/rustc_resolve/src/errors.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(dead_code)]// TODO : non
21
use rustc_errors::{codes::*,Applicability,MultiSpan};
32
use rustc_macros::{Diagnostic,Subdiagnostic};
43
use rustc_span::{
@@ -955,4 +954,4 @@ pub(crate) struct PatternDoesntBindName {
955954
pub(crate)structVariableNotInAllPatterns{
956955
#[primary_span]
957956
pub(crate)span:Span,
958-
}
957+
}

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
77
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
88
9-
usecrate::errors::ImportsCannotReferTo;
10-
usecrate::{path_names_to_string, rustdoc,BindingError,Finalize,LexicalScopeBinding};
9+
usecrate::{errors, path_names_to_string, rustdoc,BindingError,Finalize,LexicalScopeBinding};
1110
usecrate::{BindingKey,Used};
1211
usecrate::{Module,ModuleOrUniformRoot,NameBinding,ParentScope,PathResult};
1312
usecrate::{ResolutionError,Resolver,Segment,UseError};
@@ -17,7 +16,7 @@ use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}
1716
use rustc_ast::*;
1817
use rustc_data_structures::fx::{FxHashMap,FxHashSet,FxIndexMap};
1918
use rustc_errors::{
20-
codes::*,struct_span_code_err,Applicability,DiagArgValue,IntoDiagArg,StashKey,
19+
codes::*,Applicability,DiagArgValue,IntoDiagArg,StashKey,
2120
};
2221
use rustc_hir::def::Namespace::{self,*};
2322
use rustc_hir::def::{self,CtorKind,DefKind,LifetimeRes,NonMacroAttrKind,PartialRes,PerNS};
@@ -1666,38 +1665,32 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16661665
);
16671666
}
16681667
LifetimeRibKind::AnonymousReportError => {
1669-
let(msg, note) = if elided {
1670-
(
1671-
"`&` without an explicit lifetime name cannot be used here",
1672-
"explicit lifetime name needed here",
1673-
)
1674-
}else{
1675-
("`'_` cannot be used here","`'_` is a reserved lifetime name")
1676-
};
1677-
letmut diag =
1678-
struct_span_code_err!(self.r.dcx(), lifetime.ident.span,E0637,"{}", msg,);
1679-
diag.span_label(lifetime.ident.span, note);
16801668
if elided {
1669+
letmut suggestion = None;
16811670
for rib inself.lifetime_ribs[i..].iter().rev(){
16821671
ifletLifetimeRibKind::Generics{
16831672
span,
16841673
kind:LifetimeBinderKind::PolyTrait | LifetimeBinderKind::WhereBound,
16851674
..
16861675
} = &rib.kind
16871676
{
1688-
diag.multipart_suggestion(
1689-
"consider introducing a higher-ranked lifetime here",
1690-
vec![
1691-
(span.shrink_to_lo(),"for<'a> ".into()),
1692-
(lifetime.ident.span.shrink_to_hi(),"'a ".into()),
1693-
],
1694-
Applicability::MachineApplicable,
1695-
);
1677+
suggestion =
1678+
Some(errors::ElidedAnonymousLivetimeReportErrorSuggestion{
1679+
lo: span.shrink_to_lo(),
1680+
hi: lifetime.ident.span.shrink_to_hi(),
1681+
});
16961682
break;
16971683
}
16981684
}
1699-
}
1700-
diag.emit();
1685+
self.r.dcx().emit_err(errors::ElidedAnonymousLivetimeReportError{
1686+
span: lifetime.ident.span,
1687+
suggestion,
1688+
});
1689+
}else{
1690+
self.r.dcx().emit_err(errors::ExplicitAnonymousLivetimeReportError{
1691+
span: lifetime.ident.span,
1692+
});
1693+
};
17011694
self.record_lifetime_res(lifetime.id,LifetimeRes::Error, elision_candidate);
17021695
return;
17031696
}
@@ -1863,13 +1856,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
18631856
// async fn foo(_: std::cell::Ref<u32>) { ... }
18641857
LifetimeRibKind::AnonymousCreateParameter{report_in_path:true, .. }
18651858
| LifetimeRibKind::AnonymousWarn(_) => {
1859+
letmut err =
1860+
self.r.dcx().create_err(errors::ImplicitElidedLifetimeNotAllowedHere{
1861+
span: path_span,
1862+
});
18661863
let sess = self.r.tcx.sess;
1867-
letmut err = struct_span_code_err!(
1868-
sess.dcx(),
1869-
path_span,
1870-
E0726,
1871-
"implicit elided lifetime not allowed here"
1872-
);
18731864
rustc_errors::add_elided_lifetime_in_path_suggestion(
18741865
sess.source_map(),
18751866
&mut err,
@@ -2313,7 +2304,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23132304
let report_error = |this:&Self, ns| {
23142305
if this.should_report_errs(){
23152306
let what = if ns == TypeNS{"type parameters"}else{"local variables"};
2316-
this.r.dcx().emit_err(ImportsCannotReferTo{span: ident.span, what });
2307+
this.r.dcx().emit_err(errors::ImportsCannotReferTo{span: ident.span, what });
23172308
}
23182309
};
23192310

@@ -2633,29 +2624,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26332624
}
26342625

26352626
if param.ident.name == kw::UnderscoreLifetime{
2636-
struct_span_code_err!(
2637-
self.r.dcx(),
2638-
param.ident.span,
2639-
E0637,
2640-
"`'_` cannot be used here"
2641-
)
2642-
.with_span_label(param.ident.span,"`'_` is a reserved lifetime name")
2643-
.emit();
2627+
self.r
2628+
.dcx()
2629+
.emit_err(errors::UnderscoreLifetimeIsReserved{span: param.ident.span});
26442630
// Record lifetime res, so lowering knows there is something fishy.
26452631
self.record_lifetime_param(param.id,LifetimeRes::Error);
26462632
continue;
26472633
}
26482634

26492635
if param.ident.name == kw::StaticLifetime{
2650-
struct_span_code_err!(
2651-
self.r.dcx(),
2652-
param.ident.span,
2653-
E0262,
2654-
"invalid lifetime parameter name: `{}`",
2655-
param.ident,
2656-
)
2657-
.with_span_label(param.ident.span,"'static is a reserved lifetime name")
2658-
.emit();
2636+
self.r.dcx().emit_err(errors::StaticLifetimeIsReserved{
2637+
span: param.ident.span,
2638+
lifetime: param.ident,
2639+
});
26592640
// Record lifetime res, so lowering knows there is something fishy.
26602641
self.record_lifetime_param(param.id,LifetimeRes::Error);
26612642
continue;

‎compiler/rustc_resolve/src/macros.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_ast_pretty::pprust;
1414
use rustc_attr::StabilityLevel;
1515
use rustc_data_structures::intern::Interned;
1616
use rustc_data_structures::sync::Lrc;
17-
use rustc_errors::{codes::*, struct_span_code_err,Applicability,StashKey};
17+
use rustc_errors::{Applicability,StashKey};
1818
use rustc_expand::base::{Annotatable,DeriveResolutions,Indeterminate,ResolverExpand};
1919
use rustc_expand::base::{SyntaxExtension,SyntaxExtensionKind};
2020
use rustc_expand::compile_declarative_macro;
@@ -916,14 +916,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
916916
rule_spans = Vec::new();
917917
}
918918
BuiltinMacroState::AlreadySeen(span) => {
919-
struct_span_code_err!(
920-
self.dcx(),
921-
item.span,
922-
E0773,
923-
"attempted to define built-in macro more than once"
924-
)
925-
.with_span_note(span,"previously defined here")
926-
.emit();
919+
self.dcx().emit_err(errors::AttemptToDefineBuiltinMacroTwice{
920+
span: item.span,
921+
note_span: span,
922+
});
927923
}
928924
}
929925
}else{

0 commit comments

Comments
 (0)