Skip to content

Commit e4f4e58

Browse files
committed
Port build_reduce_graph
1 parent 7106800 commit e4f4e58

File tree

4 files changed

+235
-51
lines changed

4 files changed

+235
-51
lines changed

compiler/rustc_resolve/messages.ftl

+58-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ resolve_added_macro_use =
1111
resolve_ancestor_only =
1212
visibilities can only be restricted to ancestor modules
1313
14+
resolve_arguments_macro_use_not_allowed = arguments to `macro_use` are not allowed here
15+
1416
resolve_associated_const_with_similar_name_exists =
1517
there is an associated constant with a similar name
1618
@@ -20,6 +22,10 @@ resolve_associated_fn_with_similar_name_exists =
2022
resolve_associated_type_with_similar_name_exists =
2123
there is an associated type with a similar name
2224
25+
resolve_attempt_to_define_builtin_macro_twice =
26+
attempted to define built-in macro more than once
27+
.note = previously defined here
28+
2329
resolve_attempt_to_use_non_constant_value_in_constant =
2430
attempt to use a non-constant value in a constant
2531
@@ -32,6 +38,8 @@ resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion =
3238
resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion =
3339
this would need to be a `{$suggestion}`
3440
41+
resolve_bad_macro_import = bad macro import
42+
3543
resolve_binding_in_never_pattern =
3644
never patterns cannot contain variable bindings
3745
.suggestion = use a wildcard `_` instead
@@ -100,13 +108,31 @@ resolve_const_param_in_non_trivial_anon_const =
100108
resolve_const_param_in_ty_of_const_param =
101109
const parameters may not be used in the type of const parameters
102110
103-
resolve_expected_found =
111+
resolve_elided_anonymous_lifetime_report_error =
112+
`&` without an explicit lifetime name cannot be used here
113+
.label = explicit lifetime name needed here
114+
115+
resolve_elided_anonymous_lifetime_report_error_suggestion =
116+
consider introducing a higher-ranked lifetime here
117+
118+
resolve_expected_module_found =
104119
expected module, found {$res} `{$path_str}`
105120
.label = not a module
106121
122+
resolve_explicit_anonymous_lifetime_report_error =
123+
`'_` cannot be used here
124+
.label = `'_` is a reserved lifetime name
125+
107126
resolve_explicit_unsafe_traits =
108127
unsafe traits like `{$ident}` should be implemented explicitly
109128
129+
resolve_extern_crate_loading_macro_not_at_crate_root =
130+
an `extern crate` loading macros must be at the crate root
131+
132+
resolve_extern_crate_self_requires_renaming =
133+
`extern crate self;` requires renaming
134+
.suggestion = rename the `self` crate to be able to import it
135+
110136
resolve_forward_declared_generic_param =
111137
generic parameters with a default cannot use forward declared identifiers
112138
.label = defaulted generic parameters cannot be forward declared
@@ -135,17 +161,20 @@ resolve_generic_params_from_outer_item_static = a `static` is a separate item fr
135161
136162
resolve_generic_params_from_outer_item_ty_param = type parameter from outer item
137163
138-
139164
resolve_ident_bound_more_than_once_in_parameter_list =
140165
identifier `{$identifier}` is bound more than once in this parameter list
141166
.label = used as parameter more than once
142167
168+
resolve_implicit_elided_lifetimes_not_allowed_here = implicit elided lifetime not allowed here
169+
143170
resolve_ident_bound_more_than_once_in_same_pattern =
144171
identifier `{$identifier}` is bound more than once in the same pattern
145172
.label = used in a pattern more than once
146173
147174
resolve_imported_crate = `$crate` may not be imported
148175
176+
resolve_imported_macro_not_found = imported macro not found
177+
149178
resolve_imports_cannot_refer_to =
150179
imports cannot refer to {$what}
151180
@@ -183,11 +212,22 @@ resolve_lowercase_self =
183212
resolve_macro_defined_later =
184213
a macro with the same name exists, but it appears later at here
185214
215+
resolve_macro_expanded_extern_crate_cannot_shadow_extern_arguments =
216+
macro-expanded `extern crate` items cannot shadow names passed with `--extern`
217+
186218
resolve_macro_expected_found =
187219
expected {$expected}, found {$found} `{$macro_path}`
188220
221+
resolve_macro_extern_deprecated =
222+
`#[macro_escape]` is a deprecated synonym for `#[macro_use]`
223+
.help = try an outer attribute: `#[macro_use]`
224+
189225
resolve_macro_use_extern_crate_self = `#[macro_use]` is not supported on `extern crate self`
190226
227+
resolve_macro_use_name_already_in_use =
228+
`{$name}` is already in scope
229+
.note = macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)
230+
191231
resolve_method_not_member_of_trait =
192232
method `{$method}` is not a member of trait `{$trait_}`
193233
.label = not a member of trait `{$trait_}`
@@ -217,6 +257,8 @@ resolve_param_in_ty_of_const_param =
217257
the type of const parameters must not depend on other generic parameters
218258
.label = the type must not depend on the parameter `{$name}`
219259
260+
resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}`
261+
220262
resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it
221263
.help = you can define integration tests in a directory named `tests`
222264
@@ -254,6 +296,9 @@ resolve_self_in_generic_param_default =
254296
generic parameters cannot use `Self` in their defaults
255297
.label = `Self` in generic parameter default
256298
299+
resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$ident}`
300+
.label = 'static is a reserved lifetime name
301+
257302
resolve_tool_module_imported =
258303
cannot use a tool module through an import
259304
.note = the tool module imported here
@@ -284,12 +329,18 @@ resolve_undeclared_label =
284329
use of undeclared label `{$name}`
285330
.label = undeclared label `{$name}`
286331
332+
resolve_underscore_lifetime_is_reserved = `'_` cannot be used here
333+
.label = `'_` is a reserved lifetime name
334+
287335
resolve_unexpected_res_change_ty_to_const_param_sugg =
288336
you might have meant to write a const parameter here
289337
290338
resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg =
291339
if you meant to collect the rest of the slice in `{$ident}`, use the at operator
292340
341+
resolve_unnamed_crate_root_import =
342+
crate root imports need to be explicitly named: `use crate as name;`
343+
293344
resolve_unreachable_label =
294345
use of unreachable label `{$name}`
295346
.label = unreachable label `{$name}`
@@ -312,3 +363,8 @@ resolve_variable_bound_with_different_mode =
312363
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
313364
.label = bound in different ways
314365
.first_binding_span = first binding
366+
367+
resolve_variable_is_not_bound_in_all_patterns =
368+
variable `{$name}` is not bound in all patterns
369+
370+
resolve_variable_not_in_all_patterns = variable not in all patterns

