-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix ICE when rustdoc is scraping examples inside of a proc macro #90583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3ad6d12
Sort scraped call locations before serializing
willcrichton 4846d10
Fix ICE when rustdoc is scraping examples inside of a proc macro
willcrichton c62817b
Move rustdoc-scrape-examples-macros test to run-make-fulldeps
willcrichton 82b23be
Fix rustdoc-scrape-examples-macros test not being cross-platform
willcrichton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
OUTPUT_DIR := "$(TMPDIR)/rustdoc" | ||
DYLIB_NAME := $(shell echo | $(RUSTC) --crate-name foobar_macro --crate-type dylib --print file-names -) | ||
|
||
all: | ||
$(RUSTC) src/proc.rs --crate-name foobar_macro --edition=2021 --crate-type proc-macro --emit=dep-info,link | ||
|
||
$(RUSTC) src/lib.rs --crate-name foobar --edition=2021 --crate-type lib --emit=dep-info,link | ||
|
||
$(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin --output $(OUTPUT_DIR) \ | ||
--extern foobar=$(TMPDIR)/libfoobar.rlib --extern foobar_macro=$(TMPDIR)/$(DYLIB_NAME) \ | ||
-Z unstable-options --scrape-examples-output-path $(TMPDIR)/ex.calls --scrape-examples-target-crate foobar | ||
|
||
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \ | ||
-Z unstable-options --with-examples $(TMPDIR)/ex.calls | ||
|
||
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs |
27 changes: 27 additions & 0 deletions
27
src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/examples/ex.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
extern crate foobar; | ||
extern crate foobar_macro; | ||
|
||
use foobar::*; | ||
use foobar_macro::*; | ||
|
||
a_proc_macro!(); // no | ||
|
||
#[an_attr_macro] | ||
fn a() { | ||
f(); // no | ||
} | ||
|
||
#[an_attr_macro(with_span)] | ||
fn b() { | ||
f(); // yes | ||
} | ||
|
||
fn c() { | ||
a_rules_macro!(f()); // yes | ||
} | ||
|
||
fn d() { | ||
a_rules_macro!(()); // no | ||
} | ||
|
||
fn main(){} |
12 changes: 12 additions & 0 deletions
12
src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Scraped example should only include line numbers for items b and c in ex.rs | ||
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14' | ||
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15' | ||
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21' | ||
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22' | ||
|
||
pub fn f() {} | ||
|
||
#[macro_export] | ||
macro_rules! a_rules_macro { | ||
($e:expr) => { ($e, foobar::f()); } | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extern crate proc_macro; | ||
use proc_macro::*; | ||
|
||
#[proc_macro] | ||
pub fn a_proc_macro(_item: TokenStream) -> TokenStream { | ||
"fn ex() { foobar::f(); }".parse().unwrap() | ||
} | ||
|
||
// inserts foobar::f() to the end of the function | ||
#[proc_macro_attribute] | ||
pub fn an_attr_macro(attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let new_call: TokenStream = "foobar::f();".parse().unwrap(); | ||
|
||
let mut tokens = item.into_iter(); | ||
|
||
let fn_tok = tokens.next().unwrap(); | ||
let ident_tok = tokens.next().unwrap(); | ||
let args_tok = tokens.next().unwrap(); | ||
let body = match tokens.next().unwrap() { | ||
TokenTree::Group(g) => { | ||
let new_g = Group::new(g.delimiter(), new_call); | ||
let mut outer_g = Group::new( | ||
g.delimiter(), | ||
[TokenTree::Group(g.clone()), TokenTree::Group(new_g)].into_iter().collect(), | ||
); | ||
|
||
if attr.to_string() == "with_span" { | ||
outer_g.set_span(g.span()); | ||
} | ||
|
||
TokenTree::Group(outer_g) | ||
} | ||
_ => unreachable!(), | ||
}; | ||
|
||
let tokens = vec![fn_tok, ident_tok, args_tok, body].into_iter().collect::<TokenStream>(); | ||
|
||
tokens | ||
} |
4 changes: 3 additions & 1 deletion
4
src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex1.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
fn main() { | ||
foobar::ok(); | ||
foobar::ok(0); | ||
|
||
// this is a | ||
|
||
// .. | ||
|
||
// BIG | ||
|
||
// item | ||
|
6 changes: 5 additions & 1 deletion
6
src/test/run-make/rustdoc-scrape-examples-ordering/examples/ex2.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
fn main() { | ||
foobar::ok(); | ||
foobar::ok(1); | ||
// small item | ||
} | ||
|
||
fn f() { | ||
foobar::ok(2); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2' | ||
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1' | ||
// @has foobar/fn.ok.html '//*[@class="highlight focus"]' '1' | ||
// @has foobar/fn.ok.html '//*[@class="highlight"]' '2' | ||
// @has foobar/fn.ok.html '//*[@class="highlight focus"]' '0' | ||
|
||
pub fn ok() {} | ||
pub fn ok(_x: i32) {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.