Skip to content

Commit f9b1614

Browse files
committedApr 19, 2024·
Auto merge of rust-lang#124170 - matthiaskrgr:rollup-ldopl64, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#123571 (Correctly change type when adding adjustments on top of `NeverToAny`) - rust-lang#123729 (run-make: refactor out command wrappers for `clang` and `llvm-readobj`) - rust-lang#124106 (Don't repeatedly duplicate TAIT lifetimes for each subsequently nested TAIT) - rust-lang#124149 (rustdoc-search: fix description on aliases in results) - rust-lang#124155 (bootstrap: don't use rayon for sysinfo) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ce3263e + f1e536d commit f9b1614

File tree

17 files changed

+347
-122
lines changed

17 files changed

+347
-122
lines changed
 

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,19 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
195195
}
196196
Some(fn_def_id.to_def_id())
197197
}
198-
ItemKind::OpaqueTy(hir::OpaqueTy {
199-
origin: hir::OpaqueTyOrigin::TyAlias { .. },
198+
ItemKind::OpaqueTy(&hir::OpaqueTy {
199+
origin: hir::OpaqueTyOrigin::TyAlias { parent, in_assoc_ty },
200200
..
201201
}) => {
202-
let parent_id = tcx.hir().get_parent_item(hir_id);
203-
assert_ne!(parent_id, hir::CRATE_OWNER_ID);
204-
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
202+
if in_assoc_ty {
203+
assert!(matches!(tcx.def_kind(parent), DefKind::AssocTy));
204+
} else {
205+
assert!(matches!(tcx.def_kind(parent), DefKind::TyAlias));
206+
}
207+
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent);
205208
// Opaque types are always nested within another item, and
206209
// inherit the generics of the item.
207-
Some(parent_id.to_def_id())
210+
Some(parent.to_def_id())
208211
}
209212
_ => None,
210213
},

‎compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279
}
280280
Entry::Occupied(mut entry) => {
281281
debug!(" - composing on top of {:?}", entry.get());
282-
match (&entry.get()[..], &adj[..]) {
283-
// Applying any adjustment on top of a NeverToAny
284-
// is a valid NeverToAny adjustment, because it can't
285-
// be reached.
286-
(&[Adjustment { kind: Adjust::NeverToAny, .. }], _) => return,
282+
match (&mut entry.get_mut()[..], &adj[..]) {
287283
(
288-
&[
284+
[Adjustment { kind: Adjust::NeverToAny, target }],
285+
&[.., Adjustment { target: new_target, .. }],
286+
) => {
287+
// NeverToAny coercion can target any type, so instead of adding a new
288+
// adjustment on top we can change the target.
289+
//
290+
// This is required for things like `a == a` (where `a: !`) to produce
291+
// valid MIR -- we need borrow adjustment from things like `==` to change
292+
// the type to `&!` (or `&()` depending on the fallback). This might be
293+
// relevant even in unreachable code.
294+
*target = new_target;
295+
}
296+
297+
(
298+
&mut [
289299
Adjustment { kind: Adjust::Deref(_), .. },
290300
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), .. },
291301
],
@@ -294,11 +304,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294304
.., // Any following adjustments are allowed.
295305
],
296306
) => {
297-
// A reborrow has no effect before a dereference.
307+
// A reborrow has no effect before a dereference, so we can safely replace adjustments.
308+
*entry.get_mut() = adj;
298309
}
299-
// FIXME: currently we never try to compose autoderefs
300-
// and ReifyFnPointer/UnsafeFnPointer, but we could.
310+
301311
_ => {
312+
// FIXME: currently we never try to compose autoderefs
313+
// and ReifyFnPointer/UnsafeFnPointer, but we could.
302314
self.dcx().span_delayed_bug(
303315
expr.span,
304316
format!(
@@ -308,9 +320,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
308320
adj
309321
),
310322
);
323+
324+
*entry.get_mut() = adj;
311325
}
312326
}
313-
*entry.get_mut() = adj;
314327
}
315328
}
316329

‎src/bootstrap/Cargo.lock

-27
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,6 @@ dependencies = [
236236
"crypto-common",
237237
]
238238

