Skip to content

Commit 8a73f50

Browse files
committed
Auto merge of rust-lang#109019 - matthiaskrgr:rollup-ihjntil, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#104363 (Make `unused_allocation` lint against `Box::new` too) - rust-lang#106633 (Stabilize `nonzero_min_max`) - rust-lang#106844 (allow negative numeric literals in `concat!`) - rust-lang#108071 (Implement goal caching with the new solver) - rust-lang#108542 (Force parentheses around `match` expression in binary expression) - rust-lang#108690 (Place size limits on query keys and values) - rust-lang#108708 (Prevent overflow through Arc::downgrade) - rust-lang#108739 (Prevent the `start_bx` basic block in codegen from having two `Builder`s at the same time) - rust-lang#108806 (Querify register_tools and post-expansion early lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67e1681 + df50001 commit 8a73f50

File tree

45 files changed

+445
-272
lines changed

Some content is hidden

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

45 files changed

+445
-272
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ fn compute_hir_hash(
436436
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
437437
let sess = tcx.sess;
438438
tcx.ensure().output_filenames(());
439+
let _ = tcx.early_lint_checks(()); // Borrows `resolver_for_lowering`.
439440
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
440441

441442
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ impl<'a> State<'a> {
244244
(&ast::ExprKind::Let { .. }, _) if !parser::needs_par_as_let_scrutinee(prec) => {
245245
parser::PREC_FORCE_PAREN
246246
}
247+
// For a binary expression like `(match () { _ => a }) OP b`, the parens are required
248+
// otherwise the parser would interpret `match () { _ => a }` as a statement,
249+
// with the remaining `OP b` not making sense. So we force parens.
250+
(&ast::ExprKind::Match(..), _) => parser::PREC_FORCE_PAREN,
247251
_ => left_prec,
248252
};
249253

compiler/rustc_builtin_macros/src/concat.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ pub fn expand_concat(
4242
has_errors = true;
4343
}
4444
},
45+
// We also want to allow negative numeric literals.
46+
ast::ExprKind::Unary(ast::UnOp::Neg, ref expr) if let ast::ExprKind::Lit(token_lit) = expr.kind => {
47+
match ast::LitKind::from_token_lit(token_lit) {
48+
Ok(ast::LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
49+
Ok(ast::LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
50+
Err(err) => {
51+
report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span);
52+
has_errors = true;
53+
}
54+
_ => missing_literal.push(e.span),
55+
}
56+
}
4557
ast::ExprKind::IncludedBytes(..) => {
4658
cx.span_err(e.span, "cannot concatenate a byte string literal")
4759
}
@@ -53,9 +65,10 @@ pub fn expand_concat(
5365
}
5466
}
5567
}
68+
5669
if !missing_literal.is_empty() {
5770
let mut err = cx.struct_span_err(missing_literal, "expected a literal");
58-
err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`");
71+
err.note("only literals (like `\"foo\"`, `-42` and `3.14`) can be passed to `concat!()`");
5972
err.emit();
6073
return DummyResult::any(sp);
6174
} else if has_errors {

compiler/rustc_codegen_ssa/src/mir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
258258
// Apply debuginfo to the newly allocated locals.
259259
fx.debug_introduce_locals(&mut start_bx);
260260

261+
// The builders will be created separately for each basic block at `codegen_block`.
262+
// So drop the builder of `start_llbb` to avoid having two at the same time.
263+
drop(start_bx);
264+
261265
// Codegen the body of each block using reverse postorder
262266
for (bb, _) in traversal::reverse_postorder(&mir) {
263267
fx.codegen_block(bb);

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ fn run_compiler(
331331
if let Some(ppm) = &sess.opts.pretty {
332332
if ppm.needs_ast_map() {
333333
queries.global_ctxt()?.enter(|tcx| {
334+
tcx.ensure().early_lint_checks(());
334335
pretty::print_after_hir_lowering(tcx, *ppm);
335336
Ok(())
336337
})?;

compiler/rustc_expand/src/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use rustc_ast::tokenstream::TokenStream;
1212
use rustc_ast::visit::{AssocCtxt, Visitor};
1313
use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind};
1414
use rustc_attr::{self as attr, Deprecation, Stability};
15-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
15+
use rustc_data_structures::fx::FxIndexMap;
1616
use rustc_data_structures::sync::{self, Lrc};
1717
use rustc_errors::{
1818
Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult,
1919
};
2020
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
21-
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
21+
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools};
2222
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
2323
use rustc_session::errors::report_lit_error;
2424
use rustc_session::{parse::ParseSess, Limit, Session};
@@ -947,14 +947,14 @@ pub trait ResolverExpand {
947947
fn declare_proc_macro(&mut self, id: NodeId);
948948

949949
/// Tools registered with `#![register_tool]` and used by tool attributes and lints.
950-
fn registered_tools(&self) -> &FxHashSet<Ident>;
950+
fn registered_tools(&self) -> &RegisteredTools;
951951
}
952952

953953
pub trait LintStoreExpand {
954954
fn pre_expansion_lint(
955955
&self,
956956
sess: &Session,
957-
registered_tools: &FxHashSet<Ident>,
957+
registered_tools: &RegisteredTools,
958958
node_id: NodeId,
959959
attrs: &[Attribute],
960960
items: &[P<Item>],

compiler/rustc_infer/src/traits/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ pub struct Obligation<'tcx, T> {
5353
pub recursion_depth: usize,
5454
}
5555

56+
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
57+
fn from(value: Obligation<'tcx, P>) -> Self {
58+
solve::Goal { param_env: value.param_env, predicate: value.predicate }
59+
}
60+
}
61+
5662
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
5763
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5864

compiler/rustc_interface/src/passes.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::parallel;
1111
use rustc_data_structures::steal::Steal;
1212
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
1313
use rustc_errors::PResult;
14-
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
14+
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
1515
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
1616
use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore};
1717
use rustc_metadata::creader::CStore;
@@ -178,7 +178,7 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
178178
let sess = tcx.sess;
179179
let lint_store = unerased_lint_store(tcx);
180180
let crate_name = tcx.crate_name(LOCAL_CRATE);
181-
pre_expansion_lint(sess, lint_store, resolver.registered_tools(), &krate, crate_name);
181+
pre_expansion_lint(sess, lint_store, tcx.registered_tools(()), &krate, crate_name);
182182
rustc_builtin_macros::register_builtin_macros(resolver);
183183

184184
krate = sess.time("crate_injection", || {
@@ -302,6 +302,16 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
302302

303303
// Done with macro expansion!
304304

305+
resolver.resolve_crate(&krate);
306+
307+
krate
308+
}
309+
310+
fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
311+
let sess = tcx.sess;
312+
let (resolver, krate) = &*tcx.resolver_for_lowering(()).borrow();
313+
let mut lint_buffer = resolver.lint_buffer.steal();
314+
305315
if sess.opts.unstable_opts.input_stats {
306316
eprintln!("Post-expansion node count: {}", count_nodes(&krate));
307317
}
@@ -310,8 +320,6 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
310320
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS", "ast-stats-2");
311321
}
312322

313-
resolver.resolve_crate(&krate);
314-
315323
// Needs to go *after* expansion to be able to check the results of macro expansion.
316324
sess.time("complete_gated_feature_checking", || {
317325
rustc_ast_passes::feature_gate::check_crate(&krate, sess);
@@ -321,7 +329,7 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
321329
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
322330
info!("{} parse sess buffered_lints", buffered_lints.len());
323331
for early_lint in buffered_lints.drain(..) {
324-
resolver.lint_buffer().add_early_lint(early_lint);
332+
lint_buffer.add_early_lint(early_lint);
325333
}
326334
});
327335

@@ -340,20 +348,16 @@ fn configure_and_expand(mut krate: ast::Crate, resolver: &mut Resolver<'_, '_>)
340348
}
341349
});
342350

