Skip to content

Commit

Permalink
Auto merge of rust-lang#129554 - matthiaskrgr:rollup-thle4kd, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Aug 25, 2024
2 parents 8910346 + 86772ec commit 2314ed4
Show file tree
Hide file tree
Showing 40 changed files with 300 additions and 125 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2226,9 +2226,12 @@ dependencies = [

[[package]]
name = "minifier"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
checksum = "9aa3f302fe0f8de065d4a2d1ed64f60204623cac58b80cd3c2a83a25d5a7d437"
dependencies = [
"clap",
]

[[package]]
name = "minimal-lexical"
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/steal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<T> Steal<T> {
///
/// This should not be used within rustc as it leaks information not tracked
/// by the query system, breaking incremental compilation.
#[cfg_attr(not(bootstrap), rustc_lint_untracked_query_information)]
pub fn is_stolen(&self) -> bool {
self.value.borrow().is_none()
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ErrorFollowing, EncodeCrossCrate::Yes,
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
),
rustc_attr!(
rustc_pub_transparent, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes,
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
),


// ==========================================================================
Expand Down Expand Up @@ -786,6 +791,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
rustc_lint_query_instability, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
),
// Used by the `rustc::untracked_query_information` lint to warn methods which
// might not be stable during incremental compilation.
rustc_attr!(
rustc_lint_untracked_query_information, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
),
// Used by the `rustc::diagnostic_outside_of_impl` lints to assist in changes to diagnostic
// APIs. Any function with this attribute will be checked by that lint.
rustc_attr!(
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
ty::Adt(def, args) => {
if !def.did().is_local() {
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
{
let non_exhaustive = def.is_variant_list_non_exhaustive()
|| def
.variants()
Expand Down
31 changes: 1 addition & 30 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rustc_infer::traits::ObligationCause;
use rustc_middle::hir::nested_filter;
use rustc_middle::query::Providers;
use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -70,7 +70,6 @@ pub fn provide(providers: &mut Providers) {
impl_super_outlives: item_bounds::impl_super_outlives,
generics_of: generics_of::generics_of,
predicates_of: predicates_of::predicates_of,
predicates_defined_on,
explicit_predicates_of: predicates_of::explicit_predicates_of,
explicit_super_predicates_of: predicates_of::explicit_super_predicates_of,
explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of,
Expand Down Expand Up @@ -1775,34 +1774,6 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
})
}

/// Returns a list of type predicates for the definition with ID `def_id`, including inferred
/// lifetime constraints. This includes all predicates returned by `explicit_predicates_of`, plus
/// inferred constraints concerning which regions outlive other regions.
#[instrument(level = "debug", skip(tcx))]
fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
let mut result = tcx.explicit_predicates_of(def_id);
debug!("predicates_defined_on: explicit_predicates_of({:?}) = {:?}", def_id, result);
let inferred_outlives = tcx.inferred_outlives_of(def_id);
if !inferred_outlives.is_empty() {
debug!(
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
def_id, inferred_outlives,
);
let inferred_outlives_iter =
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
if result.predicates.is_empty() {
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
} else {
result.predicates = tcx.arena.alloc_from_iter(
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
);
}
}

debug!("predicates_defined_on({:?}) = {:?}", def_id, result);
result
}

fn compute_sig_of_foreign_fn_decl<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
Expand Down
25 changes: 21 additions & 4 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@ use crate::delegation::inherit_predicates_for_delegation_item;
use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter, RegionInferReason};

/// Returns a list of all type predicates (explicit and implicit) for the definition with
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
/// `Self: Trait` predicates for traits.
/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus
/// inferred constraints concerning which regions outlive other regions.
#[instrument(level = "debug", skip(tcx))]
pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> {
let mut result = tcx.predicates_defined_on(def_id);
let mut result = tcx.explicit_predicates_of(def_id);
debug!("predicates_of: explicit_predicates_of({:?}) = {:?}", def_id, result);

let inferred_outlives = tcx.inferred_outlives_of(def_id);
if !inferred_outlives.is_empty() {
debug!("predicates_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,);
let inferred_outlives_iter =
inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span));
if result.predicates.is_empty() {
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
} else {
result.predicates = tcx.arena.alloc_from_iter(
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
);
}
}

if tcx.is_trait(def_id) {
// For traits, add `Self: Trait` predicate. This is
Expand Down Expand Up @@ -51,7 +67,8 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
);
}
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);

debug!("predicates_of({:?}) = {:?}", def_id, result);
result
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
#![cfg_attr(feature = "nightly", allow(internal_features))]
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
// tidy-alphabetical-end

pub mod bit_set;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ lint_ptr_null_checks_ref = references are not nullable, so checking them for nul
lint_query_instability = using `{$query}` can result in unstable query results
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
lint_query_untracked = `{$method}` accesses information that is not tracked by the query system
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
lint_range_endpoint_out_of_range = range endpoint is out of range for `{$ty}`
lint_range_use_inclusive_range = use an inclusive range instead
Expand Down
24 changes: 21 additions & 3 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use tracing::debug;

use crate::lints::{
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
NonGlobImportTypeIrInherent, QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag,
TykindKind, UntranslatableDiag,
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag, TyQualified,
TykindDiag, TykindKind, UntranslatableDiag,
};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};

