Skip to content

Commit 310e497

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 548dcbb + 76249e1 commit 310e497

File tree

11 files changed

+80
-87
lines changed

11 files changed

+80
-87
lines changed

src/bin/log/setup.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env::{self, VarError};
22
use std::str::FromStr;
33
use std::sync::{Mutex, OnceLock};
44

5+
use rustc_log::tracing;
56
use rustc_middle::ty::TyCtxt;
67
use rustc_session::{CtfeBacktrace, EarlyDiagCtxt};
78

@@ -72,8 +73,8 @@ fn init_logger_once(early_dcx: &EarlyDiagCtxt) {
7273
early_dcx,
7374
rustc_logger_config(),
7475
|| {
75-
tracing_subscriber::layer::SubscriberExt::with(
76-
tracing_subscriber::Registry::default(),
76+
rustc_log::tracing_subscriber::layer::SubscriberExt::with(
77+
rustc_log::tracing_subscriber::Registry::default(),
7778
chrome_layer,
7879
)
7980
},

src/bin/log/tracing_chrome.rs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
#![allow(warnings)]
2525
#![cfg(feature = "tracing")]
2626

27-
// This is here and not in src/lib.rs since it is a direct dependency of tracing_chrome.rs and
28-
// should not be included if the "tracing" feature is disabled.
29-
extern crate tracing_core;
30-
31-
use tracing_core::{field::Field, span, Event, Subscriber};
32-
use tracing_subscriber::{
27+
use rustc_log::tracing_core::{field::Field, span, Event, Subscriber};
28+
use rustc_log::tracing_subscriber::{
29+
self,
3330
layer::Context,
3431
registry::{LookupSpan, SpanRef},
3532
Layer,
@@ -526,16 +523,16 @@ where
526523
}
527524
},
528525
TraceStyle::Async => Some(
529-
span.scope()
530-
.from_root()
531-
.take(1)
532-
.next()
533-
.unwrap_or(span)
534-
.id()
535-
.into_u64()
526+
span.scope()
527+
.from_root()
528+
.take(1)
529+
.next()
530+
.unwrap_or(span)
531+
.id()
532+
.into_u64()
536533
.cast_signed() // the comment above explains the cast
537534
),
538-
}
535+
}
539536
}
540537

541538
fn enter_span(&self, span: SpanRef<S>, ts: f64, tid: usize, out: &Sender<Message>) {
@@ -570,11 +567,11 @@ where
570567
Some(thread_data) => (thread_data, false),
571568
None => {
572569
let tid = self.max_tid.fetch_add(1, Ordering::SeqCst);
573-
let out = self.out.lock().unwrap().clone();
570+
let out = self.out.lock().unwrap().clone();
574571
let start = TracingChromeInstant::setup_for_thread_and_start(tid);
575572
*thread_data = Some(ThreadData { tid, out, start });
576573
(thread_data.as_mut().unwrap(), true)
577-
}
574+
}
578575
};
579576

580577
start.with_elapsed_micros_subtracting_tracing(|ts| {
@@ -586,7 +583,7 @@ where
586583
let _ignored = out.send(Message::NewThread(*tid, name));
587584
}
588585
f(ts, *tid, out);
589-
});
586+
});
590587
});
591588
}
592589
}
@@ -608,15 +605,15 @@ where
608605
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
609606
if self.include_args {
610607
self.with_elapsed_micros_subtracting_tracing(|_, _, _| {
611-
let span = ctx.span(id).unwrap();
612-
let mut exts = span.extensions_mut();
608+
let span = ctx.span(id).unwrap();
609+
let mut exts = span.extensions_mut();
613610

614-
let args = exts.get_mut::<ArgsWrapper>();
611+
let args = exts.get_mut::<ArgsWrapper>();
615612

616-
if let Some(args) = args {
617-
let args = Arc::make_mut(&mut args.args);
618-
values.record(&mut JsonVisitor { object: args });
619-
}
613+
if let Some(args) = args {
614+
let args = Arc::make_mut(&mut args.args);
615+
values.record(&mut JsonVisitor { object: args });
616+
}
620617
});
621618
}
622619
}
@@ -639,16 +636,16 @@ where
639636

