Skip to content

Commit 64033a4

Browse files
committed
Auto merge of #142483 - workingjubilee:rollup-8qnhueh, r=workingjubilee
Rollup of 16 pull requests Successful merges: - #140969 (Allow initializing logger with additional tracing Layer) - #141352 (builtin dyn impl no guide inference) - #142046 (add Vec::peek_mut) - #142273 (tests: Minicore `extern "gpu-kernel"` feature test) - #142302 (Rework how the disallowed qualifier in function type diagnostics are generated) - #142405 (Don't hardcode the intrinsic return types twice in the compiler) - #142434 ( Pre-install JS dependencies in tidy Dockerfile) - #142439 (doc: mention that intrinsics should not be called in user code) - #142441 (Delay replacing escaping bound vars in `FindParamInClause`) - #142449 (Require generic params for const generic params) - #142452 (Remove "intermittent" wording from `ReadDir`) - #142459 (Remove output helper bootstrap) - #142460 (cleanup search graph impl) - #142461 (compiletest: Clarify that `--no-capture` is needed with `--verbose`) - #142475 (Add platform support docs & maintainers for *-windows-msvc) - #142480 (tests: Convert two handwritten minicores to add-core-stubs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 64c81fd + 572b452 commit 64033a4

File tree

71 files changed

