Skip to content

Commit e54f933

Browse files
authored
Rollup merge of rust-lang#110798 - ozkanonur:rustdoc-unused-extern-crates, r=jyn514
pass `unused_extern_crates` in `librustdoc::doctest::make_test` blocker for rust-lang#106621
2 parents 0b395f9 + f56b6d0 commit e54f933

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/librustdoc/doctest.rs

+4
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ pub(crate) fn make_test(
679679
// parse the source, but only has false positives, not false
680680
// negatives.
681681
if s.contains(crate_name) {
682+
// rustdoc implicitly inserts an `extern crate` item for the own crate
683+
// which may be unused, so we need to allow the lint.
684+
prog.push_str(&format!("#[allow(unused_extern_crates)]\n"));
685+
682686
prog.push_str(&format!("extern crate r#{crate_name};\n"));
683687
line_offset += 1;
684688
}

src/librustdoc/doctest/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn make_test_crate_name() {
3838
let input = "use asdf::qwop;
3939
assert_eq!(2+2, 4);";
4040
let expected = "#![allow(unused)]
41+
#[allow(unused_extern_crates)]
4142
extern crate r#asdf;
4243
fn main() {
4344
use asdf::qwop;
@@ -128,6 +129,7 @@ fn make_test_opts_attrs() {
128129
let input = "use asdf::qwop;
129130
assert_eq!(2+2, 4);";
130131
let expected = "#![feature(sick_rad)]
132+
#[allow(unused_extern_crates)]
131133
extern crate r#asdf;
132134
fn main() {
133135
use asdf::qwop;
@@ -141,6 +143,7 @@ assert_eq!(2+2, 4);
141143
opts.attrs.push("feature(hella_dope)".to_string());
142144
let expected = "#![feature(sick_rad)]
143145
#![feature(hella_dope)]
146+
#[allow(unused_extern_crates)]
144147
extern crate r#asdf;
145148
fn main() {
146149
use asdf::qwop;
@@ -236,6 +239,7 @@ assert_eq!(asdf::foo, 4);";
236239

237240
let expected = "#![allow(unused)]
238241
extern crate hella_qwop;
242+
#[allow(unused_extern_crates)]
239243
extern crate r#asdf;
240244
fn main() {
241245
assert_eq!(asdf::foo, 4);

tests/rustdoc/playground-arg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
pub fn dummy() {}
1111

1212
// ensure that `extern crate foo;` was inserted into code snips automatically:
13-
// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern+crate+r%23foo;%0Afn+main()+%7B%0Ause+foo::dummy;%0Adummy();%0A%7D&edition=2015"]' "Run"
13+
// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0A%23%5Ballow(unused_extern_crates)%5D%0Aextern+crate+r%23foo;%0Afn+main()+%7B%0Ause+foo::dummy;%0Adummy();%0A%7D&edition=2015"]' "Run"

0 commit comments

Comments
 (0)