Skip to content

Commit 2314ed4

Browse files
committed
Auto merge of rust-lang#129554 - matthiaskrgr:rollup-thle4kd, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128919 (Add an internal lint that warns when accessing untracked data) - rust-lang#129134 (bootstrap: improve error recovery flags to curl) - rust-lang#129416 (library: Move unstable API of new_uninit to new features) - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately) - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types) - rust-lang#129511 (Update minifier to 0.3.1) - rust-lang#129523 (Make `rustc_type_ir` build on stable) - rust-lang#129546 (Get rid of `predicates_defined_on`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8910346 + 86772ec commit 2314ed4

File tree

40 files changed

+300
-125
lines changed

40 files changed

+300
-125
lines changed

Cargo.lock

+5-2
Original file line numberDiff line numberDiff line change
@@ -2226,9 +2226,12 @@ dependencies = [
22262226

22272227
[[package]]
22282228
name = "minifier"
2229-
version = "0.3.0"
2229+
version = "0.3.1"
22302230
source = "registry+https://github.com/rust-lang/crates.io-index"
2231-
checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
2231+
checksum = "9aa3f302fe0f8de065d4a2d1ed64f60204623cac58b80cd3c2a83a25d5a7d437"
2232+
dependencies = [
2233+
"clap",
2234+
]
22322235

22332236
[[package]]
22342237
name = "minimal-lexical"

compiler/rustc_data_structures/src/steal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl<T> Steal<T> {
5757
///
5858
/// This should not be used within rustc as it leaks information not tracked
5959
/// by the query system, breaking incremental compilation.
60+
#[cfg_attr(not(bootstrap), rustc_lint_untracked_query_information)]
6061
pub fn is_stolen(&self) -> bool {
6162
self.value.borrow().is_none()
6263
}

compiler/rustc_feature/src/builtin_attrs.rs

+11
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
641641
ErrorFollowing, EncodeCrossCrate::Yes,
642642
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
643643
),
644+
rustc_attr!(
645+
rustc_pub_transparent, Normal, template!(Word),
646+
WarnFollowing, EncodeCrossCrate::Yes,
647+
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
648+
),
644649

645650

646651
// ==========================================================================
@@ -786,6 +791,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
786791
rustc_lint_query_instability, Normal, template!(Word),
787792
WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
788793
),
794+
// Used by the `rustc::untracked_query_information` lint to warn methods which
795+
// might not be stable during incremental compilation.
796+
rustc_attr!(
797+
rustc_lint_untracked_query_information, Normal, template!(Word),
798+
WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
799+
),
789800
// Used by the `rustc::diagnostic_outside_of_impl` lints to assist in changes to diagnostic
790801
// APIs. Any function with this attribute will be checked by that lint.
791802
rustc_attr!(

compiler/rustc_hir_analysis/src/check/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
12591259
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
12601260
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
12611261
ty::Adt(def, args) => {
1262-
if !def.did().is_local() {
1262+
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
1263+
{
12631264
let non_exhaustive = def.is_variant_list_non_exhaustive()
12641265
|| def
12651266
.variants()

compiler/rustc_hir_analysis/src/collect.rs

+1-30
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_infer::traits::ObligationCause;
3434
use rustc_middle::hir::nested_filter;
3535
use rustc_middle::query::Providers;
3636
use rustc_middle::ty::util::{Discr, IntTypeExt};
37-
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
37+
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt};
3838
use rustc_middle::{bug, span_bug};
3939
use rustc_span::symbol::{kw, sym, Ident, Symbol};
4040
use rustc_span::{Span, DUMMY_SP};
@@ -70,7 +70,6 @@ pub fn provide(providers: &mut Providers) {
7070
impl_super_outlives: item_bounds::impl_super_outlives,
7171
generics_of: generics_of::generics_of,
7272
predicates_of: predicates_of::predicates_of,
73-
predicates_defined_on,
7473
explicit_predicates_of: predicates_of::explicit_predicates_of,
7574
explicit_super_predicates_of: predicates_of::explicit_super_predicates_of,
7675
explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of,
@@ -1775,34 +1774,6 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
17751774
})
17761775
}
17771776

1778-
/// Returns a list of type predicates for the definition with ID `def_id`, including inferred
1779-
/// lifetime constraints. This includes all predicates returned by `explicit_predicates_of`, plus
1780-
/// inferred constraints concerning which regions outlive other regions.
1781-
#[instrument(level = "debug", skip(tcx))]
1782-
fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
1783-
let mut result = tcx.explicit_predicates_of(def_id);
1784-
debug!("predicates_defined_on: explicit_predicates_of({:?}) = {:?}", def_id, result);
1785-
let inferred_outlives = tcx.inferred_outlives_of(def_id);
1786-
if !inferred_outlives.is_empty() {
1787-
debug!(
1788-
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
1789-
def_id, inferred_outlives,
1790-
);
1791-
let inferred_outlives_iter =
1792-
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
1793-
if result.predicates.is_empty() {
1794-
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
1795-
} else {
1796-
result.predicates = tcx.arena.alloc_from_iter(
1797-
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
1798-
);
1799-
}
1800-
}
1801-
1802-
debug!("predicates_defined_on({:?}) = {:?}", def_id, result);
1803-
result
1804-
}
1805-
18061777
fn compute_sig_of_foreign_fn_decl<'tcx>(
18071778
tcx: TyCtxt<'tcx>,
18081779
def_id: LocalDefId,

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,26 @@ use crate::delegation::inherit_predicates_for_delegation_item;
1818
use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter, RegionInferReason};
1919

