Skip to content

Commit bbac68b

Browse files
committed
Auto merge of #143548 - Diggsey:db-limit-extern-crate-usage, r=oli-obk
Restrict sysroot crate imports to those defined in this repo. It's common to import dependencies from the sysroot via `extern crate` rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, the `extern crate` fails to resolve. To address this, re-export all such dependencies from the appropriate `rustc_*` crates, and use this alias from crates which would otherwise need to use `extern crate`. See rust-lang/rust#143492 for an example of the kind of issue that can occur.
2 parents 5c61e91 + 9800dfa commit bbac68b

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

clippy_lints/src/doc/broken_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use pulldown_cmark::BrokenLink as PullDownBrokenLink;
32
use rustc_lint::LateContext;
3+
use rustc_resolve::rustdoc::pulldown_cmark::BrokenLink as PullDownBrokenLink;
44
use rustc_resolve::rustdoc::{DocFragment, source_span_for_markdown_range};
55
use rustc_span::{BytePos, Pos, Span};
66

clippy_lints/src/doc/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ use clippy_config::Conf;
44
use clippy_utils::attrs::is_doc_hidden;
55
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then};
66
use clippy_utils::{is_entrypoint_fn, is_trait_impl_item};
7-
use pulldown_cmark::Event::{
8-
Code, DisplayMath, End, FootnoteReference, HardBreak, Html, InlineHtml, InlineMath, Rule, SoftBreak, Start,
9-
TaskListMarker, Text,
10-
};
11-
use pulldown_cmark::Tag::{BlockQuote, CodeBlock, FootnoteDefinition, Heading, Item, Link, Paragraph};
12-
use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options, TagEnd};
137
use rustc_data_structures::fx::FxHashSet;
148
use rustc_errors::Applicability;
159
use rustc_hir::{Attribute, ImplItemKind, ItemKind, Node, Safety, TraitItemKind};
1610
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
11+
use rustc_resolve::rustdoc::pulldown_cmark::Event::{
12+
Code, DisplayMath, End, FootnoteReference, HardBreak, Html, InlineHtml, InlineMath, Rule, SoftBreak, Start,
13+
TaskListMarker, Text,
14+
};
15+
use rustc_resolve::rustdoc::pulldown_cmark::Tag::{
16+
BlockQuote, CodeBlock, FootnoteDefinition, Heading, Item, Link, Paragraph,
17+
};
18+
use rustc_resolve::rustdoc::pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options, TagEnd};
1719
use rustc_resolve::rustdoc::{
18-
DocFragment, add_doc_fragment, attrs_to_doc_fragments, main_body_opts, source_span_for_markdown_range,
19-
span_of_fragments,
20+
DocFragment, add_doc_fragment, attrs_to_doc_fragments, main_body_opts, pulldown_cmark,
21+
source_span_for_markdown_range, span_of_fragments,
2022
};
2123
use rustc_session::impl_lint_pass;
2224
use rustc_span::Span;

clippy_lints/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
rustc::internal
2828
)]
2929

30-
// FIXME: switch to something more ergonomic here, once available.
31-
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
32-
extern crate pulldown_cmark;
3330
extern crate rustc_abi;
3431
extern crate rustc_arena;
3532
extern crate rustc_ast;
@@ -53,8 +50,6 @@ extern crate rustc_session;
5350
extern crate rustc_span;
5451
extern crate rustc_target;
5552
extern crate rustc_trait_selection;
56-
extern crate smallvec;
57-
extern crate thin_vec;
5853

5954
#[macro_use]
6055
extern crate clippy_utils;

clippy_lints/src/methods/ip_constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::span_lint_and_then;
3+
use rustc_data_structures::smallvec::SmallVec;
34
use rustc_errors::Applicability;
45
use rustc_hir::{Expr, ExprKind, QPath, TyKind};
56
use rustc_lint::LateContext;
67
use rustc_span::sym;
7-
use smallvec::SmallVec;
88

