Stop ConstraintCategory Ord impl from relying on Ty's Ord impl.

This commit is contained in:
Oli Scherer 2024-03-21 10:11:44 +00:00
parent 1cf345e10a
commit cda209bf43
5 changed files with 32 additions and 22 deletions

View File

@ -4236,6 +4236,7 @@ name = "rustc_middle"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"derivative",
"either", "either",
"field-offset", "field-offset",
"gsgdt", "gsgdt",

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
# tidy-alphabetical-start # tidy-alphabetical-start
bitflags = "2.4.1" bitflags = "2.4.1"
derivative = "2.2.0"
either = "1.5.0" either = "1.5.0"
field-offset = "0.3.5" field-offset = "0.3.5"
gsgdt = "0.1.2" gsgdt = "0.1.2"

View File

@ -284,8 +284,15 @@ pub struct ClosureOutlivesRequirement<'tcx> {
/// order of the category, thereby influencing diagnostic output. /// order of the category, thereby influencing diagnostic output.
/// ///
/// See also `rustc_const_eval::borrow_check::constraints`. /// 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(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> { pub enum ConstraintCategory<'tcx> {
Return(ReturnConstraint), Return(ReturnConstraint),
Yield, Yield,
@ -295,6 +302,7 @@ pub enum ConstraintCategory<'tcx> {
Cast { Cast {
/// Whether this is an unsizing cast and if yes, this contains the target type. /// Whether this is an unsizing cast and if yes, this contains the target type.
/// Region variables are erased to ReErased. /// Region variables are erased to ReErased.
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
unsize_to: Option<Ty<'tcx>>, unsize_to: Option<Ty<'tcx>>,
}, },
@ -304,7 +312,7 @@ pub enum ConstraintCategory<'tcx> {
ClosureBounds, ClosureBounds,
/// Contains the function type if available. /// Contains the function type if available.
CallArgument(Option<Ty<'tcx>>), CallArgument(#[derivative(PartialOrd = "ignore", Ord = "ignore")] Option<Ty<'tcx>>),
CopyBound, CopyBound,
SizedBound, SizedBound,
Assignment, Assignment,

View File

@ -56,12 +56,11 @@ error[E0597]: `a` does not live long enough
LL | let a = 0; LL | let a = 0;
| - binding `a` declared here | - binding `a` declared here
LL | let cell = Cell::new(&a); LL | let cell = Cell::new(&a);
| ^^ borrowed value does not live long enough | ----------^^-
| | |
| | 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 | } LL | }
| - `a` dropped here while still borrowed | - `a` dropped here while still borrowed

View File

@ -3,12 +3,13 @@ error[E0597]: `c` does not live long enough
| |
LL | let c = 66; LL | let c = 66;
| - binding `c` declared here | - binding `c` declared here
LL | / combine( LL | combine(
LL | | SomeEnum::SomeVariant(Cell::new(&c)), LL | SomeEnum::SomeVariant(Cell::new(&c)),
| | ^^ borrowed value does not live long enough | ----------^^-
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>, | | |
LL | | ); | | borrowed value does not live long enough
| |_____- argument requires that `c` is borrowed for `'static` | argument requires that `c` is borrowed for `'static`
...
LL | } LL | }
| - `c` dropped here while still borrowed | - `c` dropped here while still borrowed