+1268
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1268
-614
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4618,7 +4618,7 @@ dependencies = [
46184618
"derive-where",
46194619
"ena",
46204620
"indexmap",
4621-
"rustc-hash 1.1.0",
4621+
"rustc-hash 2.1.1",
46224622
"rustc_ast_ir",
46234623
"rustc_data_structures",
46244624
"rustc_index",

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21472147
ty_id,
21482148
&None,
21492149
path,
2150-
ParamMode::Optional,
2150+
ParamMode::Explicit,
21512151
AllowReturnTypeNotation::No,
21522152
// FIXME(mgca): update for `fn foo() -> Bar<FOO<impl Trait>>` support
21532153
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
@@ -2219,7 +2219,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22192219
expr.id,
22202220
qself,
22212221
path,
2222-
ParamMode::Optional,
2222+
ParamMode::Explicit,
22232223
AllowReturnTypeNotation::No,
22242224
// FIXME(mgca): update for `fn foo() -> Bar<FOO<impl Trait>>` support
22252225
ImplTraitContext::Disallowed(ImplTraitPosition::Path),

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
139139

140140
sym::needs_drop | sym::type_id | sym::type_name | sym::variant_count => {
141141
let gid = GlobalId { instance, promoted: None };
142-
let ty = match intrinsic_name {
143-
sym::variant_count => self.tcx.types.usize,
144-
sym::needs_drop => self.tcx.types.bool,
145-
sym::type_id => self.tcx.types.u128,
146-
sym::type_name => Ty::new_static_str(self.tcx.tcx),
147-
_ => bug!(),
148-
};
142+
let ty = self
143+
.tcx
144+
.fn_sig(instance.def_id())
145+
.instantiate(self.tcx.tcx, instance.args)
146+
.output()
147+
.no_bound_vars()
148+
.unwrap();
149149
let val = self
150150
.ctfe_query(|tcx| tcx.const_eval_global_id(self.typing_env, gid, tcx.span))?;
151151
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,13 +1500,31 @@ pub fn init_rustc_env_logger(early_dcx: &EarlyDiagCtxt) {
15001500

15011501
/// This allows tools to enable rust logging without having to magically match rustc's
15021502
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose
1503-
/// the values directly rather than having to set an environment variable.
1503+
/// the logger config directly rather than having to set an environment variable.
15041504
pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
15051505
if let Err(error) = rustc_log::init_logger(cfg) {
15061506
early_dcx.early_fatal(error.to_string());
15071507
}
15081508
}
15091509

1510+
/// This allows tools to enable rust logging without having to magically match rustc's
1511+
/// tracing crate version. In contrast to `init_rustc_env_logger`, it allows you to
1512+
/// choose the logger config directly rather than having to set an environment variable.
1513+
/// Moreover, in contrast to `init_logger`, it allows you to add a custom tracing layer
1514+
/// via `build_subscriber`, for example `|| Registry::default().with(custom_layer)`.
1515+
pub fn init_logger_with_additional_layer<F, T>(
1516+
early_dcx: &EarlyDiagCtxt,
1517+
cfg: rustc_log::LoggerConfig,
1518+
build_subscriber: F,
1519+
) where
1520+
F: FnOnce() -> T,
1521+
T: rustc_log::BuildSubscriberRet,
1522+
{
1523+
if let Err(error) = rustc_log::init_logger_with_additional_layer(cfg, build_subscriber) {
1524+
early_dcx.early_fatal(error.to_string());
1525+
}
1526+
}
1527+
15101528
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
15111529
/// Making this handler optional lets tools can install a different handler, if they wish.
15121530
pub fn install_ctrlc_handler() {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::bug;
1111
use rustc_middle::ty::{
12-
self as ty, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable,
13-
TypeVisitableExt, TypeVisitor, Upcast,
12+
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
13+
TypeVisitor, Upcast,
1414
};
1515
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
1616
use rustc_trait_selection::traits;
@@ -927,7 +927,7 @@ struct GenericParamAndBoundVarCollector<'a, 'tcx> {
927927
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 'tcx> {
928928
type Result = ControlFlow<ErrorGuaranteed>;
929929

930-
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
930+
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
931931
&mut self,
932932
binder: &ty::Binder<'tcx, T>,
933933
) -> Self::Result {

compiler/rustc_lint/src/impl_trait_overcaptures.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use rustc_middle::ty::relate::{
1515
Relate, RelateResult, TypeRelation, structurally_relate_consts, structurally_relate_tys,
1616
};
1717
use rustc_middle::ty::{
18-
self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
19-
TypeVisitor,
18+
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
2019
};
2120
use rustc_middle::{bug, span_bug};
2221
use rustc_session::lint::FutureIncompatibilityReason;
@@ -210,7 +209,7 @@ where
210209
VarFn: FnOnce() -> FxHashMap<DefId, ty::Variance>,
211210
OutlivesFn: FnOnce() -> OutlivesEnvironment<'tcx>,
212211
{
213-
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
212+
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
214213
// When we get into a binder, we need to add its own bound vars to the scope.
215214
let mut added = vec![];
216215
for arg in t.bound_vars() {

compiler/rustc_log/src/lib.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
4343
use tracing_subscriber::fmt::FmtContext;
4444
use tracing_subscriber::fmt::format::{self, FormatEvent, FormatFields};
4545
use tracing_subscriber::layer::SubscriberExt;
46+
use tracing_subscriber::{Layer, Registry};
4647

4748
/// The values of all the environment variables that matter for configuring a logger.
4849
/// Errors are explicitly preserved so that we can share error handling.
@@ -72,6 +73,36 @@ impl LoggerConfig {
7273

7374
/// Initialize the logger with the given values for the filter, coloring, and other options env variables.
7475
pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
76+
init_logger_with_additional_layer(cfg, || Registry::default())
77+
}
78+
79+
/// Trait alias for the complex return type of `build_subscriber` in
80+
/// [init_logger_with_additional_layer]. A [Registry] with any composition of [tracing::Subscriber]s
81+
/// (e.g. `Registry::default().with(custom_layer)`) should be compatible with this type.
82+
/// Having an alias is also useful so rustc_driver_impl does not need to explicitly depend on
83+
/// `tracing_subscriber`.
84+
pub trait BuildSubscriberRet:
85+
tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span> + Send + Sync
86+
{
87+
}
88+
89+
impl<
90+
T: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span> + Send + Sync,
91+
> BuildSubscriberRet for T
92+
{
93+
}
94+
95+
/// Initialize the logger with the given values for the filter, coloring, and other options env variables.
96+
/// Additionally add a custom layer to collect logging and tracing events via `build_subscriber`,
97+
/// for example: `|| Registry::default().with(custom_layer)`.
98+
pub fn init_logger_with_additional_layer<F, T>(
99+
cfg: LoggerConfig,
100+
build_subscriber: F,
101+
) -> Result<(), Error>
102+
where
103+
F: FnOnce() -> T,
104+
T: BuildSubscriberRet,
105+
{
75106
let filter = match cfg.filter {
76107
Ok(env) => EnvFilter::new(env),
77108
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
@@ -124,7 +155,7 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
124155
Err(_) => {} // no wraptree
125156
}
126157

127-
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
158+
let subscriber = build_subscriber().with(layer.with_filter(filter));
128159
match cfg.backtrace {
129160
Ok(backtrace_target) => {
130161
let fmt_layer = tracing_subscriber::fmt::layer()

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
163163
Const::new_bound(tcx, debruijn, var)
164164
}
165165

166+
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst) -> Self {
167+
Const::new_placeholder(tcx, placeholder)
168+
}
169+
166170
fn new_unevaluated(interner: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Self {
167171
Const::new_unevaluated(interner, uv)
168172
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ impl Placeholder<BoundVar> {
933933

934934
pub type PlaceholderRegion = Placeholder<BoundRegion>;
935935

936-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
936+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderRegion {
937+
type Bound = BoundRegion;
938+
937939
fn universe(self) -> UniverseIndex {
938940
self.universe
939941
}
@@ -946,14 +948,20 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
946948
Placeholder { universe: ui, ..self }
947949
}
948950

949-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
951+
fn new(ui: UniverseIndex, bound: BoundRegion) -> Self {
952+
Placeholder { universe: ui, bound }
953+
}
954+
955+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
950956
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::Anon } }
951957
}
952958
}
953959

954960
pub type PlaceholderType = Placeholder<BoundTy>;
955961

956-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderType {
962+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderType {
963+
type Bound = BoundTy;
964+
957965
fn universe(self) -> UniverseIndex {
958966
self.universe
959967
}
@@ -966,7 +974,11 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderType {
966974
Placeholder { universe: ui, ..self }
967975
}
968976

969-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
977+
fn new(ui: UniverseIndex, bound: BoundTy) -> Self {
978+
Placeholder { universe: ui, bound }
979+
}
980+
981+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
970982
Placeholder { universe: ui, bound: BoundTy { var, kind: BoundTyKind::Anon } }
971983
}
972984
}
@@ -980,7 +992,9 @@ pub struct BoundConst<'tcx> {
980992

981993
pub type PlaceholderConst = Placeholder<BoundVar>;
982994

983-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
995+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderConst {
996+
type Bound = BoundVar;
997+
984998
fn universe(self) -> UniverseIndex {
985999
self.universe
9861000
}
@@ -993,7 +1007,11 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
9931007
Placeholder { universe: ui, ..self }
9941008
}
9951009

996-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
1010+
fn new(ui: UniverseIndex, bound: BoundVar) -> Self {
1011+
Placeholder { universe: ui, bound }
1012+
}
1013+
1014+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
9971015
Placeholder { universe: ui, bound: var }
9981016
}
9991017
}

compiler/rustc_middle/src/ty/region.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
148148
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon })
149149
}
150150

151+
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion) -> Self {
152+
Region::new_placeholder(tcx, placeholder)
153+
}
154+
151155
fn new_static(tcx: TyCtxt<'tcx>) -> Self {
152156
tcx.lifetimes.re_static
153157
}

