Expand description
Utils for extracting, inspecting or transforming source code
Re-exportsΒ§
use std::sync::Arc;πuse rustc_ast::LitKind;πuse rustc_ast::StrStyle;πuse rustc_errors::Applicability;πuse rustc_hir::BlockCheckMode;πuse rustc_hir::Expr;πuse rustc_hir::ExprKind;πuse rustc_hir::UnsafeSource;πuse rustc_lexer::FrontmatterAllowed;πuse rustc_lexer::LiteralKind;πuse rustc_lexer::TokenKind;πuse rustc_lexer::tokenize;πuse rustc_lint::EarlyContext;πuse rustc_lint::LateContext;πuse rustc_middle::ty::TyCtxt;πuse rustc_session::Session;πuse rustc_span::source_map::SourceMap;πuse rustc_span::source_map::original_sp;πuse rustc_span::BytePos;πuse rustc_span::DUMMY_SP;πuse rustc_span::DesugaringKind;πuse rustc_span::Pos as _;πuse rustc_span::RelativeBytePos;πuse rustc_span::SourceFile;πuse rustc_span::SourceFileAndLine;πuse rustc_span::Span;πuse rustc_span::SpanData;πuse rustc_span::SyntaxContext;πuse rustc_span::hygiene;πuse std::borrow::Cow;πuse std::fmt;πuse std::ops::Deref;πuse std::ops::Index;πuse std::ops::Range;π
StructsΒ§
- Source
File Range - A range within a specific source file.
- Source
Text - Handle to a range of text in a source file.
TraitsΒ§
- HasSource
Map - Types from which a
SourceMapcan be obtained. - Into
Span - Conversion of a value into a
Span - SpanExt
- Extension methods for span-like types (anything implementing
SpanRange) that need access to the underlying source text via aHasSourceMap. - Span
Range - Conversion of a value into the range portion of a
Span.
FunctionsΒ§
- ends_
with_ πline_ comment_ or_ broken - expand_
past_ previous_ comma - Expand a span to include a preceding comma
- expr_
block - Like
snippet_block, but add braces if the expr is not anExprKind::Blockwith no label. - first_
char_ πin_ first_ line - first_
line_ of_ span - Returns a new Span that extends the original Span to the first non-whitespace char of the first line.
- get_
source_ πrange - indent_
of - Returns the indentation of the line of a span
- is_
present_ in_ source - Checks whether the code snippet referred to by the given [
Span] is present in the source code. - line_
span π - Extends the span to the beginning of the spans line, incl. whitespaces.
- map_
range π - position_
before_ rarrow - Returns the position just before rarrow
- reindent_
multiline - Reindent a multiline string with possibility of ignoring the first line.
- reindent_
multiline_ πinner - snippet
- Converts a span to a code snippet if available, otherwise returns the default.
- snippet_
block - Converts a span (from a block) to a code snippet if available, otherwise use default.
- snippet_
block_ with_ applicability - Same as
snippet_block, but adapts the applicability level by the rules ofsnippet_with_applicability. - snippet_
block_ with_ context - Combination of
snippet_blockandsnippet_with_context. - snippet_
indent - Gets a snippet of the indentation of the line of a span
- snippet_
opt - Converts a span to a code snippet. Returns
Noneif not available. - snippet_
with_ applicability - Same as
snippet, but it adapts the applicability level by following rules: - snippet_
with_ πapplicability_ sm - snippet_
with_ context - Same as
snippet_with_applicability, but first walks the span up to the given context. - snippet_
with_ πcontext_ sm - str_
literal_ to_ char_ literal - Converts
exprto acharliteral if itβs astrliteral containing a single character (or a single byte withascii_only) - trim_
span - Trims the whitespace from the start and the end of the span.
- trim_
start π - walk_
span_ to_ context - Walks the span up to the target context, thereby returning the macro call site if the span is inside a macro expansion, or the original span if it is not.
- with_
leading_ πwhitespace - with_
leading_ πwhitespace_ inner - with_
source_ πtext - with_
source_ πtext_ and_ range