Skip to content

Commit 72bcf92

Browse files
committed
Macrofy more Lift impls
1 parent e42b21b commit 72bcf92

File tree

1 file changed

+48
-200
lines changed

1 file changed

+48
-200
lines changed

src/librustc/ty/context.rs

+48-200
Original file line numberDiff line numberDiff line change
@@ -1709,104 +1709,63 @@ pub trait Lift<'tcx>: fmt::Debug {
17091709
fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted>;
17101710
}
17111711

1712-
impl<'a, 'tcx> Lift<'tcx> for Ty<'a> {
1713-
type Lifted = Ty<'tcx>;
1714-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Ty<'tcx>> {
1715-
if tcx.interners.arena.in_arena(*self as *const _) {
1716-
return Some(unsafe { mem::transmute(*self) });
1717-
}
1718-
// Also try in the global tcx if we're not that.
1719-
if !tcx.is_global() {
1720-
self.lift_to_tcx(tcx.global_tcx())
1721-
} else {
1722-
None
1723-
}
1724-
}
1725-
}
17261712

1727-
impl<'a, 'tcx> Lift<'tcx> for Region<'a> {
1728-
type Lifted = Region<'tcx>;
1729-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Region<'tcx>> {
1730-
if tcx.interners.arena.in_arena(*self as *const _) {
1731-
return Some(unsafe { mem::transmute(*self) });
1732-
}
1733-
// Also try in the global tcx if we're not that.
1734-
if !tcx.is_global() {
1735-
self.lift_to_tcx(tcx.global_tcx())
1736-
} else {
1737-
None
1738-
}
1739-
}
1740-
}
1741-
1742-
impl<'a, 'tcx> Lift<'tcx> for Goal<'a> {
1743-
type Lifted = Goal<'tcx>;
1744-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Goal<'tcx>> {
1745-
if tcx.interners.arena.in_arena(*self as *const _) {
1746-
return Some(unsafe { mem::transmute(*self) });
1713+
macro_rules! nop_lift {
1714+
($ty:ty => $lifted:ty) => {
1715+
impl<'a, 'tcx> Lift<'tcx> for $ty {
1716+
type Lifted = $lifted;
1717+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
1718+
if tcx.interners.arena.in_arena(*self as *const _) {
1719+
return Some(unsafe { mem::transmute(*self) });
1720+
}
1721+
// Also try in the global tcx if we're not that.
1722+
if !tcx.is_global() {
1723+
self.lift_to_tcx(tcx.global_tcx())
1724+
} else {
1725+
None
1726+
}
1727+
}
17471728
}
1748-
Some(tcx.intern_const_alloc(mir::interpret::Allocation::clone(self)))
1749-
}
1729+
};
17501730
}
17511731

1752-
impl<'a, 'tcx> Lift<'tcx> for &'a List<Goal<'a>> {
1753-
type Lifted = &'tcx List<Goal<'tcx>>;
1754-
fn lift_to_tcx<'b, 'gcx>(
1755-
&self,
1756-
tcx: TyCtxt<'b, 'gcx, 'tcx>,
1757-
) -> Option<&'tcx List<Goal<'tcx>>> {
1758-
if self.is_empty() {
1759-
return Some(List::empty());
1760-
}
1761-
1762-
if tcx.interners.arena.in_arena(*self as *const _) {
1763-
return Some(unsafe { mem::transmute(*self) });
1764-
}
1765-
// Also try in the global tcx if we're not that.
1766-
if !tcx.is_global() {
1767-
self.lift_to_tcx(tcx.global_tcx())
1768-
} else {
1769-
None
1732+
macro_rules! nop_list_lift {
1733+
($ty:ty => $lifted:ty) => {
1734+
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
1735+
type Lifted = &'tcx List<$lifted>;
1736+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
1737+
if self.is_empty() {
1738+
return Some(List::empty());
1739+
}
1740+
if tcx.interners.arena.in_arena(*self as *const _) {
1741+
return Some(unsafe { mem::transmute(*self) });
1742+
}
1743+
// Also try in the global tcx if we're not that.
1744+
if !tcx.is_global() {
1745+
self.lift_to_tcx(tcx.global_tcx())
1746+
} else {
1747+
None
1748+
}
1749+
}
17701750
}
1771-
}
1751+
};
17721752
}
17731753

