When there is "dead hand" control of something, the people living in the present have to comply with the law (although some land use regulations and some tax treatments are indeed grandfathered), and the terms of the long term obligation can be "reformed" by a court to be consistent with the new law, if possible.
If the gift is charitable, the doctrine that authorizes this is called the "cy pres" doctrine and the charitable purpose is revised in a manner as consistent with the original intent as feasible. For example, if you make a charitable trust for the Boy Scouts and the Boy Scouts cease to exist, a court authorizes you under this doctrine to substitute another beneficiary with a similar purpose, perhaps, for example, the Boys and Girls Club. What is most similar is based upon testimony about the testator's intent in making the gift, if available.
In the case of an easement or covenant, it is usually just called reformation of the provision. In the farm case, someone might have the trust reformed to state that the farm must be managed with a goal towards maintaining traditional methods to the extent feasible to do so.
If reformation is simply impossible (e.g. a covenant mandating racial discrimination), then the person subject to it can get a declaratory judgment that the provision is void.
And, if there is no longer any purpose for keeping a trust arrangement in place, a trust can be terminated entirely.
The legal process of procedurally carrying out these tasks varies quite a bit from jurisdiction to jurisdiction. The Uniform Trust Code adopted by a number of U.S. states, for example, sets forth a fairly easy standard for reforming trusts, while the common law rules for doing so are more onerous.