From 4b8149f481aadf26593288effc424f65a5adecf7 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 26 Apr 2024 21:14:37 +0200 Subject: [PATCH 1/2] Consider inner modules to be local in the `non_local_definitions` lint (cherry picked from commit 21c688af86a52cf5d44c69c274179e7410e01a49) --- compiler/rustc_lint/src/non_local_def.rs | 16 +++++--- .../ui/lint/non-local-defs/module_as_local.rs | 38 +++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tests/ui/lint/non-local-defs/module_as_local.rs diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 004c2c2e4f44f..3ab15a5be5888 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -356,7 +356,7 @@ fn path_has_local_parent( } /// Given a def id and a parent impl def id, this checks if the parent -/// def id correspond to the def id of the parent impl definition. +/// def id (modulo modules) correspond to the def id of the parent impl definition. #[inline] fn did_has_local_parent( did: DefId, @@ -364,8 +364,14 @@ fn did_has_local_parent( impl_parent: DefId, impl_parent_parent: Option, ) -> bool { - did.is_local() && { - let res_parent = tcx.parent(did); - res_parent == impl_parent || Some(res_parent) == impl_parent_parent - } + did.is_local() + && if let Some(did_parent) = tcx.opt_parent(did) { + did_parent == impl_parent + || Some(did_parent) == impl_parent_parent + || !did_parent.is_crate_root() + && tcx.def_kind(did_parent) == DefKind::Mod + && did_has_local_parent(did_parent, tcx, impl_parent, impl_parent_parent) + } else { + false + } } diff --git a/tests/ui/lint/non-local-defs/module_as_local.rs b/tests/ui/lint/non-local-defs/module_as_local.rs new file mode 100644 index 0000000000000..bb215026c7d40 --- /dev/null +++ b/tests/ui/lint/non-local-defs/module_as_local.rs @@ -0,0 +1,38 @@ +//! This test checks that module are treated as if they were local +//! +//! https://github.com/rust-lang/rust/issues/124396 + +//@ check-pass + +trait JoinTo {} + +fn simple_one() { + mod posts { + #[allow(non_camel_case_types)] + pub struct table {} + } + + impl JoinTo for posts::table {} +} + +fn simple_two() { + mod posts { + pub mod posts { + #[allow(non_camel_case_types)] + pub struct table {} + } + } + + impl JoinTo for posts::posts::table {} +} + +struct Global; +fn trait_() { + mod posts { + pub trait AdjecentTo {} + } + + impl posts::AdjecentTo for Global {} +} + +fn main() {} From 6c68ae64dfe66e9e495a64f6f3b19cd48c92a7ad Mon Sep 17 00:00:00 2001 From: 12101111 Date: Fri, 3 May 2024 22:53:53 +0800 Subject: [PATCH 2/2] Fix bootstrap panic when build from tarball (cherry picked from commit f13edeb4514368b4b3748e8f437fd6a166d95aff) --- src/bootstrap/src/core/builder.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index ae5440de57293..d0d9b1c4aeb16 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -2226,13 +2226,8 @@ impl<'a> Builder<'a> { out } - /// Return paths of all submodules managed by git. - /// If the current checkout is not managed by git, returns an empty slice. + /// Return paths of all submodules. pub fn get_all_submodules(&self) -> &[String] { - if !self.rust_info().is_managed_git_subrepository() { - return &[]; - } - static SUBMODULES_PATHS: OnceLock> = OnceLock::new(); let init_submodules_paths = |src: &PathBuf| {