mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Merge branch 'master' into sync-from-rust
This commit is contained in:
commit
d39b45a58d
195 changed files with 5778 additions and 2751 deletions
281
crates/ide-db/src/documentation.rs
Normal file
281
crates/ide-db/src/documentation.rs
Normal file
|
@ -0,0 +1,281 @@
|
|||
//! Documentation attribute related utilties.
|
||||
use either::Either;
|
||||
use hir::{
|
||||
db::{DefDatabase, HirDatabase},
|
||||
resolve_doc_path_on, AttrId, AttrSourceMap, AttrsWithOwner, HasAttrs, InFile,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use syntax::{
|
||||
ast::{self, IsString},
|
||||
AstToken,
|
||||
};
|
||||
use text_edit::{TextRange, TextSize};
|
||||
|
||||
/// Holds documentation
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Documentation(String);
|
||||
|
||||
impl Documentation {
|
||||
pub fn new(s: String) -> Self {
|
||||
Documentation(s)
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Documentation> for String {
|
||||
fn from(Documentation(string): Documentation) -> Self {
|
||||
string
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasDocs: HasAttrs {
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation>;
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<hir::Namespace>,
|
||||
) -> Option<hir::DocLinkDef>;
|
||||
}
|
||||
/// A struct to map text ranges from [`Documentation`] back to TextRanges in the syntax tree.
|
||||
#[derive(Debug)]
|
||||
pub struct DocsRangeMap {
|
||||
source_map: AttrSourceMap,
|
||||
// (docstring-line-range, attr_index, attr-string-range)
|
||||
// a mapping from the text range of a line of the [`Documentation`] to the attribute index and
|
||||
// the original (untrimmed) syntax doc line
|
||||
mapping: Vec<(TextRange, AttrId, TextRange)>,
|
||||
}
|
||||
|
||||
impl DocsRangeMap {
|
||||
/// Maps a [`TextRange`] relative to the documentation string back to its AST range
|
||||
pub fn map(&self, range: TextRange) -> Option<InFile<TextRange>> {
|
||||
let found = self.mapping.binary_search_by(|(probe, ..)| probe.ordering(range)).ok()?;
|
||||
let (line_docs_range, idx, original_line_src_range) = self.mapping[found];
|
||||
if !line_docs_range.contains_range(range) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let relative_range = range - line_docs_range.start();
|
||||
|
||||
let InFile { file_id, value: source } = self.source_map.source_of_id(idx);
|
||||
match source {
|
||||
Either::Left(attr) => {
|
||||
let string = get_doc_string_in_attr(attr)?;
|
||||
let text_range = string.open_quote_text_range()?;
|
||||
let range = TextRange::at(
|
||||
text_range.end() + original_line_src_range.start() + relative_range.start(),
|
||||
string.syntax().text_range().len().min(range.len()),
|
||||
);
|
||||
Some(InFile { file_id, value: range })
|
||||
}
|
||||
Either::Right(comment) => {
|
||||
let text_range = comment.syntax().text_range();
|
||||
let range = TextRange::at(
|
||||
text_range.start()
|
||||
+ TextSize::try_from(comment.prefix().len()).ok()?
|
||||
+ original_line_src_range.start()
|
||||
+ relative_range.start(),
|
||||
text_range.len().min(range.len()),
|
||||
);
|
||||
Some(InFile { file_id, value: range })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn docs_with_rangemap(
|
||||
db: &dyn DefDatabase,
|
||||
attrs: &AttrsWithOwner,
|
||||
) -> Option<(Documentation, DocsRangeMap)> {
|
||||
let docs =
|
||||
attrs.by_key("doc").attrs().filter_map(|attr| attr.string_value().map(|s| (s, attr.id)));
|
||||
let indent = doc_indent(attrs);
|
||||
let mut buf = String::new();
|
||||
let mut mapping = Vec::new();
|
||||
for (doc, idx) in docs {
|
||||
if !doc.is_empty() {
|
||||
let mut base_offset = 0;
|
||||
for raw_line in doc.split('\n') {
|
||||
let line = raw_line.trim_end();
|
||||
let line_len = line.len();
|
||||
let (offset, line) = match line.char_indices().nth(indent) {
|
||||
Some((offset, _)) => (offset, &line[offset..]),
|
||||
None => (0, line),
|
||||
};
|
||||
let buf_offset = buf.len();
|
||||
buf.push_str(line);
|
||||
mapping.push((
|
||||
TextRange::new(buf_offset.try_into().ok()?, buf.len().try_into().ok()?),
|
||||
idx,
|
||||
TextRange::at(
|
||||
(base_offset + offset).try_into().ok()?,
|
||||
line_len.try_into().ok()?,
|
||||
),
|
||||
));
|
||||
buf.push('\n');
|
||||
base_offset += raw_line.len() + 1;
|
||||
}
|
||||
} else {
|
||||
buf.push('\n');
|
||||
}
|
||||
}
|
||||
buf.pop();
|
||||
if buf.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((Documentation(buf), DocsRangeMap { mapping, source_map: attrs.source_map(db) }))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn docs_from_attrs(attrs: &hir::Attrs) -> Option<String> {
|
||||
let docs = attrs.by_key("doc").attrs().filter_map(|attr| attr.string_value());
|
||||
let indent = doc_indent(attrs);
|
||||
let mut buf = String::new();
|
||||
for doc in docs {
|
||||
// str::lines doesn't yield anything for the empty string
|
||||
if !doc.is_empty() {
|
||||
buf.extend(Itertools::intersperse(
|
||||
doc.lines().map(|line| {
|
||||
line.char_indices()
|
||||
.nth(indent)
|
||||
.map_or(line, |(offset, _)| &line[offset..])
|
||||
.trim_end()
|
||||
}),
|
||||
"\n",
|
||||
));
|
||||
}
|
||||
buf.push('\n');
|
||||
}
|
||||
buf.pop();
|
||||
if buf.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(buf)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_has_docs {
|
||||
($($def:ident,)*) => {$(
|
||||
impl HasDocs for hir::$def {
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||
docs_from_attrs(&self.attrs(db)).map(Documentation)
|
||||
}
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<hir::Namespace>
|
||||
) -> Option<hir::DocLinkDef> {
|
||||
resolve_doc_path_on(db, self, link, ns)
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
impl_has_docs![
|
||||
Variant, Field, Static, Const, Trait, TraitAlias, TypeAlias, Macro, Function, Adt, Module,
|
||||
Impl,
|
||||
];
|
||||
|
||||
macro_rules! impl_has_docs_enum {
|
||||
($($variant:ident),* for $enum:ident) => {$(
|
||||
impl HasDocs for hir::$variant {
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||
hir::$enum::$variant(self).docs(db)
|
||||
}
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<hir::Namespace>
|
||||
) -> Option<hir::DocLinkDef> {
|
||||
hir::$enum::$variant(self).resolve_doc_path(db, link, ns)
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
impl_has_docs_enum![Struct, Union, Enum for Adt];
|
||||
|
||||
impl HasDocs for hir::AssocItem {
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||
match self {
|
||||
hir::AssocItem::Function(it) => it.docs(db),
|
||||
hir::AssocItem::Const(it) => it.docs(db),
|
||||
hir::AssocItem::TypeAlias(it) => it.docs(db),
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<hir::Namespace>,
|
||||
) -> Option<hir::DocLinkDef> {
|
||||
match self {
|
||||
hir::AssocItem::Function(it) => it.resolve_doc_path(db, link, ns),
|
||||
hir::AssocItem::Const(it) => it.resolve_doc_path(db, link, ns),
|
||||
hir::AssocItem::TypeAlias(it) => it.resolve_doc_path(db, link, ns),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasDocs for hir::ExternCrateDecl {
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||
let crate_docs =
|
||||
docs_from_attrs(&self.resolved_crate(db)?.root_module().attrs(db)).map(String::from);
|
||||
let decl_docs = docs_from_attrs(&self.attrs(db)).map(String::from);
|
||||
match (decl_docs, crate_docs) {
|
||||
(None, None) => None,
|
||||
(Some(decl_docs), None) => Some(decl_docs),
|
||||
(None, Some(crate_docs)) => Some(crate_docs),
|
||||
(Some(mut decl_docs), Some(crate_docs)) => {
|
||||
decl_docs.push('\n');
|
||||
decl_docs.push('\n');
|
||||
decl_docs += &crate_docs;
|
||||
Some(decl_docs)
|
||||
}
|
||||
}
|
||||
.map(Documentation::new)
|
||||
}
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<hir::Namespace>,
|
||||
) -> Option<hir::DocLinkDef> {
|
||||
resolve_doc_path_on(db, self, link, ns)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_doc_string_in_attr(it: &ast::Attr) -> Option<ast::String> {
|
||||
match it.expr() {
|
||||
// #[doc = lit]
|
||||
Some(ast::Expr::Literal(lit)) => match lit.kind() {
|
||||
ast::LiteralKind::String(it) => Some(it),
|
||||
_ => None,
|
||||
},
|
||||
// #[cfg_attr(..., doc = "", ...)]
|
||||
None => {
|
||||
// FIXME: See highlight injection for what to do here
|
||||
None
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn doc_indent(attrs: &hir::Attrs) -> usize {
|
||||
attrs
|
||||
.by_key("doc")
|
||||
.attrs()
|
||||
.filter_map(|attr| attr.string_value())
|
||||
.flat_map(|s| s.lines())
|
||||
.filter(|line| !line.chars().all(|c| c.is_whitespace()))
|
||||
.map(|line| line.chars().take_while(|c| c.is_whitespace()).count())
|
||||
.min()
|
||||
.unwrap_or(0)
|
||||
}
|
|
@ -22,6 +22,7 @@ pub mod symbol_index;
|
|||
pub mod traits;
|
||||
pub mod ty_filter;
|
||||
pub mod use_trivial_constructor;
|
||||
pub mod documentation;
|
||||
|
||||
pub mod imports {
|
||||
pub mod import_assets;
|
||||
|
|
|
@ -71,12 +71,29 @@ impl Definition {
|
|||
sema: &Semantics<'_, RootDatabase>,
|
||||
new_name: &str,
|
||||
) -> Result<SourceChange> {
|
||||
// self.krate() returns None if
|
||||
// self is a built-in attr, built-in type or tool module.
|
||||
// it is not allowed for these defs to be renamed.
|
||||
// cases where self.krate() is None is handled below.
|
||||
if let Some(krate) = self.krate(sema.db) {
|
||||
if !krate.origin(sema.db).is_local() {
|
||||
bail!("Cannot rename a non-local definition.")
|
||||
}
|
||||
}
|
||||
|
||||
match *self {
|
||||
Definition::Module(module) => rename_mod(sema, module, new_name),
|
||||
Definition::ToolModule(_) => {
|
||||
bail!("Cannot rename a tool module")
|
||||
}
|
||||
Definition::BuiltinType(_) => {
|
||||
bail!("Cannot rename builtin type")
|
||||
}
|
||||
Definition::BuiltinAttr(_) => {
|
||||
bail!("Cannot rename a builtin attr.")
|
||||
}
|
||||
Definition::SelfType(_) => bail!("Cannot rename `Self`"),
|
||||
Definition::Macro(mac) => rename_reference(sema, Definition::Macro(mac), new_name),
|
||||
def => rename_reference(sema, def, new_name),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Rustdoc specific doc comment handling
|
||||
|
||||
use crate::documentation::Documentation;
|
||||
|
||||
// stripped down version of https://github.com/rust-lang/rust/blob/392ba2ba1a7d6c542d2459fb8133bebf62a4a423/src/librustdoc/html/markdown.rs#L810-L933
|
||||
pub fn is_rust_fence(s: &str) -> bool {
|
||||
let mut seen_rust_tags = false;
|
||||
|
@ -32,3 +34,170 @@ pub fn is_rust_fence(s: &str) -> bool {
|
|||
|
||||
!seen_other_tags || seen_rust_tags
|
||||
}
|
||||
|
||||
const RUSTDOC_FENCES: [&str; 2] = ["```", "~~~"];
|
||||
|
||||
pub fn format_docs(src: &Documentation) -> String {
|
||||
format_docs_(src.as_str())
|
||||
}
|
||||
|
||||
fn format_docs_(src: &str) -> String {
|
||||
let mut processed_lines = Vec::new();
|
||||
let mut in_code_block = false;
|
||||
let mut is_rust = false;
|
||||
|
||||
for mut line in src.lines() {
|
||||
if in_code_block && is_rust && code_line_ignored_by_rustdoc(line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(header) = RUSTDOC_FENCES.into_iter().find_map(|fence| line.strip_prefix(fence))
|
||||
{
|
||||
in_code_block ^= true;
|
||||
|
||||
if in_code_block {
|
||||
is_rust = is_rust_fence(header);
|
||||
|
||||
if is_rust {
|
||||
line = "```rust";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if in_code_block {
|
||||
let trimmed = line.trim_start();
|
||||
if is_rust && trimmed.starts_with("##") {
|
||||
line = &trimmed[1..];
|
||||
}
|
||||
}
|
||||
|
||||
processed_lines.push(line);
|
||||
}
|
||||
processed_lines.join("\n")
|
||||
}
|
||||
|
||||
fn code_line_ignored_by_rustdoc(line: &str) -> bool {
|
||||
let trimmed = line.trim();
|
||||
trimmed == "#" || trimmed.starts_with("# ") || trimmed.starts_with("#\t")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_adds_rust() {
|
||||
let comment = "```\nfn some_rust() {}\n```";
|
||||
assert_eq!(format_docs_(comment), "```rust\nfn some_rust() {}\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_plain_text() {
|
||||
let comment = "```text\nthis is plain text\n```";
|
||||
assert_eq!(format_docs_(comment), "```text\nthis is plain text\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_non_rust() {
|
||||
let comment = "```sh\nsupposedly shell code\n```";
|
||||
assert_eq!(format_docs_(comment), "```sh\nsupposedly shell code\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_rust_alias() {
|
||||
let comment = "```ignore\nlet z = 55;\n```";
|
||||
assert_eq!(format_docs_(comment), "```rust\nlet z = 55;\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_complex_code_block_attrs() {
|
||||
let comment = "```rust,no_run\nlet z = 55;\n```";
|
||||
assert_eq!(format_docs_(comment), "```rust\nlet z = 55;\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_error_codes() {
|
||||
let comment = "```compile_fail,E0641\nlet b = 0 as *const _;\n```";
|
||||
assert_eq!(format_docs_(comment), "```rust\nlet b = 0 as *const _;\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_skips_comments_in_rust_block() {
|
||||
let comment =
|
||||
"```rust\n # skip1\n# skip2\n#stay1\nstay2\n#\n #\n # \n #\tskip3\n\t#\t\n```";
|
||||
assert_eq!(format_docs_(comment), "```rust\n#stay1\nstay2\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_does_not_skip_lines_if_plain_text() {
|
||||
let comment =
|
||||
"```text\n # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t\n```";
|
||||
assert_eq!(
|
||||
format_docs_(comment),
|
||||
"```text\n # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t\n```",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_keeps_comments_outside_of_rust_block() {
|
||||
let comment = " # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t";
|
||||
assert_eq!(format_docs_(comment), comment);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_preserves_newlines() {
|
||||
let comment = "this\nis\nmultiline";
|
||||
assert_eq!(format_docs_(comment), comment);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_blocks_in_comments_marked_as_rust() {
|
||||
let comment = r#"```rust
|
||||
fn main(){}
|
||||
```
|
||||
Some comment.
|
||||
```
|
||||
let a = 1;
|
||||
```"#;
|
||||
|
||||
assert_eq!(
|
||||
format_docs_(comment),
|
||||
"```rust\nfn main(){}\n```\nSome comment.\n```rust\nlet a = 1;\n```"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_blocks_in_comments_marked_as_text() {
|
||||
let comment = r#"```text
|
||||
filler
|
||||
text
|
||||
```
|
||||
Some comment.
|
||||
```
|
||||
let a = 1;
|
||||
```"#;
|
||||
|
||||
assert_eq!(
|
||||
format_docs_(comment),
|
||||
"```text\nfiller\ntext\n```\nSome comment.\n```rust\nlet a = 1;\n```"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_escape_double_hashes() {
|
||||
let comment = r#"```rust
|
||||
let s = "foo
|
||||
## bar # baz";
|
||||
```"#;
|
||||
|
||||
assert_eq!(format_docs_(comment), "```rust\nlet s = \"foo\n# bar # baz\";\n```");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_docs_handles_double_hashes_non_rust() {
|
||||
let comment = r#"```markdown
|
||||
## A second-level heading
|
||||
```"#;
|
||||
assert_eq!(format_docs_(comment), "```markdown\n## A second-level heading\n```");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use std::mem;
|
||||
|
||||
use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
|
||||
use base_db::{salsa::Database, FileId, FileRange, SourceDatabase, SourceDatabaseExt};
|
||||
use hir::{
|
||||
AsAssocItem, DefWithBody, HasAttrs, HasSource, InFile, ModuleSource, Semantics, Visibility,
|
||||
};
|
||||
|
@ -221,7 +221,6 @@ impl Definition {
|
|||
}
|
||||
|
||||
// def is crate root
|
||||
// FIXME: We don't do searches for crates currently, as a crate does not actually have a single name
|
||||
if let &Definition::Module(module) = self {
|
||||
if module.is_crate_root() {
|
||||
return SearchScope::reverse_dependencies(db, module.krate());
|
||||
|
@ -393,7 +392,10 @@ impl<'a> FindUsages<'a> {
|
|||
let name = match self.def {
|
||||
// special case crate modules as these do not have a proper name
|
||||
Definition::Module(module) if module.is_crate_root() => {
|
||||
// FIXME: This assumes the crate name is always equal to its display name when it really isn't
|
||||
// FIXME: This assumes the crate name is always equal to its display name when it
|
||||
// really isn't
|
||||
// we should instead look at the dependency edge name and recursively search our way
|
||||
// up the ancestors
|
||||
module
|
||||
.krate()
|
||||
.display_name(self.sema.db)
|
||||
|
@ -468,6 +470,7 @@ impl<'a> FindUsages<'a> {
|
|||
};
|
||||
|
||||
for (text, file_id, search_range) in scope_files(sema, &search_scope) {
|
||||
self.sema.db.unwind_if_cancelled();
|
||||
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
|
||||
|
||||
// Search for occurrences of the items name
|
||||
|
@ -504,6 +507,7 @@ impl<'a> FindUsages<'a> {
|
|||
let finder = &Finder::new("super");
|
||||
|
||||
for (text, file_id, search_range) in scope_files(sema, &scope) {
|
||||
self.sema.db.unwind_if_cancelled();
|
||||
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
|
||||
|
||||
for offset in match_indices(&text, finder, search_range) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Tools to work with format string literals for the `format_args!` family of macros.
|
||||
use crate::syntax_helpers::node_ext::macro_call_for_string_token;
|
||||
use syntax::{
|
||||
ast::{self, IsString},
|
||||
TextRange, TextSize,
|
||||
AstNode, AstToken, TextRange, TextSize,
|
||||
};
|
||||
|
||||
// FIXME: This can probably be re-implemented via the HIR?
|
||||
pub fn is_format_string(string: &ast::String) -> bool {
|
||||
// Check if `string` is a format string argument of a macro invocation.
|
||||
// `string` is a string literal, mapped down into the innermost macro expansion.
|
||||
|
@ -15,19 +15,9 @@ pub fn is_format_string(string: &ast::String) -> bool {
|
|||
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
||||
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
||||
(|| {
|
||||
let name = macro_call_for_string_token(string)?.path()?.segment()?.name_ref()?;
|
||||
|
||||
if !matches!(
|
||||
name.text().as_str(),
|
||||
"format_args" | "format_args_nl" | "const_format_args" | "panic_2015" | "panic_2021"
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// NB: we match against `panic_2015`/`panic_2021` here because they have a special-cased arm for
|
||||
// `"{}"`, which otherwise wouldn't get highlighted.
|
||||
|
||||
Some(())
|
||||
let lit = string.syntax().parent().and_then(ast::Literal::cast)?;
|
||||
let fa = lit.syntax().parent().and_then(ast::FormatArgsExpr::cast)?;
|
||||
(fa.template()? == ast::Expr::Literal(lit)).then_some(|| ())
|
||||
})()
|
||||
.is_some()
|
||||
}
|
||||
|
|
|
@ -312,7 +312,6 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
|
|||
ast::Expr::ArrayExpr(_)
|
||||
| ast::Expr::AwaitExpr(_)
|
||||
| ast::Expr::BinExpr(_)
|
||||
| ast::Expr::BoxExpr(_)
|
||||
| ast::Expr::BreakExpr(_)
|
||||
| ast::Expr::CallExpr(_)
|
||||
| ast::Expr::CastExpr(_)
|
||||
|
@ -335,7 +334,10 @@ pub fn for_each_tail_expr(expr: &ast::Expr, cb: &mut dyn FnMut(&ast::Expr)) {
|
|||
| ast::Expr::LetExpr(_)
|
||||
| ast::Expr::UnderscoreExpr(_)
|
||||
| ast::Expr::YieldExpr(_)
|
||||
| ast::Expr::YeetExpr(_) => cb(expr),
|
||||
| ast::Expr::YeetExpr(_)
|
||||
| ast::Expr::OffsetOfExpr(_)
|
||||
| ast::Expr::FormatArgsExpr(_)
|
||||
| ast::Expr::AsmExpr(_) => cb(expr),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue