Auto merge of #123327 - BoxyUwU:param_env_docs_rewrite, r=compiler-errors

Update `ParamEnv` docs

There is now a wealth of information in the dev guide about `ParamEnv` so we should explicitly link to it from the doc comments. I also added a caution against using `ParamEnv` and removed the comment about it being "suitable for type checking" as you should practically never use `ParamEnv::empty` for type checking

r? `@compiler-errors`
This commit is contained in:
bors 2024-04-01 23:02:17 +00:00
commit dd5e502d4b

View File

@ -1034,9 +1034,11 @@ fn new(ui: UniverseIndex, var: BoundVar) -> Self {
} }
} }
/// When type checking, we use the `ParamEnv` to track /// When interacting with the type system we must provide information about the
/// details about the set of where-clauses that are in scope at this /// environment. `ParamEnv` is the type that represents this information. See the
/// particular point. /// [dev guide chapter][param_env_guide] for more information.
///
/// [param_env_guide]: https://rustc-dev-guide.rust-lang.org/param_env/param_env_summary.html
#[derive(Copy, Clone, Hash, PartialEq, Eq)] #[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub struct ParamEnv<'tcx> { pub struct ParamEnv<'tcx> {
/// This packs both caller bounds and the reveal enum into one pointer. /// This packs both caller bounds and the reveal enum into one pointer.
@ -1103,8 +1105,11 @@ fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result
impl<'tcx> ParamEnv<'tcx> { impl<'tcx> ParamEnv<'tcx> {
/// Construct a trait environment suitable for contexts where /// Construct a trait environment suitable for contexts where
/// there are no where-clauses in scope. Hidden types (like `impl /// there are no where-clauses in scope. Hidden types (like `impl
/// Trait`) are left hidden, so this is suitable for ordinary /// Trait`) are left hidden. In majority of cases it is incorrect
/// type-checking. /// to use an empty environment. See the [dev guide section][param_env_guide]
/// for information on what a `ParamEnv` is and how to acquire one.
///
/// [param_env_guide]: https://rustc-dev-guide.rust-lang.org/param_env/param_env_summary.html
#[inline] #[inline]
pub fn empty() -> Self { pub fn empty() -> Self {
Self::new(List::empty(), Reveal::UserFacing) Self::new(List::empty(), Reveal::UserFacing)