Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ use tracing::debug;

use crate::Namespace::{MacroNS, TypeNS, ValueNS};
use crate::def_collector::DefCollector;
use crate::diagnostics::StructCtor;
use crate::error_helper::StructCtor;
use crate::imports::{ImportData, ImportKind, OnUnknownData};
use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef};
use crate::ref_mut::CmCell;
use crate::{
BindingKey, Decl, DeclData, DeclKind, DelayedVisResolutionError, ExternModule,
ExternPreludeEntry, Finalize, IdentKey, LocalModule, Module, ModuleKind, ModuleOrUniformRoot,
ParentScope, PathResult, Res, Resolver, Segment, Used, VisResolutionError, errors,
ParentScope, PathResult, Res, Resolver, Segment, Used, VisResolutionError, diagnostics,
};

impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
Expand Down Expand Up @@ -706,9 +706,9 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
// Deny importing path-kw without renaming
if rename.is_none() && ident.is_path_segment_keyword() {
let ident = use_tree.ident();
self.r.dcx().emit_err(errors::UnnamedImport {
self.r.dcx().emit_err(diagnostics::UnnamedImport {
span: ident.span,
sugg: errors::UnnamedImportSugg { span: ident.span, ident },
sugg: diagnostics::UnnamedImportSugg { span: ident.span, ident },
});
return;
}
Expand Down Expand Up @@ -996,7 +996,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
let expansion = parent_scope.expansion;

let (used, module, decl) = if orig_name.is_none() && orig_ident.name == kw::SelfLower {
self.r.dcx().emit_err(errors::ExternCrateSelfRequiresRenaming { span: sp });
self.r.dcx().emit_err(diagnostics::ExternCrateSelfRequiresRenaming { span: sp });
return;
} else if orig_name == Some(kw::SelfLower) {
Some(self.r.graph_root.to_module())
Expand Down Expand Up @@ -1054,7 +1054,9 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
&& entry.item_decl.is_none()
{
self.r.dcx().emit_err(
errors::MacroExpandedExternCrateCannotShadowExternArguments { span: item.span },
diagnostics::MacroExpandedExternCrateCannotShadowExternArguments {
span: item.span,
},
);
}

Expand Down Expand Up @@ -1125,7 +1127,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
allow_shadowing: bool,
) {
if self.r.macro_use_prelude.insert(name, decl).is_some() && !allow_shadowing {
self.r.dcx().emit_err(errors::MacroUseNameAlreadyInUse { span, name });
self.r.dcx().emit_err(diagnostics::MacroUseNameAlreadyInUse { span, name });
}
}

Expand All @@ -1137,14 +1139,14 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
AttributeParser::parse_limited(self.r.tcx.sess, &item.attrs, &[sym::macro_use])
{
if self.parent_scope.module.expect_local().parent.is_some() {
self.r
.dcx()
.emit_err(errors::ExternCrateLoadingMacroNotAtCrateRoot { span: item.span });
self.r.dcx().emit_err(diagnostics::ExternCrateLoadingMacroNotAtCrateRoot {
span: item.span,
});
}
if let ItemKind::ExternCrate(Some(orig_name), _) = item.kind
&& orig_name == kw::SelfLower
{
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span });
self.r.dcx().emit_err(diagnostics::MacroUseExternCrateSelf { span });
}

match arguments {
Expand Down Expand Up @@ -1208,7 +1210,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
let import_decl = self.r.new_import_decl(binding, import);
self.add_macro_use_decl(ident.name, import_decl, ident.span, allow_shadowing);
} else {
self.r.dcx().emit_err(errors::ImportedMacroNotFound { span: ident.span });
self.r.dcx().emit_err(diagnostics::ImportedMacroNotFound { span: ident.span });
}
}
}
Expand All @@ -1220,15 +1222,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
for attr in attrs {
if attr.has_name(sym::macro_escape) {
let inner_attribute = matches!(attr.style, ast::AttrStyle::Inner);
self.r
.dcx()
.emit_warn(errors::MacroExternDeprecated { span: attr.span, inner_attribute });
self.r.dcx().emit_warn(diagnostics::MacroExternDeprecated {
span: attr.span,
inner_attribute,
});
} else if !attr.has_name(sym::macro_use) {
continue;
}

if !attr.is_word() {
self.r.dcx().emit_err(errors::ArgumentsMacroUseNotAllowed { span: attr.span });
self.r.dcx().emit_err(diagnostics::ArgumentsMacroUseNotAllowed { span: attr.span });
}
return true;
}
Expand Down
21 changes: 12 additions & 9 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc_session::lint::builtin::{
use rustc_span::{DUMMY_SP, Ident, Span, kw};

use crate::imports::{Import, ImportKind};
use crate::{DeclKind, IdentKey, LateDecl, Resolver, errors, module_to_string};
use crate::{DeclKind, IdentKey, LateDecl, Resolver, diagnostics, module_to_string};

struct UnusedImport {
use_tree: ast::UseTree,
Expand Down Expand Up @@ -170,7 +170,7 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
UNUSED_EXTERN_CRATES,
extern_crate.id,
span,
crate::errors::UnusedExternCrate {
crate::diagnostics::UnusedExternCrate {
span: extern_crate.span,
removal_span: extern_crate.span_with_attributes,
},
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
UNUSED_EXTERN_CRATES,
extern_crate.id,
extern_crate.span,
crate::errors::ExternCrateNotIdiomatic {
crate::diagnostics::ExternCrateNotIdiomatic {
span: vis_span.between(ident_span),
code: if vis_span.is_empty() { "use " } else { " use " },
},
Expand Down Expand Up @@ -426,7 +426,7 @@ impl Resolver<'_, '_> {
MACRO_USE_EXTERN_CRATE,
import.root_id,
import.span,
crate::errors::MacroUseDeprecated,
crate::diagnostics::MacroUseDeprecated,
);
}
}
Expand All @@ -450,7 +450,7 @@ impl Resolver<'_, '_> {
UNUSED_IMPORTS,
import.root_id,
import.span,
crate::errors::UnusedMacroUse,
crate::diagnostics::UnusedMacroUse,
);
}
_ => {}
Expand Down Expand Up @@ -524,9 +524,12 @@ impl Resolver<'_, '_> {
move |dcx, level, sess| {
let sugg = can_suggest_removal.then(|| {
if remove_whole_use {
errors::UnusedImportsSugg::RemoveWholeUse { span: remove_spans[0] }
diagnostics::UnusedImportsSugg::RemoveWholeUse { span: remove_spans[0] }
} else {
errors::UnusedImportsSugg::RemoveImports { remove_spans, num_to_remove }
diagnostics::UnusedImportsSugg::RemoveImports {
remove_spans,
num_to_remove,
}
}
});
let test_module_span = test_module_span.map(|span| {
Expand All @@ -536,7 +539,7 @@ impl Resolver<'_, '_> {
.guess_head_span(span)
});

errors::UnusedImports {
diagnostics::UnusedImports {
sugg,
test_module_span,
num_snippets: span_snippets.len(),
Expand Down Expand Up @@ -593,7 +596,7 @@ impl Resolver<'_, '_> {
UNUSED_QUALIFICATIONS,
unn_qua.node_id,
unn_qua.path_span,
errors::UnusedQualifications { removal_span: unn_qua.removal_span },
diagnostics::UnusedQualifications { removal_span: unn_qua.removal_span },
);
}

Expand Down
Loading
Loading