2020
/// Returns a list of all type predicates (explicit and implicit) for the definition with
21-
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
22-
/// `Self: Trait` predicates for traits.
21+
/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus
22+
/// inferred constraints concerning which regions outlive other regions.
23+
#[instrument(level = "debug", skip(tcx))]
2324
pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
24-
let mut result = tcx.predicates_defined_on(def_id);
25+
let mut result = tcx.explicit_predicates_of(def_id);
26+
debug!("predicates_of: explicit_predicates_of({:?}) = {:?}", def_id, result);
27+
28+
let inferred_outlives = tcx.inferred_outlives_of(def_id);
29+
if !inferred_outlives.is_empty() {
30+
debug!("predicates_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,);
31+
let inferred_outlives_iter =
32+
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
33+
if result.predicates.is_empty() {
34+
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
35+
} else {
36+
result.predicates = tcx.arena.alloc_from_iter(
37+
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
38+
);
39+
}
40+
}
2541

2642
if tcx.is_trait(def_id) {
2743
// For traits, add `Self: Trait` predicate. This is
@@ -51,7 +67,8 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
5167
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
5268
);
5369
}
54-
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
70+
71+
debug!("predicates_of({:?}) = {:?}", def_id, result);
5572
result
5673
}
5774

compiler/rustc_index/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
33
#![cfg_attr(feature = "nightly", allow(internal_features))]
44
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
5+
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
56
// tidy-alphabetical-end
67

78
pub mod bit_set;

compiler/rustc_lint/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ lint_ptr_null_checks_ref = references are not nullable, so checking them for nul
695695
lint_query_instability = using `{$query}` can result in unstable query results
696696
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
697697
698+
lint_query_untracked = `{$method}` accesses information that is not tracked by the query system
699+
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
700+
698701
lint_range_endpoint_out_of_range = range endpoint is out of range for `{$ty}`
699702
700703
lint_range_use_inclusive_range = use an inclusive range instead

compiler/rustc_lint/src/internal.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use tracing::debug;
1717

1818
use crate::lints::{
1919
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
20-
NonGlobImportTypeIrInherent, QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag,
21-
TykindKind, UntranslatableDiag,
20+
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag, TyQualified,
21+
TykindDiag, TykindKind, UntranslatableDiag,
2222
};
2323
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2424

