Skip to content

Commit 0a32ca9

Browse files
committed
Auto merge of #113146 - matthiaskrgr:rollup-bxtr51e, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #112670 (privacy: Type privacy lints fixes and cleanups) - #112929 (Test that we require implementing trait items whose bounds don't hold in the current impl) - #113054 (Make `rustc_on_unimplemented` std-agnostic) - #113137 (don't suggest `move` for borrows that aren't closures) - #113139 (style-guide: Clarify let-else further) - #113140 (style-guide: Add an example of formatting a multi-line attribute) - #113143 (style-guide: Narrow guidance about references and dereferencing) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 75726ca + 7a7ffce commit 0a32ca9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+569
-204
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1730,18 +1730,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17301730
(
17311731
Some(name),
17321732
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
1733-
) => self.report_escaping_closure_capture(
1734-
borrow_spans,
1735-
borrow_span,
1736-
&RegionName {
1737-
name: self.synthesize_region_name(),
1738-
source: RegionNameSource::Static,
1739-
},
1740-
ConstraintCategory::CallArgument(None),
1741-
var_or_use_span,
1742-
&format!("`{}`", name),
1743-
"block",
1744-
),
1733+
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
1734+
.report_escaping_closure_capture(
1735+
borrow_spans,
1736+
borrow_span,
1737+
&RegionName {
1738+
name: self.synthesize_region_name(),
1739+
source: RegionNameSource::Static,
1740+
},
1741+
ConstraintCategory::CallArgument(None),
1742+
var_or_use_span,
1743+
&format!("`{}`", name),
1744+
"block",
1745+
),
17451746
(
17461747
Some(name),
17471748
BorrowExplanation::MustBeValidFor {
@@ -1754,7 +1755,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17541755
span,
17551756
..
17561757
},
1757-
) if borrow_spans.for_generator() | borrow_spans.for_closure() => self
1758+
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
17581759
.report_escaping_closure_capture(
17591760
borrow_spans,
17601761
borrow_span,

Diff for: compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ declare_features! (
543543
/// Allows creation of instances of a struct by moving fields that have
544544
/// not changed from prior instances of the same struct (RFC #2528)
545545
(active, type_changing_struct_update, "1.58.0", Some(86555), None),
546+
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
547+
(active, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054), None),
546548
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
547549
(active, unix_sigpipe, "1.65.0", Some(97889), None),
548550
/// Allows unsized fn parameters.

Diff for: compiler/rustc_lint/src/builtin.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,7 @@ declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS])
665665

