]> git.lizzy.rs Git - rust.git/commitdiff
Bypass ppaux for `Outlives` predicates
authorscalexm <alexandre@scalexm.fr>
Thu, 1 Nov 2018 13:32:32 +0000 (14:32 +0100)
committerscalexm <alexandre@scalexm.fr>
Tue, 13 Nov 2018 11:28:43 +0000 (12:28 +0100)
src/librustc/traits/structural_impls.rs
src/librustc/util/ppaux.rs
src/librustc_traits/chalk_context/program_clauses.rs
src/test/ui/chalkify/lower_env2.stderr
src/test/ui/chalkify/lower_env3.stderr
src/test/ui/chalkify/lower_impl.stderr
src/test/ui/chalkify/lower_struct.stderr
src/test/ui/chalkify/lower_trait_where_clause.stderr

index 66d9c6711bb5804304aa8d9750eb749b44e57a5e..3fed2f2e3dc04ff7eb4ab7e073d2e52f8b1fe61f 100644 (file)
@@ -442,11 +442,41 @@ impl<'tcx> fmt::Display for traits::WhereClause<'tcx> {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         use traits::WhereClause::*;
 
+        // Bypass ppaux because it does not print out anonymous regions.
+        fn write_region_name<'tcx>(
+            r: ty::Region<'tcx>,
+            fmt: &mut fmt::Formatter<'_>
+        ) -> fmt::Result {
+            match r {
+                ty::ReLateBound(index, br) => match br {
+                    ty::BoundRegion::BrNamed(_, name) => write!(fmt, "{}", name),
+                    ty::BoundRegion::BrAnon(var) => {
+                        if *index == ty::INNERMOST {
+                            write!(fmt, "'^{}", var)
+                        } else {
+                            write!(fmt, "'^{}_{}", index.index(), var)
+                        }
+                    }
+                    _ => write!(fmt, "'_"),
+                }
+
+                _ => write!(fmt, "{}", r),
+            }
+        }
+
         match self {
             Implemented(trait_ref) => write!(fmt, "Implemented({})", trait_ref),
             ProjectionEq(projection) => write!(fmt, "ProjectionEq({})", projection),
-            RegionOutlives(predicate) => write!(fmt, "RegionOutlives({})", predicate),
-            TypeOutlives(predicate) => write!(fmt, "TypeOutlives({})", predicate),
+            RegionOutlives(predicate) => {
+                write!(fmt, "RegionOutlives({}: ", predicate.0)?;
+                write_region_name(predicate.1, fmt)?;
+                write!(fmt, ")")
+            }
+            TypeOutlives(predicate) => {
+                write!(fmt, "TypeOutlives({}: ", predicate.0)?;
+                write_region_name(predicate.1, fmt)?;
+                write!(fmt, ")")
+            }
         }
     }
 }
@@ -567,7 +597,7 @@ fn visit_ty(&mut self, t: ty::Ty<'tcx>) -> bool {
                     match bound_ty.kind {
                         ty::BoundTyKind::Param(name) => name,
                         ty::BoundTyKind::Anon => Symbol::intern(
-                            &format!("?{}", bound_ty.var.as_u32())
+                            &format!("^{}", bound_ty.var.as_u32())
                         ).as_interned_str(),
                     }
                 );
@@ -591,7 +621,7 @@ fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
 
                     ty::BoundRegion::BrAnon(var) => {
                         self.regions.insert(Symbol::intern(
-                            &format!("?'{}", var)
+                            &format!("'^{}", var)
                         ).as_interned_str());
                     }
 
index 5ec4f55b142ebbfcac4c74ae4f0eb63de550c5dd..e44c0c05bb1a6c78fdc829f2f509cd002a5f3677 100644 (file)
@@ -1114,9 +1114,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                     match bound_ty.kind {
                         ty::BoundTyKind::Anon => {
                             if bound_ty.index == ty::INNERMOST {
-                                write!(f, "?{}", bound_ty.var.index())
+                                write!(f, "^{}", bound_ty.var.index())
                             } else {
-                                write!(f, "?{}_{}", bound_ty.index.index(), bound_ty.var.index())
+                                write!(f, "^{}_{}", bound_ty.index.index(), bound_ty.var.index())
                             }
                         }
 
index 20d23a5bd2857a86e962059ba53fa9a9c6a32184..31f97b72e1927d1686489ac2555935a71854f498 100644 (file)
@@ -191,7 +191,7 @@ fn program_clauses_for_tuple<'tcx>(
             .map(|i| ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from(i)))
             .map(|t| tcx.mk_ty(ty::Bound(t)))
     );
