Skip to content

Commit e350fe4

Browse files
committed
Auto merge of rust-lang#109001 - matthiaskrgr:rollup-a3agnwp, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#105798 (Relax ordering rules for `asm!` operands) - rust-lang#105962 (Stabilize path_as_mut_os_str) - rust-lang#106085 (use problem matchers for tidy CI) - rust-lang#107711 (Stabilize movbe target feature) - rust-lang#108017 (Add `--no-undefined-version` link flag and fix associated breakage) - rust-lang#108891 (Remove an extraneous include) - rust-lang#108902 (no more do while :<) - rust-lang#108912 (Document tool lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 19c5376 + 030ea05 commit e350fe4

File tree

24 files changed

+267
-368
lines changed

24 files changed

+267
-368
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+4-31
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,6 @@ pub fn parse_asm_args<'a>(
203203
// Validate the order of named, positional & explicit register operands and
204204
// clobber_abi/options. We do this at the end once we have the full span
205205
// of the argument available.
206-
if !args.options_spans.is_empty() {
207-
diag.struct_span_err(span, "arguments are not allowed after options")
208-
.span_labels(args.options_spans.clone(), "previous options")
209-
.span_label(span, "argument")
210-
.emit();
211-
} else if let Some((_, abi_span)) = args.clobber_abis.last() {
212-
diag.struct_span_err(span, "arguments are not allowed after clobber_abi")
213-
.span_label(*abi_span, "clobber_abi")
214-
.span_label(span, "argument")
215-
.emit();
216-
}
217206
if explicit_reg {
218207
if name.is_some() {
219208
diag.struct_span_err(span, "explicit register arguments cannot have names").emit();
@@ -227,17 +216,6 @@ pub fn parse_asm_args<'a>(
227216
.emit();
228217
continue;
229218
}
230-
if !args.reg_args.is_empty() {
231-
let mut err = diag.struct_span_err(
232-
span,
233-
"named arguments cannot follow explicit register arguments",
234-
);
235-
err.span_label(span, "named argument");
236-
for pos in &args.reg_args {
237-
err.span_label(args.operands[*pos].1, "explicit register argument");
238-
}
239-
err.emit();
240-
}
241219
args.named_args.insert(name, slot);
242220
} else {
243221
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
@@ -478,15 +456,6 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
478456

479457
let full_span = span_start.to(p.prev_token.span);
480458

481-
if !args.options_spans.is_empty() {
482-
let mut err = p
483-
.sess
484-
.span_diagnostic
485-
.struct_span_err(full_span, "clobber_abi is not allowed after options");
486-
err.span_labels(args.options_spans.clone(), "options");
487-
return Err(err);
488-
}
489-
490459
match &new_abis[..] {
491460
// should have errored above during parsing
492461
[] => unreachable!(),
@@ -699,6 +668,10 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
699668
args.operands[idx].1,
700669
"explicit register arguments cannot be used in the asm template",
701670
);
671+
err.span_help(
672+
args.operands[idx].1,
673+
"use the register name directly in the assembly code",
674+
);
702675
}
703676
err.emit();
704677
None

compiler/rustc_codegen_cranelift/src/allocator.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::prelude::*;
55

66
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
7+
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
78
use rustc_session::config::OomStrategy;
89
use rustc_span::symbol::sym;
910

@@ -13,24 +14,15 @@ pub(crate) fn codegen(
1314
module: &mut impl Module,
1415
unwind_context: &mut UnwindContext,
1516
) -> bool {
16-
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
17-
use rustc_middle::middle::dependency_format::Linkage;
18-
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
19-
});
20-
if any_dynamic_crate {
21-
false
22-
} else if let Some(kind) = tcx.allocator_kind(()) {
23-
codegen_inner(
24-
module,
25-
unwind_context,
26-
kind,
27-
tcx.alloc_error_handler_kind(()).unwrap(),
28-
tcx.sess.opts.unstable_opts.oom,
29-
);
30-
true
31-
} else {
32-
false
33-
}
17+
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
18+
codegen_inner(
19+
module,
20+
unwind_context,
21+
kind,
22+
tcx.alloc_error_handler_kind(()).unwrap(),
23+
tcx.sess.opts.unstable_opts.oom,
24+
);
25+
true
3426
}
3527

