diff options
| author | bors <bors@rust-lang.org> | 2023-04-05 23:10:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-05 23:10:09 +0000 |
| commit | 8c7ad16e82dd19ea03b19d78a02a815f2f138db5 (patch) | |
| tree | aac4f51adbfa0bf927885b323365abf1e253d628 /compiler/rustc_resolve/src | |
| parent | 2eaeb1eee1b21772de8b935236d16ff8e03fdcf5 (diff) | |
| parent | 9960e9f851a314dc3b241c26b09f4e1c4d7717b9 (diff) | |
| download | rust-8c7ad16e82dd19ea03b19d78a02a815f2f138db5.tar.gz rust-8c7ad16e82dd19ea03b19d78a02a815f2f138db5.zip | |
Auto merge of #109986 - JohnTitor:rollup-3aax38t, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #109909 (Deny `use`ing tool paths) - #109921 (Don't ICE when encountering `dyn*` in statics or consts) - #109922 (Disable `has_thread_local` on OpenHarmony) - #109926 (write threads info into log only when debugging) - #109968 (Add regression test for #80409) - #109969 (Add regression test for #86351) - #109973 (rustdoc: Improve logo display very small screen) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/errors.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 18 |
2 files changed, 16 insertions, 11 deletions
diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 867363f4246..07aaaa1eb7f 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -470,5 +470,14 @@ pub(crate) struct ExpectedFound { pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span); #[derive(Diagnostic)] +#[diag(resolve_tool_module_imported)] +pub(crate) struct ToolModuleImported { + #[primary_span] + pub(crate) span: Span, + #[note] + pub(crate) import: Span, +} + +#[derive(Diagnostic)] #[diag(resolve_module_only)] pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 7ff440e49aa..5a56d7b99a9 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -17,7 +17,7 @@ use crate::late::{ ConstantHasGenerics, ConstantItemKind, HasGenericParams, PathSource, Rib, RibKind, }; use crate::macros::{sub_namespace_match, MacroRulesScope}; -use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize}; +use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize}; use crate::{Import, ImportKind, LexicalScopeBinding, Module, ModuleKind, ModuleOrUniformRoot}; use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, Res}; use crate::{ResolutionError, Resolver, Scope, ScopeSet, Segment, ToNameBinding, Weak}; @@ -1364,7 +1364,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - let is_last = i == path.len() - 1; + let is_last = i + 1 == path.len(); let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS }; let name = ident.name; @@ -1501,16 +1501,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(next_module) = binding.module() { module = Some(ModuleOrUniformRoot::Module(next_module)); record_segment_res(self, res); - } else if res == Res::ToolMod && i + 1 != path.len() { + } else if res == Res::ToolMod && !is_last && opt_ns.is_some() { if binding.is_import() { - self.tcx - .sess - .struct_span_err( - ident.span, - "cannot use a tool module through an import", - ) - .span_note(binding.span, "the tool module imported here") - .emit(); + self.tcx.sess.emit_err(errors::ToolModuleImported { + span: ident.span, + import: binding.span, + }); } let res = Res::NonMacroAttr(NonMacroAttrKind::Tool); return PathResult::NonModule(PartialRes::new(res)); |