239-
[[package]]
240-
name = "either"
241-
version = "1.9.0"
242-
source = "registry+https://github.com/rust-lang/crates.io-index"
243-
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
244-
245239
[[package]]
246240
name = "errno"
247241
version = "0.3.8"
@@ -448,26 +442,6 @@ dependencies = [
448442
"proc-macro2",
449443
]
450444

451-
[[package]]
452-
name = "rayon"
453-
version = "1.8.0"
454-
source = "registry+https://github.com/rust-lang/crates.io-index"
455-
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
456-
dependencies = [
457-
"either",
458-
"rayon-core",
459-
]
460-
461-
[[package]]
462-
name = "rayon-core"
463-
version = "1.12.0"
464-
source = "registry+https://github.com/rust-lang/crates.io-index"
465-
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
466-
dependencies = [
467-
"crossbeam-deque",
468-
"crossbeam-utils",
469-
]
470-
471445
[[package]]
472446
name = "redox_syscall"
473447
version = "0.4.1"
@@ -598,7 +572,6 @@ dependencies = [
598572
"libc",
599573
"ntapi",
600574
"once_cell",
601-
"rayon",
602575
"windows",
603576
]
604577

‎src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ walkdir = "2.4"
6464
xz2 = "0.1"
6565

6666
# Dependencies needed by the build-metrics feature
67-
sysinfo = { version = "0.30", optional = true }
67+
sysinfo = { version = "0.30", default-features = false, optional = true }
6868

6969
[target.'cfg(windows)'.dependencies.junction]
7070
version = "1.0.0"

‎src/librustdoc/html/static/js/search.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1464,16 +1464,7 @@ function initSearch(rawSearchIndex) {
14641464
return 0;
14651465
});
14661466

1467-
const transformed = transformResults(result_list);
1468-
const descs = await Promise.all(transformed.map(result => {
1469-
return searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
1470-
"" :
1471-
searchState.loadDesc(result);
1472-
}));
1473-
for (const [i, result] of transformed.entries()) {
1474-
result.desc = descs[i];
1475-
}
1476-
return transformed;
1467+
return transformResults(result_list);
14771468
}
14781469

