File tree 3 files changed +10
-7
lines changed
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(
546
546
// compiler.
547
547
if !already_has_extern_crate && !opts. no_crate_inject && cratename != Some ( "std" ) {
548
548
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.
550
553
if s. contains ( cratename) {
551
- prog. push_str ( & format ! ( "extern crate {};\n " , cratename) ) ;
554
+ prog. push_str ( & format ! ( "extern crate r# {};\n " , cratename) ) ;
552
555
line_offset += 1 ;
553
556
}
554
557
}
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ fn make_test_crate_name() {
38
38
let input = "use asdf::qwop;
39
39
assert_eq!(2+2, 4);" ;
40
40
let expected = "#![allow(unused)]
41
- extern crate asdf;
41
+ extern crate r# asdf;
42
42
fn main() {
43
43
use asdf::qwop;
44
44
assert_eq!(2+2, 4);
@@ -128,7 +128,7 @@ fn make_test_opts_attrs() {
128
128
let input = "use asdf::qwop;
129
129
assert_eq!(2+2, 4);" ;
130
130
let expected = "#![feature(sick_rad)]
131
- extern crate asdf;
131
+ extern crate r# asdf;
132
132
fn main() {
133
133
use asdf::qwop;
134
134
assert_eq!(2+2, 4);
@@ -141,7 +141,7 @@ assert_eq!(2+2, 4);
141
141
opts. attrs . push ( "feature(hella_dope)" . to_string ( ) ) ;
142
142
let expected = "#![feature(sick_rad)]
143
143
#![feature(hella_dope)]
144
- extern crate asdf;
144
+ extern crate r# asdf;
145
145
fn main() {
146
146
use asdf::qwop;
147
147
assert_eq!(2+2, 4);
@@ -250,7 +250,7 @@ assert_eq!(asdf::foo, 4);";
250
250
251
251
let expected = "#![allow(unused)]
252
252
extern crate hella_qwop;
253
- extern crate asdf;
253
+ extern crate r# asdf;
254
254
fn main() {
255
255
assert_eq!(asdf::foo, 4);
256
256
}"
Original file line number Diff line number Diff line change 11
11
pub fn dummy ( ) { }
12
12
13
13
// 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