Skip to content

Commit 42313dd

Browse files
committed
Auto merge of rust-lang#93245 - matthiaskrgr:rollup-djsi6jr, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#91526 (rustc_lint: Some early linting refactorings) - rust-lang#92555 (Implement RFC 3151: Scoped threads.) - rust-lang#93213 (Fix `let_chains` and `if_let_guard` feature flags) - rust-lang#93219 (Add preliminary support for inline assembly for msp430.) - rust-lang#93226 (Normalize field access types during borrowck) - rust-lang#93227 (Liberate late bound regions when collecting GAT substs in wfcheck) - rust-lang#93229 (Remove DiagnosticBuilder.quiet) - rust-lang#93234 (rustc_mir_itertools: Avoid needless `collect` with itertools) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 84322ef + eea833f commit 42313dd

File tree

66 files changed

+1136
-330
lines changed

Some content is hidden

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

66 files changed

+1136
-330
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
758758
},
759759
ProjectionElem::Field(field, fty) => {
760760
let fty = self.sanitize_type(place, fty);
761+
let fty = self.cx.normalize(fty, location);
761762
match self.field_ty(place, base, field, location) {
762763
Ok(ty) => {
763764
let ty = self.cx.normalize(ty, location);

compiler/rustc_codegen_gcc/src/asm.rs

+3
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
560560
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => unimplemented!(),
561561
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => unimplemented!(),
562562
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::freg) => unimplemented!(),
563+
InlineAsmRegClass::Msp430(_) => unimplemented!(),
563564
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => unimplemented!(),
564565
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => unimplemented!(),
565566
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => unimplemented!(),
@@ -622,6 +623,7 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
622623
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
623624
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),
624625
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::freg) => cx.type_f32(),
626+
InlineAsmRegClass::Msp430(_) => unimplemented!(),
625627
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => cx.type_i16(),
626628
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => cx.type_i32(),
627629
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => cx.type_i64(),
@@ -729,6 +731,7 @@ fn modifier_to_gcc(arch: InlineAsmArch, reg: InlineAsmRegClass, modifier: Option
729731
InlineAsmRegClass::Bpf(_) => unimplemented!(),
730732
InlineAsmRegClass::Hexagon(_) => unimplemented!(),
731733
InlineAsmRegClass::Mips(_) => unimplemented!(),
734+
InlineAsmRegClass::Msp430(_) => unimplemented!(),
732735
InlineAsmRegClass::Nvptx(_) => unimplemented!(),
733736
InlineAsmRegClass::PowerPC(_) => unimplemented!(),
734737
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)

compiler/rustc_codegen_llvm/src/asm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
232232
InlineAsmArch::SpirV => {}
233233
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
234234
InlineAsmArch::Bpf => {}
235+
InlineAsmArch::Msp430 => {
236+
constraints.push("~{sr}".to_string());
237+
}
235238
}
236239
}
237240
if !options.contains(InlineAsmOptions::NOMEM) {
@@ -580,6 +583,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
580583
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => "e",
581584
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
582585
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
586+
InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => "r",
583587
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
584588
bug!("LLVM backend does not support SPIR-V")
585589
}
@@ -666,6 +670,7 @@ fn modifier_to_llvm(
666670
},
667671
InlineAsmRegClass::Avr(_) => None,
668672
InlineAsmRegClass::S390x(_) => None,
673+
InlineAsmRegClass::Msp430(_) => None,
669674
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
670675
bug!("LLVM backend does not support SPIR-V")
671676
}
@@ -734,6 +739,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
734739
InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => cx.type_i16(),
735740
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
736741
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
742+
InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => cx.type_i16(),
737743
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
738744
bug!("LLVM backend does not support SPIR-V")
739745
}

compiler/rustc_errors/src/lib.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,6 @@ struct HandlerInner {
445445
deduplicated_warn_count: usize,
446446

447447
future_breakage_diagnostics: Vec<Diagnostic>,
448-
449-
/// If set to `true`, no warning or error will be emitted.
450-
quiet: bool,
451448
}
452449