1774-
impl<'a, 'tcx> Lift<'tcx> for &'a List<Clause<'a>> {
1775-
type Lifted = &'tcx List<Clause<'tcx>>;
1776-
fn lift_to_tcx<'b, 'gcx>(
1777-
&self,
1778-
tcx: TyCtxt<'b, 'gcx, 'tcx>,
1779-
) -> Option<&'tcx List<Clause<'tcx>>> {
1780-
if self.is_empty() {
1781-
return Some(List::empty());
1782-
}
1754+
nop_lift!{Ty<'a> => Ty<'tcx>}
1755+
nop_lift!{Region<'a> => Region<'tcx>}
1756+
nop_lift!{Goal<'a> => Goal<'tcx>}
1757+
nop_lift!{&'a LazyConst<'a> => &'tcx LazyConst<'tcx>}
17831758

1784-
if tcx.interners.arena.in_arena(*self as *const _) {
1785-
return Some(unsafe { mem::transmute(*self) });
1786-
}
1787-
// Also try in the global tcx if we're not that.
1788-
if !tcx.is_global() {
1789-
self.lift_to_tcx(tcx.global_tcx())
1790-
} else {
1791-
None
1792-
}
1793-
}
1794-
}
1759+
nop_list_lift!{Goal<'a> => Goal<'tcx>}
1760+
nop_list_lift!{Clause<'a> => Clause<'tcx>}
1761+
nop_list_lift!{Ty<'a> => Ty<'tcx>}
1762+
nop_list_lift!{ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
1763+
nop_list_lift!{Predicate<'a> => Predicate<'tcx>}
1764+
nop_list_lift!{CanonicalVarInfo => CanonicalVarInfo}
1765+
nop_list_lift!{ProjectionKind<'a> => ProjectionKind<'tcx>}
17951766

1796-
impl<'a, 'tcx> Lift<'tcx> for &'a LazyConst<'a> {
1797-
type Lifted = &'tcx LazyConst<'tcx>;
1798-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<&'tcx LazyConst<'tcx>> {
1799-
if tcx.interners.arena.in_arena(*self as *const _) {
1800-
return Some(unsafe { mem::transmute(*self) });
1801-
}
1802-
// Also try in the global tcx if we're not that.
1803-
if !tcx.is_global() {
1804-
self.lift_to_tcx(tcx.global_tcx())
1805-
} else {
1806-
None
1807-
}
1808-
}
1809-
}
1767+
// this is the impl for `&'a Substs<'a>`
1768+
nop_list_lift!{Kind<'a> => Kind<'tcx>}
18101769

18111770
impl<'a, 'tcx> Lift<'tcx> for &'a mir::interpret::Allocation {
18121771
type Lifted = &'tcx mir::interpret::Allocation;
@@ -1816,117 +1775,6 @@ impl<'a, 'tcx> Lift<'tcx> for &'a mir::interpret::Allocation {
18161775
}
18171776
}
18181777