640637
fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
641638
self.with_elapsed_micros_subtracting_tracing(|ts, tid, out| {
642-
if self.include_args {
643-
let mut args = Object::new();
644-
attrs.record(&mut JsonVisitor { object: &mut args });
645-
ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper {
646-
args: Arc::new(args),
647-
});
648-
}
649-
if let TraceStyle::Threaded = self.trace_style {
650-
return;
651-
}
639+
if self.include_args {
640+
let mut args = Object::new();
641+
attrs.record(&mut JsonVisitor { object: &mut args });
642+
ctx.span(id).unwrap().extensions_mut().insert(ArgsWrapper {
643+
args: Arc::new(args),
644+
});
645+
}
646+
if let TraceStyle::Threaded = self.trace_style {
647+
return;
648+
}
652649

653650
self.enter_span(ctx.span(id).expect("Span not found."), ts, tid, out);
654651
});

src/bin/miri.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
rustc::untranslatable_diagnostic
99
)]
1010

11-
// Some "regular" crates we want to share with rustc
12-
extern crate tracing;
13-
#[cfg(feature = "tracing")]
14-
extern crate tracing_subscriber;
15-
1611
// The rustc crates we need
1712
extern crate rustc_abi;
1813
extern crate rustc_data_structures;
@@ -48,6 +43,7 @@ use rustc_hir::def_id::LOCAL_CRATE;
4843
use rustc_hir::{self as hir, Node};
4944
use rustc_hir_analysis::check::check_function_signature;
5045
use rustc_interface::interface::Config;
46+
use rustc_log::tracing::debug;
5147
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
5248
use rustc_middle::middle::exported_symbols::{
5349
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
@@ -60,7 +56,6 @@ use rustc_session::EarlyDiagCtxt;
6056
use rustc_session::config::{CrateType, ErrorOutputType, OptLevel};
6157
use rustc_session::search_paths::PathKind;
6258
use rustc_span::def_id::DefId;
63-
use tracing::debug;
6459

6560
use crate::log::setup::{deinit_loggers, init_early_loggers, init_late_loggers};
6661

src/borrow_tracker/stacked_borrows/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::ops::Range;
33

44
use rustc_data_structures::fx::FxHashSet;
5-
use tracing::trace;
5+
use rustc_log::tracing::trace;
66

77
use crate::borrow_tracker::stacked_borrows::{Item, Permission};
88
use crate::borrow_tracker::{AccessKind, BorTag};

src/concurrency/data_race.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use rustc_abi::{Align, HasDataLayout, Size};
4848
use rustc_ast::Mutability;
4949
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5050
use rustc_index::{Idx, IndexVec};
51+
use rustc_log::tracing;
5152
use rustc_middle::mir;
5253
use rustc_middle::ty::Ty;
5354
use rustc_span::Span;

src/concurrency/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::sync::atomic::Ordering::Relaxed;
55
use std::task::Poll;
66
use std::time::{Duration, SystemTime};
77

8-
use either::Either;
98
use rand::seq::IteratorRandom;
109
use rustc_abi::ExternAbi;
1110
use rustc_const_eval::CTRL_C_RECEIVED;
11+
use rustc_data_structures::either::Either;
1212
use rustc_data_structures::fx::FxHashMap;
1313
use rustc_hir::def_id::DefId;
1414
use rustc_index::{Idx, IndexVec};

src/intrinsics/simd.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,47 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3838
for i in 0..dest_len {
3939
let op = this.read_immediate(&this.project_index(&op, i)?)?;
4040
let dest = this.project_index(&dest, i)?;
41-
let ty::Float(float_ty) = op.layout.ty.kind() else {
42-
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
43-
};
44-
// Using host floats except for sqrt (but it's fine, these operations do not
45-
// have guaranteed precision).
41+
let ty::Float(float_ty) = op.layout.ty.kind() else {
42+
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
43+
};
44+
// Using host floats except for sqrt (but it's fine, these operations do not
45+
// have guaranteed precision).
4646
let val = match float_ty {
47-
FloatTy::F16 => unimplemented!("f16_f128"),
48-
FloatTy::F32 => {
49-
let f = op.to_scalar().to_f32()?;
47+
FloatTy::F16 => unimplemented!("f16_f128"),
48+
FloatTy::F32 => {
49+
let f = op.to_scalar().to_f32()?;
5050
let res = match intrinsic_name {
51-
"fsqrt" => math::sqrt(f),
52-
"fsin" => f.to_host().sin().to_soft(),
53-
"fcos" => f.to_host().cos().to_soft(),
54-
"fexp" => f.to_host().exp().to_soft(),
55-
"fexp2" => f.to_host().exp2().to_soft(),
56-
"flog" => f.to_host().ln().to_soft(),
57-
"flog2" => f.to_host().log2().to_soft(),
58-
"flog10" => f.to_host().log10().to_soft(),
59-
_ => bug!(),
60-
};
61-
let res = this.adjust_nan(res, &[f]);
62-
Scalar::from(res)
63-
}
64-
FloatTy::F64 => {
65-
let f = op.to_scalar().to_f64()?;
51+
"fsqrt" => math::sqrt(f),
52+
"fsin" => f.to_host().sin().to_soft(),
53+
"fcos" => f.to_host().cos().to_soft(),
54+
"fexp" => f.to_host().exp().to_soft(),
55+
"fexp2" => f.to_host().exp2().to_soft(),
56+
"flog" => f.to_host().ln().to_soft(),
57+
"flog2" => f.to_host().log2().to_soft(),
58+
"flog10" => f.to_host().log10().to_soft(),
59+
_ => bug!(),
60+
};
61+
let res = this.adjust_nan(res, &[f]);
62+
Scalar::from(res)
63+
}
64+
FloatTy::F64 => {
65+
let f = op.to_scalar().to_f64()?;
6666
let res = match intrinsic_name {
67-
"fsqrt" => math::sqrt(f),
68-
"fsin" => f.to_host().sin().to_soft(),
69-
"fcos" => f.to_host().cos().to_soft(),
70-
"fexp" => f.to_host().exp().to_soft(),
71-
"fexp2" => f.to_host().exp2().to_soft(),
72-
"flog" => f.to_host().ln().to_soft(),
73-
"flog2" => f.to_host().log2().to_soft(),
74-
"flog10" => f.to_host().log10().to_soft(),
75-
_ => bug!(),
67+
"fsqrt" => math::sqrt(f),
68+
"fsin" => f.to_host().sin().to_soft(),
69+
"fcos" => f.to_host().cos().to_soft(),
70+
"fexp" => f.to_host().exp().to_soft(),
71+
"fexp2" => f.to_host().exp2().to_soft(),
72+
"flog" => f.to_host().ln().to_soft(),
73+
"flog2" => f.to_host().log2().to_soft(),
74+
"flog10" => f.to_host().log10().to_soft(),
75+
_ => bug!(),
76+
};
77+
let res = this.adjust_nan(res, &[f]);
78+
Scalar::from(res)
79+
}
80+
FloatTy::F128 => unimplemented!("f16_f128"),
7681
};
77-
let res = this.adjust_nan(res, &[f]);
78-
Scalar::from(res)
79-
}
80-
FloatTy::F128 => unimplemented!("f16_f128"),
81-
};
8282

