Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions compiler/rustc_attr_parsing/src/attributes/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,14 @@ pub fn parse_cfg_select(
}
}

if let Some(features) = features
&& features.enabled(sym::cfg_select)
{
let it = branches
.reachable
.iter()
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
.chain(
branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)),
);

lint_unreachable(p, it, lint_node_id);
}
let it = branches
.reachable
.iter()
.map(|(entry, _, _)| CfgSelectPredicate::Cfg(entry.clone()))
.chain(branches.wildcard.as_ref().map(|(t, _, _)| CfgSelectPredicate::Wildcard(*t)))
.chain(branches.unreachable.iter().map(|(entry, _, _)| CfgSelectPredicate::clone(entry)));

lint_unreachable(p, it, lint_node_id);

Ok(branches)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ index 1e336bf..35e6f54 100644
@@ -2,4 +2,3 @@
// tidy-alphabetical-start
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_select))]
#![feature(array_ptr_get)]
#![feature(array_try_from_fn)]
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
index b735957..ea728b6 100644
--- a/coretests/tests/atomic.rs
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(bootstrap, feature(assert_matches))]
#![cfg_attr(bootstrap, feature(cfg_select))]
#![cfg_attr(bootstrap, feature(cold_path))]
#![cfg_attr(test, feature(test))]
#![deny(unsafe_op_in_unsafe_fn)]
#![feature(allocator_api)]
#![feature(ascii_char)]
#![feature(ascii_char_variants)]
#![feature(auto_traits)]
#![feature(cfg_select)]
#![feature(const_default)]
#![feature(const_trait_impl)]
#![feature(dropck_eyepatch)]
Expand Down Expand Up @@ -47,6 +47,9 @@ use std::fmt;
#[cfg(not(bootstrap))]
pub use std::{assert_matches, debug_assert_matches};

// This allows derive macros to reference this crate
extern crate self as rustc_data_structures;

pub use atomic_ref::AtomicRef;
pub use ena::{snapshot_vec, undo_log, unify};
// Re-export `hashbrown::hash_table`, because it's part of our API
Expand Down
23 changes: 4 additions & 19 deletions compiler/rustc_data_structures/src/sorted_map/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::hash::{Hash, Hasher};

use rustc_index::{Idx, IndexVec};

use crate::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable_NoContext;

/// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of
/// an item by key and *O*(1) lookup by index.
Expand All @@ -24,11 +23,13 @@ use crate::stable_hasher::{HashStable, StableHasher};
/// in-place.
///
/// [`SortedMap`]: super::SortedMap
#[derive(Clone, Debug)]
#[derive(Clone, Debug, HashStable_NoContext)]
pub struct SortedIndexMultiMap<I: Idx, K, V> {
/// The elements of the map in insertion order.
items: IndexVec<I, (K, V)>,

// We can ignore this field because it is not observable from the outside.
#[stable_hasher(ignore)]
/// Indices of the items in the set, sorted by the item's key.
idx_sorted_by_item_key: Vec<I>,
}
Expand Down Expand Up @@ -126,22 +127,6 @@ where
}
}

impl<I: Idx, K, V, C> HashStable<C> for SortedIndexMultiMap<I, K, V>
where
K: HashStable<C>,
V: HashStable<C>,
{
fn hash_stable(&self, ctx: &mut C, hasher: &mut StableHasher) {
let SortedIndexMultiMap {
items,
// We can ignore this field because it is not observable from the outside.
idx_sorted_by_item_key: _,
} = self;

items.hash_stable(ctx, hasher)
}
}

impl<I: Idx, K: Ord, V> FromIterator<(K, V)> for SortedIndexMultiMap<I, K, V> {
fn from_iter<J>(iter: J) -> Self
where
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_data_structures/src/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@

use std::fmt;

use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};

use crate::fingerprint::Fingerprint;
use crate::stable_hasher;

#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable_NoContext, Decodable_NoContext, Hash)]
#[derive(
Copy,
Clone,
PartialEq,
Eq,
Debug,
Encodable_NoContext,
Decodable_NoContext,
Hash,
HashStable_NoContext
)]
pub struct Svh {
hash: Fingerprint,
}
Expand All @@ -39,11 +48,3 @@ impl fmt::Display for Svh {
f.pad(&self.to_hex())
}
}

