Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 30 deletions
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

Lines changed: 21 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 21 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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),

0 commit comments

Comments
 (0)