Skip to content

Commit a269819

Browse files
committed
Auto merge of rust-lang#124947 - cuviper:beta-next, r=cuviper
[beta] backports - Consider inner modules to be local in the `non_local_definitions` lint rust-lang#124539 - Fix bootstrap panic when build from tarball rust-lang#124668 r? cuviper
2 parents f5d04ca + 6c68ae6 commit a269819

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

compiler/rustc_lint/src/non_local_def.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,22 @@ fn path_has_local_parent(
356356
}
357357

358358
/// Given a def id and a parent impl def id, this checks if the parent
359-
/// def id correspond to the def id of the parent impl definition.
359+
/// def id (modulo modules) correspond to the def id of the parent impl definition.
360360
#[inline]
361361
fn did_has_local_parent(
362362
did: DefId,
363363
tcx: TyCtxt<'_>,
364364
impl_parent: DefId,
365365
impl_parent_parent: Option<DefId>,
366366
) -> bool {
367-
did.is_local() && {
368-
let res_parent = tcx.parent(did);
369-
res_parent == impl_parent || Some(res_parent) == impl_parent_parent
370-
}
367+
did.is_local()
368+
&& if let Some(did_parent) = tcx.opt_parent(did) {
369+
did_parent == impl_parent
370+
|| Some(did_parent) == impl_parent_parent
371+
|| !did_parent.is_crate_root()
372+
&& tcx.def_kind(did_parent) == DefKind::Mod
373+
&& did_has_local_parent(did_parent, tcx, impl_parent, impl_parent_parent)
374+
} else {
375+
false
376+
}
371377
}

src/bootstrap/src/core/builder.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2226,13 +2226,8 @@ impl<'a> Builder<'a> {
22262226
out
22272227
}
22282228

2229-
/// Return paths of all submodules managed by git.
2230-
/// If the current checkout is not managed by git, returns an empty slice.
2229+
/// Return paths of all submodules.
22312230
pub fn get_all_submodules(&self) -> &[String] {
2232-
if !self.rust_info().is_managed_git_subrepository() {
2233-
return &[];
2234-
}
2235-
22362231
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
22372232

22382233
let init_submodules_paths = |src: &PathBuf| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! This test checks that module are treated as if they were local
2+
//!
3+
//! https://github.com/rust-lang/rust/issues/124396
4+
5+
//@ check-pass
6+
7+
trait JoinTo {}
8+
9+
fn simple_one() {
10+
mod posts {
11+
#[allow(non_camel_case_types)]
12+
pub struct table {}
13+
}
14+
15+
impl JoinTo for posts::table {}
16+
}
17+
18+
fn simple_two() {
19+
mod posts {
20+
pub mod posts {
21+
#[allow(non_camel_case_types)]
22+
pub struct table {}
23+
}
24+
}
25+
26+
impl JoinTo for posts::posts::table {}
27+
}
28+
29+
struct Global;
30+
fn trait_() {
31+
mod posts {
32+
pub trait AdjecentTo {}
33+
}
34+
35+
impl posts::AdjecentTo for Global {}
36+
}
37+
38+
fn main() {}

0 commit comments

Comments
 (0)