@@ -51,29 +51,7 @@ impl LateLintPass<'_> for MyStructLint {
5151 fn check_expr (& mut self , cx : & LateContext <'_ >, expr : & Expr <'_ >) {
5252 // Get type of `expr`
5353 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+
7755 // Check if the `Ty` of this expression is of character type
7856 if ty . is_char () {
7957 println! (" Our expression is a char!" );
@@ -92,79 +70,18 @@ pub fn is_char(self) -> bool {
9270}
9371```
9472
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- =======
11473Indeed, we just discovered ` Ty ` 's [ ` kind() ` method] [ kind ] , which provides us
115- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
116- =======
117- >>>>>>> 4da6e7e06 (rebase attempt)
11874with [ ` TyKind ` ] [ TyKind ] of a ` Ty ` .
11975
12076## ` TyKind `
12177
12278` TyKind ` defines the kinds of types in Rust's type system.
12379Peeking 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- =======
16280enum of over 25 variants, including items such as ` Bool ` , ` Int ` , ` Ref ` , etc.
16381
16482### ` kind ` Usage
16583
16684The ` TyKind ` of ` Ty ` can be returned by calling [ ` Ty.kind() ` method] [ kind ] .
167- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
16885We often use this method to perform pattern matching in Clippy.
16986
17087For instance, if we want to check for a ` struct ` , we could examine if the
@@ -190,61 +107,8 @@ impl LateLintPass<'_> for MyStructLint {
190107We've been talking about [ ` ty::Ty ` ] [ middle_ty ] this whole time without addressing [ ` hir::Ty ` ] [ hir_ty ] , but the latter
191108is also important to understand.
192109
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- =======
245110` hir::Ty ` would represent * what* the user wrote, while ` ty::Ty ` is how the compiler sees the type and has more
246111information. Example:
247- >>>>>>> a1b75c510 (Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup)
248112
249113``` rust
250114fn foo (x : u32 ) -> u32 { x }
@@ -254,17 +118,10 @@ Here the HIR sees the types without "thinking" about them, it knows that the fun
254118an ` u32 ` . As far as ` hir::Ty ` is concerned those might be different types. But at the ` ty::Ty ` level the compiler
255119understands that they're the same type, in-depth lifetimes, etc...
256120
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- =======
261121To 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
262122outside of bodies the [ ` TypeckResults::node_type() ` ] [ node_type ] method.
263123
264124> ** 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)
268125
269126## Useful Links
270127
@@ -279,27 +136,7 @@ in this chapter:
279136[ Adt ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html#variant.Adt
280137[ AdtDef ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html
281138[ 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- =======
299139[ 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)
303140[ is_char ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.is_char
304141[ is_char_source ] : https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/sty.rs.html#1831-1834
305142[ kind ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind
0 commit comments