Skip to content

Commit c666fcb

Browse files
committed
Auto merge of #159384 - Mark-Simulacrum:beta-backports, r=Mark-Simulacrum
[beta] backports This backports: * resolve: fix effective visibilities for items in ambiguous glob sets #159039 * Revert extension of -1 for None-like tags rust-lang/rust #159047 * Gate tests/debuginfo/function-call.rs on min GDB 15.1 #159401 and also bumps to the just-released 1.97.1 compiler. r? me
2 parents d2586d6 + c5e8afc commit c666fcb

10 files changed

Lines changed: 584 additions & 452 deletions

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,8 +2086,7 @@ impl Niche {
20862086
let distance_end_zero = max_value - v.end;
20872087
// FIXME: this ought to work for `bool` too, but that seems to be hitting a miscompilation
20882088
// <https://github.com/rust-lang/rust/pull/155473#issuecomment-4302036343>
2089-
let is_bool = size.bytes() == 1 && v == WrappingRange { start: 0, end: 1 };
2090-
if count == 1 && !is_bool {
2089+
if count == 1 && v != (WrappingRange { start: 0, end: 1 }) {
20912090
// We only need one, so just pick the one closest to zero.
20922091
// Not only does that obviously use zero if it's possible, but it also
20932092
// simplifies testing things like `Option<char>`, since looking for `-1`

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,42 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
125125
fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) {
126126
let module = self.r.expect_module(module_id.to_def_id());
127127
for (_, name_resolution) in self.r.resolutions(module).borrow().iter() {
128-
let Some(mut decl) = name_resolution.borrow().best_decl() else {
128+
let Some(decl) = name_resolution.borrow().best_decl() else {
129129
continue;
130130
};
131-
// Set the given effective visibility level to `Level::Direct` and
132-
// sets the rest of the `use` chain to `Level::Reexported` until
133-
// we hit the actual exported item.
134-
let priv_vis = |this: &Self, parent_id, decl| match parent_id {
135-
ParentId::Def(_) => this.current_private_vis,
136-
ParentId::Import(_) => this.r.private_vis_decl(decl),
137-
};
138-
let mut parent_id = ParentId::Def(module_id);
139-
while let DeclKind::Import { source_decl, .. } = decl.kind {
140-
self.update_import(decl, parent_id, priv_vis(self, parent_id, decl));
141-
parent_id = ParentId::Import(decl);
142-
decl = source_decl;
143-
}
144-
if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) {
145-
let priv_vis = priv_vis(self, parent_id, decl);
146-
self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis);
131+
self.update_decl_chain(decl, ParentId::Def(module_id));
132+
}
133+
}
134+
135+
/// Update effective visibilities for the whole reexport chain of a declaration.
136+
/// Set the given effective visibility level to `Level::Direct` and
137+
/// sets the rest of the `use` chain to `Level::Reexported` until
138+
/// we hit the actual exported item.
139+
fn update_decl_chain(&mut self, mut decl: Decl<'ra>, mut parent_id: ParentId<'ra>) {
140+
let priv_vis = |this: &Self, parent_id, decl| match parent_id {
141+
ParentId::Def(_) => this.current_private_vis,
142+
ParentId::Import(_) => this.r.private_vis_decl(decl),
143+
};
144+
while let DeclKind::Import { source_decl, .. } = decl.kind {
145+
self.update_import(decl, parent_id, priv_vis(self, parent_id, decl));
146+
if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() {
147+
// The name is exported with the visibility of the most visible declaration
148+
// in its ambiguous glob set (see `DeclData::vis`), so everything on that
149+
// declaration's reexport chain, including the final item, must get its
150+
// effective visibility from that declaration as well. Otherwise the item
151+
// would be considered unreachable by dead code analysis and metadata
152+
// encoding despite being exported (see the regression test
153+
// `ambiguous-import-visibility-globglob-mir.rs`).
154+
// This also avoids the most visible import in an ambiguous glob set
155+
// being reported as unused.
156+
self.update_decl_chain(max_vis_decl, parent_id);
147157
}
158+
parent_id = ParentId::Import(decl);
159+
decl = source_decl;
160+
}
161+
if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) {
162+
let priv_vis = priv_vis(self, parent_id, decl);
163+
self.update_def(def_id, decl.vis().expect_local(), parent_id, priv_vis);
148164
}
149165
}
150166

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

203215
fn update_def(

0 commit comments

Comments
 (0)