@@ -51,29 +51,7 @@ impl LateLintPass<'_> for MyStructLint {
51
51
fn check_expr (& mut self , cx : & LateContext <'_ >, expr : & Expr <'_ >) {
52
52
// Get type of `expr`
53
53
let ty = cx . typeck_results (). expr_ty (expr );
54
- <<<<<< < HEAD
55
- <<<<<< < HEAD
56
- <<<<<< < HEAD
57
- <<<<<< < HEAD
58
- <<<<<< < HEAD
59
- ====== =
60
- >>>>>> > 4da6e7e06 (rebase attempt )
61
-
62
- ====== =
63
-
64
- >>>>>> > 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup )
65
- ====== =
66
-
67
- >>>>>> > a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup )
68
- <<<<<< < HEAD
69
- ====== =
70
-
71
- >>>>>> > 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup )
72
- ====== =
73
-
74
- >>>>>> > a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup )
75
- ====== =
76
- >>>>>> > 4da6e7e06 (rebase attempt )
54
+
77
55
// Check if the `Ty` of this expression is of character type
78
56
if ty . is_char () {
79
57
println! (" Our expression is a char!" );
@@ -92,79 +70,18 @@ pub fn is_char(self) -> bool {
92
70
}
93
71
```
94
72
95
- <<<<<<< HEAD
96
- <<<<<<< HEAD
97
- <<<<<<< HEAD
98
- <<<<<<< HEAD
99
- <<<<<<< HEAD
100
- =======
101
- >>>>>>> 4da6e7e06 (rebase attempt)
102
- Indeed, we just discovered ` Ty ` 's [ ` kind() ` method] [ kind ] , which provides us
103
- =======
104
- Indeed, we just discovered ` Ty ` 's [ ` kind ` method] [ kind ] , which provides us
105
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
106
- =======
107
- Indeed, we just discovered ` Ty ` 's [ ` kind() ` method] [ kind ] , which provides us
108
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
109
- <<<<<<< HEAD
110
- =======
111
- Indeed, we just discovered ` Ty ` 's [ ` kind ` method] [ kind ] , which provides us
112
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
113
- =======
114
73
Indeed, we just discovered ` Ty ` 's [ ` kind() ` method] [ kind ] , which provides us
115
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
116
- =======
117
- >>>>>>> 4da6e7e06 (rebase attempt)
118
74
with [ ` TyKind ` ] [ TyKind ] of a ` Ty ` .
119
75
120
76
## ` TyKind `
121
77
122
78
` TyKind ` defines the kinds of types in Rust's type system.
123
79
Peeking into [ ` TyKind ` documentation] [ TyKind ] , we will see that it is an
124
- <<<<<<< HEAD
125
- <<<<<<< HEAD
126
- <<<<<<< HEAD
127
- <<<<<<< HEAD
128
- <<<<<<< HEAD
129
- =======
130
- >>>>>>> 4da6e7e06 (rebase attempt)
131
- enum of over 25 variants, including items such as ` Bool ` , ` Int ` , ` Ref ` , etc.
132
-
133
- ### ` kind ` Usage
134
-
135
- The ` TyKind ` of ` Ty ` can be returned by calling [ ` Ty.kind() ` method] [ kind ] .
136
- =======
137
- <<<<<<< HEAD
138
- =======
139
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
140
- =======
141
- >>>>>>> 4da6e7e06 (rebase attempt)
142
- enum of 27 variants, including items such as ` Bool ` , ` Int ` , ` Ref ` , etc.
143
-
144
- ### ` kind ` Usage
145
-
146
- The ` TyKind ` of ` Ty ` can be returned by calling [ ` Ty.kind ` method] [ kind ] .
147
- <<<<<<< HEAD
148
- <<<<<<< HEAD
149
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
150
- =======
151
- enum of over 25 variants, including items such as ` Bool ` , ` Int ` , ` Ref ` , etc.
152
-
153
- ### ` kind ` Usage
154
-
155
- The ` TyKind ` of ` Ty ` can be returned by calling [ ` Ty.kind() ` method] [ kind ] .
156
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
157
- =======
158
- =======
159
- >>>>>>> 4da6e7e06 (rebase attempt)
160
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
161
- =======
162
80
enum of over 25 variants, including items such as ` Bool ` , ` Int ` , ` Ref ` , etc.
163
81
164
82
### ` kind ` Usage
165
83
166
84
The ` TyKind ` of ` Ty ` can be returned by calling [ ` Ty.kind() ` method] [ kind ] .
167
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
168
85
We often use this method to perform pattern matching in Clippy.
169
86
170
87
For instance, if we want to check for a ` struct ` , we could examine if the
@@ -190,61 +107,8 @@ impl LateLintPass<'_> for MyStructLint {
190
107
We've been talking about [ ` ty::Ty ` ] [ middle_ty ] this whole time without addressing [ ` hir::Ty ` ] [ hir_ty ] , but the latter
191
108
is also important to understand.
192
109
193
- <<<<<<< HEAD
194
- <<<<<<< HEAD
195
- <<<<<<< HEAD
196
- <<<<<<< HEAD
197
- <<<<<<< HEAD
198
- =======
199
- >>>>>>> 4da6e7e06 (rebase attempt)
200
- ` hir::Ty ` would represent * what* the user wrote, while ` ty::Ty ` is how the compiler sees the type and has more
201
- information. Example:
202
-
203
- ``` rust
204
- fn foo (x : u32 ) -> u32 { x }
205
- ```
206
-
207
- Here the HIR sees the types without "thinking" about them, it knows that the function takes an ` u32 ` and returns
208
- an ` u32 ` . As far as ` hir::Ty ` is concerned those might be different types. But at the ` ty::Ty ` level the compiler
209
- understands that they're the same type, in-depth lifetimes, etc...
210
-
211
- To get from a ` hir::Ty ` to a ` ty::Ty ` , you can use the [ ` hir_ty_to_ty ` ] [ hir_ty_to_ty ] function outside of bodies or
212
- outside of bodies the [ ` TypeckResults::node_type() ` ] [ node_type ] method.
213
-
214
- > ** Warning** : Don't use ` hir_ty_to_ty ` inside of bodies, because this can cause ICEs.
215
- =======
216
- ` hir::Ty ` would represent * what* an user wrote, while ` ty::Ty ` would understand the meaning of it (because it has more
217
- information).
218
- =======
219
- ` hir::Ty ` would represent * what* the user wrote, while ` ty::Ty ` is how the compiler sees the type and has more
220
- information. Example:
221
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
222
-
223
- ``` rust
224
- fn foo (x : u32 ) -> u32 { x }
225
- ```
226
-
227
- Here the HIR sees the types without "thinking" about them, it knows that the function takes an ` u32 ` and returns
228
- an ` u32 ` . As far as ` hir::Ty ` is concerned those might be different types. But at the ` ty::Ty ` level the compiler
229
- understands that they're the same type, in-depth lifetimes, etc...
230
-
231
- <<<<<<< HEAD
232
- you can use the [ ` hir_ty_to_ty ` ] [ hir_ty_to_ty ] function to convert from a ` hir::Ty ` to a ` ty::Ty `
233
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
234
- =======
235
- To get from a ` hir::Ty ` to a ` ty::Ty ` , you can use the [ ` hir_ty_to_ty ` ] [ hir_ty_to_ty ] function outside of bodies or
236
- outside of bodies the [ ` TypeckResults::node_type() ` ] [ node_type ] method.
237
-
238
- > ** Warning** : Don't use ` hir_ty_to_ty ` inside of bodies, because this can cause ICEs.
239
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
240
- <<<<<<< HEAD
241
- =======
242
- ` hir::Ty ` would represent * what* an user wrote, while ` ty::Ty ` would understand the meaning of it (because it has more
243
- information).
244
- =======
245
110
` hir::Ty ` would represent * what* the user wrote, while ` ty::Ty ` is how the compiler sees the type and has more
246
111
information. Example:
247
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
248
112
249
113
``` rust
250
114
fn foo (x : u32 ) -> u32 { x }
@@ -254,17 +118,10 @@ Here the HIR sees the types without "thinking" about them, it knows that the fun
254
118
an ` u32 ` . As far as ` hir::Ty ` is concerned those might be different types. But at the ` ty::Ty ` level the compiler
255
119
understands that they're the same type, in-depth lifetimes, etc...
256
120
257
- <<<<<<< HEAD
258
- you can use the [ ` hir_ty_to_ty ` ] [ hir_ty_to_ty ] function to convert from a ` hir::Ty ` to a ` ty::Ty `
259
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
260
- =======
261
121
To get from a ` hir::Ty ` to a ` ty::Ty ` , you can use the [ ` hir_ty_to_ty ` ] [ hir_ty_to_ty ] function outside of bodies or
262
122
outside of bodies the [ ` TypeckResults::node_type() ` ] [ node_type ] method.
263
123
264
124
> ** Warning** : Don't use ` hir_ty_to_ty ` inside of bodies, because this can cause ICEs.
265
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
266
- =======
267
- >>>>>>> 4da6e7e06 (rebase attempt)
268
125
269
126
## Useful Links
270
127
@@ -279,27 +136,7 @@ in this chapter:
279
136
[ Adt ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html#variant.Adt
280
137
[ AdtDef ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html
281
138
[ expr_ty ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty
282
- <<<<<<< HEAD
283
- <<<<<<< HEAD
284
- <<<<<<< HEAD
285
- <<<<<<< HEAD
286
- <<<<<<< HEAD
287
- =======
288
- >>>>>>> 4da6e7e06 (rebase attempt)
289
- [ node_type ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
290
- =======
291
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
292
- =======
293
- [ node_type ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
294
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
295
- <<<<<<< HEAD
296
- =======
297
- >>>>>>> 6b95029f1 (Merge commit '83e42a2337dadac915c956d125f1d69132f36425' into clippyup)
298
- =======
299
139
[ node_type ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
300
- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
301
- =======
302
- >>>>>>> 4da6e7e06 (rebase attempt)
303
140
[ is_char ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.is_char
304
141
[ is_char_source ] : https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/sty.rs.html#1831-1834
305
142
[ kind ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind
0 commit comments