Skip to content

Commit

Permalink
Stop ConstraintCategory Ord impl from relying on Ty's Ord impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 21, 2024
1 parent 1cf345e commit cda209b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4236,6 +4236,7 @@ name = "rustc_middle"
version = "0.0.0"
dependencies = [
"bitflags 2.4.2",
"derivative",
"either",
"field-offset",
"gsgdt",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
derivative = "2.2.0"
either = "1.5.0"
field-offset = "0.3.5"
gsgdt = "0.1.2"
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,15 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
/// order of the category, thereby influencing diagnostic output.
///
/// See also `rustc_const_eval::borrow_check::constraints`.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
#[derive(derivative::Derivative)]
#[derivative(
PartialOrd,
Ord,
PartialOrd = "feature_allow_slow_enum",
Ord = "feature_allow_slow_enum"
)]
pub enum ConstraintCategory<'tcx> {
Return(ReturnConstraint),
Yield,
Expand All @@ -295,6 +302,7 @@ pub enum ConstraintCategory<'tcx> {
Cast {
/// Whether this is an unsizing cast and if yes, this contains the target type.
/// Region variables are erased to ReErased.
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
unsize_to: Option<Ty<'tcx>>,
},

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

/// Contains the function type if available.
CallArgument(Option<Ty<'tcx>>),
CallArgument(#[derivative(PartialOrd = "ignore", Ord = "ignore")] Option<Ty<'tcx>>),
CopyBound,
SizedBound,
Assignment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ LL | fn case2() {
error[E0597]: `a` does not live long enough
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26
|
LL | let a = 0;
| - binding `a` declared here
LL | let cell = Cell::new(&a);
| ^^ borrowed value does not live long enough
LL | let a = 0;
| - binding `a` declared here
LL | let cell = Cell::new(&a);
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `a` is borrowed for `'static`
...
LL | / foo(cell, |cell_a, cell_x| {
LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
LL | | })
| |______- argument requires that `a` is borrowed for `'static`
LL | }
| - `a` dropped here while still borrowed
LL | }
| - `a` dropped here while still borrowed

error: aborting due to 2 previous errors

Expand Down
21 changes: 11 additions & 10 deletions tests/ui/nll/user-annotations/adt-nullary-enums.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
error[E0597]: `c` does not live long enough
--> $DIR/adt-nullary-enums.rs:33:41
|
LL | let c = 66;
| - binding `c` declared here
LL | / combine(
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
| | ^^ borrowed value does not live long enough
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
LL | | );
| |_____- argument requires that `c` is borrowed for `'static`
LL | }
| - `c` dropped here while still borrowed
LL | let c = 66;
| - binding `c` declared here
LL | combine(
LL | SomeEnum::SomeVariant(Cell::new(&c)),
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'static`
...
LL | }
| - `c` dropped here while still borrowed

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

0 comments on commit cda209b

Please sign in to comment.