3628
fn codegen_inner(

compiler/rustc_codegen_ssa/src/back/linker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ impl<'a> Linker for GccLinker<'a> {
720720
let mut arg = OsString::from("--version-script=");
721721
arg.push(path);
722722
self.linker_arg(arg);
723+
self.linker_arg("--no-undefined-version");
723724
}
724725
}
725726
}

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::base::allocator_kind_for_codegen;
2+
13
use std::collections::hash_map::Entry::*;
24

35
use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
@@ -200,7 +202,8 @@ fn exported_symbols_provider_local(
200202
));
201203
}
202204

203-
if tcx.allocator_kind(()).is_some() {
205+
// Mark allocator shim symbols as exported only if they were generated.
206+
if allocator_kind_for_codegen(tcx).is_some() {
204207
for symbol_name in ALLOCATOR_METHODS
205208
.iter()
206209
.map(|method| format!("__rust_{}", method.name))

compiler/rustc_codegen_ssa/src/base.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::mir::place::PlaceRef;
1313
use crate::traits::*;
1414
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};
1515

16+
use rustc_ast::expand::allocator::AllocatorKind;
1617
use rustc_attr as attr;
1718
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1819
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -545,6 +546,23 @@ pub fn collect_debugger_visualizers_transitive(
545546
.collect::<BTreeSet<_>>()
546547
}
547548

549+
/// Decide allocator kind to codegen. If `Some(_)` this will be the same as
550+
/// `tcx.allocator_kind`, but it may be `None` in more cases (e.g. if using
551+
/// allocator definitions from a dylib dependency).
552+
pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
553+
// If the crate doesn't have an `allocator_kind` set then there's definitely
554+
// no shim to generate. Otherwise we also check our dependency graph for all
555+
// our output crate types. If anything there looks like its a `Dynamic`
556+
// linkage, then it's already got an allocator shim and we'll be using that
557+
// one instead. If nothing exists then it's our job to generate the
558+
// allocator!
559+
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
560+
use rustc_middle::middle::dependency_format::Linkage;
561+
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
562+
});
563+
if any_dynamic_crate { None } else { tcx.allocator_kind(()) }
564+
}
565+
548566
pub fn codegen_crate<B: ExtraBackendMethods>(
549567
backend: B,
550568
tcx: TyCtxt<'_>,
@@ -615,20 +633,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
615633
);
616634

617635
// Codegen an allocator shim, if necessary.
618-
//
619-
// If the crate doesn't have an `allocator_kind` set then there's definitely
620-
// no shim to generate. Otherwise we also check our dependency graph for all
621-
// our output crate types. If anything there looks like its a `Dynamic`
622-
// linkage, then it's already got an allocator shim and we'll be using that
623-
// one instead. If nothing exists then it's our job to generate the
624-
// allocator!
625-
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
626-
use rustc_middle::middle::dependency_format::Linkage;
627-
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
628-
});
629-
let allocator_module = if any_dynamic_crate {
630-
None
631-
} else if let Some(kind) = tcx.allocator_kind(()) {
636+
if let Some(kind) = allocator_kind_for_codegen(tcx) {
632637
let llmod_id =
633638
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
634639
let module_llvm = tcx.sess.time("write_allocator_module", || {
@@ -642,13 +647,10 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
642647
)
643648
});
644649

645-
Some(ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator })
646-
} else {
647-
None
648-
};
649-
650-
if let Some(allocator_module) = allocator_module {
651-
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, allocator_module);
650+
ongoing_codegen.submit_pre_codegened_module_to_llvm(
651+
tcx,
652+
ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator },
653+
);
652654
}
653655

654656
// For better throughput during parallel processing by LLVM, we used to sort