343-
sess.time("early_lint_checks", || {
344-
let lint_buffer = Some(std::mem::take(resolver.lint_buffer()));
345-
rustc_lint::check_ast_node(
346-
sess,
347-
false,
348-
lint_store,
349-
resolver.registered_tools(),
350-
lint_buffer,
351-
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
352-
&krate,
353-
)
354-
});
355-
356-
krate
351+
let lint_store = unerased_lint_store(tcx);
352+
rustc_lint::check_ast_node(
353+
sess,
354+
false,
355+
lint_store,
356+
tcx.registered_tools(()),
357+
Some(lint_buffer),
358+
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
359+
&**krate,
360+
)
357361
}
358362

359363
// Returns all the paths that correspond to generated files.
@@ -557,6 +561,7 @@ fn resolver_for_lowering<'tcx>(
557561
(): (),
558562
) -> &'tcx Steal<(ty::ResolverAstLowering, Lrc<ast::Crate>)> {
559563
let arenas = Resolver::arenas();
564+
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
560565
let krate = tcx.crate_for_resolver(()).steal();
561566
let mut resolver = Resolver::new(tcx, &krate, &arenas);
562567
let krate = configure_and_expand(krate, &mut resolver);
@@ -629,6 +634,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
629634
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
630635
providers.output_filenames = output_filenames;
631636
providers.resolver_for_lowering = resolver_for_lowering;
637+
providers.early_lint_checks = early_lint_checks;
632638
proc_macro_decls::provide(providers);
633639
rustc_const_eval::provide(providers);
634640
rustc_middle::hir::provide(providers);
@@ -637,6 +643,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
637643
rustc_mir_transform::provide(providers);
638644
rustc_monomorphize::provide(providers);
639645
rustc_privacy::provide(providers);
646+
rustc_resolve::provide(providers);
640647
rustc_hir_analysis::provide(providers);
641648
rustc_hir_typeck::provide(providers);
642649
ty::provide(providers);

