mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
3a57388d13
commit
4f55ebbd4f
122 changed files with 2885 additions and 1093 deletions
|
@ -8,13 +8,15 @@ use ide_db::{
|
|||
use syntax::{ast::HasName, AstNode, TextRange};
|
||||
|
||||
use crate::{
|
||||
fn_references::find_all_methods,
|
||||
annotations::fn_references::find_all_methods,
|
||||
goto_implementation::goto_implementation,
|
||||
references::find_all_refs,
|
||||
runnables::{runnables, Runnable},
|
||||
NavigationTarget, RunnableKind,
|
||||
};
|
||||
|
||||
mod fn_references;
|
||||
|
||||
// Feature: Annotations
|
||||
//
|
||||
// Provides user with annotations above items for looking up references or impl blocks
|
||||
|
@ -30,8 +32,8 @@ pub struct Annotation {
|
|||
#[derive(Debug)]
|
||||
pub enum AnnotationKind {
|
||||
Runnable(Runnable),
|
||||
HasImpls { file_id: FileId, data: Option<Vec<NavigationTarget>> },
|
||||
HasReferences { file_id: FileId, data: Option<Vec<FileRange>> },
|
||||
HasImpls { pos: FilePosition, data: Option<Vec<NavigationTarget>> },
|
||||
HasReferences { pos: FilePosition, data: Option<Vec<FileRange>> },
|
||||
}
|
||||
|
||||
pub struct AnnotationConfig {
|
||||
|
@ -68,13 +70,23 @@ pub(crate) fn annotations(
|
|||
}
|
||||
}
|
||||
|
||||
let mk_ranges = |(range, focus): (_, Option<_>)| {
|
||||
let cmd_target: TextRange = focus.unwrap_or(range);
|
||||
let annotation_range = match config.location {
|
||||
AnnotationLocation::AboveName => cmd_target,
|
||||
AnnotationLocation::AboveWholeItem => range,
|
||||
};
|
||||
let target_pos = FilePosition { file_id, offset: cmd_target.start() };
|
||||
(annotation_range, target_pos)
|
||||
};
|
||||
|
||||
visit_file_defs(&Semantics::new(db), file_id, &mut |def| {
|
||||
let range = match def {
|
||||
Definition::Const(konst) if config.annotate_references => {
|
||||
konst.source(db).and_then(|node| name_range(db, config, node, file_id))
|
||||
konst.source(db).and_then(|node| name_range(db, node, file_id))
|
||||
}
|
||||
Definition::Trait(trait_) if config.annotate_references || config.annotate_impls => {
|
||||
trait_.source(db).and_then(|node| name_range(db, config, node, file_id))
|
||||
trait_.source(db).and_then(|node| name_range(db, node, file_id))
|
||||
}
|
||||
Definition::Adt(adt) => match adt {
|
||||
hir::Adt::Enum(enum_) => {
|
||||
|
@ -83,27 +95,29 @@ pub(crate) fn annotations(
|
|||
.variants(db)
|
||||
.into_iter()
|
||||
.map(|variant| {
|
||||
variant
|
||||
.source(db)
|
||||
.and_then(|node| name_range(db, config, node, file_id))
|
||||
variant.source(db).and_then(|node| name_range(db, node, file_id))
|
||||
})
|
||||
.flatten()
|
||||
.for_each(|range| {
|
||||
let (annotation_range, target_position) = mk_ranges(range);
|
||||
annotations.push(Annotation {
|
||||
range,
|
||||
kind: AnnotationKind::HasReferences { file_id, data: None },
|
||||
range: annotation_range,
|
||||
kind: AnnotationKind::HasReferences {
|
||||
pos: target_position,
|
||||
data: None,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
if config.annotate_references || config.annotate_impls {
|
||||
enum_.source(db).and_then(|node| name_range(db, config, node, file_id))
|
||||
enum_.source(db).and_then(|node| name_range(db, node, file_id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if config.annotate_references || config.annotate_impls {
|
||||
adt.source(db).and_then(|node| name_range(db, config, node, file_id))
|
||||
adt.source(db).and_then(|node| name_range(db, node, file_id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -116,33 +130,32 @@ pub(crate) fn annotations(
|
|||
Some(range) => range,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let (annotation_range, target_pos) = mk_ranges(range);
|
||||
if config.annotate_impls && !matches!(def, Definition::Const(_)) {
|
||||
annotations
|
||||
.push(Annotation { range, kind: AnnotationKind::HasImpls { file_id, data: None } });
|
||||
annotations.push(Annotation {
|
||||
range: annotation_range,
|
||||
kind: AnnotationKind::HasImpls { pos: target_pos, data: None },
|
||||
});
|
||||
}
|
||||
|
||||
if config.annotate_references {
|
||||
annotations.push(Annotation {
|
||||
range,
|
||||
kind: AnnotationKind::HasReferences { file_id, data: None },
|
||||
range: annotation_range,
|
||||
kind: AnnotationKind::HasReferences { pos: target_pos, data: None },
|
||||
});
|
||||
}
|
||||
|
||||
fn name_range<T: HasName>(
|
||||
db: &RootDatabase,
|
||||
config: &AnnotationConfig,
|
||||
node: InFile<T>,
|
||||
source_file_id: FileId,
|
||||
) -> Option<TextRange> {
|
||||
) -> Option<(TextRange, Option<TextRange>)> {
|
||||
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
|
||||
if file_id == source_file_id.into() {
|
||||
return match config.location {
|
||||
AnnotationLocation::AboveName => {
|
||||
value.name().map(|name| name.syntax().text_range())
|
||||
}
|
||||
AnnotationLocation::AboveWholeItem => Some(value.syntax().text_range()),
|
||||
};
|
||||
return Some((
|
||||
value.syntax().text_range(),
|
||||
value.name().map(|name| name.syntax().text_range()),
|
||||
));
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -150,12 +163,13 @@ pub(crate) fn annotations(
|
|||
});
|
||||
|
||||
if config.annotate_method_references {
|
||||
annotations.extend(find_all_methods(db, file_id).into_iter().map(
|
||||
|FileRange { file_id, range }| Annotation {
|
||||
range,
|
||||
kind: AnnotationKind::HasReferences { file_id, data: None },
|
||||
},
|
||||
));
|
||||
annotations.extend(find_all_methods(db, file_id).into_iter().map(|range| {
|
||||
let (annotation_range, target_range) = mk_ranges(range);
|
||||
Annotation {
|
||||
range: annotation_range,
|
||||
kind: AnnotationKind::HasReferences { pos: target_range, data: None },
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
annotations
|
||||
|
@ -163,18 +177,11 @@ pub(crate) fn annotations(
|
|||
|
||||
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
|
||||
match annotation.kind {
|
||||
AnnotationKind::HasImpls { file_id, ref mut data } => {
|
||||
*data =
|
||||
goto_implementation(db, FilePosition { file_id, offset: annotation.range.start() })
|
||||
.map(|range| range.info);
|
||||
AnnotationKind::HasImpls { pos, ref mut data } => {
|
||||
*data = goto_implementation(db, pos).map(|range| range.info);
|
||||
}
|
||||
AnnotationKind::HasReferences { file_id, ref mut data } => {
|
||||
*data = find_all_refs(
|
||||
&Semantics::new(db),
|
||||
FilePosition { file_id, offset: annotation.range.start() },
|
||||
None,
|
||||
)
|
||||
.map(|result| {
|
||||
AnnotationKind::HasReferences { pos, ref mut data } => {
|
||||
*data = find_all_refs(&Semantics::new(db), pos, None).map(|result| {
|
||||
result
|
||||
.into_iter()
|
||||
.flat_map(|res| res.references)
|
||||
|
@ -268,9 +275,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 6..10,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 6,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -286,9 +296,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 30..36,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 30,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -297,9 +310,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 53..57,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 53,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -344,9 +360,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasImpls {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -355,9 +374,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -373,9 +395,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 17..21,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 17,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -424,9 +449,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasImpls {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
NavigationTarget {
|
||||
|
@ -445,9 +473,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -469,9 +500,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 20..31,
|
||||
kind: HasImpls {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 20,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
NavigationTarget {
|
||||
|
@ -490,9 +524,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 20..31,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 20,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -508,9 +545,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 69..73,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 69,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -551,9 +591,12 @@ fn main() {}
|
|||
Annotation {
|
||||
range: 3..7,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 3,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -602,9 +645,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasImpls {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
NavigationTarget {
|
||||
|
@ -623,9 +669,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 7..11,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 7,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -647,9 +696,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 33..44,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 33,
|
||||
},
|
||||
data: Some(
|
||||
[
|
||||
FileRange {
|
||||
|
@ -665,9 +717,12 @@ fn main() {
|
|||
Annotation {
|
||||
range: 61..65,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 61,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -761,9 +816,12 @@ mod tests {
|
|||
Annotation {
|
||||
range: 3..7,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 3,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -821,9 +879,12 @@ struct Foo;
|
|||
Annotation {
|
||||
range: 0..71,
|
||||
kind: HasImpls {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 67,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
|
@ -832,10 +893,15 @@ struct Foo;
|
|||
Annotation {
|
||||
range: 0..71,
|
||||
kind: HasReferences {
|
||||
file_id: FileId(
|
||||
0,
|
||||
pos: FilePosition {
|
||||
file_id: FileId(
|
||||
0,
|
||||
),
|
||||
offset: 67,
|
||||
},
|
||||
data: Some(
|
||||
[],
|
||||
),
|
||||
data: None,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
|
|
@ -4,30 +4,38 @@
|
|||
use hir::Semantics;
|
||||
use ide_assists::utils::test_related_attribute;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{ast, ast::HasName, AstNode, SyntaxNode};
|
||||
use syntax::{ast, ast::HasName, AstNode, SyntaxNode, TextRange};
|
||||
|
||||
use crate::{FileId, FileRange};
|
||||
use crate::FileId;
|
||||
|
||||
pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec<FileRange> {
|
||||
pub(super) fn find_all_methods(
|
||||
db: &RootDatabase,
|
||||
file_id: FileId,
|
||||
) -> Vec<(TextRange, Option<TextRange>)> {
|
||||
let sema = Semantics::new(db);
|
||||
let source_file = sema.parse(file_id);
|
||||
source_file.syntax().descendants().filter_map(|it| method_range(it, file_id)).collect()
|
||||
source_file.syntax().descendants().filter_map(|it| method_range(it)).collect()
|
||||
}
|
||||
|
||||
fn method_range(item: SyntaxNode, file_id: FileId) -> Option<FileRange> {
|
||||
fn method_range(item: SyntaxNode) -> Option<(TextRange, Option<TextRange>)> {
|
||||
ast::Fn::cast(item).and_then(|fn_def| {
|
||||
if test_related_attribute(&fn_def).is_some() {
|
||||
None
|
||||
} else {
|
||||
fn_def.name().map(|name| FileRange { file_id, range: name.syntax().text_range() })
|
||||
Some((
|
||||
fn_def.syntax().text_range(),
|
||||
fn_def.name().map(|name| name.syntax().text_range()),
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use syntax::TextRange;
|
||||
|
||||
use crate::fixture;
|
||||
use crate::{FileRange, TextSize};
|
||||
use crate::TextSize;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
#[test]
|
||||
|
@ -42,7 +50,7 @@ mod tests {
|
|||
"#,
|
||||
);
|
||||
|
||||
let refs = analysis.find_all_methods(pos.file_id).unwrap();
|
||||
let refs = super::find_all_methods(&analysis.db, pos.file_id);
|
||||
check_result(&refs, &[3..=13, 27..=33, 47..=57]);
|
||||
}
|
||||
|
||||
|
@ -57,7 +65,7 @@ mod tests {
|
|||
"#,
|
||||
);
|
||||
|
||||
let refs = analysis.find_all_methods(pos.file_id).unwrap();
|
||||
let refs = super::find_all_methods(&analysis.db, pos.file_id);
|
||||
check_result(&refs, &[19..=22, 35..=38]);
|
||||
}
|
||||
|
||||
|
@ -78,17 +86,18 @@ mod tests {
|
|||
"#,
|
||||
);
|
||||
|
||||
let refs = analysis.find_all_methods(pos.file_id).unwrap();
|
||||
let refs = super::find_all_methods(&analysis.db, pos.file_id);
|
||||
check_result(&refs, &[28..=34]);
|
||||
}
|
||||
|
||||
fn check_result(refs: &[FileRange], expected: &[RangeInclusive<u32>]) {
|
||||
fn check_result(refs: &[(TextRange, Option<TextRange>)], expected: &[RangeInclusive<u32>]) {
|
||||
assert_eq!(refs.len(), expected.len());
|
||||
|
||||
for (i, item) in refs.iter().enumerate() {
|
||||
for (i, &(full, focus)) in refs.iter().enumerate() {
|
||||
let range = &expected[i];
|
||||
assert_eq!(TextSize::from(*range.start()), item.range.start());
|
||||
assert_eq!(TextSize::from(*range.end()), item.range.end());
|
||||
let item = focus.unwrap_or(full);
|
||||
assert_eq!(TextSize::from(*range.start()), item.start());
|
||||
assert_eq!(TextSize::from(*range.end()), item.end());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -232,8 +232,13 @@ pub(crate) fn token_as_doc_comment(doc_token: &SyntaxToken) -> Option<DocComment
|
|||
(match_ast! {
|
||||
match doc_token {
|
||||
ast::Comment(comment) => TextSize::try_from(comment.prefix().len()).ok(),
|
||||
ast::String(string) => doc_token.parent_ancestors().find_map(ast::Attr::cast)
|
||||
.filter(|attr| attr.simple_name().as_deref() == Some("doc")).and_then(|_| string.open_quote_text_range().map(|it| it.len())),
|
||||
ast::String(string) => {
|
||||
doc_token.parent_ancestors().find_map(ast::Attr::cast).filter(|attr| attr.simple_name().as_deref() == Some("doc"))?;
|
||||
if doc_token.parent_ancestors().find_map(ast::MacroCall::cast).filter(|mac| mac.path().and_then(|p| p.segment()?.name_ref()).as_ref().map(|n| n.text()).as_deref() == Some("include_str")).is_some() {
|
||||
return None;
|
||||
}
|
||||
string.open_quote_text_range().map(|it| it.len())
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}).map(|prefix_len| DocCommentToken { prefix_len, doc_token: doc_token.clone() })
|
||||
|
|
|
@ -95,6 +95,14 @@ fn try_lookup_include_path(
|
|||
if !matches!(&*name.text(), "include" | "include_str" | "include_bytes") {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Ignore non-built-in macros to account for shadowing
|
||||
if let Some(it) = sema.resolve_macro_call(¯o_call) {
|
||||
if !matches!(it.kind(sema.db), hir::MacroKind::BuiltIn) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
|
||||
let size = sema.db.file_text(file_id).len().try_into().ok()?;
|
||||
Some(NavigationTarget {
|
||||
|
@ -156,9 +164,6 @@ mod tests {
|
|||
fn check(ra_fixture: &str) {
|
||||
let (analysis, position, expected) = fixture::annotations(ra_fixture);
|
||||
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
|
||||
if navs.is_empty() {
|
||||
panic!("unresolved reference")
|
||||
}
|
||||
|
||||
let cmp = |&FileRange { file_id, range }: &_| (file_id, range.start());
|
||||
let navs = navs
|
||||
|
@ -1348,6 +1353,10 @@ fn f(e: Enum) {
|
|||
check(
|
||||
r#"
|
||||
//- /main.rs
|
||||
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! include_str {}
|
||||
|
||||
fn main() {
|
||||
let str = include_str!("foo.txt$0");
|
||||
}
|
||||
|
@ -1357,6 +1366,42 @@ fn main() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_doc_include_str() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! include_str {}
|
||||
|
||||
#[doc = include_str!("docs.md$0")]
|
||||
struct Item;
|
||||
|
||||
//- /docs.md
|
||||
// docs
|
||||
//^file
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_shadow_include() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs
|
||||
macro_rules! include {
|
||||
("included.rs") => {}
|
||||
}
|
||||
|
||||
include!("included.rs$0");
|
||||
|
||||
//- /included.rs
|
||||
// empty
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod goto_impl_of_trait_fn {
|
||||
use super::check;
|
||||
|
|
|
@ -1373,6 +1373,22 @@ fn main() {
|
|||
().func$0();
|
||||
//^^^^
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_assoc_type_highlighting() {
|
||||
check(
|
||||
r#"
|
||||
trait Trait {
|
||||
type Output;
|
||||
// ^^^^^^
|
||||
}
|
||||
impl Trait for () {
|
||||
type Output$0 = ();
|
||||
// ^^^^^^
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -346,7 +346,16 @@ pub(super) fn definition(
|
|||
Definition::Module(it) => label_and_docs(db, it),
|
||||
Definition::Function(it) => label_and_docs(db, it),
|
||||
Definition::Adt(it) => label_and_docs(db, it),
|
||||
Definition::Variant(it) => label_and_docs(db, it),
|
||||
Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
|
||||
if !it.parent_enum(db).is_data_carrying(db) {
|
||||
match it.eval(db) {
|
||||
Ok(x) => Some(format!("{}", x)),
|
||||
Err(_) => it.value(db).map(|x| format!("{:?}", x)),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}),
|
||||
Definition::Const(it) => label_value_and_docs(db, it, |it| {
|
||||
let body = it.eval(db);
|
||||
match body {
|
||||
|
|
|
@ -698,6 +698,7 @@ fn hover_enum_variant() {
|
|||
check(
|
||||
r#"
|
||||
enum Option<T> {
|
||||
Some(T)
|
||||
/// The None variant
|
||||
Non$0e
|
||||
}
|
||||
|
@ -3527,6 +3528,112 @@ impl<const LEN: usize> Foo<LEN$0> {}
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_const_eval_variant() {
|
||||
// show hex for <10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A$0 = 1 << 3,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 8
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// show hex for >10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A$0 = (1 << 3) + (1 << 2),
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 12 (0xC)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// enums in const eval
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
A = 1,
|
||||
/// This is a doc
|
||||
B$0 = E::A as u8 + 1,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*B*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
B = 2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// unspecified variant should increment by one
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
A = 4,
|
||||
/// This is a doc
|
||||
B$0,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*B*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
B = 5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_const_eval() {
|
||||
// show hex for <10
|
||||
|
@ -3820,6 +3927,35 @@ fn foo() {
|
|||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A = 3,
|
||||
}
|
||||
fn foo(e: E) {
|
||||
match e {
|
||||
E::A$0 => (),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
|
|
|
@ -176,12 +176,6 @@ impl fmt::Debug for InlayHintLabelPart {
|
|||
// * elided lifetimes
|
||||
// * compiler inserted reborrows
|
||||
//
|
||||
// |===
|
||||
// | Editor | Action Name
|
||||
//
|
||||
// | VS Code | **rust-analyzer: Toggle inlay hints*
|
||||
// |===
|
||||
//
|
||||
// image::https://user-images.githubusercontent.com/48062697/113020660-b5f98b80-917a-11eb-8d70-3be3fd558cdd.png[]
|
||||
pub(crate) fn inlay_hints(
|
||||
db: &RootDatabase,
|
||||
|
@ -2030,7 +2024,14 @@ impl<T> Vec<T> {
|
|||
}
|
||||
|
||||
impl<T> IntoIterator for Vec<T> {
|
||||
type Item=T;
|
||||
type Item = T;
|
||||
type IntoIter = IntoIter<T>;
|
||||
}
|
||||
|
||||
struct IntoIter<T> {}
|
||||
|
||||
impl<T> Iterator for IntoIter<T> {
|
||||
type Item = T;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -31,7 +31,6 @@ mod highlight_related;
|
|||
mod expand_macro;
|
||||
mod extend_selection;
|
||||
mod file_structure;
|
||||
mod fn_references;
|
||||
mod folding_ranges;
|
||||
mod goto_declaration;
|
||||
mod goto_definition;
|
||||
|
@ -236,7 +235,7 @@ impl Analysis {
|
|||
Env::default(),
|
||||
Ok(Vec::new()),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None },
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
);
|
||||
change.change_file(file_id, Some(Arc::new(text)));
|
||||
change.set_crate_graph(crate_graph);
|
||||
|
@ -429,11 +428,6 @@ impl Analysis {
|
|||
self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope))
|
||||
}
|
||||
|
||||
/// Finds all methods and free functions for the file. Does not return tests!
|
||||
pub fn find_all_methods(&self, file_id: FileId) -> Cancellable<Vec<FileRange>> {
|
||||
self.with_db(|db| fn_references::find_all_methods(db, file_id))
|
||||
}
|
||||
|
||||
/// Returns a short text describing element at position.
|
||||
pub fn hover(
|
||||
&self,
|
||||
|
|
|
@ -253,10 +253,14 @@ pub(crate) fn def_to_moniker(
|
|||
},
|
||||
kind: if krate == from_crate { MonikerKind::Export } else { MonikerKind::Import },
|
||||
package_information: {
|
||||
let name = krate.display_name(db)?.to_string();
|
||||
let (repo, version) = match krate.origin(db) {
|
||||
CrateOrigin::CratesIo { repo } => (repo?, krate.version(db)?),
|
||||
let (name, repo, version) = match krate.origin(db) {
|
||||
CrateOrigin::CratesIo { repo, name } => (
|
||||
name.unwrap_or(krate.display_name(db)?.canonical_name().to_string()),
|
||||
repo?,
|
||||
krate.version(db)?,
|
||||
),
|
||||
CrateOrigin::Lang(lang) => (
|
||||
krate.display_name(db)?.canonical_name().to_string(),
|
||||
"https://github.com/rust-lang/rust/".to_string(),
|
||||
match lang {
|
||||
LangCrateOrigin::Other => {
|
||||
|
|
|
@ -87,9 +87,9 @@ fn punctuation(
|
|||
let parent = token.parent();
|
||||
let parent_kind = parent.as_ref().map_or(EOF, SyntaxNode::kind);
|
||||
match (kind, parent_kind) {
|
||||
(T![?], _) => HlTag::Operator(HlOperator::Other) | HlMod::ControlFlow,
|
||||
(T![?], TRY_EXPR) => HlTag::Operator(HlOperator::Other) | HlMod::ControlFlow,
|
||||
(T![&], BIN_EXPR) => HlOperator::Bitwise.into(),
|
||||
(T![&], _) => {
|
||||
(T![&], REF_EXPR) => {
|
||||
let h = HlTag::Operator(HlOperator::Other).into();
|
||||
let is_unsafe = parent
|
||||
.and_then(ast::RefExpr::cast)
|
||||
|
@ -100,7 +100,9 @@ fn punctuation(
|
|||
h
|
||||
}
|
||||
}
|
||||
(T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.], _) => HlOperator::Other.into(),
|
||||
(T![::] | T![->] | T![=>] | T![..] | T![..=] | T![=] | T![@] | T![.], _) => {
|
||||
HlOperator::Other.into()
|
||||
}
|
||||
(T![!], MACRO_CALL | MACRO_RULES) => HlPunct::MacroBang.into(),
|
||||
(T![!], NEVER_TYPE) => HlTag::BuiltinType.into(),
|
||||
(T![!], PREFIX_EXPR) => HlOperator::Logical.into(),
|
||||
|
@ -129,7 +131,7 @@ fn punctuation(
|
|||
(T![+=] | T![-=] | T![*=] | T![/=] | T![%=], BIN_EXPR) => {
|
||||
Highlight::from(HlOperator::Arithmetic) | HlMod::Mutable
|
||||
}
|
||||
(T![|] | T![&] | T![!] | T![^] | T![>>] | T![<<], BIN_EXPR) => HlOperator::Bitwise.into(),
|
||||
(T![|] | T![&] | T![^] | T![>>] | T![<<], BIN_EXPR) => HlOperator::Bitwise.into(),
|
||||
(T![|=] | T![&=] | T![^=] | T![>>=] | T![<<=], BIN_EXPR) => {
|
||||
Highlight::from(HlOperator::Bitwise) | HlMod::Mutable
|
||||
}
|
||||
|
@ -137,7 +139,6 @@ fn punctuation(
|
|||
(T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=], BIN_EXPR) => {
|
||||
HlOperator::Comparison.into()
|
||||
}
|
||||
(_, PREFIX_EXPR | BIN_EXPR | RANGE_EXPR | RANGE_PAT | REST_PAT) => HlOperator::Other.into(),
|
||||
(_, ATTR) => HlTag::AttributeBracket.into(),
|
||||
(kind, _) => match kind {
|
||||
T!['['] | T![']'] => HlPunct::Bracket,
|
||||
|
|
|
@ -48,15 +48,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
|
||||
<span class="keyword">impl</span> <span class="struct">foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public static">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration static trait">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">t_is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public static trait">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference trait">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference trait">is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span></code></pre>
|
|
@ -125,7 +125,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="comment documentation">/// ```sh</span>
|
||||
<span class="comment documentation">/// echo 1</span>
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">foo</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">bool</span> <span class="brace">{</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">foo</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">bool</span> <span class="brace">{</span>
|
||||
<span class="bool_literal">true</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
|
|
@ -61,11 +61,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
@ -75,11 +75,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="value_param">f</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="self_keyword consuming mutable">self</span><span class="parenthesis">)</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="self_keyword mutable reference">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
@ -96,11 +96,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="self_keyword mutable reference">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span>
|
||||
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
|
|
@ -42,7 +42,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
|
||||
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
|
||||
</style>
|
||||
<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span><span class="parenthesis">(</span><span class="value_param declaration reference">ra_fixture</span><span class="colon">:</span> <span class="operator">&</span><span class="builtin_type">str</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span><span class="parenthesis">(</span><span class="value_param declaration reference">ra_fixture</span><span class="colon">:</span> <span class="punctuation">&</span><span class="builtin_type">str</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="function">fixture</span><span class="parenthesis">(</span><span class="string_literal">r#"</span>
|
||||
|
|
|
@ -45,8 +45,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<pre><code>
|
||||
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
|
||||
<span class="keyword">struct</span> <span class="struct declaration">Foo</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="lifetime declaration">'b</span><span class="comma">,</span> <span class="lifetime declaration">'c</span><span class="angle">></span> <span class="keyword">where</span> <span class="lifetime">'a</span><span class="colon">:</span> <span class="lifetime">'a</span><span class="comma">,</span> <span class="lifetime">'static</span><span class="colon">:</span> <span class="lifetime">'static</span> <span class="brace">{</span>
|
||||
<span class="field declaration">field</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'a</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="field declaration">field2</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'static</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="field declaration">field</span><span class="colon">:</span> <span class="punctuation">&</span><span class="lifetime">'a</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="field declaration">field2</span><span class="colon">:</span> <span class="punctuation">&</span><span class="lifetime">'static</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="keyword">impl</span><span class="angle"><</span><span class="lifetime declaration">'a</span><span class="angle">></span> <span class="struct">Foo</span><span class="angle"><</span><span class="lifetime">'_</span><span class="comma">,</span> <span class="lifetime">'a</span><span class="comma">,</span> <span class="lifetime">'static</span><span class="angle">></span>
|
||||
<span class="keyword">where</span>
|
||||
|
|
|
@ -62,16 +62,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic<span class="parenthesis">(</span><span class="string_literal">"explicit panic"</span><span class="parenthesis">)</span>
|
||||
<span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>literal <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>literal <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="parenthesis">)</span>
|
||||
<span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="comment">// Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_str<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="parenthesis">)</span>
|
||||
<span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="comment">// Special-case the single-argument case for const_panic.</span>
|
||||
<span class="parenthesis">(</span><span class="string_literal">"{}"</span><span class="comma">,</span> <span class="punctuation">$</span>arg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_display<span class="parenthesis">(</span><span class="operator">&</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span>
|
||||
<span class="parenthesis">(</span><span class="string_literal">"{}"</span><span class="comma">,</span> <span class="punctuation">$</span>arg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_display<span class="parenthesis">(</span><span class="punctuation">&</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span>
|
||||
<span class="parenthesis">)</span><span class="comma">,</span>
|
||||
<span class="parenthesis">(</span><span class="punctuation">$</span>fmt<span class="colon">:</span>expr<span class="comma">,</span> <span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>arg<span class="colon">:</span>tt<span class="parenthesis">)</span><span class="punctuation">+</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="parenthesis">(</span>
|
||||
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_fmt<span class="parenthesis">(</span><span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>const_format_args<span class="punctuation">!</span><span class="parenthesis">(</span><span class="punctuation">$</span>fmt<span class="comma">,</span> <span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span><span class="punctuation">+</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
|
||||
|
|
|
@ -49,7 +49,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="brace">}</span>
|
||||
<span class="keyword">macro_rules</span><span class="macro_bang">!</span> <span class="macro declaration">unsafe_deref</span> <span class="brace">{</span>
|
||||
<span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="brace">{</span>
|
||||
<span class="punctuation">*</span><span class="parenthesis">(</span><span class="operator">&</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="keyword">as</span> <span class="punctuation">*</span><span class="keyword">const</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
|
||||
<span class="punctuation">*</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="keyword">as</span> <span class="punctuation">*</span><span class="keyword">const</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
|
||||
<span class="brace">}</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">MUT_GLOBAL</span><span class="colon">:</span> <span class="struct">Struct</span> <span class="operator">=</span> <span class="struct">Struct</span> <span class="brace">{</span> <span class="field">field</span><span class="colon">:</span> <span class="numeric_literal">0</span> <span class="brace">}</span><span class="semicolon">;</span>
|
||||
|
@ -63,7 +63,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
|
||||
<span class="keyword">struct</span> <span class="struct declaration">Struct</span> <span class="brace">{</span> <span class="field declaration">field</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="brace">}</span>
|
||||
<span class="keyword">impl</span> <span class="struct">Struct</span> <span class="brace">{</span>
|
||||
<span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function associated declaration reference unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function associated declaration reference unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">repr</span><span class="parenthesis attribute">(</span><span class="none attribute">packed</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
|
||||
|
@ -78,11 +78,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="keyword">fn</span> <span class="function declaration">unsafe_trait_bound</span><span class="angle"><</span><span class="type_param declaration">T</span><span class="colon">:</span> <span class="trait">UnsafeTrait</span><span class="angle">></span><span class="parenthesis">(</span><span class="punctuation">_</span><span class="colon">:</span> <span class="type_param">T</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue