Skip to content

Commit 9fd1c38

Browse files
committed
Auto merge of #125320 - matthiaskrgr:rollup-go9b2jx, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #125219 (Update `unexpected_cfgs` lint for Cargo new `check-cfg` config) - #125255 (Make `EvalCtxt` generic over `InferCtxtLike`) - #125283 (Use a single static for all default slice Arcs.) - #125300 (rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper`) - #125309 (Fix `tests/debuginfo/strings-and-strs`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e8ada6a + b937bd3 commit 9fd1c38

33 files changed

+499
-267
lines changed

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+32-18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ fn check_cfg_expected_note(
4141
note
4242
}
4343

44+
enum EscapeQuotes {
45+
Yes,
46+
No,
47+
}
48+
49+
fn to_check_cfg_arg(name: Symbol, value: Option<Symbol>, quotes: EscapeQuotes) -> String {
50+
if let Some(value) = value {
51+
let value = str::escape_debug(value.as_str()).to_string();
52+
let values = match quotes {
53+
EscapeQuotes::Yes => format!("\\\"{}\\\"", value.replace("\"", "\\\\\\\\\"")),
54+
EscapeQuotes::No => format!("\"{value}\""),
55+
};
56+
format!("cfg({name}, values({values}))")
57+
} else {
58+
format!("cfg({name})")
59+
}
60+
}
61+
4462
pub(super) fn unexpected_cfg_name(
4563
sess: &Session,
4664
diag: &mut Diag<'_, ()>,
@@ -155,20 +173,18 @@ pub(super) fn unexpected_cfg_name(
155173
}
156174
}
157175

158-
let inst = if let Some((value, _value_span)) = value {
159-
let pre = if is_from_cargo { "\\" } else { "" };
160-
format!("cfg({name}, values({pre}\"{value}{pre}\"))")
161-
} else {
162-
format!("cfg({name})")
163-
};
176+
let inst = |escape_quotes| to_check_cfg_arg(name, value.map(|(v, _s)| v), escape_quotes);
164177

165178
if is_from_cargo {
166179
if !is_feature_cfg {
167-
diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo::rustc-check-cfg={inst}\");` to the top of the `build.rs`"));
180+
diag.help(format!("consider using a Cargo feature instead"));
181+
diag.help(format!("or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{}'] }}", inst(EscapeQuotes::No)));
182+
diag.help(format!("or consider adding `println!(\"cargo::rustc-check-cfg={}\");` to the top of the `build.rs`", inst(EscapeQuotes::Yes)));
168183
}
169-
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration");
184+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration");
170185
} else {
171-
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
186+
let inst = inst(EscapeQuotes::No);
187+
diag.help(format!("to expect this configuration use `--check-cfg={inst}`",));
172188
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
173189
}
174190
}
@@ -251,12 +267,7 @@ pub(super) fn unexpected_cfg_value(
251267
// do it if they want, but should not encourage them.
252268
let is_cfg_a_well_know_name = sess.psess.check_config.well_known_names.contains(&name);
253269

254-
let inst = if let Some((value, _value_span)) = value {
255-
let pre = if is_from_cargo { "\\" } else { "" };
256-
format!("cfg({name}, values({pre}\"{value}{pre}\"))")
257-
} else {
258-
format!("cfg({name})")
259-
};
270+
let inst = |escape_quotes| to_check_cfg_arg(name, value.map(|(v, _s)| v), escape_quotes);
260271

261272
if is_from_cargo {
262273
if name == sym::feature {
@@ -266,12 +277,15 @@ pub(super) fn unexpected_cfg_value(
266277
diag.help("consider defining some features in `Cargo.toml`");
267278
}
268279
} else if !is_cfg_a_well_know_name {
269-
diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo::rustc-check-cfg={inst}\");` to the top of the `build.rs`"));
280+
diag.help(format!("consider using a Cargo feature instead"));
281+
diag.help(format!("or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{}'] }}", inst(EscapeQuotes::No)));
282+
diag.help(format!("or consider adding `println!(\"cargo::rustc-check-cfg={}\");` to the top of the `build.rs`", inst(EscapeQuotes::Yes)));
270283
}
271-
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration");
284+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration");
272285
} else {
273286
if !is_cfg_a_well_know_name {
274-
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
287+
let inst = inst(EscapeQuotes::No);
288+
diag.help(format!("to expect this configuration use `--check-cfg={inst}`",));
275289
}
276290
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
277291
}