@@ -88,7 +88,18 @@ declare_tool_lint! {
8888
report_in_external_macro: true
8989
}
9090

91-
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
91+
declare_tool_lint! {
92+
/// The `untracked_query_information` lint detects use of methods which leak information not
93+
/// tracked by the query system, such as whether a `Steal<T>` value has already been stolen. In
94+
/// order not to break incremental compilation, such methods must be used very carefully or not
95+
/// at all.
96+
pub rustc::UNTRACKED_QUERY_INFORMATION,
97+
Allow,
98+
"require explicit opt-in when accessing information not tracked by the query system",
99+
report_in_external_macro: true
100+
}
101+
102+
declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUERY_INFORMATION]);
92103

93104
impl LateLintPass<'_> for QueryStability {
94105
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
@@ -102,6 +113,13 @@ impl LateLintPass<'_> for QueryStability {
102113
QueryInstability { query: cx.tcx.item_name(def_id) },
103114
);
104115
}
116+
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
117+
cx.emit_span_lint(
118+
UNTRACKED_QUERY_INFORMATION,
119+
span,
120+
QueryUntracked { method: cx.tcx.item_name(def_id) },
121+
);
122+
}
105123
}
106124
}
107125
}

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ fn register_internals(store: &mut LintStore) {
608608
vec![
609609
LintId::of(DEFAULT_HASH_TYPES),
610610
LintId::of(POTENTIAL_QUERY_INSTABILITY),
611+
LintId::of(UNTRACKED_QUERY_INFORMATION),
611612
LintId::of(USAGE_OF_TY_TYKIND),
612613
LintId::of(PASS_BY_VALUE),
613614
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),

compiler/rustc_lint/src/lints.rs

+7
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ pub struct QueryInstability {
894894
pub query: Symbol,
895895
}
896896

897+
#[derive(LintDiagnostic)]
898+
#[diag(lint_query_untracked)]
899+
#[note]
900+
pub struct QueryUntracked {
901+
pub method: Symbol,
902+
}
903+
897904
#[derive(LintDiagnostic)]
898905
#[diag(lint_span_use_eq_ctxt)]
899906
pub struct SpanUseEqCtxtDiag;

compiler/rustc_middle/src/query/mod.rs

-19
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,6 @@ rustc_queries! {
312312
/// predicates (where-clauses) that must be proven true in order
313313
/// to reference it. This is almost always the "predicates query"
314314
/// that you want.
315-
///
316-
/// `predicates_of` builds on `predicates_defined_on` -- in fact,
317-
/// it is almost always the same as that query, except for the
318-
/// case of traits. For traits, `predicates_of` contains
319-
/// an additional `Self: Trait<...>` predicate that users don't
320-
/// actually write. This reflects the fact that to invoke the
321-
/// trait (e.g., via `Default::default`) you must supply types
322-
/// that actually implement the trait. (However, this extra
323-
/// predicate gets in the way of some checks, which are intended
324-
/// to operate over only the actual where-clauses written by the
325-
/// user.)
326315
query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
327316
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
328317
cache_on_disk_if { key.is_local() }
@@ -617,14 +606,6 @@ rustc_queries! {
617606
desc { "getting wasm import module map" }
618607
}
619608

620-
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
621-
/// predicates (where-clauses) directly defined on it. This is
622-
/// equal to the `explicit_predicates_of` predicates plus the
623-
/// `inferred_outlives_of` predicates.
624-
query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
625-
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
626-
}
627-
628609
/// Returns everything that looks like a predicate written explicitly
629610
/// by the user on a trait item.
630611
///

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ passes_rustc_lint_opt_ty =
657657
`#[rustc_lint_opt_ty]` should be applied to a struct
658658
.label = not a struct
659659
660+
passes_rustc_pub_transparent =
661+
attribute should be applied to `#[repr(transparent)]` types
662+
.label = not a `#[repr(transparent)]` type
663+
660664
passes_rustc_safe_intrinsic =
661665
attribute should be applied to intrinsic functions
662666
.label = not an intrinsic function

compiler/rustc_passes/src/check_attr.rs

+21-32
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
125125
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
126126
[sym::coverage, ..] => self.check_coverage(attr, span, target),
127127
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
128-
[sym::no_sanitize, ..] => self.check_no_sanitize(hir_id, attr, span, target),
128+
[sym::no_sanitize, ..] => {
129+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
130+
}
129131
[sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target),
130132
[sym::marker, ..] => self.check_marker(hir_id, attr, span, target),
131133
[sym::target_feature, ..] => {
@@ -166,10 +168,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
166168
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
167169
}
168170
[sym::rustc_lint_query_instability, ..] => {
169-
self.check_rustc_lint_query_instability(hir_id, attr, span, target)
171+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
172+
}
173+
[sym::rustc_lint_untracked_query_information, ..] => {
174+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
170175
}
171176
[sym::rustc_lint_diagnostics, ..] => {
172-
self.check_rustc_lint_diagnostics(hir_id, attr, span, target)
177+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
173178
}
174179
[sym::rustc_lint_opt_ty, ..] => self.check_rustc_lint_opt_ty(attr, span, target),
175180
[sym::rustc_lint_opt_deny_field_access, ..] => {
@@ -245,6 +250,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
245250
self.check_coroutine(attr, target);
246251
}
247252
[sym::linkage, ..] => self.check_linkage(attr, span, target),
253+
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent( attr.span, span, attrs),
248254
[
249255
// ok
250256
sym::allow
@@ -451,11 +457,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
451457
}
452458
}
453459

