Skip to content
Merged
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
6 changes: 1 addition & 5 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,7 @@ impl Pat {
| PatKind::Or(s) => s.iter().for_each(|p| p.walk(it)),

// Trivial wrappers over inner patterns.
PatKind::Box(s)
| PatKind::Deref(s)
PatKind::Deref(s)
| PatKind::Ref(s, _, _)
| PatKind::Paren(s)
| PatKind::Guard(s, _) => s.walk(it),
Expand Down Expand Up @@ -901,9 +900,6 @@ pub enum PatKind {
/// A tuple pattern (`(a, b)`).
Tuple(ThinVec<Pat>),

/// A `box` pattern.
Box(Box<Pat>),

/// A `deref` pattern (currently `deref!()` macro-based syntax).
Deref(Box<Pat>),

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple");
break hir::PatKind::Tuple(pats, ddpos);
}
PatKind::Box(inner) => {
break hir::PatKind::Box(self.lower_pat(inner));
}
PatKind::Deref(inner) => {
break hir::PatKind::Deref(self.lower_pat(inner));
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}
}
PatKind::Box(..) => {
gate!(self, box_patterns, pattern.span, "box pattern syntax is experimental");
}
_ => {}
}
visit::walk_pat(self, pattern)
Expand Down Expand Up @@ -596,7 +593,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {

// tidy-alphabetical-start
soft_gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
soft_gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
soft_gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
soft_gate_all_legacy_dont_use!(negative_impls, "negative impls are experimental");
soft_gate_all_legacy_dont_use!(specialization, "specialization is experimental");
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2011,10 +2011,6 @@ impl<'a> State<'a> {
}
self.pclose();
}
PatKind::Box(inner) => {
self.word("box ");
self.print_pat_paren_if_or(inner);
}
PatKind::Deref(inner) => {
self.word("deref!");
self.popen();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn process_builtin_attrs(
codegen_fn_attrs: &mut CodegenFnAttrs,
) -> InterestingAttributeDiagnosticSpans {
let mut interesting_spans = InterestingAttributeDiagnosticSpans::default();
let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);
let rust_target_features = tcx.all_rust_target_features(LOCAL_CRATE);

let parsed_attrs = attrs
.iter()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ pub fn sanitizer_features_by_flags(sess: &Session, features: &mut Vec<String>) {

pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
rust_target_features: |tcx, cnum| {
all_rust_target_features: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
if tcx.sess.opts.actually_rustdoc {
// HACK: rustdoc would like to pretend that we have all the target features, so we
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ declare_features! (
Some("merged into `min_generic_const_args`")),
(removed, await_macro, "1.38.0", Some(50547),
Some("subsumed by `.await` syntax"), 62293),
/// Allows using `box` in patterns (RFC 469).
(removed, box_patterns, "CURRENT_RUSTC_VERSION", Some(29641), Some("superseded by `deref_patterns`")),
/// Allows using the `box $expr` syntax.
(removed, box_syntax, "1.70.0", Some(49733), Some("replaced with `#[rustc_box]`"), 108471),
/// Allows capturing disjoint fields in a closure/coroutine (RFC 2229).
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 @@ -313,8 +313,6 @@ declare_features! (
/// Allows features specific to auto traits.
/// Renamed from `optin_builtin_traits`.
(unstable, auto_traits, "1.50.0", Some(13231)),
/// Allows using `box` in patterns (RFC 469).
(unstable, box_patterns, "1.0.0", Some(29641)),
/// Allows builtin # foo() syntax
(internal, builtin_syntax, "1.71.0", Some(110680)),
/// Allows `#[doc(notable_trait)]`.
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,7 @@ impl<'hir> Pat<'hir> {
match self.kind {
Missing => unreachable!(),
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => true,
Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => {
s.walk_short_(it)
}
Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it),
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
Slice(before, slice, after) => {
Expand All @@ -1564,7 +1562,7 @@ impl<'hir> Pat<'hir> {
use PatKind::*;
match self.kind {
Missing | Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => {}
Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
Slice(before, slice, after) => {
Expand Down Expand Up @@ -1646,7 +1644,6 @@ impl<'hir> Pat<'hir> {
| PatKind::Struct(_, _, _)
| PatKind::TupleStruct(_, _, _)
| PatKind::Tuple(_, _)
| PatKind::Box(_)
| PatKind::Ref(_, _, _)
| PatKind::Deref(_)
| PatKind::Expr(_)
Expand Down Expand Up @@ -1792,9 +1789,6 @@ pub enum PatKind<'hir> {
/// `0 <= position <= subpats.len()`
Tuple(&'hir [Pat<'hir>], DotDotPos),

/// A `box` pattern.
Box(&'hir Pat<'hir>),

/// A `deref` pattern (currently `deref!()` macro-based syntax).
Deref(&'hir Pat<'hir>),

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V:
PatKind::Tuple(tuple_elements, _) => {
walk_list!(visitor, visit_pat, tuple_elements);
}
PatKind::Box(ref subpattern)
| PatKind::Deref(ref subpattern)
| PatKind::Ref(ref subpattern, _, _) => {
PatKind::Deref(ref subpattern) | PatKind::Ref(ref subpattern, _, _) => {
try_visit!(visitor.visit_pat(subpattern));
}
PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ fn resolve_local<'tcx>(
| PatKind::TupleStruct(_, subpats, _)
| PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(p)),

PatKind::Box(subpat) | PatKind::Deref(subpat) | PatKind::Guard(subpat, _) => {
is_binding_pat(subpat)
}
PatKind::Deref(subpat) | PatKind::Guard(subpat, _) => is_binding_pat(subpat),

PatKind::Ref(_, _, _)
| PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..)
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2088,17 +2088,6 @@ impl<'a> State<'a> {
}
self.pclose();
}
PatKind::Box(inner) => {
let is_range_inner = matches!(inner.kind, PatKind::Range(..));
self.word("box ");
if is_range_inner {
self.popen();
}
self.print_pat(inner);
if is_range_inner {
self.pclose();
}
}
PatKind::Deref(inner) => {
self.word("deref!");
self.popen();
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
}
}
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Ref(..)
| PatKind::Guard(..)
| PatKind::Tuple(..)
Expand Down Expand Up @@ -1763,8 +1762,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
self.cat_pattern(place_with_id, subpat, op)?;
}

PatKind::Box(subpat) | PatKind::Ref(subpat, _, _) => {
// box p1, &p1, &mut p1. we can ignore the mutability of
PatKind::Ref(subpat, _, _) => {
// &p1, &mut p1. we can ignore the mutability of
// PatKind::Ref since that information is already contained
// in the type.
let subplace = self.cat_deref(pat.hir_id, place_with_id)?;
Expand Down
32 changes: 1 addition & 31 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
PatKind::Tuple(elements, ddpos) => {
self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info)
}
PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info),
PatKind::Deref(inner) => self.check_pat_deref(pat.span, inner, expected, pat_info),
PatKind::Ref(inner, pinned, mutbl) => {
self.check_pat_ref(pat, inner, pinned, mutbl, expected, pat_info)
Expand Down Expand Up @@ -762,9 +761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// that the expected type be of those types and not reference types.
PatKind::Tuple(..) | PatKind::Range(..) | PatKind::Slice(..) => AdjustMode::peel_all(),
// When checking an explicit deref pattern, only peel reference types.
// FIXME(deref_patterns): If box patterns and deref patterns need to coexist, box
// patterns may want `PeelKind::Implicit`, stopping on encountering a box.
PatKind::Box(_) | PatKind::Deref(_) => {
PatKind::Deref(_) => {
AdjustMode::Peel { kind: PeelKind::ExplicitDerefPat }
}
// A never pattern behaves somewhat like a literal or unit variant.
Expand Down Expand Up @@ -1386,7 +1383,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| PatKind::Wild
| PatKind::Never
| PatKind::Binding(..)
| PatKind::Box(..)
| PatKind::Deref(_)
| PatKind::Ref(..)
| PatKind::Expr(..)
Expand Down Expand Up @@ -2709,32 +2705,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err
}

fn check_pat_box(
&self,
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let (box_ty, inner_ty) = self
.check_dereferenceable(span, expected, inner)
.and_then(|()| {
// Here, `demand::subtype` is good enough, but I don't
// think any errors can be introduced by using `demand::eqtype`.
let inner_ty = self.next_ty_var(inner.span);
let box_ty = Ty::new_box(tcx, inner_ty);
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
Ok((box_ty, inner_ty))
})
.unwrap_or_else(|guar| {
let err = Ty::new_error(tcx, guar);
(err, err)
});
self.check_pat(inner, inner_ty, pat_info);
box_ty
}

fn check_pat_deref(
&self,
span: Span,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,6 @@ impl EarlyLintPass for BadUseOfFindAttr {
find_attr_kind_in_pat(cx, pat);
}
}
PatKind::Box(pat) => {
find_attr_kind_in_pat(cx, pat);
}
PatKind::Deref(pat) => {
find_attr_kind_in_pat(cx, pat);
}
Expand Down Expand Up @@ -763,7 +760,6 @@ fn pat_is_not_exhaustive_heuristic(pat: &hir::Pat<'_>) -> Option<(Span, &'static
hir::PatKind::Or(..) => None,
hir::PatKind::Never => None,
hir::PatKind::Tuple(..) => None,
hir::PatKind::Box(pat) => pat_is_not_exhaustive_heuristic(&*pat),
hir::PatKind::Deref(pat) => pat_is_not_exhaustive_heuristic(&*pat),
hir::PatKind::Ref(pat, _, _) => pat_is_not_exhaustive_heuristic(&*pat),
hir::PatKind::Expr(..) => None,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ impl EarlyLintPass for UnusedParens {
self.check_unused_parens_pat(cx, &f.pat, false, false, keep_space);
}
}
// Avoid linting on `i @ (p0 | .. | pn)` and `box (p0 | .. | pn)`, #64106.
Ident(.., Some(p)) | Box(p) | Deref(p) | Guard(p, _) => {
// Avoid linting on `i @ (p0 | .. | pn)`, #64106.
Ident(.., Some(p)) | Deref(p) | Guard(p, _) => {
self.check_unused_parens_pat(cx, p, true, false, keep_space)
}
// Avoid linting on `&(mut x)` as `&mut x` has a different meaning, #55342.
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2648,8 +2648,9 @@ rustc_queries! {
desc { "computing proof tree for `{}` with depth `{}`", key.0.canonical.value.goal.predicate, key.1 }
}

/// Returns the Rust target features for the current target. These are not always the same as LLVM target features!
query rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
/// Returns a list of all Rust target features for the current target (not just the ones that
/// are enabled). These are not always the same as LLVM target features!
query all_rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
arena_cache
eval_always
desc { "looking up Rust target features" }
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,6 @@ pub enum PatKind<'tcx> {

/// Explicit or implicit `deref!(..)` pattern, under `feature(deref_patterns)`.
/// Represents a call to `Deref` or `DerefMut`, or a deref-move of `Box`.
///
/// `box P` patterns also lower to this, under `feature(box_patterns)`.
DerefPattern {
subpattern: Box<Pat<'tcx>>,
/// Whether the pattern scrutinee needs to be borrowed in order to call `Deref::deref` or
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{self as hir, RangeEnd};
use rustc_index::Idx;
use rustc_middle::thir::{
Ascription, DerefPatBorrowMode, FieldPat, LocalVarId, Pat, PatKind, PatRange, PatRangeBoundary,
Ascription, FieldPat, LocalVarId, Pat, PatKind, PatRange, PatRangeBoundary,
};
use rustc_middle::ty::adjustment::{PatAdjust, PatAdjustment};
use rustc_middle::ty::layout::IntegerExt;
Expand Down Expand Up @@ -352,11 +352,6 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
}
PatKind::Deref { pin, subpattern }
}
hir::PatKind::Box(subpattern) => PatKind::DerefPattern {
subpattern: self.lower_pattern(subpattern),
borrow: DerefPatBorrowMode::Box,
},

hir::PatKind::Slice(prefix, slice, suffix) => {
return self.slice_or_array_pattern(pat, prefix, slice, suffix);
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_parse/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3749,6 +3749,13 @@ pub(crate) struct AddBoxNew {
pub hi: Span,
}

#[derive(Diagnostic)]
#[diag("`box_patterns` has been removed")]
pub(crate) struct BoxPatternsRemoved {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("return type not allowed with return type notation")]
pub(crate) struct BadReturnTypeNotationOutput {
Expand Down
Loading
Loading