Skip to content

Commit

Permalink
Fix builtin macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Jul 24, 2018
1 parent 99f76e6 commit 7aa6033
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
18 changes: 13 additions & 5 deletions src/racer/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,21 +2009,29 @@ fn get_std_macros(
if !macro_path.exists() {
return;
}
get_std_macros_(&macro_path, searchstr, search_type, session, out);
get_std_macros_(
&macro_path,
searchstr,
macro_file == &"libcore/macros.rs",
search_type,
session,
out
);
}
}

fn get_std_macros_(
macro_path: &Path,
searchstr: &str,
is_core: bool,
search_type: SearchType,
session: &Session,
out: &mut Vec<Match>,
) {
let src = session.load_file(&macro_path);
let mut export = false;
let mut get_macro_def = |blob: &str| -> Option<(BytePos, String)> {
if blob.starts_with("#[macro_export]") {
if blob.starts_with("#[macro_export]") | blob.starts_with("#[rustc_doc_only_macro]") {
export = true;
return None;
}
Expand Down Expand Up @@ -2057,9 +2065,9 @@ fn get_std_macros_(
.iter_stmts()
.filter_map(|range| {
let blob = &src[range.to_range()];
// for builtin macros in libstd/macros.rs
if blob.starts_with("pub mod builtin") {
builtin_start = blob.find("#[macro_export]").map(|u| range.start + u.into());
// for builtin macros in libcore/macros.rs
if is_core && blob.starts_with("mod builtin") {
builtin_start = blob.find("#").map(|u| range.start + u.into());
}
let (offset, matchstr) = get_macro_def(blob)?;
let start = range.start + offset;
Expand Down
19 changes: 1 addition & 18 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4289,24 +4289,7 @@ fn finds_std_macro_doc() {
}
"#;
let got = get_definition(src, None);
let doc = r#"Expands to a string that represents the current module path.
The current module path can be thought of as the hierarchy of modules
leading back up to the crate root. The first component of the path
returned is the name of the crate currently being compiled.
# Examples
```
mod test {
pub fn foo() {
assert!(module_path!().ends_with("test"));
}
}
test::foo();
```"#;
assert_eq!(got.docs, doc);
assert!(!got.docs.is_empty());
}

#[test]
Expand Down

0 comments on commit 7aa6033

Please sign in to comment.