Skip to content

Rollup of 11 pull requests #122454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f21da1
compiletest: Allow `only-unix` in test headers
Enselic Mar 11, 2024
ee8efd7
fix: typos
testwill Mar 13, 2024
cdeeed8
Increase timeout for new bors bot
Kobzol Mar 13, 2024
e0488c0
Fix StableMIR is_full computation
celinval Mar 13, 2024
d919b04
Generate link to `Local` in `hir::Let` documentation
GuillaumeGomez Mar 13, 2024
cb15bf6
Rename `ValidityConstraint` -> `PlaceValidity`
Nadrieril Mar 13, 2024
4fc35c4
Rename `TypeCx` -> `PatCx`
Nadrieril Mar 13, 2024
f275406
Rename `RustcMatchCheckCtxt` -> `RustcPatCtxt`
Nadrieril Mar 13, 2024
c423678
Remove `MaybeInfiniteInt::JustAfterMax`
Nadrieril Mar 13, 2024
2366d97
extend docs of -Zprint-mono-items
RalfJung Mar 13, 2024
533ddf9
Add Exploit Mitigations PG to triagebot.toml
rcvalle Mar 13, 2024
216df4a
safe transmute: require that src referent is smaller than dst
jswrenn Mar 13, 2024
026eb3d
Delay a bug for stranded opaques
compiler-errors Mar 13, 2024
fa98724
Rollup merge of #122422 - Enselic:only-unix, r=oli-obk
matthiaskrgr Mar 13, 2024
ff5e1eb
Rollup merge of #122424 - testwill:typos, r=michaelwoerister
matthiaskrgr Mar 13, 2024
cf79540
Rollup merge of #122425 - Kobzol:new-bors-update-timeout, r=lqd
matthiaskrgr Mar 13, 2024
96a41ce
Rollup merge of #122426 - celinval:smir-fix-full, r=oli-obk
matthiaskrgr Mar 13, 2024
c6acc47
Rollup merge of #122429 - rcvalle:rust-triagebot-add-exploit-mitigati…
matthiaskrgr Mar 13, 2024
b84d1b8
Rollup merge of #122430 - GuillaumeGomez:link-to-local, r=TaKO8Ki
matthiaskrgr Mar 13, 2024
b3376bb
Rollup merge of #122434 - Nadrieril:renames, r=compiler-errors
matthiaskrgr Mar 13, 2024
5c2aa6d
Rollup merge of #122437 - Nadrieril:no-after-max, r=compiler-errors
matthiaskrgr Mar 13, 2024
89c3fa9
Rollup merge of #122438 - jswrenn:check-referent-size, r=compiler-errors
matthiaskrgr Mar 13, 2024
8d2f79c
Rollup merge of #122442 - RalfJung:print-mono-items, r=compiler-errors
matthiaskrgr Mar 13, 2024
c52ce4e
Rollup merge of #122449 - compiler-errors:stranded-opaque, r=oli-obk
matthiaskrgr Mar 13, 2024
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
Prev Previous commit
Next Next commit
Rename TypeCx -> PatCx
  • Loading branch information
Nadrieril committed Mar 13, 2024
commit 4fc35c46ff70821a37fec5f7a4c36087704d9f23
18 changes: 9 additions & 9 deletions compiler/rustc_pattern_analysis/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//! - That have no non-trivial intersection with any of the constructors in the column (i.e. they're
//! each either disjoint with or covered by any given column constructor).
//!
//! We compute this in two steps: first [`TypeCx::ctors_for_ty`] determines the
//! We compute this in two steps: first [`PatCx::ctors_for_ty`] determines the
//! set of all possible constructors for the type. Then [`ConstructorSet::split`] looks at the
//! column of constructors and splits the set into groups accordingly. The precise invariants of
//! [`ConstructorSet::split`] is described in [`SplitConstructorSet`].
Expand Down Expand Up @@ -136,7 +136,7 @@
//! the algorithm can't distinguish them from a nonempty constructor. The only known case where this
//! could happen is the `[..]` pattern on `[!; N]` with `N > 0` so we must take care to not emit it.
//!
//! This is all handled by [`TypeCx::ctors_for_ty`] and
//! This is all handled by [`PatCx::ctors_for_ty`] and
//! [`ConstructorSet::split`]. The invariants of [`SplitConstructorSet`] are also of interest.
//!
//!
Expand All @@ -162,7 +162,7 @@ use self::MaybeInfiniteInt::*;
use self::SliceKind::*;

use crate::index;
use crate::TypeCx;
use crate::PatCx;

