You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/param_env.md
+5-4
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
The type system relies on information in the environment in order for it to function correctly. This information is stored in the [`ParamEnv`][pe] type and it is important to use the correct `ParamEnv` when interacting with the type system.
6
6
7
-
The information represented by `ParamEnv` is a list of inscope whereclauses, and a [`Reveal`][reveal]. A `ParamEnv` typically corresponds to a specific item's environment however it can also be created with arbitrary data that is not derived from a specific item. In most cases `ParamEnv`s are initially created via the [`param_env` query][query] which returns a `ParamEnv` derived from the provided item's where clauses.
7
+
The information represented by `ParamEnv` is a list of in-scope where-clauses, and a [`Reveal`][reveal]. A `ParamEnv` typically corresponds to a specific item's environment however it can also be created with arbitrary data that is not derived from a specific item. In most cases `ParamEnv`s are initially created via the [`param_env` query][query] which returns a `ParamEnv` derived from the provided item's where clauses.
8
8
9
9
If we have a function such as:
10
10
```rust
@@ -21,7 +21,7 @@ A more concrete example:
21
21
```rust
22
22
// `foo` would have a `ParamEnv` of:
23
23
// `[T: Sized, T: Clone]`
24
-
fnfoo<T:Clone>(a:T) -> (T, T) {
24
+
fnfoo<T:Clone>(a:T) {
25
25
// when typechecking `foo` we require all the where clauses on `bar`
26
26
// to hold in order for it to be legal to call. This means we have to
27
27
// prove `T: Clone`. As we are type checking `foo` we use `foo`'s
@@ -37,14 +37,15 @@ Or alternatively an example that would not compile:
37
37
```rust
38
38
// `foo2` would have a `ParamEnv` of:
39
39
// `[T: Sized]`
40
-
fnfoo2<T>(a:T) -> (T, T) {
40
+
fnfoo2<T>(a:T) {
41
41
// When typechecking `foo2` we attempt to prove `T: Clone`.
42
42
// As we are type checking `foo2` we use `foo2`'s environment
43
43
// when trying to prove `T: Clone`.
44
44
//
45
45
// Trying to prove `T: Clone` with a `ParamEnv` of `[T: Sized]` will
46
46
// fail as there is nothing in the environment telling the trait solver
47
-
// that `T` implements `Clone`.
47
+
// that `T` implements `Clone` and there exists no user written impl
0 commit comments