Skip to content

Commit

Permalink
Auto merge of #124947 - cuviper:beta-next, r=cuviper
Browse files Browse the repository at this point in the history
[beta] backports

- Consider inner modules to be local in the `non_local_definitions` lint #124539
- Fix bootstrap panic when build from tarball #124668

r? cuviper
  • Loading branch information
bors committed May 10, 2024
2 parents f5d04ca + 6c68ae6 commit a269819
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
16 changes: 11 additions & 5 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,22 @@ 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,
tcx: TyCtxt<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
) -> 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
}
}
7 changes: 1 addition & 6 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> = OnceLock::new();

let init_submodules_paths = |src: &PathBuf| {
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/lint/non-local-defs/module_as_local.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit a269819

Please sign in to comment.