Auto merge of #124947 - cuviper:beta-next, r=cuviper · rust-lang/rust@a269819 (original) (raw)
File tree
3 files changed
lines changed
- tests/ui/lint/non-local-defs
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -356,16 +356,22 @@ fn path_has_local_parent( | ||
356 | 356 | } |
357 | 357 | |
358 | 358 | /// 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. | |
360 | 360 | #[inline] |
361 | 361 | fn did_has_local_parent( |
362 | 362 | did: DefId, |
363 | 363 | tcx: TyCtxt<'_>, |
364 | 364 | impl_parent: DefId, |
365 | 365 | impl_parent_parent: Option<DefId>, |
366 | 366 | ) -> bool { |
367 | - did.is_local() && { | |
368 | -let res_parent = tcx.parent(did); | |
369 | - res_parent == impl_parent | | |
370 | -} | |
367 | + did.is_local() | |
368 | + && if let Some(did_parent) = tcx.opt_parent(did) { | |
369 | + did_parent == impl_parent | |
370 | + | | |
371 | + | | |
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 | +} | |
371 | 377 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2226,13 +2226,8 @@ impl<'a> Builder<'a> { | ||
2226 | 2226 | out |
2227 | 2227 | } |
2228 | 2228 | |
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. | |
2231 | 2230 | pub fn get_all_submodules(&self) -> &[String] { |
2232 | -if !self.rust_info().is_managed_git_subrepository() { | |
2233 | -return &[]; | |
2234 | -} | |
2235 | - | |
2236 | 2231 | static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new(); |
2237 | 2232 | |
2238 | 2233 | let init_submodules_paths = |src: &PathBuf |
Original file line number | Diff line number | Diff 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() {} |