impl<T> stable_hasher::HashStable<T> for Svh {
#[inline]
fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {
let Svh { hash } = *self;
hash.hash_stable(ctx, hasher);
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ declare_features! (
(accepted, cfg_doctest, "1.40.0", Some(62210)),
/// Enables `#[cfg(panic = "...")]` config key.
(accepted, cfg_panic, "1.60.0", Some(77443)),
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
(accepted, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
/// Allows `cfg(target_abi = "...")`.
(accepted, cfg_target_abi, "1.78.0", Some(80970)),
/// Allows `cfg(target_feature = "...")`.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ declare_features! (
(unstable, cfg_sanitize, "1.41.0", Some(39699)),
/// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
(unstable, cfg_sanitizer_cfi, "1.77.0", Some(89653)),
/// Provides a native way to easily manage multiple conditional flags without having to rewrite each clause multiple times.
(unstable, cfg_select, "CURRENT_RUSTC_VERSION", Some(115585)),
/// Allows `cfg(target(abi = "..."))`.
(unstable, cfg_target_compact, "1.63.0", Some(96901)),
/// Allows `cfg(target_has_atomic_load_store = "...")`.
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_hir/src/diagnostic_items.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_macros::HashStable_Generic;
use rustc_span::Symbol;
use rustc_span::def_id::DefIdMap;

use crate::def_id::DefId;

#[derive(Debug, Default)]
#[derive(Debug, Default, HashStable_Generic)]
pub struct DiagnosticItems {
#[stable_hasher(ignore)]
pub id_to_name: DefIdMap<Symbol>,
pub name_to_id: FxIndexMap<Symbol, DefId>,
}

impl<CTX: crate::HashStableContext> HashStable<CTX> for DiagnosticItems {
#[inline]
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.name_to_id.hash_stable(ctx, hasher);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE};
use rustc_middle::span_bug;
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::print::{with_no_trimmed_paths, with_types_for_signature};
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor, TypingMode,
Expand Down Expand Up @@ -332,6 +333,17 @@ fn report_mismatched_rpitit_signature<'tcx>(
hir::FnRetTy::Return(ty) => ty.span,
});

// Use ForSignature mode to ensure RPITITs are printed as `impl Trait` rather than
// `impl Trait { T::method(..) }` when RTN is enabled.
//
// We use `with_no_trimmed_paths!` to avoid triggering the `trimmed_def_paths` query,
// which requires diagnostic context (via `must_produce_diag`). Since we're formatting
// the type before creating the diagnostic, we need to avoid this query. This is the
// standard approach used elsewhere in the compiler for formatting types in suggestions
// (e.g., see `rustc_hir_typeck/src/demand.rs`).
let return_ty_suggestion =
with_no_trimmed_paths!(with_types_for_signature!(format!("{return_ty}")));

let span = unmatched_bound.unwrap_or(span);
tcx.emit_node_span_lint(
if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE },
Expand All @@ -342,7 +354,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
trait_return_span,
pre,
post,
return_ty,
return_ty: return_ty_suggestion,
unmatched_bound,
},
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ pub(crate) struct UnusedAssociatedTypeBounds {
#[note(
"we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information"
)]
pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> {
pub(crate) struct ReturnPositionImplTraitInTraitRefined {
#[suggestion(
"replace the return type so that it matches the trait",
applicability = "maybe-incorrect",
Expand All @@ -1146,7 +1146,7 @@ pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> {

pub pre: &'static str,
pub post: &'static str,
pub return_ty: Ty<'tcx>,
pub return_ty: String,
}

#[derive(LintDiagnostic)]
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(cfg_select)]
/// # #![cfg_attr(bootstrap, feature(cfg_select))]
/// cfg_select! {
/// _ => (),
/// windows => (),
Expand All @@ -882,7 +882,6 @@ declare_lint! {
pub UNREACHABLE_CFG_SELECT_PREDICATES,
Warn,
"detects unreachable configuration predicates in the cfg_select macro",
@feature_gate = cfg_select;
}

declare_lint! {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ decl_derive!(
hash_stable::hash_stable_generic_derive
);
decl_derive!(
[HashStable_NoContext] =>
[HashStable_NoContext, attributes(stable_hasher)] =>
/// `HashStable` implementation that has no `HashStableContext` bound and
/// which adds `where` bounds for `HashStable` based off of fields and not
/// generics. This is suitable for use in crates like `rustc_type_ir`.
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathHash;
use rustc_macros::{Decodable, Encodable};
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_span::Symbol;

use super::{KeyFingerprintStyle, SerializedDepNodeIndex};
Expand Down Expand Up @@ -290,7 +290,9 @@ pub struct DepKindVTable<'tcx> {
/// some independent path or string that persists between runs without
/// the need to be mapped or unmapped. (This ensures we can serialize
/// them even in the absence of a tcx.)
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, HashStable
)]
pub struct WorkProductId {
hash: Fingerprint,
}
Expand All @@ -302,13 +304,6 @@ impl WorkProductId {
WorkProductId { hash: hasher.finish() }
}
}

