Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,8 +2086,7 @@ impl Niche {
let distance_end_zero = max_value - v.end;
// FIXME: this ought to work for `bool` too, but that seems to be hitting a miscompilation
// <https://github.com/rust-lang/rust/pull/155473#issuecomment-4302036343>
let is_bool = size.bytes() == 1 && v == WrappingRange { start: 0, end: 1 };
if count == 1 && !is_bool {
if count == 1 && v != (WrappingRange { start: 0, end: 1 }) {
// We only need one, so just pick the one closest to zero.
// Not only does that obviously use zero if it's possible, but it also
// simplifies testing things like `Option<char>`, since looking for `-1`
Expand Down
54 changes: 33 additions & 21 deletions compiler/rustc_resolve/src/effective_visibilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,42 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) {
let module = self.r.expect_module(module_id.to_def_id());
for (_, name_resolution) in self.r.resolutions(module).borrow().iter() {
let Some(mut decl) = name_resolution.borrow().best_decl() else {
let Some(decl) = name_resolution.borrow().best_decl() else {
continue;
};
// Set the given effective visibility level to `Level::Direct` and
// sets the rest of the `use` chain to `Level::Reexported` until
// we hit the actual exported item.
let priv_vis = |this: &Self, parent_id, decl| match parent_id {
ParentId::Def(_) => this.current_private_vis,
ParentId::Import(_) => this.r.private_vis_decl(decl),
};
let mut parent_id = ParentId::Def(module_id);
while let DeclKind::Import { source_decl, .. } = decl.kind {
self.update_import(decl, parent_id, priv_vis(self, parent_id, decl));
parent_id = ParentId::Import(decl);
decl = source_decl;
}
if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) {
let priv_vis = priv_vis(self, parent_id, decl);
self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis);
self.update_decl_chain(decl, ParentId::Def(module_id));
}
}

/// Update effective visibilities for the whole reexport chain of a declaration.
/// Set the given effective visibility level to `Level::Direct` and
/// sets the rest of the `use` chain to `Level::Reexported` until
/// we hit the actual exported item.
fn update_decl_chain(&mut self, mut decl: Decl<'ra>, mut parent_id: ParentId<'ra>) {
let priv_vis = |this: &Self, parent_id, decl| match parent_id {
ParentId::Def(_) => this.current_private_vis,
ParentId::Import(_) => this.r.private_vis_decl(decl),
};
while let DeclKind::Import { source_decl, .. } = decl.kind {
self.update_import(decl, parent_id, priv_vis(self, parent_id, decl));
if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() {
// The name is exported with the visibility of the most visible declaration
// in its ambiguous glob set (see `DeclData::vis`), so everything on that
// declaration's reexport chain, including the final item, must get its
// effective visibility from that declaration as well. Otherwise the item
// would be considered unreachable by dead code analysis and metadata
// encoding despite being exported (see the regression test
// `ambiguous-import-visibility-globglob-mir.rs`).
// This also avoids the most visible import in an ambiguous glob set
// being reported as unused.
self.update_decl_chain(max_vis_decl, parent_id);
}
parent_id = ParentId::Import(decl);
decl = source_decl;
}
if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) {
let priv_vis = priv_vis(self, parent_id, decl);
self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis);
}
}

Expand Down Expand Up @@ -194,10 +210,6 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
parent_id.level(),
tcx,
);
if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() {
// Avoid the most visible import in an ambiguous glob set being reported as unused.
self.update_import(max_vis_decl, parent_id, priv_vis);
}
}

fn update_def(
Expand Down
Loading
Loading