Skip to content

Commit cda209b

Browse files
committed
Stop ConstraintCategory Ord impl from relying on Ty's Ord impl.
1 parent 1cf345e commit cda209b

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4236,6 +4236,7 @@ name = "rustc_middle"
42364236
version = "0.0.0"
42374237
dependencies = [
42384238
"bitflags 2.4.2",
4239+
"derivative",
42394240
"either",
42404241
"field-offset",
42414242
"gsgdt",

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
derivative = "2.2.0"
910
either = "1.5.0"
1011
field-offset = "0.3.5"
1112
gsgdt = "0.1.2"

compiler/rustc_middle/src/mir/query.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,15 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
284284
/// order of the category, thereby influencing diagnostic output.
285285
///
286286
/// See also `rustc_const_eval::borrow_check::constraints`.
287-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
287+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
288288
#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
289+
#[derive(derivative::Derivative)]
290+
#[derivative(
291+
PartialOrd,
292+
Ord,
293+
PartialOrd = "feature_allow_slow_enum",
294+
Ord = "feature_allow_slow_enum"
295+
)]
289296
pub enum ConstraintCategory<'tcx> {
290297
Return(ReturnConstraint),
291298
Yield,
@@ -295,6 +302,7 @@ pub enum ConstraintCategory<'tcx> {
295302
Cast {
296303
/// Whether this is an unsizing cast and if yes, this contains the target type.
297304
/// Region variables are erased to ReErased.
305+
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
298306
unsize_to: Option<Ty<'tcx>>,
299307
},
300308

@@ -304,7 +312,7 @@ pub enum ConstraintCategory<'tcx> {
304312
ClosureBounds,
305313

306314
/// Contains the function type if available.
307-
CallArgument(Option<Ty<'tcx>>),
315+
CallArgument(#[derivative(PartialOrd = "ignore", Ord = "ignore")] Option<Ty<'tcx>>),
308316
CopyBound,
309317
SizedBound,
310318
Assignment,

tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr

+9-10
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ LL | fn case2() {
5353
error[E0597]: `a` does not live long enough
5454
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
5555
|
56-
LL | let a = 0;
57-
| - binding `a` declared here
58-
LL | let cell = Cell::new(&a);
59-
| ^^ borrowed value does not live long enough
56+
LL | let a = 0;
57+
| - binding `a` declared here
58+
LL | let cell = Cell::new(&a);
59+
| ----------^^-
60+
| | |
61+
| | borrowed value does not live long enough
62+
| argument requires that `a` is borrowed for `'static`
6063
...
61-
LL | / foo(cell, |cell_a, cell_x| {
62-
LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
63-
LL | | })
64-
| |______- argument requires that `a` is borrowed for `'static`
65-
LL | }
66-
| - `a` dropped here while still borrowed
64+
LL | }
65+
| - `a` dropped here while still borrowed
6766

6867
error: aborting due to 2 previous errors
6968

tests/ui/nll/user-annotations/adt-nullary-enums.stderr

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
error[E0597]: `c` does not live long enough
22
--> $DIR/adt-nullary-enums.rs:33:41
33
|
4-
LL | let c = 66;
5-
| - binding `c` declared here
6-
LL | / combine(
7-
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
8-
| | ^^ borrowed value does not live long enough
9-
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
10-
LL | | );
11-
| |_____- argument requires that `c` is borrowed for `'static`
12-
LL | }
13-
| - `c` dropped here while still borrowed
4+
LL | let c = 66;
5+
| - binding `c` declared here
6+
LL | combine(
7+
LL | SomeEnum::SomeVariant(Cell::new(&c)),
8+
| ----------^^-
9+
| | |
10+
| | borrowed value does not live long enough
11+
| argument requires that `c` is borrowed for `'static`
12+
...
13+
LL | }
14+
| - `c` dropped here while still borrowed
1415

1516
error[E0597]: `c` does not live long enough
1617
--> $DIR/adt-nullary-enums.rs:41:41

0 commit comments

Comments
 (0)