-    
+
     let tuple_ty = tcx.mk_ty(ty::Tuple(type_list));
 
     let sized_trait = match tcx.lang_items().sized_trait() {
index aaf6eda641dbb7d52187c3a8b05ad9c56d7bf437..74833ef064f9d24039d0c37f56ccec536a10c64f 100644 (file)
@@ -5,8 +5,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: forall<'a, T> { FromEnv(T: Foo) :- FromEnv(S<'a, T>). }
-   = note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(S<'a, T>). }
-   = note: forall<'a, T> { WellFormed(S<'a, T>) :- Implemented(T: Foo), TypeOutlives(T : 'a). }
+   = note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(S<'a, T>). }
+   = note: forall<'a, T> { WellFormed(S<'a, T>) :- Implemented(T: Foo), TypeOutlives(T: 'a). }
 
 error: program clause dump
   --> $DIR/lower_env2.rs:21:1
@@ -15,7 +15,7 @@ LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: forall<'a, T> { FromEnv(T: Foo) :- FromEnv(S<'a, T>). }
-   = note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(S<'a, T>). }
+   = note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(S<'a, T>). }
    = note: forall<Self> { Implemented(Self: Foo) :- FromEnv(Self: Foo). }
    = note: forall<Self> { Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized). }
 
index 7c59b9046f5495f7bda27f3024a4ac70bda71883..eef6405f8f805e916217566dcb4152e1c8febc61 100644 (file)
@@ -4,7 +4,7 @@ error: program clause dump
 LL |     #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: forall<?'0, ?1> { TypeOutlives(?1 : ) :- FromEnv(&?1). }
+   = note: forall<'^0, ^1> { TypeOutlives(^1: '^0) :- FromEnv(&^1). }
    = note: forall<Self> { Implemented(Self: Foo) :- FromEnv(Self: Foo). }
 
 error: program clause dump
@@ -13,7 +13,7 @@ error: program clause dump
 LL |     #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: forall<?'0, ?1> { TypeOutlives(?1 : ) :- FromEnv(&?1). }
+   = note: forall<'^0, ^1> { TypeOutlives(^1: '^0) :- FromEnv(&^1). }
    = note: forall<Self> { FromEnv(Self: std::marker::Sized) :- FromEnv(Self: std::clone::Clone). }
    = note: forall<Self> { Implemented(Self: std::clone::Clone) :- FromEnv(Self: std::clone::Clone). }
    = note: forall<Self> { Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized). }
index ed84fe4eb26c52c7f4b7710fd740f2a0e38b7a93..92a209f673d5c1143ab52f9d6765cf33ccf6e5b9 100644 (file)
@@ -4,7 +4,7 @@ error: program clause dump
 LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: forall<T> { Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T : 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized). }
+   = note: forall<T> { Implemented(T: Foo) :- ProjectionEq(<T as std::iter::Iterator>::Item == i32), TypeOutlives(T: 'static), Implemented(T: std::iter::Iterator), Implemented(T: std::marker::Sized). }
 
 error: program clause dump
   --> $DIR/lower_impl.rs:23:5
index a12ee52a086f64f8a679c29d6581c58b362eb0d7..a0dd9369700af63d3d81de46f7376261a0d54594 100644 (file)
@@ -6,8 +6,8 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
    |
    = note: forall<'a, T> { FromEnv(T: std::marker::Sized) :- FromEnv(Foo<'a, T>). }
    = note: forall<'a, T> { FromEnv(std::boxed::Box<T>: std::clone::Clone) :- FromEnv(Foo<'a, T>). }
-   = note: forall<'a, T> { TypeOutlives(T : 'a) :- FromEnv(Foo<'a, T>). }
-   = note: forall<'a, T> { WellFormed(Foo<'a, T>) :- Implemented(T: std::marker::Sized), Implemented(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T : 'a). }
+   = note: forall<'a, T> { TypeOutlives(T: 'a) :- FromEnv(Foo<'a, T>). }
+   = note: forall<'a, T> { WellFormed(Foo<'a, T>) :- Implemented(T: std::marker::Sized), Implemented(std::boxed::Box<T>: std::clone::Clone), TypeOutlives(T: 'a). }
 
 error: aborting due to previous error
 
index f4f3effaaaef78f9a7c9e5f60d0e93012578ce84..f04f53f24969a45dff6e4b439c1132052cb82c8a 100644 (file)
@@ -6,9 +6,9 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
    |
    = note: forall<'a, 'b, Self, T, U> { FromEnv(T: std::borrow::Borrow<U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
    = note: forall<'a, 'b, Self, T, U> { Implemented(Self: Foo<'a, 'b, T, U>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
-   = note: forall<'a, 'b, Self, T, U> { RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
-   = note: forall<'a, 'b, Self, T, U> { TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
-   = note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U : 'b), RegionOutlives('a : 'b), WellFormed(std::boxed::Box<T>). }
+   = note: forall<'a, 'b, Self, T, U> { RegionOutlives('a: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
+   = note: forall<'a, 'b, Self, T, U> { TypeOutlives(U: 'b) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
+   = note: forall<'a, 'b, Self, T, U> { WellFormed(Self: Foo<'a, 'b, T, U>) :- Implemented(Self: Foo<'a, 'b, T, U>), WellFormed(T: std::borrow::Borrow<U>), TypeOutlives(U: 'b), RegionOutlives('a: 'b), WellFormed(std::boxed::Box<T>). }
    = note: forall<'a, 'b, Self, T, U> { WellFormed(std::boxed::Box<T>) :- FromEnv(Self: Foo<'a, 'b, T, U>). }
 
 error: aborting due to previous error