compiler/rustc_codegen_ssa/src/target_features.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
192192
("fxsr", None),
193193
("gfni", Some(sym::avx512_target_feature)),
194194
("lzcnt", None),
195-
("movbe", Some(sym::movbe_target_feature)),
195+
("movbe", None),
196196
("pclmulqdq", None),
197197
("popcnt", None),
198198
("rdrand", None),
@@ -394,7 +394,6 @@ pub fn from_target_feature(
394394
Some(sym::sse4a_target_feature) => rust_features.sse4a_target_feature,
395395
Some(sym::tbm_target_feature) => rust_features.tbm_target_feature,
396396
Some(sym::wasm_target_feature) => rust_features.wasm_target_feature,
397-
Some(sym::movbe_target_feature) => rust_features.movbe_target_feature,
398397
Some(sym::rtm_target_feature) => rust_features.rtm_target_feature,
399398
Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature,
400399
Some(sym::bpf_target_feature) => rust_features.bpf_target_feature,

compiler/rustc_feature/src/accepted.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ declare_features! (
9090
(accepted, clone_closures, "1.26.0", Some(44490), None),
9191
/// Allows coercing non capturing closures to function pointers.
9292
(accepted, closure_to_fn_coercion, "1.19.0", Some(39817), None),
93-
/// Allows using `cmpxchg16b` from `core::arch::x86_64`.
93+
/// Allows using the CMPXCHG16B target feature.
9494
(accepted, cmpxchg16b_target_feature, "CURRENT_RUSTC_VERSION", Some(44839), None),
9595
/// Allows usage of the `compile_error!` macro.
9696
(accepted, compile_error, "1.20.0", Some(40872), None),
@@ -238,6 +238,8 @@ declare_features! (
238238
(accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None),
239239
/// Allows using `Self` and associated types in struct expressions and patterns.
240240
(accepted, more_struct_aliases, "1.16.0", Some(37544), None),
241+
/// Allows using the MOVBE target feature.
242+
(accepted, movbe_target_feature, "CURRENT_RUSTC_VERSION", Some(44839), None),
241243
/// Allows patterns with concurrent by-move and by-ref bindings.
242244
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
243245
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),

compiler/rustc_feature/src/active.rs

-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ declare_features! (
259259
(active, ermsb_target_feature, "1.49.0", Some(44839), None),
260260
(active, hexagon_target_feature, "1.27.0", Some(44839), None),
261261
(active, mips_target_feature, "1.27.0", Some(44839), None),
262-
(active, movbe_target_feature, "1.34.0", Some(44839), None),
263262
(active, powerpc_target_feature, "1.27.0", Some(44839), None),
264263
(active, riscv_target_feature, "1.45.0", Some(44839), None),
265264
(active, rtm_target_feature, "1.35.0", Some(44839), None),

compiler/rustc_lint/src/internal.rs

+30
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ use rustc_span::symbol::{kw, sym, Symbol};
1717
use rustc_span::Span;
1818

1919
declare_tool_lint! {
20+
/// The `default_hash_type` lint detects use of [`std::collections::HashMap`]/[`std::collections::HashSet`],
21+
/// suggesting the use of `FxHashMap`/`FxHashSet`.
22+
///
23+
/// This can help as `FxHasher` can perform better than the default hasher. DOS protection is not
24+
/// required as input is assumed to be trusted.
2025
pub rustc::DEFAULT_HASH_TYPES,
2126
Allow,
2227
"forbid HashMap and HashSet and suggest the FxHash* variants",
@@ -67,6 +72,12 @@ fn typeck_results_of_method_fn<'tcx>(
6772
}
6873

6974
declare_tool_lint! {
75+
/// The `potential_query_instability` lint detects use of methods which can lead to
76+
/// potential query instability, such as iterating over a `HashMap`.
77+
///
78+
/// Due to the [incremental compilation](https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html) model,
79+
/// queries must return deterministic, stable results. `HashMap` iteration order can change between compilations,
80+
/// and will introduce instability if query results expose the order.
7081
pub rustc::POTENTIAL_QUERY_INSTABILITY,
7182
Allow,
7283
"require explicit opt-in when using potentially unstable methods or functions",
@@ -92,13 +103,17 @@ impl LateLintPass<'_> for QueryStability {
92103
}
93104

94105
declare_tool_lint! {
106+
/// The `usage_of_ty_tykind` lint detects usages of `ty::TyKind::<kind>`,
107+
/// where `ty::<kind>` would suffice.
95108
pub rustc::USAGE_OF_TY_TYKIND,
96109
Allow,
97110
"usage of `ty::TyKind` outside of the `ty::sty` module",
98111
report_in_external_macro: true
99112
}
100113

101114
declare_tool_lint! {
115+
/// The `usage_of_qualified_ty` lint detects usages of `ty::TyKind`,
116+
/// where `Ty` should be used instead.
102117
pub rustc::USAGE_OF_QUALIFIED_TY,
103118
Allow,
104119
"using `ty::{Ty,TyCtxt}` instead of importing it",
@@ -254,6 +269,8 @@ fn gen_args(segment: &PathSegment<'_>) -> String {
254269
}
255270

256271
declare_tool_lint! {
272+
/// The `lint_pass_impl_without_macro` detects manual implementations of a lint
273+
/// pass, without using [`declare_lint_pass`] or [`impl_lint_pass`].
257274
pub rustc::LINT_PASS_IMPL_WITHOUT_MACRO,
258275
Allow,
259276
"`impl LintPass` without the `declare_lint_pass!` or `impl_lint_pass!` macros"
@@ -285,6 +302,8 @@ impl EarlyLintPass for LintPassImpl {
285302
}
286303

287304
declare_tool_lint! {
305+
/// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
306+
/// that don't exist, e.g. `#[doc(keyword = "..")]`.
288307
pub rustc::EXISTING_DOC_KEYWORD,
289308
Allow,
290309
"Check that documented keywords in std and core actually exist",
@@ -325,13 +344,22 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
325344
}
326345

327346
declare_tool_lint! {
347+
/// The `untranslatable_diagnostic` lint detects diagnostics created
348+
/// without using translatable Fluent strings.
349+
///
350+
/// More details on translatable diagnostics can be found [here](https://rustc-dev-guide.rust-lang.org/diagnostics/translation.html).
328351
pub rustc::UNTRANSLATABLE_DIAGNOSTIC,
329352
Allow,
330353
"prevent creation of diagnostics which cannot be translated",
331354
report_in_external_macro: true
332355
}
333356

334357
declare_tool_lint! {
358+
/// The `diagnostic_outside_of_impl` lint detects diagnostics created manually,
359+
/// and inside an `IntoDiagnostic`/`AddToDiagnostic` implementation,
360+
/// or a `#[derive(Diagnostic)]`/`#[derive(Subdiagnostic)]` expansion.
361+
///
362+
/// More details on diagnostics implementations can be found [here](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html).
335363
pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL,
336364
Allow,
337365
"prevent creation of diagnostics outside of `IntoDiagnostic`/`AddToDiagnostic` impls",
@@ -396,6 +424,8 @@ impl LateLintPass<'_> for Diagnostics {
396424
}
397425

398426
declare_tool_lint! {
427+
/// The `bad_opt_access` lint detects accessing options by field instad of
428+
/// the wrapper function.
399429
pub rustc::BAD_OPT_ACCESS,
400430
Deny,
401431
"prevent using options by field access when there is a wrapper function",

compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "llvm/IR/LLVMContext.h"
1111
#include "llvm/Object/ObjectFile.h"
12-
#include "llvm/ADT/Optional.h"
1312

1413
using namespace llvm;
1514
using namespace llvm::sys;

compiler/rustc_mir_build/src/build/matches/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
588588
// let PATTERN = ... might not even exist until we do the assignment.
589589
// so we set it here instead.
590590
if set_match_place {
591-
let mut candidate_ref = &candidate;
592-
while let Some(next) = {
591+
let mut next = Some(&candidate);
592+
while let Some(candidate_ref) = next.take() {
593593
for binding in &candidate_ref.bindings {
594594
let local = self.var_local_id(binding.var_id, OutsideGuard);
595595
// `try_to_place` may fail if it is unable to resolve the given
@@ -617,9 +617,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
617617
}
618618
// All of the subcandidates should bind the same locals, so we
619619
// only visit the first one.
620-
candidate_ref.subcandidates.get(0)
621-
} {
622-
candidate_ref = next;
620+
next = candidate_ref.subcandidates.get(0)
623621
}
624622
}
625623

0 commit comments

Comments
 (0)