@@ -62,6 +62,15 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
6262 rhs. ctxt ( ) != lhs. ctxt ( )
6363}
6464
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+ /// ```
6574pub fn in_constant ( cx : & LateContext < ' _ , ' _ > , id : NodeId ) -> bool {
6675 let parent_id = cx. tcx . hir ( ) . get_parent ( id) ;
6776 match cx. tcx . hir ( ) . body_owner_kind ( parent_id) {
@@ -377,6 +386,9 @@ pub fn contains_name(name: Name, expr: &Expr) -> bool {
377386
378387/// Convert a span to a code snippet if available, otherwise use default.
379388///
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+ ///
380392/// # Example
381393/// ```rust,ignore
382394/// snippet(cx, expr.span, "..")
@@ -430,7 +442,7 @@ pub fn snippet_opt<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Option<String>
430442///
431443/// # Example
432444/// ```rust,ignore
433- /// snippet (cx, expr.span, "..")
445+ /// snippet_block (cx, expr.span, "..")
434446/// ```
435447pub fn snippet_block < ' a , ' b , T : LintContext < ' b > > ( cx : & T , span : Span , default : & ' a str ) -> Cow < ' a , str > {
436448 let snip = snippet ( cx, span, default) ;
@@ -741,6 +753,13 @@ pub fn is_integer_literal(expr: &Expr, value: u128) -> bool {
741753 false
742754}
743755
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.
744763pub fn is_adjusted ( cx : & LateContext < ' _ , ' _ > , e : & Expr ) -> bool {
745764 cx. tables . adjustments ( ) . get ( e. hir_id ) . is_some ( )
746765}
0 commit comments