454-
/// Checks that `#[no_sanitize(..)]` is applied to a function or method.
455-
fn check_no_sanitize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
456-
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
457-
}
458-
459460
fn check_generic_attr(
460461
&self,
461462
hir_id: HirId,
@@ -1623,30 +1624,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16231624
}
16241625
}
16251626

1626-
/// Checks that the `#[rustc_lint_query_instability]` attribute is only applied to a function
1627-
/// or method.
1628-
fn check_rustc_lint_query_instability(
1629-
&self,
1630-
hir_id: HirId,
1631-
attr: &Attribute,
1632-
span: Span,
1633-
target: Target,
1634-
) {
1635-
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
1636-
}
1637-
1638-
/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
1639-
/// method.
1640-
fn check_rustc_lint_diagnostics(
1641-
&self,
1642-
hir_id: HirId,
1643-
attr: &Attribute,
1644-
span: Span,
1645-
target: Target,
1646-
) {
1647-
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
1648-
}
1649-
16501627
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
16511628
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
16521629
match target {
@@ -2381,6 +2358,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23812358
}
23822359
}
23832360
}
2361+
2362+
fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) {
2363+
if !attrs
2364+
.iter()
2365+
.filter(|attr| attr.has_name(sym::repr))
2366+
.filter_map(|attr| attr.meta_item_list())
2367+
.flatten()
2368+
.any(|nmi| nmi.has_name(sym::transparent))
2369+
{
2370+
self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span });
2371+
}
2372+
}
23842373
}
23852374

23862375
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

compiler/rustc_passes/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ pub struct RustcStdInternalSymbol {
622622
pub span: Span,
623623
}
624624

625+
#[derive(Diagnostic)]
626+
#[diag(passes_rustc_pub_transparent)]
627+
pub struct RustcPubTransparent {
628+
#[primary_span]
629+
pub attr_span: Span,
630+
#[label]
631+
pub span: Span,
632+
}
633+
625634
#[derive(Diagnostic)]
626635
#[diag(passes_link_ordinal)]
627636
pub struct LinkOrdinal {

0 commit comments

Comments
 (0)