/// Whether we have seen a constructor in the column or not.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -651,7 +651,7 @@ impl OpaqueId {
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
/// `Fields`.
#[derive(Debug)]
pub enum Constructor<Cx: TypeCx> {
pub enum Constructor<Cx: PatCx> {
/// Tuples and structs.
Struct,
/// Enum variants.
Expand Down Expand Up @@ -696,7 +696,7 @@ pub enum Constructor<Cx: TypeCx> {
PrivateUninhabited,
}

impl<Cx: TypeCx> Clone for Constructor<Cx> {
impl<Cx: PatCx> Clone for Constructor<Cx> {
fn clone(&self) -> Self {
match self {
Constructor::Struct => Constructor::Struct,
Expand All @@ -720,7 +720,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
}
}

impl<Cx: TypeCx> Constructor<Cx> {
impl<Cx: PatCx> Constructor<Cx> {
pub(crate) fn is_non_exhaustive(&self) -> bool {
matches!(self, NonExhaustive)
}
Expand Down Expand Up @@ -838,7 +838,7 @@ pub enum VariantVisibility {
/// In terms of division of responsibility, [`ConstructorSet::split`] handles all of the
/// `exhaustive_patterns` feature.
#[derive(Debug)]
pub enum ConstructorSet<Cx: TypeCx> {
pub enum ConstructorSet<Cx: PatCx> {
/// The type is a tuple or struct. `empty` tracks whether the type is empty.
Struct { empty: bool },
/// This type has the following list of constructors. If `variants` is empty and
Expand Down Expand Up @@ -889,13 +889,13 @@ pub enum ConstructorSet<Cx: TypeCx> {
/// of the `ConstructorSet` for the type, yet if we forgot to include them in `present` we would be
/// ignoring any row with `Opaque`s in the algorithm. Hence the importance of point 4.
#[derive(Debug)]
pub struct SplitConstructorSet<Cx: TypeCx> {
pub struct SplitConstructorSet<Cx: PatCx> {
pub present: SmallVec<[Constructor<Cx>; 1]>,
pub missing: Vec<Constructor<Cx>>,
pub missing_empty: Vec<Constructor<Cx>>,
}

impl<Cx: TypeCx> ConstructorSet<Cx> {
impl<Cx: PatCx> ConstructorSet<Cx> {
/// This analyzes a column of constructors to 1/ determine which constructors of the type (if
/// any) are missing; 2/ split constructors to handle non-trivial intersections e.g. on ranges
/// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_pattern_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct PrivateUninhabitedField(pub bool);
/// Context that provides type information about constructors.
///
/// Most of the crate is parameterized on a type that implements this trait.
pub trait TypeCx: Sized + fmt::Debug {
pub trait PatCx: Sized + fmt::Debug {
/// The type of a pattern.
type Ty: Clone + fmt::Debug;
/// Errors that can abort analysis.
Expand Down Expand Up @@ -155,19 +155,19 @@ pub trait TypeCx: Sized + fmt::Debug {

/// The arm of a match expression.
#[derive(Debug)]
pub struct MatchArm<'p, Cx: TypeCx> {
pub struct MatchArm<'p, Cx: PatCx> {
pub pat: &'p DeconstructedPat<Cx>,
pub has_guard: bool,
pub arm_data: Cx::ArmData,
}

impl<'p, Cx: TypeCx> Clone for MatchArm<'p, Cx> {
impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
fn clone(&self) -> Self {
Self { pat: self.pat, has_guard: self.has_guard, arm_data: self.arm_data }
}
}

impl<'p, Cx: TypeCx> Copy for MatchArm<'p, Cx> {}
impl<'p, Cx: PatCx> Copy for MatchArm<'p, Cx> {}

/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
/// useful, and runs some lints.
Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_pattern_analysis/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
use smallvec::{smallvec, SmallVec};

use crate::constructor::{Constructor, Slice, SliceKind};
use crate::{PrivateUninhabitedField, TypeCx};
use crate::{PatCx, PrivateUninhabitedField};

use self::Constructor::*;

Expand All @@ -21,15 +21,15 @@ impl PatId {
}

/// A pattern with an index denoting which field it corresponds to.
pub struct IndexedPat<Cx: TypeCx> {
pub struct IndexedPat<Cx: PatCx> {
pub idx: usize,
pub pat: DeconstructedPat<Cx>,
}

/// Values and patterns can be represented as a constructor applied to some fields. This represents
/// a pattern in this form. A `DeconstructedPat` will almost always come from user input; the only
/// exception are some `Wildcard`s introduced during pattern lowering.
pub struct DeconstructedPat<Cx: TypeCx> {
pub struct DeconstructedPat<Cx: PatCx> {
ctor: Constructor<Cx>,
fields: Vec<IndexedPat<Cx>>,
/// The number of fields in this pattern. E.g. if the pattern is `SomeStruct { field12: true, ..
Expand All @@ -43,7 +43,7 @@ pub struct DeconstructedPat<Cx: TypeCx> {
pub(crate) uid: PatId,
}

impl<Cx: TypeCx> DeconstructedPat<Cx> {
impl<Cx: PatCx> DeconstructedPat<Cx> {
pub fn new(
ctor: Constructor<Cx>,
fields: Vec<IndexedPat<Cx>>,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
}

/// This is best effort and not good enough for a `Display` impl.
impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
impl<Cx: PatCx> fmt::Debug for DeconstructedPat<Cx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let pat = self;
let mut first = true;
Expand Down Expand Up @@ -219,14 +219,14 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
/// algorithm. Do not use `Wild` to represent a wildcard pattern comping from user input.
///
/// This is morally `Option<&'p DeconstructedPat>` where `None` is interpreted as a wildcard.
pub(crate) enum PatOrWild<'p, Cx: TypeCx> {
pub(crate) enum PatOrWild<'p, Cx: PatCx> {
/// A non-user-provided wildcard, created during specialization.
Wild,
/// A user-provided pattern.
Pat(&'p DeconstructedPat<Cx>),
}

impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
impl<'p, Cx: PatCx> Clone for PatOrWild<'p, Cx> {
fn clone(&self) -> Self {
match self {
PatOrWild::Wild => PatOrWild::Wild,
Expand All @@ -235,9 +235,9 @@ impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
}
}

impl<'p, Cx: TypeCx> Copy for PatOrWild<'p, Cx> {}
impl<'p, Cx: PatCx> Copy for PatOrWild<'p, Cx> {}

impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
impl<'p, Cx: PatCx> PatOrWild<'p, Cx> {
pub(crate) fn as_pat(&self) -> Option<&'p DeconstructedPat<Cx>> {
match self {
PatOrWild::Wild => None,
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
}
}

impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
impl<'p, Cx: PatCx> fmt::Debug for PatOrWild<'p, Cx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PatOrWild::Wild => write!(f, "_"),
Expand All @@ -295,19 +295,19 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
/// purposes. As such they don't use interning and can be cloned.
#[derive(Debug)]
pub struct WitnessPat<Cx: TypeCx> {
pub struct WitnessPat<Cx: PatCx> {
ctor: Constructor<Cx>,
pub(crate) fields: Vec<WitnessPat<Cx>>,
ty: Cx::Ty,
}

impl<Cx: TypeCx> Clone for WitnessPat<Cx> {
impl<Cx: PatCx> Clone for WitnessPat<Cx> {
fn clone(&self) -> Self {
Self { ctor: self.ctor.clone(), fields: self.fields.clone(), ty: self.ty.clone() }
}
}

impl<Cx: TypeCx> WitnessPat<Cx> {
impl<Cx: PatCx> WitnessPat<Cx> {
pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self {
Self { ctor, fields, ty }
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_pattern_analysis/src/pat_column.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constructor::{Constructor, SplitConstructorSet};
use crate::pat::{DeconstructedPat, PatOrWild};
use crate::{Captures, MatchArm, TypeCx};
use crate::{Captures, MatchArm, PatCx};

/// A column of patterns in a match, where a column is the intuitive notion of "subpatterns that
/// inspect the same subvalue/place".
Expand All @@ -11,12 +11,12 @@ use crate::{Captures, MatchArm, TypeCx};
///
/// This is not used in the usefulness algorithm; only in lints.
#[derive(Debug)]
pub struct PatternColumn<'p, Cx: TypeCx> {
pub struct PatternColumn<'p, Cx: PatCx> {
/// This must not contain an or-pattern. `expand_and_push` takes care to expand them.
patterns: Vec<&'p DeconstructedPat<Cx>>,
}

impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
impl<'p, Cx: PatCx> PatternColumn<'p, Cx> {
pub fn new(arms: &[MatchArm<'p, Cx>]) -> Self {
let patterns = Vec::with_capacity(arms.len());
let mut column = PatternColumn { patterns };
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT};
use crate::constructor::{
IntRange, MaybeInfiniteInt, OpaqueId, RangeEnd, Slice, SliceKind, VariantVisibility,
};
use crate::{errors, Captures, PrivateUninhabitedField, TypeCx};
use crate::{errors, Captures, PatCx, PrivateUninhabitedField};

use crate::constructor::Constructor::*;

Expand Down Expand Up @@ -843,7 +843,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
}
}

impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
impl<'p, 'tcx: 'p> PatCx for RustcMatchCheckCtxt<'p, 'tcx> {
type Ty = RevealedTy<'tcx>;
type Error = ErrorGuaranteed;
type VariantIdx = VariantIdx;
Expand Down
Loading