pass unused_extern_crates
in librustdoc::doctest::make_test
Signed-off-by: ozkanonur <work@onurozkan.dev>
This commit is contained in:
parent
3128fd8ddf
commit
f56b6d0b12
3 changed files with 9 additions and 1 deletions
|
@ -679,6 +679,10 @@ pub(crate) fn make_test(
|
||||||
// parse the source, but only has false positives, not false
|
// parse the source, but only has false positives, not false
|
||||||
// negatives.
|
// negatives.
|
||||||
if s.contains(crate_name) {
|
if s.contains(crate_name) {
|
||||||
|
// rustdoc implicitly inserts an `extern crate` item for the own crate
|
||||||
|
// which may be unused, so we need to allow the lint.
|
||||||
|
prog.push_str(&format!("#[allow(unused_extern_crates)]\n"));
|
||||||
|
|
||||||
prog.push_str(&format!("extern crate r#{crate_name};\n"));
|
prog.push_str(&format!("extern crate r#{crate_name};\n"));
|
||||||
line_offset += 1;
|
line_offset += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ fn make_test_crate_name() {
|
||||||
let input = "use asdf::qwop;
|
let input = "use asdf::qwop;
|
||||||
assert_eq!(2+2, 4);";
|
assert_eq!(2+2, 4);";
|
||||||
let expected = "#![allow(unused)]
|
let expected = "#![allow(unused)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
extern crate r#asdf;
|
extern crate r#asdf;
|
||||||
fn main() {
|
fn main() {
|
||||||
use asdf::qwop;
|
use asdf::qwop;
|
||||||
|
@ -128,6 +129,7 @@ fn make_test_opts_attrs() {
|
||||||
let input = "use asdf::qwop;
|
let input = "use asdf::qwop;
|
||||||
assert_eq!(2+2, 4);";
|
assert_eq!(2+2, 4);";
|
||||||
let expected = "#![feature(sick_rad)]
|
let expected = "#![feature(sick_rad)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
extern crate r#asdf;
|
extern crate r#asdf;
|
||||||
fn main() {
|
fn main() {
|
||||||
use asdf::qwop;
|
use asdf::qwop;
|
||||||
|
@ -141,6 +143,7 @@ assert_eq!(2+2, 4);
|
||||||
opts.attrs.push("feature(hella_dope)".to_string());
|
opts.attrs.push("feature(hella_dope)".to_string());
|
||||||
let expected = "#![feature(sick_rad)]
|
let expected = "#![feature(sick_rad)]
|
||||||
#![feature(hella_dope)]
|
#![feature(hella_dope)]
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
extern crate r#asdf;
|
extern crate r#asdf;
|
||||||
fn main() {
|
fn main() {
|
||||||
use asdf::qwop;
|
use asdf::qwop;
|
||||||
|
@ -236,6 +239,7 @@ assert_eq!(asdf::foo, 4);";
|
||||||
|
|
||||||
let expected = "#![allow(unused)]
|
let expected = "#![allow(unused)]
|
||||||
extern crate hella_qwop;
|
extern crate hella_qwop;
|
||||||
|
#[allow(unused_extern_crates)]
|
||||||
extern crate r#asdf;
|
extern crate r#asdf;
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(asdf::foo, 4);
|
assert_eq!(asdf::foo, 4);
|
||||||
|
|
|
@ -10,4 +10,4 @@
|
||||||
pub fn dummy() {}
|
pub fn dummy() {}
|
||||||
|
|
||||||
// ensure that `extern crate foo;` was inserted into code snips automatically:
|
// ensure that `extern crate foo;` was inserted into code snips automatically:
|
||||||
// @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"
|
// @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"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue