Skip to content

Commit 0406441

Browse files
committed
Auto merge of #80928 - JohnTitor:rollup-sgerm3j, r=JohnTitor
Rollup of 9 pull requests Successful merges: - #79997 (Emit a reactor for cdylib target on wasi) - #79998 (Use correct ABI for wasm32 by default) - #80042 (Split a func into cold/hot parts, reducing binary size) - #80324 (Explain method-call move errors in loops) - #80864 (std/core docs: fix wrong link in PartialEq) - #80870 (resolve: Simplify built-in macro table) - #80885 (rustdoc: Resolve `&str` as `str`) - #80904 (Fix small typo) - #80923 (Merge different function exits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe531d5 + 4e69c5d commit 0406441

File tree

36 files changed

+231
-153
lines changed

36 files changed

+231
-153
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ extern crate proc_macro;
1414

1515
use crate::deriving::*;
1616

17-
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
17+
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
1818
use rustc_expand::proc_macro::BangProcMacro;
19-
use rustc_span::edition::Edition;
20-
use rustc_span::symbol::{sym, Ident};
19+
use rustc_span::symbol::sym;
2120

2221
mod asm;
2322
mod assert;
@@ -44,13 +43,8 @@ pub mod proc_macro_harness;
4443
pub mod standard_library_imports;
4544
pub mod test_harness;
4645

47-
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
48-
let mut register = |name, kind| {
49-
resolver.register_builtin_macro(
50-
Ident::with_dummy_span(name),
51-
SyntaxExtension::default(kind, edition),
52-
)
53-
};
46+
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
47+
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
5448
macro register_bang($($name:ident: $f:expr,)*) {
5549
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
5650
}

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ fn exec_linker(
12761276

12771277
fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
12781278
let kind = match (crate_type, sess.crt_static(Some(crate_type)), sess.relocation_model()) {
1279+
(CrateType::Executable, _, _) if sess.is_wasi_reactor() => LinkOutputKind::WasiReactorExe,
12791280
(CrateType::Executable, false, RelocModel::Pic) => LinkOutputKind::DynamicPicExe,
12801281
(CrateType::Executable, false, _) => LinkOutputKind::DynamicNoPicExe,
12811282
(CrateType::Executable, true, RelocModel::Pic) => LinkOutputKind::StaticPicExe,

compiler/rustc_codegen_ssa/src/back/linker.rs

+11
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ impl<'a> Linker for GccLinker<'a> {
314314
self.cmd.arg("-static");
315315
self.build_dylib(out_filename);
316316
}
317+
LinkOutputKind::WasiReactorExe => {
318+
self.linker_arg("--entry");
319+
self.linker_arg("_initialize");
320+
}
317321
}
318322
// VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
319323
// it switches linking for libc and similar system libraries to static without using
@@ -662,6 +666,9 @@ impl<'a> Linker for MsvcLinker<'a> {
662666
arg.push(out_filename.with_extension("dll.lib"));
663667
self.cmd.arg(arg);
664668
}
669+
LinkOutputKind::WasiReactorExe => {
670+
panic!("can't link as reactor on non-wasi target");
671+
}
665672
}
666673
}
667674

@@ -1085,6 +1092,10 @@ impl<'a> Linker for WasmLd<'a> {
10851092
LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
10861093
self.cmd.arg("--no-entry");
10871094
}
1095+
LinkOutputKind::WasiReactorExe => {
1096+
self.cmd.arg("--entry");
1097+
self.cmd.arg("_initialize");
1098+
}
10881099
}
10891100
}
10901101

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ pub trait ResolverExpand {
868868

869869
fn resolve_dollar_crates(&mut self);
870870
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment);
871-
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension);
871+
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
872872