Expand Down Expand Up @@ -88,7 +88,18 @@ declare_tool_lint! {
report_in_external_macro: true
}

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

declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUERY_INFORMATION]);

impl LateLintPass<'_> for QueryStability {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
Expand All @@ -102,6 +113,13 @@ impl LateLintPass<'_> for QueryStability {
QueryInstability { query: cx.tcx.item_name(def_id) },
);
}
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
cx.emit_span_lint(
UNTRACKED_QUERY_INFORMATION,
span,
QueryUntracked { method: cx.tcx.item_name(def_id) },
);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ fn register_internals(store: &mut LintStore) {
vec![
LintId::of(DEFAULT_HASH_TYPES),
LintId::of(POTENTIAL_QUERY_INSTABILITY),
LintId::of(UNTRACKED_QUERY_INFORMATION),
LintId::of(USAGE_OF_TY_TYKIND),
LintId::of(PASS_BY_VALUE),
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,13 @@ pub struct QueryInstability {
pub query: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(lint_query_untracked)]
#[note]
pub struct QueryUntracked {
pub method: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(lint_span_use_eq_ctxt)]
pub struct SpanUseEqCtxtDiag;
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,6 @@ rustc_queries! {
/// predicates (where-clauses) that must be proven true in order
/// to reference it. This is almost always the "predicates query"
/// that you want.
///
/// `predicates_of` builds on `predicates_defined_on` -- in fact,
/// it is almost always the same as that query, except for the
/// case of traits. For traits, `predicates_of` contains
/// an additional `Self: Trait<...>` predicate that users don't
/// actually write. This reflects the fact that to invoke the
/// trait (e.g., via `Default::default`) you must supply types
/// that actually implement the trait. (However, this extra
/// predicate gets in the way of some checks, which are intended
/// to operate over only the actual where-clauses written by the
/// user.)
query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
Expand Down Expand Up @@ -617,14 +606,6 @@ rustc_queries! {
desc { "getting wasm import module map" }
}

/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
/// predicates (where-clauses) directly defined on it. This is
/// equal to the `explicit_predicates_of` predicates plus the
/// `inferred_outlives_of` predicates.
query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
}

/// Returns everything that looks like a predicate written explicitly
/// by the user on a trait item.
///
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ passes_rustc_lint_opt_ty =
`#[rustc_lint_opt_ty]` should be applied to a struct
.label = not a struct
passes_rustc_pub_transparent =
attribute should be applied to `#[repr(transparent)]` types
.label = not a `#[repr(transparent)]` type
passes_rustc_safe_intrinsic =
attribute should be applied to intrinsic functions
.label = not an intrinsic function
Expand Down
53 changes: 21 additions & 32 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
[sym::coverage, ..] => self.check_coverage(attr, span, target),
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
[sym::no_sanitize, ..] => self.check_no_sanitize(hir_id, attr, span, target),
[sym::no_sanitize, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target),
[sym::marker, ..] => self.check_marker(hir_id, attr, span, target),
[sym::target_feature, ..] => {
Expand Down Expand Up @@ -166,10 +168,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
}
[sym::rustc_lint_query_instability, ..] => {
self.check_rustc_lint_query_instability(hir_id, attr, span, target)
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::rustc_lint_untracked_query_information, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::rustc_lint_diagnostics, ..] => {
self.check_rustc_lint_diagnostics(hir_id, attr, span, target)
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::rustc_lint_opt_ty, ..] => self.check_rustc_lint_opt_ty(attr, span, target),
[sym::rustc_lint_opt_deny_field_access, ..] => {
Expand Down Expand Up @@ -245,6 +250,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_coroutine(attr, target);
}
[sym::linkage, ..] => self.check_linkage(attr, span, target),
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent( attr.span, span, attrs),
[
// ok
sym::allow
Expand Down Expand Up @@ -451,11 +457,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks that `#[no_sanitize(..)]` is applied to a function or method.
fn check_no_sanitize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}

fn check_generic_attr(
&self,
hir_id: HirId,
Expand Down Expand Up @@ -1623,30 +1624,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks that the `#[rustc_lint_query_instability]` attribute is only applied to a function
/// or method.
fn check_rustc_lint_query_instability(
&self,
hir_id: HirId,
attr: &Attribute,
span: Span,
target: Target,
) {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}

/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
/// method.
fn check_rustc_lint_diagnostics(
&self,
hir_id: HirId,
attr: &Attribute,
span: Span,
target: Target,
) {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}

/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
match target {
Expand Down Expand Up @@ -2381,6 +2358,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
}

fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) {
if !attrs
.iter()
.filter(|attr| attr.has_name(sym::repr))
.filter_map(|attr| attr.meta_item_list())
.flatten()
.any(|nmi| nmi.has_name(sym::transparent))
{
self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span });
}
}
}

impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ pub struct RustcStdInternalSymbol {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(passes_rustc_pub_transparent)]
pub struct RustcPubTransparent {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(passes_link_ordinal)]
pub struct LinkOrdinal {
Expand Down
Loading

0 comments on commit 2314ed4

Please sign in to comment.