14791470
/**
@@ -2517,6 +2508,16 @@ function initSearch(rawSearchIndex) {
25172508
sorted_others,
25182509
parsedQuery);
25192510
handleAliases(ret, parsedQuery.original.replace(/"/g, ""), filterCrates, currentCrate);
2511+
await Promise.all([ret.others, ret.returned, ret.in_args].map(async list => {
2512+
const descs = await Promise.all(list.map(result => {
2513+
return searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
2514+
"" :
2515+
searchState.loadDesc(result);
2516+
}));
2517+
for (const [i, result] of list.entries()) {
2518+
result.desc = descs[i];
2519+
}
2520+
}));
25202521
if (parsedQuery.error !== null && ret.others.length !== 0) {
25212522
// It means some doc aliases were found so let's "remove" the error!
25222523
ret.query.error = null;
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use std::env;
2+
use std::path::Path;
3+
use std::process::Command;
4+
5+
use crate::{bin_name, handle_failed_output, tmp_dir};
6+
7+
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
8+
pub fn clang() -> Clang {
9+
Clang::new()
10+
}
11+
12+
/// A `clang` invocation builder.
13+
#[derive(Debug)]
14+
pub struct Clang {
15+
cmd: Command,
16+
}
17+
18+
crate::impl_common_helpers!(Clang);
19+
20+
impl Clang {
21+
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
22+
pub fn new() -> Self {
23+
let clang =
24+
env::var("CLANG").expect("`CLANG` not specified, but this is required to find `clang`");
25+
let cmd = Command::new(clang);
26+
Self { cmd }
27+
}
28+
29+
/// Provide an input file.
30+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
31+
self.cmd.arg(path.as_ref());
32+
self
33+
}
34+
35+
/// Specify the name of the executable. The executable will be placed under `$TMPDIR`, and the
36+
/// extension will be determined by [`bin_name`].
37+
pub fn out_exe(&mut self, name: &str) -> &mut Self {
38+
self.cmd.arg("-o");
39+
self.cmd.arg(tmp_dir().join(bin_name(name)));
40+
self
41+
}
42+
43+
/// Specify which target triple clang should target.
44+
pub fn target(&mut self, target_triple: &str) -> &mut Self {
45+
self.cmd.arg("-target");
46+
self.cmd.arg(target_triple);
47+
self
48+
}
49+
50+
/// Pass `-nostdlib` to disable linking the C standard library.
51+
pub fn no_stdlib(&mut self) -> &mut Self {
52+
self.cmd.arg("-nostdlib");
53+
self
54+
}
55+
56+
/// Specify architecture.
57+
pub fn arch(&mut self, arch: &str) -> &mut Self {
58+
self.cmd.arg(format!("-march={arch}"));
59+
self
60+
}
61+
62+
/// Specify LTO settings.
63+
pub fn lto(&mut self, lto: &str) -> &mut Self {
64+
self.cmd.arg(format!("-flto={lto}"));
65+
self
66+
}
67+
68+
/// Specify which ld to use.
69+
pub fn use_ld(&mut self, ld: &str) -> &mut Self {
70+
self.cmd.arg(format!("-fuse-ld={ld}"));
71+
self
72+
}
73+
}

‎src/tools/run-make-support/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! as `object` or `wasmparser`, they can be re-exported and be made available through this library.
55
66
pub mod cc;
7+
pub mod clang;
8+
pub mod llvm_readobj;
79
pub mod run;
810
pub mod rustc;
911
pub mod rustdoc;
@@ -17,6 +19,8 @@ pub use regex;
1719
pub use wasmparser;
1820

1921
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
22+
pub use clang::{clang, Clang};
23+
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
2024
pub use run::{run, run_fail};
2125
pub use rustc::{aux_build, rustc, Rustc};
2226
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::env;
2+
use std::path::{Path, PathBuf};
3+
use std::process::Command;
4+
5+
use crate::handle_failed_output;
6+
7+
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
8+
/// at `$LLVM_BIN_DIR/llvm-readobj`.
9+
pub fn llvm_readobj() -> LlvmReadobj {
10+
LlvmReadobj::new()
11+
}
12+
13+
/// A `llvm-readobj` invocation builder.
14+
#[derive(Debug)]
15+
pub struct LlvmReadobj {
16+
cmd: Command,
17+
}
18+
19+
crate::impl_common_helpers!(LlvmReadobj);
20+
21+
impl LlvmReadobj {
22+
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
23+
/// at `$LLVM_BIN_DIR/llvm-readobj`.
24+
pub fn new() -> Self {
25+
let llvm_bin_dir = env::var("LLVM_BIN_DIR")
26+
.expect("`LLVM_BIN_DIR` not specified, but this is required to find `llvm-readobj`");
27+
let llvm_bin_dir = PathBuf::from(llvm_bin_dir);
28+
let llvm_readobj = llvm_bin_dir.join("llvm-readobj");
29+
let cmd = Command::new(llvm_readobj);
30+
Self { cmd }
31+
}
32+
33+
/// Provide an input file.
34+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
35+
self.cmd.arg(path.as_ref());
36+
self
37+
}
38+
39+
/// Pass `--file-header` to display file headers.
40+
pub fn file_header(&mut self) -> &mut Self {
41+
self.cmd.arg("--file-header");
42+
self
43+
}
44+
}

‎tests/crashes/120600-2.rs

-13
This file was deleted.

‎tests/crashes/120600.rs

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// MIR for `_f` after built
2+
3+
fn _f(_1: !, _2: !) -> () {
4+
debug a => _1;
5+
debug b => _2;
6+
let mut _0: ();
7+
let mut _3: !;
8+
let _4: bool;
9+
let mut _5: &();
10+
let mut _6: !;
11+
let mut _7: &();
12+
let _8: ();
13+
let mut _9: !;
14+
15+
bb0: {
16+
StorageLive(_4);
17+
StorageLive(_5);
18+
StorageLive(_6);
19+
_6 = _1;
20+
unreachable;
21+
}
22+
23+
bb1: {
24+
StorageDead(_6);
25+
StorageLive(_7);
26+
StorageLive(_8);
27+
StorageLive(_9);
28+
_9 = _2;
29+
unreachable;
30+
}
31+
32+
bb2: {
33+
_7 = &_8;
34+
StorageDead(_9);
35+
_4 = <() as PartialEq>::eq(move _5, move _7) -> [return: bb3, unwind: bb5];
36+
}
37+
38+
bb3: {
39+
StorageDead(_7);
40+
StorageDead(_5);
41+
StorageDead(_8);
42+
StorageDead(_4);
43+
unreachable;
44+
}
45+
46+
bb4: {
47+
return;
48+
}
49+
50+
bb5 (cleanup): {
51+
resume;
52+
}
53+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// skip-filecheck
2+
#![feature(never_type)]
3+
#![allow(unreachable_code)]
4+
5+
// EMIT_MIR eq_never_type._f.built.after.mir
6+
fn _f(a: !, b: !) {
7+
// Both arguments must be references (i.e. == should auto-borrow/coerce-to-ref both arguments)
8+
// (this previously was buggy due to `NeverToAny` coercion incorrectly throwing out other
9+
// coercions)
10+
a == b;
11+
}
12+
13+
fn main() {}

‎tests/run-make/cross-lang-lto-riscv-abi/rmake.rs

+19-42
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
//! Make sure that cross-language LTO works on riscv targets,
2-
//! which requires extra abi metadata to be emitted.
2+
//! which requires extra `target-abi` metadata to be emitted.
33
//@ needs-matching-clang
44
//@ needs-llvm-components riscv
55
extern crate run_make_support;
66

7-
use run_make_support::{bin_name, rustc, tmp_dir};
7+
use run_make_support::{bin_name, clang, llvm_readobj, rustc, tmp_dir};
88
use std::{
99
env,
1010
path::PathBuf,
1111
process::{Command, Output},
1212
str,
1313
};
1414

15-
fn handle_failed_output(output: Output) {
16-
eprintln!("output status: `{}`", output.status);
17-
eprintln!("=== STDOUT ===\n{}\n\n", String::from_utf8(output.stdout).unwrap());
18-
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
19-
std::process::exit(1)
20-
}
21-
2215
fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float: bool) {
2316
eprintln!("Checking target {target}");
2417
// Rust part
@@ -30,40 +23,24 @@ fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float:
3023
.linker_plugin_lto("on")
3124
.run();
3225
// C part
33-
let clang = env::var("CLANG").unwrap();
34-
let mut cmd = Command::new(clang);
35-
let executable = tmp_dir().join("riscv-xlto");
36-
cmd.arg("-target")
37-
.arg(clang_target)
38-
.arg(format!("-march={carch}"))
39-
.arg(format!("-flto=thin"))
40-
.arg(format!("-fuse-ld=lld"))
41-
.arg("-nostdlib")
42-
.arg("-o")
43-
.arg(&executable)
44-
.arg("cstart.c")
45-
.arg(tmp_dir().join("libriscv_xlto.rlib"));
46-
eprintln!("{cmd:?}");
47-
let output = cmd.output().unwrap();
48-
if !output.status.success() {
49-
handle_failed_output(output);
50-
}
26+
clang()
27+
.target(clang_target)
28+
.arch(carch)
29+
.lto("thin")
30+
.use_ld("lld")
31+
.no_stdlib()
32+
.out_exe("riscv-xlto")
33+
.input("cstart.c")
34+
.input(tmp_dir().join("libriscv_xlto.rlib"))
35+
.run();
36+
5137
// Check that the built binary has correct float abi
52-
let llvm_readobj =
53-
PathBuf::from(env::var("LLVM_BIN_DIR").unwrap()).join(bin_name("llvm-readobj"));
54-
let mut cmd = Command::new(llvm_readobj);
55-
cmd.arg("--file-header").arg(executable);
56-
eprintln!("{cmd:?}");
57-
let output = cmd.output().unwrap();
58-
if output.status.success() {
59-
assert!(
60-
!(is_double_float
61-
^ dbg!(str::from_utf8(&output.stdout).unwrap())
62-
.contains("EF_RISCV_FLOAT_ABI_DOUBLE"))
63-
)
64-
} else {
65-
handle_failed_output(output);
66-
}
38+
let executable = tmp_dir().join(bin_name("riscv-xlto"));
39+
let output = llvm_readobj().input(&executable).file_header().run();
40+
let stdout = String::from_utf8_lossy(&output.stdout);
41+
eprintln!("obj:\n{}", stdout);
42+
43+
assert!(!(is_double_float ^ stdout.contains("EF_RISCV_FLOAT_ABI_DOUBLE")));
6744
}
6845

6946
fn main() {

‎tests/rustdoc-js-std/alias-1.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const EXPECTED = {
22
'query': '&',
33
'others': [
4-
{ 'path': 'std', 'name': 'reference' },
4+
{
5+
'path': 'std',
6+
'name': 'reference',
7+
'desc': "References, <code>&amp;T</code> and <code>&amp;mut T</code>.",
8+
},
59
],
610
};

‎tests/ui/never_type/eq-never-types.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
//
3+
// issue: rust-lang/rust#120600
4+
5+
#![allow(internal_features)]
6+
#![feature(never_type, rustc_attrs)]
7+
#![rustc_never_type_options(fallback = "never")]
8+
9+
fn ice(a: !) {
10+
a == a;
11+
}
12+
13+
fn main() {}

‎tests/ui/type-alias-impl-trait/variance.rs

+24
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,28 @@ impl<'i> Foo<'i> for () {
5252
//~^ ERROR: unconstrained opaque type
5353
}
5454

55+
trait Nesting<'a> {
56+
type Output;
57+
}
58+
impl<'a> Nesting<'a> for &'a () {
59+
type Output = &'a ();
60+
}
61+
type NestedDeeply<'a> =
62+
impl Nesting< //~ [*, o]
63+
'a,
64+
Output = impl Nesting< //~ [*, o]
65+
'a,
66+
Output = impl Nesting< //~ [*, o]
67+
'a,
68+
Output = impl Nesting< //~ [*, o]
69+
'a,
70+
Output = impl Nesting<'a> //~ [*, o]
71+
>
72+
>,
73+
>,
74+
>;
75+
fn test<'a>() -> NestedDeeply<'a> {
76+
&()
77+
}
78+
5579
fn main() {}

‎tests/ui/type-alias-impl-trait/variance.stderr

+55-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,60 @@ error: [*, *, o, o]
176176
LL | type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>;
177177
| ^^^^^^^^^^^^^^^^^^^^^^^^^
178178

179-
error: aborting due to 24 previous errors
179+
error: [*, o]
180+
--> $DIR/variance.rs:62:5
181+
|
182+
LL | / impl Nesting<
183+
LL | | 'a,
184+
LL | | Output = impl Nesting<
185+
LL | | 'a,
186+
... |
187+
LL | | >,
188+
LL | | >;
189+
| |_____^
190+
191+
error: [*, o]
192+
--> $DIR/variance.rs:64:18
193+
|
194+
LL | Output = impl Nesting<
195+
| __________________^
196+
LL | | 'a,
197+
LL | | Output = impl Nesting<
198+
LL | | 'a,
199+
... |
200+
LL | | >,
201+
LL | | >,
202+
| |_________^
203+
204+
error: [*, o]
205+
--> $DIR/variance.rs:66:22
206+
|
207+
LL | Output = impl Nesting<
208+
| ______________________^
209+
LL | | 'a,
210+
LL | | Output = impl Nesting<
211+
LL | | 'a,
212+
LL | | Output = impl Nesting<'a>
213+
LL | | >
214+
LL | | >,
215+
| |_____________^
216+
217+
error: [*, o]
218+
--> $DIR/variance.rs:68:26
219+
|
220+
LL | Output = impl Nesting<
221+
| __________________________^
222+
LL | | 'a,
223+
LL | | Output = impl Nesting<'a>
224+
LL | | >
225+
| |_________________^
226+
227+
error: [*, o]
228+
--> $DIR/variance.rs:70:30
229+
|
230+
LL | Output = impl Nesting<'a>
231+
| ^^^^^^^^^^^^^^^^
232+
233+
error: aborting due to 29 previous errors
180234

181235
For more information about this error, try `rustc --explain E0657`.

0 commit comments

Comments
 (0)
Please sign in to comment.