873873
fn expansion_for_ast_pass(
874874
&mut self,

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn configure_and_expand_inner<'a>(
236236
pre_expansion_lint(sess, lint_store, &krate);
237237

238238
let mut resolver = Resolver::new(sess, &krate, crate_name, metadata_loader, &resolver_arenas);
239-
rustc_builtin_macros::register_builtin_macros(&mut resolver, sess.edition());
239+
rustc_builtin_macros::register_builtin_macros(&mut resolver);
240240

241241
krate = sess.time("crate_injection", || {
242242
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_session::config::{build_configuration, build_session_options, to_crate
77
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
88
use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
99
use rustc_session::config::{
10-
Externs, OutputType, OutputTypes, SanitizerSet, SymbolManglingVersion,
10+
Externs, OutputType, OutputTypes, SanitizerSet, SymbolManglingVersion, WasiExecModel,
1111
};
1212
use rustc_session::lint::Level;
1313
use rustc_session::search_paths::SearchPath;
@@ -597,6 +597,7 @@ fn test_debugging_options_tracking_hash() {
597597
tracked!(unleash_the_miri_inside_of_you, true);
598598
tracked!(use_ctors_section, Some(true));
599599
tracked!(verify_llvm_ir, true);
600+
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
600601
}
601602

602603
#[test]

compiler/rustc_middle/src/hir/map/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -710,15 +710,10 @@ impl<'hir> Map<'hir> {
710710
let mut scope = id;
711711
loop {
712712
scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID);
713-
if scope == CRATE_HIR_ID {
714-
return CRATE_HIR_ID;
715-
}
716-
match self.get(scope) {
717-
Node::Block(_) => {}
718-
_ => break,
713+
if scope == CRATE_HIR_ID || !matches!(self.get(scope), Node::Block(_)) {
714+
return scope;
719715
}
720716
}
721-
scope
722717
}
723718

724719
pub fn get_parent_did(&self, id: HirId) -> LocalDefId {

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+68-74
Original file line numberDiff line numberDiff line change
@@ -151,95 +151,88 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
151151

152152
let move_msg = if move_spans.for_closure() { " into closure" } else { "" };
153153

154+
let loop_message = if location == move_out.source || move_site.traversed_back_edge {
155+
", in previous iteration of loop"
156+
} else {
157+
""
158+
};
159+
154160
if location == move_out.source {
155-
err.span_label(
156-
span,
157-
format!(
158-
"value {}moved{} here, in previous iteration of loop",
159-
partially_str, move_msg
160-
),
161-
);
162161
is_loop_move = true;
163-
} else if move_site.traversed_back_edge {
164-
err.span_label(
165-
move_span,
166-
format!(
167-
"value {}moved{} here, in previous iteration of loop",
168-
partially_str, move_msg
169-
),
170-
);
171-
} else {
172-
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } =
173-
move_spans
174-
{
175-
let place_name = self
176-
.describe_place(moved_place.as_ref())
177-
.map(|n| format!("`{}`", n))
178-
.unwrap_or_else(|| "value".to_owned());
179-
match kind {
180-
FnSelfUseKind::FnOnceCall => {
162+
}
163+
164+
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } = move_spans {
165+
let place_name = self
166+
.describe_place(moved_place.as_ref())
167+
.map(|n| format!("`{}`", n))
168+
.unwrap_or_else(|| "value".to_owned());
169+
match kind {
170+
FnSelfUseKind::FnOnceCall => {
171+
err.span_label(
172+
fn_call_span,
173+
&format!(
174+
"{} {}moved due to this call{}",
175+
place_name, partially_str, loop_message
176+
),
177+
);
178+
err.span_note(
179+
var_span,
180+
"this value implements `FnOnce`, which causes it to be moved when called",
181+
);
182+
}
183+
FnSelfUseKind::Operator { self_arg } => {
184+
err.span_label(
185+
fn_call_span,
186+
&format!(
187+
"{} {}moved due to usage in operator{}",
188+
place_name, partially_str, loop_message
189+
),
190+
);
191+
if self.fn_self_span_reported.insert(fn_span) {
192+
err.span_note(
193+
self_arg.span,
194+
"calling this operator moves the left-hand side",
195+
);
196+
}
197+
}
198+
FnSelfUseKind::Normal { self_arg, implicit_into_iter } => {
199+
if implicit_into_iter {
181200
err.span_label(
182201
fn_call_span,
183202
&format!(
184-
"{} {}moved due to this call",
185-
place_name, partially_str
203+
"{} {}moved due to this implicit call to `.into_iter()`{}",
204+
place_name, partially_str, loop_message
186205
),
187206
);
188-
err.span_note(
189-
var_span,
190-
"this value implements `FnOnce`, which causes it to be moved when called",
191-
);
192-
}
193-
FnSelfUseKind::Operator { self_arg } => {
207+
} else {
194208
err.span_label(
195209
fn_call_span,
196210
&format!(
197-
"{} {}moved due to usage in operator",
198-
place_name, partially_str
211+
"{} {}moved due to this method call{}",
212+
place_name, partially_str, loop_message
199213
),
200214
);
201-
if self.fn_self_span_reported.insert(fn_span) {
202-
err.span_note(
203-
self_arg.span,
204-
"calling this operator moves the left-hand side",
205-
);
206-
}
207215
}
208-
FnSelfUseKind::Normal { self_arg, implicit_into_iter } => {
209-
if implicit_into_iter {
210-
err.span_label(
211-
fn_call_span,
212-
&format!(
213-
"{} {}moved due to this implicit call to `.into_iter()`",
214-
place_name, partially_str
215-
),
216-
);
217-
} else {
218-
err.span_label(
219-
fn_call_span,
220-
&format!(
221-
"{} {}moved due to this method call",
222-
place_name, partially_str
223-
),
224-
);
225-
}
226-
// Avoid pointing to the same function in multiple different
227-
// error messages
228-
if self.fn_self_span_reported.insert(self_arg.span) {
229-
err.span_note(
230-
self_arg.span,
231-
&format!("this function consumes the receiver `self` by taking ownership of it, which moves {}", place_name)
232-
);
233-
}
216+
// Avoid pointing to the same function in multiple different
217+
// error messages
218+
if self.fn_self_span_reported.insert(self_arg.span) {
219+
err.span_note(
220+
self_arg.span,
221+
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
222+
);
234223
}
235-
// Deref::deref takes &self, which cannot cause a move
236-
FnSelfUseKind::DerefCoercion { .. } => unreachable!(),
237224
}
238-
} else {
239-
err.span_label(
240-
move_span,
241-
format!("value {}moved{} here", partially_str, move_msg),
242-
);
225+
// Deref::deref takes &self, which cannot cause a move
226+
FnSelfUseKind::DerefCoercion { .. } => unreachable!(),
227+
}
228+
} else {
229+
err.span_label(
230+
move_span,
231+
format!("value {}moved{} here{}", partially_str, move_msg, loop_message),
232+
);
233+
// If the move error occurs due to a loop, don't show
234+
// another message for the same span
235+
if loop_message.is_empty() {
243236
move_spans.var_span_label(
244237
&mut err,
245238
format!(
@@ -250,6 +243,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
250243
);
251244
}
252245
}
246+
253247
if let UseSpans::PatUse(span) = move_spans {
254248
err.span_suggestion_verbose(
255249
span.shrink_to_lo(),

compiler/rustc_passes/src/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl ExprVisitor<'tcx> {
7878
return;
7979
}
8080

81-
// Special-case transmutting from `typeof(function)` and
81+
// Special-case transmuting from `typeof(function)` and
8282
// `Option<typeof(function)>` to present a clearer error.
8383
let from = unpack_option_like(self.tcx, from);
8484
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) {

compiler/rustc_resolve/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
3333
use rustc_data_structures::ptr_key::PtrKey;
3434
use rustc_data_structures::sync::Lrc;
3535
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
36-
use rustc_expand::base::SyntaxExtension;
36+
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
3737
use rustc_hir::def::Namespace::*;
3838
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
3939
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
@@ -874,7 +874,7 @@ pub struct ExternPreludeEntry<'a> {
874874

875875
/// Used for better errors for E0773
876876
enum BuiltinMacroState {
877-
NotYetSeen(SyntaxExtension),
877+
NotYetSeen(SyntaxExtensionKind),
878878
AlreadySeen(Span),
879879
}
880880

compiler/rustc_resolve/src/macros.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use rustc_data_structures::fx::FxHashSet;
1414
use rustc_data_structures::ptr_key::PtrKey;
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::struct_span_err;
17-
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand, SyntaxExtension};
17+
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand};
18+
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1819
use rustc_expand::compile_declarative_macro;
1920
use rustc_expand::expand::{AstFragment, Invocation, InvocationKind};
2021
use rustc_feature::is_builtin_attr_name;
@@ -176,10 +177,11 @@ impl<'a> ResolverExpand for Resolver<'a> {
176177
parent_scope.module.unexpanded_invocations.borrow_mut().remove(&expansion);
177178
}
178179

179-
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension) {
180-
if self.builtin_macros.insert(ident.name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
180+
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
181+
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
181182
self.session
182-
.span_err(ident.span, &format!("built-in macro `{}` was already defined", ident));
183+
.diagnostic()
184+
.bug(&format!("built-in macro `{}` was already registered", name));
183185
}
184186
}
185187

@@ -1097,7 +1099,7 @@ impl<'a> Resolver<'a> {
10971099
// while still taking everything else from the source code.
10981100
// If we already loaded this builtin macro, give a better error message than 'no such builtin macro'.
10991101
match mem::replace(builtin_macro, BuiltinMacroState::AlreadySeen(item.span)) {
1100-
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext.kind,
1102+
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext,
11011103
BuiltinMacroState::AlreadySeen(span) => {
11021104
struct_span_err!(
11031105
self.session,

compiler/rustc_session/src/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ crate mod dep_tracking {
21722172
SymbolManglingVersion, TrimmedDefPaths,
21732173
};
21742174
use crate::lint;
2175+
use crate::options::WasiExecModel;
21752176
use crate::utils::NativeLibKind;
21762177
use rustc_feature::UnstableFeatures;
21772178
use rustc_span::edition::Edition;
@@ -2227,6 +2228,7 @@ crate mod dep_tracking {
22272228
impl_dep_tracking_hash_via_hash!(Option<RelocModel>);
22282229
impl_dep_tracking_hash_via_hash!(Option<CodeModel>);
22292230
impl_dep_tracking_hash_via_hash!(Option<TlsModel>);
2231+
impl_dep_tracking_hash_via_hash!(Option<WasiExecModel>);
22302232
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
22312233
impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
22322234
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);

0 commit comments

Comments
 (0)