compiler/rustc_lint_defs/src/builtin.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3339,11 +3339,14 @@ declare_lint! {
33393339
///
33403340
/// ### Explanation
33413341
///
3342-
/// This lint is only active when `--check-cfg` arguments are being passed
3343-
/// to the compiler and triggers whenever an unexpected condition name or value is used.
3342+
/// This lint is only active when [`--check-cfg`][check-cfg] arguments are being
3343+
/// passed to the compiler and triggers whenever an unexpected condition name or value is
3344+
/// used.
3345+
///
3346+
/// See the [Checking Conditional Configurations][check-cfg] section for more
3347+
/// details.
33443348
///
3345-
/// The known condition include names or values passed in `--check-cfg`, and some
3346-
/// well-knows names and values built into the compiler.
3349+
/// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
33473350
pub UNEXPECTED_CFGS,
33483351
Warn,
33493352
"detects unexpected names and values in `#[cfg]` conditions",

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
233233
fn parent(self, def_id: Self::DefId) -> Self::DefId {
234234
self.parent(def_id)
235235
}
236+
237+
fn recursion_limit(self) -> usize {
238+
self.recursion_limit().0
239+
}
236240
}
237241

238242
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {

compiler/rustc_middle/src/ty/predicate.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ pub struct Predicate<'tcx>(
3737
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
3838
);
3939

40-
impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx> {}
40+
impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx> {
41+
fn is_coinductive(self, interner: TyCtxt<'tcx>) -> bool {
42+
self.is_coinductive(interner)
43+
}
44+
}
4145