8383
this.write_scalar(val, &dest)?;
8484
}

src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
// Needed for rustdoc from bootstrap (with `-Znormalize-docs`).
5050
#![recursion_limit = "256"]
5151

52-
// Some "regular" crates we want to share with rustc
53-
extern crate either;
54-
extern crate tracing;
55-
5652
// The rustc crates we need
5753
extern crate rustc_abi;
5854
extern crate rustc_apfloat;
@@ -63,6 +59,7 @@ extern crate rustc_errors;
6359
extern crate rustc_hash;
6460
extern crate rustc_hir;
6561
extern crate rustc_index;
62+
extern crate rustc_log;
6663
extern crate rustc_middle;
6764
extern crate rustc_session;
6865
extern crate rustc_span;
@@ -96,8 +93,8 @@ pub use rustc_const_eval::interpret::*;
9693
// Resolve ambiguity.
9794
#[doc(no_inline)]
9895
pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _};
96+
use rustc_log::tracing::{self, info, trace};
9997
use rustc_middle::{bug, span_bug};
100-
use tracing::{info, trace};
10198

10299
#[cfg(all(unix, feature = "native-lib"))]
103100
pub mod native_lib {

src/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1616
#[allow(unused)]
1717
use rustc_data_structures::static_assert_size;
1818
use rustc_hir::attrs::InlineAttr;
19+
use rustc_log::tracing;
1920
use rustc_middle::middle::codegen_fn_attrs::TargetFeatureKind;
2021
use rustc_middle::mir;
2122
use rustc_middle::query::TyCtxtAt;

src/provenance_gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use either::Either;
1+
use rustc_data_structures::either::Either;
22
use rustc_data_structures::fx::FxHashSet;
33

44
use crate::*;

0 commit comments

Comments
 (0)