99
use super::IP_CONSTANT;
1010

clippy_lints/src/unnested_or_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::PatKind::*;
99
use rustc_ast::mut_visit::*;
1010
use rustc_ast::{self as ast, DUMMY_NODE_ID, Mutability, Pat, PatKind};
1111
use rustc_ast_pretty::pprust;
12+
use rustc_data_structures::thin_vec::{ThinVec, thin_vec};
1213
use rustc_errors::Applicability;
1314
use rustc_lint::{EarlyContext, EarlyLintPass};
1415
use rustc_session::impl_lint_pass;
@@ -17,7 +18,6 @@ use rustc_span::DUMMY_SP;
1718
use std::boxed::Box;
1819
use std::cell::Cell;
1920
use std::mem;
20-
use thin_vec::{ThinVec, thin_vec};
2121

2222
declare_clippy_lint! {
2323
/// ### What it does

clippy_utils/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
// FIXME: switch to something more ergonomic here, once available.
2727
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
28-
extern crate indexmap;
2928
extern crate rustc_abi;
3029
extern crate rustc_ast;
3130
extern crate rustc_attr_parsing;
@@ -47,7 +46,6 @@ extern crate rustc_mir_dataflow;
4746
extern crate rustc_session;
4847
extern crate rustc_span;
4948
extern crate rustc_trait_selection;
50-
extern crate smallvec;
5149

5250
pub mod ast_utils;
5351
pub mod attrs;
@@ -90,6 +88,7 @@ use rustc_abi::Integer;
9088
use rustc_ast::ast::{self, LitKind, RangeLimits};
9189
use rustc_ast::join_path_syms;
9290
use rustc_data_structures::fx::FxHashMap;
91+
use rustc_data_structures::indexmap;
9392
use rustc_data_structures::packed::Pu128;
9493
use rustc_data_structures::unhash::UnindexMap;
9594
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};

clippy_utils/src/msrvs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use crate::sym;
22
use rustc_ast::Attribute;
33
use rustc_ast::attr::AttributeExt;
44
use rustc_attr_parsing::parse_version;
5+
use rustc_data_structures::smallvec::SmallVec;
56
use rustc_hir::RustcVersion;
67
use rustc_lint::LateContext;
78
use rustc_session::Session;
89
use rustc_span::Symbol;
910
use serde::Deserialize;
10-
use smallvec::SmallVec;
1111
use std::iter::once;
1212
use std::sync::atomic::{AtomicBool, Ordering};
1313

@@ -192,21 +192,21 @@ fn parse_attrs(sess: &Session, attrs: &[impl AttributeExt]) -> Option<RustcVersi
192192

193193
let msrv_attr = msrv_attrs.next()?;
194194

195-
if let Some(duplicate) = msrv_attrs.next_back() {
196-
sess.dcx()
197-
.struct_span_err(duplicate.span(), "`clippy::msrv` is defined multiple times")
198-
.with_span_note(msrv_attr.span(), "first definition found here")
199-
.emit();
200-
}
195+
if let Some(duplicate) = msrv_attrs.next_back() {
196+
sess.dcx()
197+
.struct_span_err(duplicate.span(), "`clippy::msrv` is defined multiple times")
198+
.with_span_note(msrv_attr.span(), "first definition found here")
199+
.emit();
200+
}
201201

202202
let Some(msrv) = msrv_attr.value_str() else {
203203
sess.dcx().span_err(msrv_attr.span(), "bad clippy attribute");
204204
return None;
205205
};
206206

207207
let Some(version) = parse_version(msrv) else {
208-
sess.dcx()
209-
.span_err(msrv_attr.span(), format!("`{msrv}` is not a valid Rust version"));
208+
sess.dcx()
209+
.span_err(msrv_attr.span(), format!("`{msrv}` is not a valid Rust version"));
210210
return None;
211211
};
212212

0 commit comments

Comments
 (0)