4246
impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> {
4347
fn flags(&self) -> TypeFlags {

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
//! relate them structurally.
1717
1818
use super::EvalCtxt;
19+
use rustc_infer::infer::InferCtxt;
1920
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
2021
use rustc_middle::ty;
2122

22-
impl<'tcx> EvalCtxt<'_, 'tcx> {
23+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
2324
#[instrument(level = "trace", skip(self), ret)]
2425
pub(super) fn compute_alias_relate_goal(
2526
&mut self,

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
3-
use crate::solve::GoalSource;
4-
use crate::solve::{EvalCtxt, SolverMode};
53
use rustc_hir::def_id::DefId;
4+
use rustc_infer::infer::InferCtxt;
65
use rustc_infer::traits::query::NoSolution;
76
use rustc_middle::bug;
87
use rustc_middle::traits::solve::inspect::ProbeKind;
@@ -17,6 +16,9 @@ use rustc_middle::ty::{TypeVisitableExt, Upcast};
1716
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
1817
use std::fmt::Debug;
1918

19+
use crate::solve::GoalSource;
20+
use crate::solve::{EvalCtxt, SolverMode};
21+
2022
pub(super) mod structural_traits;
2123

2224
/// A candidate is a possible way to prove a goal.
@@ -46,18 +48,18 @@ pub(super) trait GoalKind<'tcx>:
4648
/// work, then produce a response (typically by executing
4749
/// [`EvalCtxt::evaluate_added_goals_and_make_canonical_response`]).
4850
fn probe_and_match_goal_against_assumption(
49-
ecx: &mut EvalCtxt<'_, 'tcx>,
51+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
5052
source: CandidateSource<'tcx>,
5153
goal: Goal<'tcx, Self>,
5254
assumption: ty::Clause<'tcx>,
53-
then: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> QueryResult<'tcx>,
55+
then: impl FnOnce(&mut EvalCtxt<'_, InferCtxt<'tcx>>) -> QueryResult<'tcx>,
5456
) -> Result<Candidate<'tcx>, NoSolution>;
5557

5658
/// Consider a clause, which consists of a "assumption" and some "requirements",
5759
/// to satisfy a goal. If the requirements hold, then attempt to satisfy our
5860
/// goal by equating it with the assumption.
5961
fn probe_and_consider_implied_clause(
60-
ecx: &mut EvalCtxt<'_, 'tcx>,
62+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
6163
parent_source: CandidateSource<'tcx>,
6264
goal: Goal<'tcx, Self>,
6365
assumption: ty::Clause<'tcx>,
@@ -75,7 +77,7 @@ pub(super) trait GoalKind<'tcx>:
7577
/// additionally checking all of the supertraits and object bounds to hold,
7678
/// since they're not implied by the well-formedness of the object type.
7779
fn probe_and_consider_object_bound_candidate(
78-
ecx: &mut EvalCtxt<'_, 'tcx>,
80+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
7981
source: CandidateSource<'tcx>,
8082
goal: Goal<'tcx, Self>,
8183
assumption: ty::Clause<'tcx>,
@@ -99,7 +101,7 @@ pub(super) trait GoalKind<'tcx>:
99101
}
100102

101103
fn consider_impl_candidate(
102-
ecx: &mut EvalCtxt<'_, 'tcx>,
104+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
103105
goal: Goal<'tcx, Self>,
104106
impl_def_id: DefId,
105107
) -> Result<Candidate<'tcx>, NoSolution>;
@@ -111,7 +113,7 @@ pub(super) trait GoalKind<'tcx>:
111113
/// Trait goals always hold while projection goals never do. This is a bit arbitrary
112114
/// but prevents incorrect normalization while hiding any trait errors.
113115
fn consider_error_guaranteed_candidate(
114-
ecx: &mut EvalCtxt<'_, 'tcx>,
116+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
115117
guar: ErrorGuaranteed,
116118
) -> Result<Candidate<'tcx>, NoSolution>;
117119

@@ -120,13 +122,13 @@ pub(super) trait GoalKind<'tcx>:
120122
/// These components are given by built-in rules from
121123
/// [`structural_traits::instantiate_constituent_tys_for_auto_trait`].
122124
fn consider_auto_trait_candidate(
123-
ecx: &mut EvalCtxt<'_, 'tcx>,
125+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
124126
goal: Goal<'tcx, Self>,
125127
) -> Result<Candidate<'tcx>, NoSolution>;
126128

127129
/// A trait alias holds if the RHS traits and `where` clauses hold.
128130
fn consider_trait_alias_candidate(
129-
ecx: &mut EvalCtxt<'_, 'tcx>,
131+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
130132
goal: Goal<'tcx, Self>,
131133
) -> Result<Candidate<'tcx>, NoSolution>;
132134

@@ -135,7 +137,7 @@ pub(super) trait GoalKind<'tcx>:
135137
/// These components are given by built-in rules from
136138
/// [`structural_traits::instantiate_constituent_tys_for_sized_trait`].
137139
fn consider_builtin_sized_candidate(
138-
ecx: &mut EvalCtxt<'_, 'tcx>,
140+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
139141
goal: Goal<'tcx, Self>,
140142
) -> Result<Candidate<'tcx>, NoSolution>;
141143

@@ -144,35 +146,35 @@ pub(super) trait GoalKind<'tcx>:
144146
/// These components are given by built-in rules from
145147
/// [`structural_traits::instantiate_constituent_tys_for_copy_clone_trait`].
146148
fn consider_builtin_copy_clone_candidate(
147-
ecx: &mut EvalCtxt<'_, 'tcx>,
149+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
148150
goal: Goal<'tcx, Self>,
149151
) -> Result<Candidate<'tcx>, NoSolution>;
150152

151153
/// A type is `PointerLike` if we can compute its layout, and that layout
152154
/// matches the layout of `usize`.
153155
fn consider_builtin_pointer_like_candidate(
154-
ecx: &mut EvalCtxt<'_, 'tcx>,
156+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
155157
goal: Goal<'tcx, Self>,
156158
) -> Result<Candidate<'tcx>, NoSolution>;
157159

158160
/// A type is a `FnPtr` if it is of `FnPtr` type.
159161
fn consider_builtin_fn_ptr_trait_candidate(
160-
ecx: &mut EvalCtxt<'_, 'tcx>,
162+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
161163
goal: Goal<'tcx, Self>,
162164
) -> Result<Candidate<'tcx>, NoSolution>;
163165

164166
/// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn<A>`
165167
/// family of traits where `A` is given by the signature of the type.
166168
fn consider_builtin_fn_trait_candidates(
167-
ecx: &mut EvalCtxt<'_, 'tcx>,
169+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
168170
goal: Goal<'tcx, Self>,
169171
kind: ty::ClosureKind,
170172
) -> Result<Candidate<'tcx>, NoSolution>;
171173

172174
/// An async closure is known to implement the `AsyncFn<A>` family of traits
173175
/// where `A` is given by the signature of the type.
174176
fn consider_builtin_async_fn_trait_candidates(
175-
ecx: &mut EvalCtxt<'_, 'tcx>,
177+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
176178
goal: Goal<'tcx, Self>,
177179
kind: ty::ClosureKind,
178180
) -> Result<Candidate<'tcx>, NoSolution>;
@@ -181,13 +183,13 @@ pub(super) trait GoalKind<'tcx>:
181183
/// is used internally to delay computation for async closures until after
182184
/// upvar analysis is performed in HIR typeck.
183185
fn consider_builtin_async_fn_kind_helper_candidate(
184-
ecx: &mut EvalCtxt<'_, 'tcx>,
186+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
185187
goal: Goal<'tcx, Self>,
186188
) -> Result<Candidate<'tcx>, NoSolution>;
187189

188190
/// `Tuple` is implemented if the `Self` type is a tuple.
189191
fn consider_builtin_tuple_candidate(
190-
ecx: &mut EvalCtxt<'_, 'tcx>,
192+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
191193
goal: Goal<'tcx, Self>,
192194
) -> Result<Candidate<'tcx>, NoSolution>;
193195

@@ -197,63 +199,63 @@ pub(super) trait GoalKind<'tcx>:
197199
/// the built-in types. For structs, the metadata type is given by the struct
198200
/// tail.
199201
fn consider_builtin_pointee_candidate(
200-
ecx: &mut EvalCtxt<'_, 'tcx>,
202+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
201203
goal: Goal<'tcx, Self>,
202204
) -> Result<Candidate<'tcx>, NoSolution>;
203205

204206
/// A coroutine (that comes from an `async` desugaring) is known to implement
205207
/// `Future<Output = O>`, where `O` is given by the coroutine's return type
206208
/// that was computed during type-checking.
207209
fn consider_builtin_future_candidate(
208-
ecx: &mut EvalCtxt<'_, 'tcx>,
210+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
209211
goal: Goal<'tcx, Self>,
210212
) -> Result<Candidate<'tcx>, NoSolution>;
211213

212214
/// A coroutine (that comes from a `gen` desugaring) is known to implement
213215
/// `Iterator<Item = O>`, where `O` is given by the generator's yield type
214216
/// that was computed during type-checking.
215217
fn consider_builtin_iterator_candidate(
216-
ecx: &mut EvalCtxt<'_, 'tcx>,
218+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
217219
goal: Goal<'tcx, Self>,
218220
) -> Result<Candidate<'tcx>, NoSolution>;
219221

220222
/// A coroutine (that comes from a `gen` desugaring) is known to implement
221223
/// `FusedIterator`
222224
fn consider_builtin_fused_iterator_candidate(
223-
ecx: &mut EvalCtxt<'_, 'tcx>,
225+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
224226
goal: Goal<'tcx, Self>,
225227
) -> Result<Candidate<'tcx>, NoSolution>;
226228

227229
fn consider_builtin_async_iterator_candidate(
228-
ecx: &mut EvalCtxt<'_, 'tcx>,
230+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
229231
goal: Goal<'tcx, Self>,
230232
) -> Result<Candidate<'tcx>, NoSolution>;
231233

232234
/// A coroutine (that doesn't come from an `async` or `gen` desugaring) is known to
233235
/// implement `Coroutine<R, Yield = Y, Return = O>`, given the resume, yield,
234236
/// and return types of the coroutine computed during type-checking.
235237
fn consider_builtin_coroutine_candidate(
236-
ecx: &mut EvalCtxt<'_, 'tcx>,
238+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
237239
goal: Goal<'tcx, Self>,
238240
) -> Result<Candidate<'tcx>, NoSolution>;
239241

240242
fn consider_builtin_discriminant_kind_candidate(
241-
ecx: &mut EvalCtxt<'_, 'tcx>,
243+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
242244
goal: Goal<'tcx, Self>,
243245
) -> Result<Candidate<'tcx>, NoSolution>;
244246

245247
fn consider_builtin_async_destruct_candidate(
246-
ecx: &mut EvalCtxt<'_, 'tcx>,
248+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
247249
goal: Goal<'tcx, Self>,
248250
) -> Result<Candidate<'tcx>, NoSolution>;
249251

250252
fn consider_builtin_destruct_candidate(
251-
ecx: &mut EvalCtxt<'_, 'tcx>,
253+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
252254
goal: Goal<'tcx, Self>,
253255
) -> Result<Candidate<'tcx>, NoSolution>;
254256

255257
fn consider_builtin_transmute_candidate(
256-
ecx: &mut EvalCtxt<'_, 'tcx>,
258+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
257259
goal: Goal<'tcx, Self>,
258260
) -> Result<Candidate<'tcx>, NoSolution>;
259261

@@ -265,12 +267,12 @@ pub(super) trait GoalKind<'tcx>:
265267
/// otherwise recompute this for codegen. This is a bit of a mess but the
266268
/// easiest way to maintain the existing behavior for now.
267269
fn consider_structural_builtin_unsize_candidates(
268-
ecx: &mut EvalCtxt<'_, 'tcx>,
270+
ecx: &mut EvalCtxt<'_, InferCtxt<'tcx>>,
269271
goal: Goal<'tcx, Self>,
270272
) -> Vec<Candidate<'tcx>>;
271273
}
272274

273-
impl<'tcx> EvalCtxt<'_, 'tcx> {
275+
impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
274276
pub(super) fn assemble_and_evaluate_candidates<G: GoalKind<'tcx>>(
275277
&mut self,
276278
goal: Goal<'tcx, G>,

0 commit comments

Comments
 (0)