Skip to content

Commit 382111a

Browse files
committed
Auto merge of #146807 - matthiaskrgr:rollup-0k37lls, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #144592 (generate list of all variants with `target_spec_enum`) - #146762 (Fix and provide instructions for running test suite on Apple simulators) - #146766 (Add attributes for #[global_allocator] functions) - #146770 (fixes for numerous clippy warnings) - #146774 (Allow running `x <cmd> <path>` from a different directory) - #146800 (Fix unsupported `std::sys::thread` after move) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f2ef0f + b48021c commit 382111a

File tree

54 files changed

+370
-171
lines changed

Some content is hidden

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

54 files changed

+370
-171
lines changed

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl AllocFnFactory<'_, '_> {
8585
body,
8686
define_opaque: None,
8787
}));
88-
let item = self.cx.item(self.span, self.attrs(), kind);
88+
let item = self.cx.item(self.span, self.attrs(method), kind);
8989
self.cx.stmt_item(self.ty_span, item)
9090
}
9191

@@ -100,8 +100,18 @@ impl AllocFnFactory<'_, '_> {
100100
self.cx.expr_call(self.ty_span, method, args)
101101
}
102102

103-
fn attrs(&self) -> AttrVec {
104-
thin_vec![self.cx.attr_word(sym::rustc_std_internal_symbol, self.span)]
103+
fn attrs(&self, method: &AllocatorMethod) -> AttrVec {
104+
let alloc_attr = match method.name {
105+
sym::alloc => sym::rustc_allocator,
106+
sym::dealloc => sym::rustc_deallocator,
107+
sym::realloc => sym::rustc_reallocator,
108+
sym::alloc_zeroed => sym::rustc_allocator_zeroed,
109+
_ => unreachable!("Unknown allocator method!"),
110+
};
111+
thin_vec![
112+
self.cx.attr_word(sym::rustc_std_internal_symbol, self.span),
113+
self.cx.attr_word(alloc_attr, self.span)
114+
]
105115
}
106116

107117
fn arg_ty(&self, input: &AllocatorMethodInput, args: &mut ThinVec<Param>) -> Box<Expr> {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_middle::util::Providers;
4545
use rustc_session::Session;
4646
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4747
use rustc_span::Symbol;
48+
use rustc_target::spec::{RelocModel, TlsModel};
4849

4950
mod abi;
5051
mod allocator;
@@ -244,16 +245,7 @@ impl CodegenBackend for LlvmCodegenBackend {
244245
match req.kind {
245246
PrintKind::RelocationModels => {
246247
writeln!(out, "Available relocation models:").unwrap();
247-
for name in &[
248-
"static",
249-
"pic",
250-
"pie",
251-
"dynamic-no-pic",
252-
"ropi",
253-
"rwpi",
254-
"ropi-rwpi",
255-
"default",
256-
] {
248+
for name in RelocModel::ALL.iter().map(RelocModel::desc).chain(["default"]) {
257249
writeln!(out, " {name}").unwrap();
258250
}
259251
writeln!(out).unwrap();
@@ -267,9 +259,7 @@ impl CodegenBackend for LlvmCodegenBackend {
267259
}
268260
PrintKind::TlsModels => {
269261
writeln!(out, "Available TLS models:").unwrap();
270-
for name in
271-
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
272-
{
262+
for name in TlsModel::ALL.iter().map(TlsModel::desc) {
273263
writeln!(out, " {name}").unwrap();
274264
}
275265
writeln!(out).unwrap();

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl Callbacks for TimePassesCallbacks {
206206
// time because it will mess up the --print output. See #64339.
207207
//
208208
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
209-
.then(|| config.opts.unstable_opts.time_passes_format);
209+
.then_some(config.opts.unstable_opts.time_passes_format);
210210
config.opts.trimmed_def_paths = true;
211211
}
212212
}
@@ -439,8 +439,9 @@ fn make_input(early_dcx: &EarlyDiagCtxt, free_matches: &[String]) -> Option<Inpu
439439
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
440440
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
441441
);
442-
let line = isize::from_str_radix(&line, 10)
443-
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
442+
let line = line
443+
.parse::<isize>()
444+
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be a number");
444445
FileName::doc_test_source_code(PathBuf::from(path), line)
445446
}
446447
Err(_) => FileName::anon_source_code(&input),
@@ -474,8 +475,7 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
474475
let mut text = String::new();
475476
// Slice off the leading newline and print.
476477
for line in description.lines() {
477-
let indent_level =
478-
line.find(|c: char| !c.is_whitespace()).unwrap_or_else(|| line.len());
478+
let indent_level = line.find(|c: char| !c.is_whitespace()).unwrap_or(line.len());
479479
let dedented_line = &line[indent_level..];
480480
if dedented_line.starts_with("```") {
481481
is_in_code_block = !is_in_code_block;
@@ -547,7 +547,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
547547

548548
// The pager failed. Try to print pretty output to stdout.
549549
if let Some((bufwtr, mdbuf)) = &pretty_data
550-
&& bufwtr.print(&mdbuf).is_ok()
550+
&& bufwtr.print(mdbuf).is_ok()
551551
{
552552
return;
553553
}
@@ -598,8 +598,7 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
598598

599599
fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) {
600600
match sess.io.input {
601-
Input::File(ref ifile) => {
602-
let path = &(*ifile);
601+
Input::File(ref path) => {
603602
let mut v = Vec::new();
604603
locator::list_file_metadata(
605604
&sess.target,
@@ -833,7 +832,7 @@ fn print_crate_info(
833832
SupportedCrateTypes => {
834833
let supported_crate_types = CRATE_TYPES
835834
.iter()
836-
.filter(|(_, crate_type)| !invalid_output_for_target(&sess, *crate_type))
835+
.filter(|(_, crate_type)| !invalid_output_for_target(sess, *crate_type))
837836
.filter(|(_, crate_type)| *crate_type != CrateType::Sdylib)
838837
.map(|(crate_type_sym, _)| *crate_type_sym)
839838
.collect::<BTreeSet<_>>();
@@ -1434,7 +1433,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt))
14341433
eprintln!();
14351434

14361435
if let Some(ice_path) = ice_path()
1437-
&& let Ok(mut out) = File::options().create(true).append(true).open(&ice_path)
1436+
&& let Ok(mut out) = File::options().create(true).append(true).open(ice_path)
14381437
{
14391438
// The current implementation always returns `Some`.
14401439
let location = info.location().unwrap();
@@ -1510,7 +1509,7 @@ fn report_ice(
15101509

15111510
let file = if let Some(path) = ice_path() {
15121511
// Create the ICE dump target file.
1513-
match crate::fs::File::options().create(true).append(true).open(&path) {
1512+
match crate::fs::File::options().create(true).append(true).open(path) {
15141513
Ok(mut file) => {
15151514
dcx.emit_note(session_diagnostics::IcePath { path: path.clone() });
15161515
if FIRST_PANIC.swap(false, Ordering::SeqCst) {

compiler/rustc_driver_impl/src/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro_rules! safe_println {
1414
}
1515

1616
pub(crate) fn print(args: fmt::Arguments<'_>) {
17-
if let Err(_) = io::stdout().write_fmt(args) {
17+
if io::stdout().write_fmt(args).is_err() {
1818
rustc_errors::FatalError.raise();
1919
}
2020
}

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn typeck_with_inspect<'tcx>(
254254
}
255255

256256
fcx.select_obligations_where_possible(|_| {});
257-
if let None = fcx.infcx.tainted_by_errors() {
257+
if fcx.infcx.tainted_by_errors().is_none() {
258258
fcx.report_ambiguity_errors();
259259
}
260260

@@ -295,7 +295,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
295295
} else if let Node::AnonConst(_) = node {
296296
let id = tcx.local_def_id_to_hir_id(def_id);
297297
match tcx.parent_hir_node(id) {
298-
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), span, .. })
298+
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(anon_const), span, .. })
299299
if anon_const.hir_id == id =>
300300
{
301301
Some(fcx.next_ty_var(span))

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
421421
// Not all upvars are captured by ref, so use
422422
// `apply_capture_kind_on_capture_ty` to ensure that we
423423
// compute the right captured type.
424-
return apply_capture_kind_on_capture_ty(
424+
apply_capture_kind_on_capture_ty(
425425
self.tcx,
426426
upvar_ty,
427427
capture,
@@ -430,7 +430,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
430430
} else {
431431
self.tcx.lifetimes.re_erased
432432
},
433-
);
433+
)
434434
},
435435
),
436436
);
@@ -529,11 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
529529
// process any deferred resolutions.
530530
let deferred_call_resolutions = self.remove_deferred_call_resolutions(closure_def_id);
531531
for deferred_call_resolution in deferred_call_resolutions {
532-
deferred_call_resolution.resolve(&mut FnCtxt::new(
533-
self,
534-
self.param_env,
535-
closure_def_id,
536-
));
532+
deferred_call_resolution.resolve(&FnCtxt::new(self, self.param_env, closure_def_id));
537533
}
538534
}
539535

@@ -1493,7 +1489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14931489
/// Notation:
14941490
/// - Ty(place): Type of place
14951491
/// - `(a, b)`: Represents the function parameters `base_path_ty` and `captured_by_move_projs`
1496-
/// respectively.
1492+
/// respectively.
14971493
/// ```ignore (illustrative)
14981494
/// (Ty(w), [ &[p, x], &[c] ])
14991495
/// // |
@@ -2179,9 +2175,10 @@ fn restrict_precision_for_unsafe(
21792175
(place, curr_mode)
21802176
}
21812177

2182-
/// Truncate projections so that following rules are obeyed by the captured `place`:
2178+
/// Truncate projections so that the following rules are obeyed by the captured `place`:
21832179
/// - No Index projections are captured, since arrays are captured completely.
2184-
/// - No unsafe block is required to capture `place`
2180+
/// - No unsafe block is required to capture `place`.
2181+
///
21852182
/// Returns the truncated place and updated capture mode.
21862183
fn restrict_capture_precision(
21872184
place: Place<'_>,

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
220220
// to use builtin indexing because the index type is known to be
221221
// usize-ish
222222
fn fix_index_builtin_expr(&mut self, e: &hir::Expr<'_>) {
223-
if let hir::ExprKind::Index(ref base, ref index, _) = e.kind {
223+
if let hir::ExprKind::Index(base, index, _) = e.kind {
224224
// All valid indexing looks like this; might encounter non-valid indexes at this point.
225225
let base_ty = self.typeck_results.expr_ty_adjusted(base);
226226
if let ty::Ref(_, base_ty_inner, _) = *base_ty.kind() {
@@ -583,7 +583,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
583583
}
584584

585585
if let Err(err) = opaque_type_has_defining_use_args(
586-
&self.fcx,
586+
self.fcx,
587587
opaque_type_key,
588588
hidden_type.span,
589589
DefiningScopeKind::HirTypeck,
@@ -792,7 +792,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
792792

793793
fn visit_potentially_region_dependent_goals(&mut self) {
794794
let obligations = self.fcx.take_hir_typeck_potentially_region_dependent_goals();
795-
if let None = self.fcx.tainted_by_errors() {
795+
if self.fcx.tainted_by_errors().is_none() {
796796
for obligation in obligations {
797797
let (predicate, mut cause) =
798798
self.fcx.resolve_vars_if_possible((obligation.predicate, obligation.cause));

compiler/rustc_interface/src/passes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn configure_and_expand(
192192
unsafe {
193193
env::set_var(
194194
"PATH",
195-
&env::join_paths(
195+
env::join_paths(
196196
new_path.iter().filter(|p| env::join_paths(iter::once(p)).is_ok()),
197197
)
198198
.unwrap(),
@@ -446,7 +446,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
446446
let prev_source = sess.psess.source_map().span_to_prev_source(first_span);
447447
let ferris_fix = prev_source
448448
.map_or(FerrisFix::SnakeCase, |source| {
449-
let mut source_before_ferris = source.trim_end().split_whitespace().rev();
449+
let mut source_before_ferris = source.split_whitespace().rev();
450450
match source_before_ferris.next() {
451451
Some("struct" | "trait" | "mod" | "union" | "type" | "enum") => {
452452
FerrisFix::PascalCase
@@ -500,7 +500,7 @@ fn env_var_os<'tcx>(tcx: TyCtxt<'tcx>, key: &'tcx OsStr) -> Option<&'tcx OsStr>
500500
// properly change-tracked.
501501
tcx.sess.psess.env_depinfo.borrow_mut().insert((
502502
Symbol::intern(&key.to_string_lossy()),
503-
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(&value)),
503+
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(value)),
504504
));
505505

506506
value_tcx
@@ -824,7 +824,7 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {
824824

825825
let outputs = tcx.output_filenames(());
826826
let output_paths =
827-
generated_output_paths(tcx, &outputs, sess.io.output_file.is_some(), crate_name);
827+
generated_output_paths(tcx, outputs, sess.io.output_file.is_some(), crate_name);
828828

829829
// Ensure the source file isn't accidentally overwritten during compilation.
830830
if let Some(input_path) = sess.io.input.opt_path() {
@@ -847,7 +847,7 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {
847847
}
848848
}
849849

850-
write_out_deps(tcx, &outputs, &output_paths);
850+
write_out_deps(tcx, outputs, &output_paths);
851851

852852
let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
853853
&& sess.opts.output_types.len() == 1;
@@ -1303,7 +1303,7 @@ pub(crate) fn parse_crate_name(
13031303
let rustc_hir::Attribute::Parsed(AttributeKind::CrateName { name, name_span, .. }) =
13041304
AttributeParser::parse_limited_should_emit(
13051305
sess,
1306-
&attrs,
1306+
attrs,
13071307
sym::crate_name,
13081308
DUMMY_SP,
13091309
rustc_ast::node_id::CRATE_NODE_ID,

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Linker {
9494
&rlink_file,
9595
&codegen_results,
9696
&self.metadata,
97-
&*self.output_filenames,
97+
&self.output_filenames,
9898
)
9999
.unwrap_or_else(|error| {
100100
sess.dcx().emit_fatal(FailedWritingFile { path: &rlink_file, error })

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
243243
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
244244
// Ensure there was no errors collecting all active jobs.
245245
// We need the complete map to ensure we find a cycle to break.
246-
QueryCtxt::new(tcx).collect_active_jobs().ok().expect("failed to collect active queries in deadlock handler")
246+
QueryCtxt::new(tcx).collect_active_jobs().expect("failed to collect active queries in deadlock handler")
247247
});
248248
break_query_cycles(query_map, &registry);
249249
})
@@ -561,7 +561,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
561561
}
562562
Some(out_file.clone())
563563
};
564-
if sess.io.output_dir != None {
564+
if sess.io.output_dir.is_some() {
565565
sess.dcx().emit_warn(errors::IgnoringOutDir);
566566
}
567567

0 commit comments

Comments
 (0)