compiler/rustc_resolve/src/build_reduced_graph.rs

+18-45
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
1919
use rustc_ast::{Block, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
2020
use rustc_attr as attr;
2121
use rustc_data_structures::sync::Lrc;
22-
use rustc_errors::{codes::*, struct_span_code_err, Applicability};
2322
use rustc_expand::expand::AstFragment;
2423
use rustc_hir::def::{self, *};
2524
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
@@ -529,11 +528,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
529528
}
530529

531530
if ident.name == kw::Crate {
532-
self.r.dcx().span_err(
533-
ident.span,
534-
"crate root imports need to be explicitly named: \
535-
`use crate as name;`",
536-
);
531+
self.r.dcx().emit_err(errors::UnnamedCrateRootImport { span: ident.span });
537532
}
538533

539534
let kind = ImportKind::Single {
@@ -848,16 +843,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
848843
let expansion = parent_scope.expansion;
849844

850845
let (used, module, binding) = if orig_name.is_none() && ident.name == kw::SelfLower {
851-
self.r
852-
.dcx()
853-
.struct_span_err(item.span, "`extern crate self;` requires renaming")
854-
.with_span_suggestion(
855-
item.span,
856-
"rename the `self` crate to be able to import it",
857-
"extern crate self as name;",
858-
Applicability::HasPlaceholders,
859-
)
860-
.emit();
846+
self.r.dcx().emit_err(errors::ExternCrateSelfRequiresRenaming { span: sp });
861847
return;
862848
} else if orig_name == Some(kw::SelfLower) {
863849
Some(self.r.graph_root)
@@ -897,9 +883,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
897883
if parent == self.r.graph_root {
898884
if let Some(entry) = self.r.extern_prelude.get(&ident.normalize_to_macros_2_0()) {
899885
if expansion != LocalExpnId::ROOT && orig_name.is_some() && !entry.is_import() {
900-
let msg = "macro-expanded `extern crate` items cannot \
901-
shadow names passed with `--extern`";
902-
self.r.dcx().span_err(item.span, msg);
886+
self.r.dcx().emit_err(
887+
errors::MacroExpandedExternCrateCannotShadowExternArguments {
888+
span: item.span,
889+
},
890+
);
903891
// `return` is intended to discard this binding because it's an
904892
// unregistered ambiguity error which would result in a panic
905893
// caused by inconsistency `path_res`
@@ -1030,10 +1018,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10301018
allow_shadowing: bool,
10311019
) {
10321020
if self.r.macro_use_prelude.insert(name, binding).is_some() && !allow_shadowing {
1033-
let msg = format!("`{name}` is already in scope");
1034-
let note =
1035-
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
1036-
self.r.dcx().struct_span_err(span, msg).with_note(note).emit();
1021+
self.r.dcx().emit_err(errors::MacroUseNameAlreadyInUse { span, name });
10371022
}
10381023
}
10391024

@@ -1044,21 +1029,17 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10441029
for attr in &item.attrs {
10451030
if attr.has_name(sym::macro_use) {
10461031
if self.parent_scope.module.parent.is_some() {
1047-
struct_span_code_err!(
1048-
self.r.dcx(),
1049-
item.span,
1050-
E0468,
1051-
"an `extern crate` loading macros must be at the crate root"
1052-
)
1053-
.emit();
1032+
self.r.dcx().emit_err(errors::ExternCrateLoadingMacroNotAtCrateRoot {
1033+
span: item.span,
1034+
});
10541035
}
10551036
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
10561037
if orig_name == kw::SelfLower {
10571038
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
10581039
}
10591040
}
10601041
let ill_formed = |span| {
1061-
struct_span_code_err!(self.r.dcx(), span, E0466, "bad macro import").emit();
1042+
self.r.dcx().emit_err(errors::BadMacroImport { span });
10621043
};
10631044
match attr.meta() {
10641045
Some(meta) => match meta.kind {
@@ -1143,13 +1124,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11431124
allow_shadowing,
11441125
);
11451126
} else {
1146-
struct_span_code_err!(
1147-
self.r.dcx(),
1148-
ident.span,
1149-
E0469,
1150-
"imported macro not found"
1151-
)
1152-
.emit();
1127+
self.r.dcx().emit_err(errors::ImportedMacroNotFound { span: ident.span });
11531128
}
11541129
}
11551130
}
@@ -1160,18 +1135,16 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11601135
fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
11611136
for attr in attrs {
11621137
if attr.has_name(sym::macro_escape) {
1163-
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
1164-
let mut err = self.r.dcx().struct_span_warn(attr.span, msg);
1165-
if let ast::AttrStyle::Inner = attr.style {
1166-
err.help("try an outer attribute: `#[macro_use]`");
1167-
}
1168-
err.emit();
1138+
let inner_attribute = matches!(attr.style, ast::AttrStyle::Inner).then_some(());
1139+
self.r
1140+
.dcx()
1141+
.emit_warn(errors::MacroExternDeprecated { span: attr.span, inner_attribute });
11691142
} else if !attr.has_name(sym::macro_use) {
11701143
continue;
11711144
}
11721145

11731146
if !attr.is_word() {
1174-
self.r.dcx().span_err(attr.span, "arguments to `macro_use` are not allowed here");
1147+
self.r.dcx().emit_err(errors::ArgumentsMacroUseNotAllowed { span: attr.span });
11751148
}
11761149
return true;
11771150
}

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10051005
ResolutionError::FailedToResolve { segment: None, label, suggestion, module: None },
10061006
),
10071007
VisResolutionError::ExpectedFound(span, path_str, res) => {
1008-
self.dcx().create_err(errs::ExpectedFound { span, res, path_str })
1008+
self.dcx().create_err(errs::ExpectedModuleFound { span, res, path_str })
10091009
}
10101010
VisResolutionError::Indeterminate(span) => {
10111011
self.dcx().create_err(errs::Indeterminate(span))

0 commit comments

Comments
 (0)