Skip to content

Commit e236587

Browse files
committed
fix stage 2
1 parent 32d11e6 commit e236587

File tree

20 files changed

+41
-9
lines changed

20 files changed

+41
-9
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(negative_impls)]
1919
#![feature(slice_internals)]
2020
#![feature(stmt_expr_attributes)]
21+
#![feature(structural_match)]
2122
#![recursion_limit = "256"]
2223
#![deny(rustc::untranslatable_diagnostic)]
2324
#![deny(rustc::diagnostic_outside_of_impl)]

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(once_cell)]
99
#![feature(rustc_attrs)]
1010
#![feature(stmt_expr_attributes)]
11+
#![feature(structural_match)]
1112
#![feature(trusted_step)]
1213
#![feature(try_blocks)]
1314
#![recursion_limit = "256"]

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(maybe_uninit_uninit_array)]
1818
#![feature(min_specialization)]
1919
#![feature(never_type)]
20+
#![feature(structural_match)]
2021
#![feature(type_alias_impl_trait)]
2122
#![feature(new_uninit)]
2223
#![feature(once_cell)]

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(min_specialization)]
1010
#![feature(never_type)]
1111
#![feature(rustc_attrs)]
12+
#![feature(structural_match)]
1213
#![feature(variant_count)]
1314
#![recursion_limit = "256"]
1415
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ This API is completely unstable and subject to change.
6969
#![feature(never_type)]
7070
#![feature(once_cell)]
7171
#![feature(slice_partition_dedup)]
72+
#![feature(structural_match)]
7273
#![feature(try_blocks)]
7374
#![feature(is_some_and)]
7475
#![feature(type_alias_impl_trait)]

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(min_specialization)]
66
#![feature(control_flow_enum)]
77
#![feature(drain_filter)]
8+
#![feature(structural_match)]
89
#![allow(rustc::potential_query_instability)]
910
#![recursion_limit = "256"]
1011

compiler/rustc_index/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
new_uninit,
1010
step_trait,
1111
stmt_expr_attributes,
12+
structural_match,
1213
test
1314
)
1415
)]

compiler/rustc_infer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(if_let_guard)]
2121
#![feature(min_specialization)]
2222
#![feature(never_type)]
23+
#![feature(structural_match)]
2324
#![feature(try_blocks)]
2425
#![recursion_limit = "512"] // For rustdoc
2526

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(min_specialization)]
3838
#![feature(never_type)]
3939
#![feature(rustc_attrs)]
40+
#![feature(structural_match)]
4041
#![recursion_limit = "256"]
4142
#![deny(rustc::untranslatable_diagnostic)]
4243
#![deny(rustc::diagnostic_outside_of_impl)]

compiler/rustc_macros/src/newtype.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Parse for Newtype {
9393
}
9494
impl<E: ::rustc_serialize::Encoder> ::rustc_serialize::Encodable<E> for #name {
9595
fn encode(&self, e: &mut E) {
96-
e.emit_u32(self.private);
96+
e.emit_u32(self.as_u32());
9797
}
9898
}
9999
}
@@ -103,11 +103,16 @@ impl Parse for Newtype {
103103

104104
if ord {
105105
derive_paths.push(parse_quote!(Ord));
106-
derive_paths.push(parse_quote!(PartialOrd));
107106
}
108107

109108
let step = if ord {
110109
quote! {
110+
impl ::std::cmp::PartialOrd for #name {
111+
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
112+
self.as_u32().partial_cmp(&other.as_u32())
113+
}
114+
}
115+
111116
impl ::std::iter::Step for #name {
112117
#[inline]
113118
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
@@ -150,7 +155,7 @@ impl Parse for Newtype {
150155
#[inline]
151156
fn eq(l: &Option<Self>, r: &Option<Self>) -> bool {
152157
if #max_val < u32::MAX {
153-
l.map(|i| i.private).unwrap_or(#max_val+1) == r.map(|i| i.private).unwrap_or(#max_val+1)
158+
l.map(|i| i.as_u32()).unwrap_or(#max_val+1) == r.map(|i| i.as_u32()).unwrap_or(#max_val+1)
154159
} else {
155160
match (l, r) {
156161
(Some(l), Some(r)) => r == l,
@@ -170,13 +175,21 @@ impl Parse for Newtype {
170175

171176
Ok(Self(quote! {
172177
#(#attrs)*
173-
#[derive(Clone, Copy, PartialEq, Eq, Hash, #(#derive_paths),*)]
178+
#[derive(Clone, Copy, Eq, Hash, #(#derive_paths),*)]
174179
#[rustc_layout_scalar_valid_range_end(#max)]
175180
#[rustc_pass_by_value]
176181
#vis struct #name {
177182
private: u32,
178183
}
179184

185+
impl ::std::cmp::PartialEq for #name {
186+
fn eq(&self, other: &Self) -> bool {
187+
self.as_u32() == other.as_u32()
188+
}
189+
}
190+
191+
impl ::std::marker::StructuralPartialEq for #name {}
192+
180193
#(#consts)*
181194

182195
impl #name {
@@ -224,7 +237,7 @@ impl Parse for Newtype {
224237
/// Prefer using `from_u32`.
225238
#[inline]
226239
#vis const unsafe fn from_u32_unchecked(value: u32) -> Self {
227-
Self { private: value }
240+
Self { private: value as _ }
228241
}
229242

230243
/// Extracts the value of this index as a `usize`.
@@ -236,7 +249,7 @@ impl Parse for Newtype {
236249
/// Extracts the value of this index as a `u32`.
237250
#[inline]
238251
#vis const fn as_u32(self) -> u32 {
239-
self.private
252+
self.private as u32
240253
}
241254

242255
/// Extracts the value of this index as a `usize`.

0 commit comments

Comments
 (0)