File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -546,9 +546,12 @@ crate fn make_test(
546546 // compiler.
547547 if !already_has_extern_crate && !opts. no_crate_inject && cratename != Some ( "std" ) {
548548 if let Some ( cratename) = cratename {
549- // Make sure its actually used if not included.
549+ // Don't inject `extern crate` if the crate is never used.
550+ // NOTE: this is terribly inaccurate because it doesn't actually
551+ // parse the source, but only has false positives, not false
552+ // negatives.
550553 if s. contains ( cratename) {
551- prog. push_str ( & format ! ( "extern crate {};\n " , cratename) ) ;
554+ prog. push_str ( & format ! ( "extern crate r# {};\n " , cratename) ) ;
552555 line_offset += 1 ;
553556 }
554557 }
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ fn make_test_crate_name() {
3838 let input = "use asdf::qwop;
3939assert_eq!(2+2, 4);" ;
4040 let expected = "#![allow(unused)]
41- extern crate asdf;
41+ extern crate r# asdf;
4242fn main() {
4343use asdf::qwop;
4444assert_eq!(2+2, 4);
@@ -128,7 +128,7 @@ fn make_test_opts_attrs() {
128128 let input = "use asdf::qwop;
129129assert_eq!(2+2, 4);" ;
130130 let expected = "#![feature(sick_rad)]
131- extern crate asdf;
131+ extern crate r# asdf;
132132fn main() {
133133use asdf::qwop;
134134assert_eq!(2+2, 4);
@@ -141,7 +141,7 @@ assert_eq!(2+2, 4);
141141 opts. attrs . push ( "feature(hella_dope)" . to_string ( ) ) ;
142142 let expected = "#![feature(sick_rad)]
143143#![feature(hella_dope)]
144- extern crate asdf;
144+ extern crate r# asdf;
145145fn main() {
146146use asdf::qwop;
147147assert_eq!(2+2, 4);
@@ -250,7 +250,7 @@ assert_eq!(asdf::foo, 4);";
250250
251251 let expected = "#![allow(unused)]
252252extern crate hella_qwop;
253- extern crate asdf;
253+ extern crate r# asdf;
254254fn main() {
255255assert_eq!(asdf::foo, 4);
256256}"
Original file line number Diff line number Diff line change 1111pub fn dummy ( ) { }
1212
1313// ensure that `extern crate foo;` was inserted into code snips automatically:
14- // @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern%20crate%20foo %3B%0Afn%20main()%20%7B%0Ause%20foo%3A%3Adummy%3B%0Adummy()%3B%0A%7D&edition=2015"]' "Run"
14+ // @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern%20crate%20r%23foo %3B%0Afn%20main()%20%7B%0Ause%20foo%3A%3Adummy%3B%0Adummy()%3B%0A%7D&edition=2015"]' "Run"
You can’t perform that action at this time.
0 commit comments