@@ -62,6 +62,15 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
62
62
rhs. ctxt ( ) != lhs. ctxt ( )
63
63
}
64
64
65
+ /// Returns `true` if the given `NodeId` is inside a constant context
66
+ ///
67
+ /// # Example
68
+ ///
69
+ /// ```rust,ignore
70
+ /// if in_constant(cx, expr.id) {
71
+ /// // Do something
72
+ /// }
73
+ /// ```
65
74
pub fn in_constant ( cx : & LateContext < ' _ , ' _ > , id : NodeId ) -> bool {
66
75
let parent_id = cx. tcx . hir ( ) . get_parent ( id) ;
67
76
match cx. tcx . hir ( ) . body_owner_kind ( parent_id) {
@@ -377,6 +386,9 @@ pub fn contains_name(name: Name, expr: &Expr) -> bool {
377
386
378
387
/// Convert a span to a code snippet if available, otherwise use default.
379
388
///
389
+ /// This is useful if you want to provide suggestions for your lint or more generally, if you want
390
+ /// to convert a given `Span` to a `str`.
391
+ ///
380
392
/// # Example
381
393
/// ```rust,ignore
382
394
/// snippet(cx, expr.span, "..")
@@ -430,7 +442,7 @@ pub fn snippet_opt<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Option<String>
430
442
///
431
443
/// # Example
432
444
/// ```rust,ignore
433
- /// snippet (cx, expr.span, "..")
445
+ /// snippet_block (cx, expr.span, "..")
434
446
/// ```
435
447
pub fn snippet_block < ' a , ' b , T : LintContext < ' b > > ( cx : & T , span : Span , default : & ' a str ) -> Cow < ' a , str > {
436
448
let snip = snippet ( cx, span, default) ;
@@ -741,6 +753,13 @@ pub fn is_integer_literal(expr: &Expr, value: u128) -> bool {
741
753
false
742
754
}
743
755
756
+ /// Returns `true` if the given `Expr` has been coerced before.
757
+ ///
758
+ /// Examples of coercions can be found in the Nomicon at
759
+ /// <https://doc.rust-lang.org/nomicon/coercions.html>.
760
+ ///
761
+ /// See `rustc::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more
762
+ /// information on adjustments and coercions.
744
763
pub fn is_adjusted ( cx : & LateContext < ' _ , ' _ > , e : & Expr ) -> bool {
745
764
cx. tables . adjustments ( ) . get ( e. hir_id ) . is_some ( )
746
765
}
0 commit comments