453450
/// A key denoting where from a diagnostic was stashed.
@@ -563,19 +560,10 @@ impl Handler {
563560
emitted_diagnostics: Default::default(),
564561
stashed_diagnostics: Default::default(),
565562
future_breakage_diagnostics: Vec::new(),
566-
quiet: false,
567563
}),
568564
}
569565
}
570566

571-
pub fn with_disabled_diagnostic<T, F: FnOnce() -> T>(&self, f: F) -> T {
572-
let prev = self.inner.borrow_mut().quiet;
573-
self.inner.borrow_mut().quiet = true;
574-
let ret = f();
575-
self.inner.borrow_mut().quiet = prev;
576-
ret
577-
}
578-
579567
// This is here to not allow mutation of flags;
580568
// as of this writing it's only used in tests in librustc_middle.
581569
pub fn can_emit_warnings(&self) -> bool {
@@ -946,7 +934,7 @@ impl HandlerInner {
946934
}
947935

948936
fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) {
949-
if diagnostic.cancelled() || self.quiet {
937+
if diagnostic.cancelled() {
950938
return;
951939
}
952940

@@ -1170,9 +1158,6 @@ impl HandlerInner {
11701158
}
11711159

11721160
fn delay_as_bug(&mut self, diagnostic: Diagnostic) {
1173-
if self.quiet {
1174-
return;
1175-
}
11761161
if self.flags.report_delayed_bugs {
11771162
self.emit_diagnostic(&diagnostic);
11781163
}

compiler/rustc_expand/src/base.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream};
88
use rustc_ast::visit::{AssocCtxt, Visitor};
99
use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
1010
use rustc_attr::{self as attr, Deprecation, Stability};
11-
use rustc_data_structures::fx::FxHashMap;
11+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_data_structures::sync::{self, Lrc};
1313
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
1414
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
@@ -920,8 +920,25 @@ pub trait ResolverExpand {
920920
/// we generated proc macros harnesses, so that we can map
921921
/// HIR proc macros items back to their harness items.
922922
fn declare_proc_macro(&mut self, id: NodeId);
923+
924+
/// Tools registered with `#![register_tool]` and used by tool attributes and lints.
925+
fn registered_tools(&self) -> &FxHashSet<Ident>;
923926
}
924927

928+
pub trait LintStoreExpand {
929+
fn pre_expansion_lint(
930+
&self,
931+
sess: &Session,
932+
registered_tools: &FxHashSet<Ident>,
933+
node_id: NodeId,
934+
attrs: &[Attribute],
935+
items: &[P<Item>],
936+
name: &str,
937+
);
938+
}
939+
940+
type LintStoreExpandDyn<'a> = Option<&'a (dyn LintStoreExpand + 'a)>;
941+
925942
#[derive(Clone, Default)]
926943
pub struct ModuleData {
927944
/// Path to the module starting from the crate name, like `my_crate::foo::bar`.
@@ -956,9 +973,6 @@ pub struct ExpansionData {
956973
pub is_trailing_mac: bool,
957974
}
958975

959-
type OnExternModLoaded<'a> =
960-
Option<&'a dyn Fn(Ident, Vec<Attribute>, Vec<P<Item>>, Span) -> (Vec<Attribute>, Vec<P<Item>>)>;
961-
962976
/// One of these is made during expansion and incrementally updated as we go;
963977
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
964978
/// -> expn_data` of their expansion context stored into their span.
@@ -973,10 +987,8 @@ pub struct ExtCtxt<'a> {
973987
/// (or during eager expansion, but that's a hack).
974988
pub force_mode: bool,
975989
pub expansions: FxHashMap<Span, Vec<String>>,
976-
/// Called directly after having parsed an external `mod foo;` in expansion.
977-
///
978-
/// `Ident` is the module name.
979-
pub(super) extern_mod_loaded: OnExternModLoaded<'a>,
990+
/// Used for running pre-expansion lints on freshly loaded modules.
991+
pub(super) lint_store: LintStoreExpandDyn<'a>,
980992
/// When we 'expand' an inert attribute, we leave it
981993
/// in the AST, but insert it here so that we know
982994
/// not to expand it again.
@@ -988,14 +1000,14 @@ impl<'a> ExtCtxt<'a> {
9881000
sess: &'a Session,
9891001
ecfg: expand::ExpansionConfig<'a>,
9901002
resolver: &'a mut dyn ResolverExpand,
991-
extern_mod_loaded: OnExternModLoaded<'a>,
1003+
lint_store: LintStoreExpandDyn<'a>,
9921004
) -> ExtCtxt<'a> {
9931005
ExtCtxt {
9941006
sess,
9951007
ecfg,
9961008
reduced_recursion_limit: None,
9971009
resolver,
998-
extern_mod_loaded,
1010+
lint_store,
9991011
root_path: PathBuf::new(),
10001012
current_expansion: ExpansionData {
10011013
id: LocalExpnId::ROOT,

compiler/rustc_expand/src/expand.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ impl InvocationCollectorNode for P<ast::Item> {
10971097
ModKind::Unloaded => {
10981098
// We have an outline `mod foo;` so we need to parse the file.
10991099
let old_attrs_len = attrs.len();
1100-
let ParsedExternalMod { mut items, inner_span, file_path, dir_path, dir_ownership } =
1100+
let ParsedExternalMod { items, inner_span, file_path, dir_path, dir_ownership } =
11011101
parse_external_mod(
11021102
&ecx.sess,
11031103
ident,
@@ -1107,8 +1107,15 @@ impl InvocationCollectorNode for P<ast::Item> {
11071107
&mut attrs,
11081108
);
11091109

1110-
if let Some(extern_mod_loaded) = ecx.extern_mod_loaded {
1111-
(attrs, items) = extern_mod_loaded(ident, attrs, items, inner_span);
1110+
if let Some(lint_store) = ecx.lint_store {
1111+
lint_store.pre_expansion_lint(
1112+
ecx.sess,
1113+
ecx.resolver.registered_tools(),
1114+
ecx.current_expansion.lint_node_id,
1115+
&attrs,
1116+
&items,
1117+
ident.name.as_str(),
1118+
);
11121119
}
11131120

11141121
*mod_kind = ModKind::Loaded(items, Inline::No, inner_span);

compiler/rustc_interface/src/passes.rs

+40-27
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ use crate::proc_macro_decls;
33
use crate::util;
44

55
use rustc_ast::mut_visit::MutVisitor;
6-
use rustc_ast::{self as ast, visit, DUMMY_NODE_ID};
6+
use rustc_ast::{self as ast, visit};
77
use rustc_borrowck as mir_borrowck;
88
use rustc_codegen_ssa::back::link::emit_metadata;
99
use rustc_codegen_ssa::traits::CodegenBackend;
1010
use rustc_data_structures::parallel;
1111
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
1212
use rustc_data_structures::temp_dir::MaybeTempDir;
1313
use rustc_errors::{Applicability, ErrorReported, PResult};
14-
use rustc_expand::base::ExtCtxt;
14+
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
1515
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
1616
use rustc_hir::Crate;
17-
use rustc_lint::LintStore;
17+
use rustc_lint::{EarlyCheckNode, LintStore};
1818
use rustc_metadata::creader::CStore;
1919
use rustc_metadata::{encode_metadata, EncodedMetadata};
2020
use rustc_middle::arena::Arena;
2121
use rustc_middle::dep_graph::DepGraph;
2222
use rustc_middle::ty::query::{ExternProviders, Providers};
23-
use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
23+
use rustc_middle::ty::{self, GlobalCtxt, RegisteredTools, ResolverOutputs, TyCtxt};
2424
use rustc_mir_build as mir_build;
2525
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
2626
use rustc_passes::{self, hir_stats, layout_test};
@@ -34,7 +34,7 @@ use rustc_session::lint;
3434
use rustc_session::output::{filename_for_input, filename_for_metadata};
3535
use rustc_session::search_paths::PathKind;
3636
use rustc_session::{Limit, Session};
37-
use rustc_span::symbol::{sym, Ident, Symbol};
37+
use rustc_span::symbol::{sym, Symbol};
3838
use rustc_span::{FileName, MultiSpan};
3939
use rustc_trait_selection::traits;
4040
use rustc_typeck as typeck;
@@ -233,26 +233,43 @@ pub fn register_plugins<'a>(
233233
Ok((krate, lint_store))
234234
}
235235

236-
fn pre_expansion_lint(
236+
fn pre_expansion_lint<'a>(
237237
sess: &Session,
238238
lint_store: &LintStore,
239-
krate: &ast::Crate,
240-
crate_attrs: &[ast::Attribute],
241-
crate_name: &str,
239+
registered_tools: &RegisteredTools,
240+
check_node: impl EarlyCheckNode<'a>,
241+
node_name: &str,
242242
) {
243-
sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", crate_name).run(|| {
244-
rustc_lint::check_ast_crate(
243+
sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name).run(|| {
244+
rustc_lint::check_ast_node(
245245
sess,
246-
lint_store,
247-
krate,
248-
crate_attrs,
249246
true,
247+
lint_store,
248+
registered_tools,
250249
None,
251250
rustc_lint::BuiltinCombinedPreExpansionLintPass::new(),
251+
check_node,
252252
);
253253
});
254254
}
255255

256+
// Cannot implement directly for `LintStore` due to trait coherence.
257+
struct LintStoreExpandImpl<'a>(&'a LintStore);
258+
259+
impl LintStoreExpand for LintStoreExpandImpl<'_> {
260+
fn pre_expansion_lint(
261+
&self,
262+
sess: &Session,
263+
registered_tools: &RegisteredTools,
264+
node_id: ast::NodeId,
265+
attrs: &[ast::Attribute],
266+
items: &[rustc_ast::ptr::P<ast::Item>],
267+
name: &str,
268+
) {
269+
pre_expansion_lint(sess, self.0, registered_tools, (node_id, attrs, items), name);
270+
}
271+
}
272+
256273
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
257274
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
258275
/// harness if one is to be provided, injection of a dependency on the
@@ -265,7 +282,7 @@ pub fn configure_and_expand(
265282
resolver: &mut Resolver<'_>,
266283
) -> Result<ast::Crate> {
267284
tracing::trace!("configure_and_expand");
268-
pre_expansion_lint(sess, lint_store, &krate, &krate.attrs, crate_name);
285+
pre_expansion_lint(sess, lint_store, resolver.registered_tools(), &krate, crate_name);
269286
rustc_builtin_macros::register_builtin_macros(resolver);
270287

271288
krate = sess.time("crate_injection", || {
@@ -321,13 +338,8 @@ pub fn configure_and_expand(
321338
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
322339
};
323340

324-
let crate_attrs = krate.attrs.clone();
325-
let extern_mod_loaded = |ident: Ident, attrs, items, span| {
326-
let krate = ast::Crate { attrs, items, span, id: DUMMY_NODE_ID, is_placeholder: false };
327-
pre_expansion_lint(sess, lint_store, &krate, &crate_attrs, ident.name.as_str());
328-
(krate.attrs, krate.items)
329-
};
330-
let mut ecx = ExtCtxt::new(sess, cfg, resolver, Some(&extern_mod_loaded));
341+
let lint_store = LintStoreExpandImpl(lint_store);
342+
let mut ecx = ExtCtxt::new(sess, cfg, resolver, Some(&lint_store));
331343

332344
// Expand macros now!
333345
let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));
@@ -499,14 +511,15 @@ pub fn lower_to_hir<'res, 'tcx>(
499511
);
500512

501513
sess.time("early_lint_checks", || {
502-
rustc_lint::check_ast_crate(
514+
let lint_buffer = Some(std::mem::take(resolver.lint_buffer()));
515+
rustc_lint::check_ast_node(
503516
sess,
504-
lint_store,
505-
&krate,
506-
&krate.attrs,
507517
false,
508-
Some(std::mem::take(resolver.lint_buffer())),
518+
lint_store,
519+
resolver.registered_tools(),
520+
lint_buffer,
509521
rustc_lint::BuiltinCombinedEarlyLintPass::new(),
522+
&*krate,
510523
)
511524
});
512525

0 commit comments

Comments
 (0)