666666
impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
667667
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
668-
if !(cx.effective_visibilities.is_reachable(item.owner_id.def_id)
669-
&& cx.tcx.local_visibility(item.owner_id.def_id).is_public())
670-
{
668+
if !cx.effective_visibilities.is_reachable(item.owner_id.def_id) {
671669
return;
672670
}
673671
let (def, ty) = match item.kind {
@@ -786,9 +784,7 @@ impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
786784

787785
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
788786
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
789-
if !(cx.effective_visibilities.is_reachable(item.owner_id.def_id)
790-
&& cx.tcx.local_visibility(item.owner_id.def_id).is_public())
791-
{
787+
if !cx.effective_visibilities.is_reachable(item.owner_id.def_id) {
792788
return;
793789
}
794790

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -4264,6 +4264,7 @@ declare_lint! {
42644264
/// ### Example
42654265
///
42664266
/// ```rust,compile_fail
4267+
/// # #![feature(type_privacy_lints)]
42674268
/// # #![allow(unused)]
42684269
/// # #![allow(private_in_public)]
42694270
/// #![deny(private_interfaces)]
@@ -4288,6 +4289,7 @@ declare_lint! {
42884289
pub PRIVATE_INTERFACES,
42894290
Allow,
42904291
"private type in primary interface of an item",
4292+
@feature_gate = sym::type_privacy_lints;
42914293
}
42924294

42934295
declare_lint! {
@@ -4298,6 +4300,7 @@ declare_lint! {
42984300
/// ### Example
42994301
///
43004302
/// ```rust,compile_fail
4303+
/// # #![feature(type_privacy_lints)]
43014304
/// # #![allow(private_in_public)]
43024305
/// # #![allow(unused)]
43034306
/// #![deny(private_bounds)]
@@ -4317,7 +4320,8 @@ declare_lint! {
43174320
/// the item actually provides.
43184321
pub PRIVATE_BOUNDS,
43194322
Allow,
4320-
"private type in secondary interface of an item"
4323+
"private type in secondary interface of an item",
4324+
@feature_gate = sym::type_privacy_lints;
43214325
}
43224326

43234327
declare_lint! {
@@ -4327,6 +4331,7 @@ declare_lint! {
43274331
/// ### Example
43284332
///
43294333
/// ```rust,compile_fail
4334+
/// # #![feature(type_privacy_lints)]
43304335
/// # #![allow(unused)]
43314336
/// #![deny(unnameable_types)]
43324337
/// mod m {
@@ -4345,5 +4350,6 @@ declare_lint! {
43454350
/// you can name the type `T` as well, this lint attempts to enforce this rule.
43464351
pub UNNAMEABLE_TYPES,
43474352
Allow,
4348-
"effective visibility of a type is larger than the area in which it can be named"
4353+
"effective visibility of a type is larger than the area in which it can be named",
4354+
@feature_gate = sym::type_privacy_lints;
43494355
}

Diff for: compiler/rustc_middle/src/middle/privacy.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::ty::{TyCtxt, Visibility};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
7+
use rustc_hir::def::DefKind;
78
use rustc_macros::HashStable;
89
use rustc_query_system::ich::StableHashingContext;
910
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
@@ -148,13 +149,12 @@ impl EffectiveVisibilities {
148149
};
149150
}
150151

151-
pub fn check_invariants(&self, tcx: TyCtxt<'_>, early: bool) {
152+
pub fn check_invariants(&self, tcx: TyCtxt<'_>) {
152153
if !cfg!(debug_assertions) {
153154
return;
154155
}
155156
for (&def_id, ev) in &self.map {
156157
// More direct visibility levels can never go farther than less direct ones,
157-
// neither of effective visibilities can go farther than nominal visibility,
158158
// and all effective visibilities are larger or equal than private visibility.
159159
let private_vis = Visibility::Restricted(tcx.parent_module_from_def_id(def_id));
160160
let span = tcx.def_span(def_id.to_def_id());
@@ -175,17 +175,20 @@ impl EffectiveVisibilities {
175175
ev.reachable_through_impl_trait
176176
);
177177
}
178-
let nominal_vis = tcx.visibility(def_id);
179-
// FIXME: `rustc_privacy` is not yet updated for the new logic and can set
180-
// effective visibilities that are larger than the nominal one.
181-
if !nominal_vis.is_at_least(ev.reachable_through_impl_trait, tcx) && early {
182-
span_bug!(
183-
span,
184-
"{:?}: reachable_through_impl_trait {:?} > nominal {:?}",
185-
def_id,
186-
ev.reachable_through_impl_trait,
187-
nominal_vis
188-
);
178+
// All effective visibilities except `reachable_through_impl_trait` are limited to
179+
// nominal visibility. For some items nominal visibility doesn't make sense so we
180+
// don't check this condition for them.
181+
if !matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) {
182+
let nominal_vis = tcx.visibility(def_id);
183+
if !nominal_vis.is_at_least(ev.reachable, tcx) {
184+
span_bug!(
185+
span,
186+
"{:?}: reachable {:?} > nominal {:?}",
187+
def_id,
188+
ev.reachable,
189+
nominal_vis
190+
);
191+
}
189192
}
190193
}
191194
}
@@ -212,7 +215,7 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
212215
pub fn update(
213216
&mut self,
214217
id: Id,
215-
nominal_vis: Option<Visibility>,
218+
max_vis: Option<Visibility>,
216219
lazy_private_vis: impl FnOnce() -> Visibility,
217220
inherited_effective_vis: EffectiveVisibility,
218221
level: Level,
@@ -236,8 +239,8 @@ impl<Id: Eq + Hash> EffectiveVisibilities<Id> {
236239
if !(inherited_effective_vis_at_prev_level == inherited_effective_vis_at_level
237240
&& level != l)
238241
{
239-
calculated_effective_vis = if let Some(nominal_vis) = nominal_vis && !nominal_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
240-
nominal_vis
242+
calculated_effective_vis = if let Some(max_vis) = max_vis && !max_vis.is_at_least(inherited_effective_vis_at_level, tcx) {
243+
max_vis
241244
} else {
242245
inherited_effective_vis_at_level
243246
}

0 commit comments

Comments
 (0)