diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_resolve/src/imports.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_resolve/src/imports.rs')
-rw-r--r-- | compiler/rustc_resolve/src/imports.rs | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 3c22d51c3..7c4c05d4b 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -405,17 +405,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { t } - // Define a dummy resolution containing a `Res::Err` as a placeholder for a failed resolution, - // also mark such failed imports as used to avoid duplicate diagnostics. - fn import_dummy_binding(&mut self, import: &'a Import<'a>) { + // Define a dummy resolution containing a `Res::Err` as a placeholder for a failed + // or indeterminate resolution, also mark such failed imports as used to avoid duplicate diagnostics. + fn import_dummy_binding(&mut self, import: &'a Import<'a>, is_indeterminate: bool) { if let ImportKind::Single { target, ref target_bindings, .. } = import.kind { - if target_bindings.iter().any(|binding| binding.get().is_some()) { + if !(is_indeterminate || target_bindings.iter().all(|binding| binding.get().is_none())) + { return; // Has resolution, do not create the dummy binding } let dummy_binding = self.dummy_binding; let dummy_binding = self.import(dummy_binding, import); self.per_ns(|this, ns| { - let key = this.new_key(target, ns); + let key = BindingKey::new(target, ns); let _ = this.try_define(import.parent_scope.module, key, dummy_binding); }); self.record_use(target, dummy_binding, false); @@ -474,7 +475,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // If this import is unresolved then create a dummy import // resolution for it so that later resolve stages won't complain. - self.import_dummy_binding(import); + self.import_dummy_binding(import, is_indeterminate); if let Some(err) = unresolved_import_error { if let ImportKind::Single { source, ref source_bindings, .. } = import.kind { @@ -578,7 +579,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let mut diag = struct_span_err!(self.tcx.sess, span, E0432, "{}", &msg); if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() { - diag.note(note); + diag.note(note.clone()); } for (import, err) in errors.into_iter().take(MAX_LABEL_COUNT) { @@ -588,10 +589,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some((suggestions, msg, applicability)) = err.suggestion { if suggestions.is_empty() { - diag.help(&msg); + diag.help(msg); continue; } - diag.multipart_suggestion(&msg, suggestions, applicability); + diag.multipart_suggestion(msg, suggestions, applicability); } if let Some(candidates) = &err.candidates { @@ -712,7 +713,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .span_label(import.span, "cannot be imported directly") .emit(); } - let key = this.new_key(target, ns); + let key = BindingKey::new(target, ns); this.update_resolution(parent, key, |_, resolution| { resolution.single_imports.remove(&Interned::new_unchecked(import)); }); @@ -1063,7 +1064,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { PUB_USE_OF_PRIVATE_EXTERN_CRATE, import_id, import.span, - &msg, + msg, ); } else { let error_msg = if crate_private_reexport { @@ -1084,7 +1085,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { struct_span_err!(self.tcx.sess, import.span, E0365, "{}", error_msg) .span_label(import.span, label_msg) - .note(&format!("consider declaring type or module `{}` with `pub`", ident)) + .note(format!("consider declaring type or module `{}` with `pub`", ident)) .emit(); } else { let mut err = @@ -1102,7 +1103,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { _ => { err.span_note( import.span, - &format!( + format!( "consider marking `{ident}` as `pub` in the imported module" ), ); @@ -1200,7 +1201,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { UNUSED_IMPORTS, id, import.span, - &format!("the item `{}` is imported redundantly", ident), + format!("the item `{}` is imported redundantly", ident), BuiltinLintDiagnostics::RedundantImport(redundant_spans, ident), ); } @@ -1261,14 +1262,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { *module.globs.borrow_mut() = Vec::new(); if let Some(def_id) = module.opt_def_id() { - let mut non_reexports = Vec::new(); - let mut reexports = Vec::new(); + let mut children = Vec::new(); module.for_each_child(self, |this, ident, _, binding| { let res = binding.res().expect_non_local(); - if !binding.is_import() { - non_reexports.push(res.def_id().expect_local()); - } else if res != def::Res::Err && !binding.is_ambiguity() { + if res != def::Res::Err && !binding.is_ambiguity() { let mut reexport_chain = SmallVec::new(); let mut next_binding = binding; while let NameBindingKind::Import { binding, import, .. } = next_binding.kind { @@ -1276,23 +1274,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { next_binding = binding; } - reexports.push(ModChild { - ident, - res, - vis: binding.vis, - span: binding.span, - reexport_chain, - }); + children.push(ModChild { ident, res, vis: binding.vis, reexport_chain }); } }); - // Should be fine because this code is only called for local modules. - let def_id = def_id.expect_local(); - if !non_reexports.is_empty() { - self.module_children_non_reexports.insert(def_id, non_reexports); - } - if !reexports.is_empty() { - self.module_children_reexports.insert(def_id, reexports); + if !children.is_empty() { + // Should be fine because this code is only called for local modules. + self.module_children.insert(def_id.expect_local(), children); } } } |