1819-
impl<'a, 'tcx> Lift<'tcx> for &'a Substs<'a> {
1820-
type Lifted = &'tcx Substs<'tcx>;
1821-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<&'tcx Substs<'tcx>> {
1822-
if self.len() == 0 {
1823-
return Some(List::empty());
1824-
}
1825-
if tcx.interners.arena.in_arena(&self[..] as *const _) {
1826-
return Some(unsafe { mem::transmute(*self) });
1827-
}
1828-
// Also try in the global tcx if we're not that.
1829-
if !tcx.is_global() {
1830-
self.lift_to_tcx(tcx.global_tcx())
1831-
} else {
1832-
None
1833-
}
1834-
}
1835-
}
1836-
1837-
impl<'a, 'tcx> Lift<'tcx> for &'a List<Ty<'a>> {
1838-
type Lifted = &'tcx List<Ty<'tcx>>;
1839-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
1840-
-> Option<&'tcx List<Ty<'tcx>>> {
1841-
if self.len() == 0 {
1842-
return Some(List::empty());
1843-
}
1844-
if tcx.interners.arena.in_arena(*self as *const _) {
1845-
return Some(unsafe { mem::transmute(*self) });
1846-
}
1847-
// Also try in the global tcx if we're not that.
1848-
if !tcx.is_global() {
1849-
self.lift_to_tcx(tcx.global_tcx())
1850-
} else {
1851-
None
1852-
}
1853-
}
1854-
}
1855-
1856-
impl<'a, 'tcx> Lift<'tcx> for &'a List<ExistentialPredicate<'a>> {
1857-
type Lifted = &'tcx List<ExistentialPredicate<'tcx>>;
1858-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
1859-
-> Option<&'tcx List<ExistentialPredicate<'tcx>>> {
1860-
if self.is_empty() {
1861-
return Some(List::empty());
1862-
}
1863-
if tcx.interners.arena.in_arena(*self as *const _) {
1864-
return Some(unsafe { mem::transmute(*self) });
1865-
}
1866-
// Also try in the global tcx if we're not that.
1867-
if !tcx.is_global() {
1868-
self.lift_to_tcx(tcx.global_tcx())
1869-
} else {
1870-
None
1871-
}
1872-
}
1873-
}
1874-
1875-
impl<'a, 'tcx> Lift<'tcx> for &'a List<Predicate<'a>> {
1876-
type Lifted = &'tcx List<Predicate<'tcx>>;
1877-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
1878-
-> Option<&'tcx List<Predicate<'tcx>>> {
1879-
if self.is_empty() {
1880-
return Some(List::empty());
1881-
}
1882-
if tcx.interners.arena.in_arena(*self as *const _) {
1883-
return Some(unsafe { mem::transmute(*self) });
1884-
}
1885-
// Also try in the global tcx if we're not that.
1886-
if !tcx.is_global() {
1887-
self.lift_to_tcx(tcx.global_tcx())
1888-
} else {
1889-
None
1890-
}
1891-
}
1892-
}
1893-
1894-
impl<'a, 'tcx> Lift<'tcx> for &'a List<CanonicalVarInfo> {
1895-
type Lifted = &'tcx List<CanonicalVarInfo>;
1896-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
1897-
if self.len() == 0 {
1898-
return Some(List::empty());
1899-
}
1900-
if tcx.interners.arena.in_arena(*self as *const _) {
1901-
return Some(unsafe { mem::transmute(*self) });
1902-
}
1903-
// Also try in the global tcx if we're not that.
1904-
if !tcx.is_global() {
1905-
self.lift_to_tcx(tcx.global_tcx())
1906-
} else {
1907-
None
1908-
}
1909-
}
1910-
}
1911-
1912-
impl<'a, 'tcx> Lift<'tcx> for &'a List<ProjectionKind<'a>> {
1913-
type Lifted = &'tcx List<ProjectionKind<'tcx>>;
1914-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
1915-
if self.len() == 0 {
1916-
return Some(List::empty());
1917-
}
1918-
if tcx.interners.arena.in_arena(*self as *const _) {
1919-
return Some(unsafe { mem::transmute(*self) });
1920-
}
1921-
// Also try in the global tcx if we're not that.
1922-
if !tcx.is_global() {
1923-
self.lift_to_tcx(tcx.global_tcx())
1924-
} else {
1925-
None
1926-
}
1927-
}
1928-
}
1929-
19301778
pub mod tls {
19311779
use super::{GlobalCtxt, TyCtxt};
19321780

0 commit comments

Comments
 (0)