compiler/rustc_middle/src/ty/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx> TyCtxt<'tcx> {
6666
{
6767
type Result = ControlFlow<()>;
6868

69-
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
69+
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
7070
&mut self,
7171
t: &Binder<'tcx, T>,
7272
) -> Self::Result {
@@ -168,7 +168,7 @@ impl LateBoundRegionsCollector {
168168
}
169169

170170
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
171-
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) {
171+
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) {
172172
self.current_index.shift_in(1);
173173
t.super_visit_with(self);
174174
self.current_index.shift_out(1);

compiler/rustc_next_trait_solver/src/canonicalizer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
435435
},
436436
ty::Placeholder(placeholder) => match self.canonicalize_mode {
437437
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
438-
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
438+
PlaceholderLike::new_anon(placeholder.universe(), self.variables.len().into()),
439439
),
440440
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
441441
},
442442
ty::Param(_) => match self.canonicalize_mode {
443443
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
444-
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
444+
PlaceholderLike::new_anon(ty::UniverseIndex::ROOT, self.variables.len().into()),
445445
),
446446
CanonicalizeMode::Response { .. } => panic!("param ty in response: {t:?}"),
447447
},
@@ -594,15 +594,15 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
594594
},
595595
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
596596
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
597-
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
597+
PlaceholderLike::new_anon(placeholder.universe(), self.variables.len().into()),
598598
),
599599
CanonicalizeMode::Response { .. } => {
600600
CanonicalVarKind::PlaceholderConst(placeholder)
601601
}
602602
},
603603
ty::ConstKind::Param(_) => match self.canonicalize_mode {
604604
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
605-
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
605+
PlaceholderLike::new_anon(ty::UniverseIndex::ROOT, self.variables.len().into()),
606606
),
607607
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),
608608
},

compiler/rustc_next_trait_solver/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
pub mod canonicalizer;
1313
pub mod coherence;
1414
pub mod delegate;
15+
pub mod placeholder;
1516
pub mod resolve;
1617
pub mod solve;

0 commit comments

Comments
 (0)