compiler/rustc_lint/src/levels.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
128128
},
129129
warn_about_weird_lints: false,
130130
store,
131-
registered_tools: &tcx.resolutions(()).registered_tools,
131+
registered_tools: &tcx.registered_tools(()),
132132
};
133133

134134
builder.add_command_line();
@@ -156,7 +156,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
156156
},
157157
warn_about_weird_lints: false,
158158
store,
159-
registered_tools: &tcx.resolutions(()).registered_tools,
159+
registered_tools: &tcx.registered_tools(()),
160160
};
161161

162162
if owner == hir::CRATE_OWNER_ID {

compiler/rustc_lint/src/unused.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,8 @@ declare_lint! {
13491349
/// ### Example
13501350
///
13511351
/// ```rust
1352-
/// #![feature(box_syntax)]
13531352
/// fn main() {
1354-
/// let a = (box [1, 2, 3]).len();
1353+
/// let a = Box::new([1, 2, 3]).len();
13551354
/// }
13561355
/// ```
13571356
///
@@ -1373,6 +1372,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
13731372
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
13741373
match e.kind {
13751374
hir::ExprKind::Box(_) => {}
1375+
hir::ExprKind::Call(path_expr, [_])
1376+
if let hir::ExprKind::Path(qpath) = &path_expr.kind
1377+
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()
1378+
&& cx.tcx.is_diagnostic_item(sym::box_new, did)
1379+
=> {}
13761380
_ => return,
13771381
}
13781382

compiler/rustc_lint_defs/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate rustc_macros;
88
pub use self::Level::*;
99
use rustc_ast::node_id::NodeId;
1010
use rustc_ast::{AttrId, Attribute};
11-
use rustc_data_structures::fx::FxIndexMap;
11+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1212
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
1313
use rustc_error_messages::{DiagnosticMessage, MultiSpan};
1414
use rustc_hir::HashStableContext;
@@ -533,6 +533,7 @@ pub enum BuiltinLintDiagnostics {
533533

534534
/// Lints that are buffered up early on in the `Session` before the
535535
/// `LintLevels` is calculated.
536+
#[derive(Debug)]
536537
pub struct BufferedEarlyLint {
537538
/// The span of code that we are linting on.
538539
pub span: MultiSpan,
@@ -551,7 +552,7 @@ pub struct BufferedEarlyLint {
551552
pub diagnostic: BuiltinLintDiagnostics,
552553
}
553554

554-
#[derive(Default)]
555+
#[derive(Default, Debug)]
555556
pub struct LintBuffer {
556557
pub map: FxIndexMap<NodeId, Vec<BufferedEarlyLint>>,
557558
}
@@ -601,6 +602,8 @@ impl LintBuffer {
601602
}
602603
}
603604

605+
pub type RegisteredTools = FxIndexSet<Ident>;
606+
604607
/// Declares a static item of type `&'static Lint`.
605608
///
606609
/// See <https://rustc-dev-guide.rust-lang.org/diagnostics.html> for

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ macro_rules! arena_types {
108108
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
109109
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
110110
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
111+
[decode] registered_tools: rustc_middle::ty::RegisteredTools,
111112
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
112113
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
113114

compiler/rustc_middle/src/query/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ rustc_queries! {
2626
desc { "triggering a delay span bug" }
2727
}
2828

29+
query registered_tools(_: ()) -> &'tcx ty::RegisteredTools {
30+
arena_cache
31+
desc { "compute registered tools for crate" }
32+
}
33+
34+
query early_lint_checks(_: ()) -> () {
35+
desc { "perform lints prior to macro expansion" }
36+
}
37+
2938
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
3039
feedable
3140
no_hash

0 commit comments

Comments
 (0)