impl<HCX> HashStable<HCX> for WorkProductId {
#[inline]
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
self.hash.hash_stable(hcx, hasher)
}
}
impl<HCX> ToStableHashKey<HCX> for WorkProductId {
type KeyType = Fingerprint;
#[inline]
Expand Down
21 changes: 1 addition & 20 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ pub struct VarBindingForm<'tcx> {
pub introductions: Vec<VarBindingIntroduction>,
}

#[derive(Clone, Debug, TyEncodable, TyDecodable)]
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum BindingForm<'tcx> {
/// This is a binding for a non-`self` binding, or a `self` that has an explicit type.
Var(VarBindingForm<'tcx>),
Expand All @@ -909,25 +909,6 @@ pub struct VarBindingIntroduction {
pub is_shorthand: bool,
}

mod binding_form_impl {
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

use crate::ich::StableHashingContext;

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for super::BindingForm<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
use super::BindingForm::*;
std::mem::discriminant(self).hash_stable(hcx, hasher);

match self {
Var(binding) => binding.hash_stable(hcx, hasher),
ImplicitSelf(kind) => kind.hash_stable(hcx, hasher),
RefForGuard(local) => local.hash_stable(hcx, hasher),
}
}
}
}

/// `BlockTailInfo` is attached to the `LocalDecl` for temporaries
/// created during evaluation of expressions in a block tail
/// expression; that is, a block like `{ STMT_1; STMT_2; EXPR }`.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>(
let callee_attrs = callee_attrs.as_ref();
check_inline::is_inline_valid_on_fn(tcx, callsite.callee.def_id())?;
check_codegen_attributes(inliner, callsite, callee_attrs)?;
inliner.check_codegen_attributes_extra(callee_attrs)?;

let terminator = caller_body[callsite.block].terminator.as_ref().unwrap();
let TerminatorKind::Call { args, destination, .. } = &terminator.kind else { bug!() };
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(cfg_select))]
#![cfg_attr(bootstrap, feature(if_let_guard))]
#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
#![feature(cfg_select)]
#![feature(core_io_borrowed_buf)]
#![feature(map_try_insert)]
#![feature(negative_impls)]
Expand Down Expand Up @@ -2653,7 +2653,7 @@ impl_pos! {
pub struct BytePos(pub u32);

/// A byte offset relative to file beginning.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, HashStable_Generic)]
pub struct RelativeBytePos(pub u32);

/// A character offset.
Expand All @@ -2677,12 +2677,6 @@ impl<D: Decoder> Decodable<D> for BytePos {
}
}

impl<H: HashStableContext> HashStable<H> for RelativeBytePos {
fn hash_stable(&self, hcx: &mut H, hasher: &mut StableHasher) {
self.0.hash_stable(hcx, hasher);
}
}

impl<S: Encoder> Encodable<S> for RelativeBytePos {
fn encode(&self, s: &mut S) {
s.emit_u32(self.0);
Expand Down
Loading
Loading