Skip to content

Commit 445f34b

Browse files
committed
Auto merge of rust-lang#76186 - tmandry:rollup-49nliiy, r=tmandry
Rollup of 12 pull requests Successful merges: - rust-lang#75945 (Use `env::func()`, not 'the function env::func' in docs for std::env) - rust-lang#76002 (Fix `-Z instrument-coverage` on MSVC) - rust-lang#76003 (Adds two source span utility functions used in source-based coverage) - rust-lang#76059 (Clean up E0764) - rust-lang#76103 (Clean up E0769) - rust-lang#76139 (Make `cow_is_borrowed` methods const) - rust-lang#76154 (Fix rustdoc strings indentation) - rust-lang#76161 (Remove notrust in rustc_middle) - rust-lang#76163 (README: Adjust Linux and macOS support platform and architecture) - rust-lang#76166 (Make `StringReader` private) - rust-lang#76172 (Revert rust-lang#75463) - rust-lang#76178 (Update expect-test to 1.0) Failed merges: r? @ghost
2 parents d824b23 + 8d328d7 commit 445f34b

File tree

39 files changed

+313
-308
lines changed

39 files changed

+313
-308
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,9 @@ dependencies = [
998998

999999
[[package]]
10001000
name = "expect-test"
1001-
version = "0.1.0"
1001+
version = "1.0.1"
10021002
source = "registry+https://github.com/rust-lang/crates.io-index"
1003-
checksum = "a3e383741ea1982866572109d1a8c807bd36aad91fca701489fdca56ef92b3b8"
1003+
checksum = "ceb96f3eaa0d4e8769c52dacfd4eb60183b817ed2f176171b3c691d5022b0f2e"
10041004
dependencies = [
10051005
"difference",
10061006
"once_cell",

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,17 @@ fetch snapshots, and an OS that can execute the available snapshot binaries.
211211
212212
Snapshot binaries are currently built and tested on several platforms:
213213
214-
| Platform / Architecture | x86 | x86_64 |
215-
|----------------------------|-----|--------|
216-
| Windows (7, 8, 10, ...) | ✓ | ✓ |
217-
| Linux (2.6.18 or later) | ✓ | ✓ |
218-
| macOS (10.7 Lion or later) | ✓ | ✓ |
214+
| Platform / Architecture | x86 | x86_64 |
215+
|---------------------------------------------|-----|--------|
216+
| Windows (7, 8, 10, ...) | ✓ | ✓ |
217+
| Linux (kernel 2.6.32, glibc 2.11 or later) | ✓ | ✓ |
218+
| macOS (10.7 Lion or later) | (\*) | ✓ |
219+
220+
(\*): Apple dropped support for running 32-bit binaries starting from macOS 10.15 and iOS 11.
221+
Due to this decision from Apple, the targets are no longer useful to our users.
222+
Please read [our blog post][macx32] for more info.
223+
224+
[macx32]: https://blog.rust-lang.org/2020/01/03/reducing-support-for-32-bit-apple-targets.html
219225
220226
You may find that other platforms work, but these are our officially
221227
supported build environments that are most likely to work.

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
16681668
// FIXME: Order dependent, applies to the following objects. Where should it be placed?
16691669
// Try to strip as much out of the generated object by removing unused
16701670
// sections if possible. See more comments in linker.rs
1671-
if sess.opts.cg.link_dead_code != Some(true) {
1671+
if !sess.link_dead_code() {
16721672
let keep_metadata = crate_type == CrateType::Dylib;
16731673
cmd.gc_sections(keep_metadata);
16741674
}

compiler/rustc_error_codes/src/error_codes/E0764.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
Mutable references (`&mut`) can only be used in constant functions, not statics
2-
or constants. This limitation exists to prevent the creation of constants that
3-
have a mutable reference in their final value. If you had a constant of `&mut
4-
i32` type, you could modify the value through that reference, making the
5-
constant essentially mutable. While there could be a more fine-grained scheme
6-
in the future that allows mutable references if they are not "leaked" to the
7-
final value, a more conservative approach was chosen for now. `const fn` do not
8-
have this problem, as the borrow checker will prevent the `const fn` from
9-
returning new mutable references.
1+
A mutable reference was used in a constant.
102

113
Erroneous code example:
124

@@ -19,6 +11,18 @@ fn main() {
1911
}
2012
```
2113

14+
Mutable references (`&mut`) can only be used in constant functions, not statics
15+
or constants. This limitation exists to prevent the creation of constants that
16+
have a mutable reference in their final value. If you had a constant of
17+
`&mut i32` type, you could modify the value through that reference, making the
18+
constant essentially mutable.
19+
20+
While there could be a more fine-grained scheme in the future that allows
21+
mutable references if they are not "leaked" to the final value, a more
22+
conservative approach was chosen for now. `const fn` do not have this problem,
23+
as the borrow checker will prevent the `const fn` from returning new mutable
24+
references.
25+
2226
Remember: you cannot use a function call inside a constant or static. However,
2327
you can totally use it in constant functions:
2428

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
A tuple struct or tuple variant was used in a pattern as if it were a
2-
struct or struct variant.
1+
A tuple struct or tuple variant was used in a pattern as if it were a struct or
2+
struct variant.
33

44
Erroneous code example:
55

66
```compile_fail,E0769
77
enum E {
88
A(i32),
99
}
10+
1011
let e = E::A(42);
12+
1113
match e {
12-
E::A { number } => println!("{}", x),
14+
E::A { number } => { // error!
15+
println!("{}", number);
16+
}
1317
}
1418
```
1519

@@ -21,19 +25,23 @@ To fix this error, you can use the tuple pattern:
2125
# }
2226
# let e = E::A(42);
2327
match e {
24-
E::A(number) => println!("{}", number),
28+
E::A(number) => { // ok!
29+
println!("{}", number);
30+
}
2531
}
2632
```
2733

28-
Alternatively, you can also use the struct pattern by using the correct
29-
field names and binding them to new identifiers:
34+
Alternatively, you can also use the struct pattern by using the correct field
35+
names and binding them to new identifiers:
3036

3137
```
3238
# enum E {
3339
# A(i32),
3440
# }
3541
# let e = E::A(42);
3642
match e {
37-
E::A { 0: number } => println!("{}", number),
43+
E::A { 0: number } => { // ok!
44+
println!("{}", number);
45+
}
3846
}
3947
```

compiler/rustc_lexer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ doctest = false
2020
unicode-xid = "0.2.0"
2121

2222
[dev-dependencies]
23-
expect-test = "0.1"
23+
expect-test = "1.0"

compiler/rustc_middle/src/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> MonoItem<'tcx> {
8585
.debugging_opts
8686
.inline_in_all_cgus
8787
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
88-
&& tcx.sess.opts.cg.link_dead_code != Some(true);
88+
&& !tcx.sess.link_dead_code();
8989

9090
match *self {
9191
MonoItem::Fn(ref instance) => {

compiler/rustc_middle/src/ty/walk.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl GenericArg<'tcx> {
5555
/// that appear in `self`, it does not descend into the fields of
5656
/// structs or variants. For example:
5757
///
58-
/// ```notrust
58+
/// ```text
5959
/// isize => { isize }
6060
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
6161
/// [isize] => { [isize], isize }
@@ -80,7 +80,7 @@ impl<'tcx> super::TyS<'tcx> {
8080
/// that appear in `self`, it does not descend into the fields of
8181
/// structs or variants. For example:
8282
///
83-
/// ```notrust
83+
/// ```text
8484
/// isize => { isize }
8585
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
8686
/// [isize] => { [isize], isize }

compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn partition<'tcx>(
190190

191191
// Next we try to make as many symbols "internal" as possible, so LLVM has
192192
// more freedom to optimize.
193-
if tcx.sess.opts.cg.link_dead_code != Some(true) {
193+
if !tcx.sess.link_dead_code() {
194194
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
195195
partitioner.internalize_symbols(tcx, &mut post_inlining, inlining_map);
196196
}
@@ -327,7 +327,7 @@ fn collect_and_partition_mono_items<'tcx>(
327327
}
328328
}
329329
None => {
330-
if tcx.sess.opts.cg.link_dead_code == Some(true) {
330+
if tcx.sess.link_dead_code() {
331331
MonoItemCollectionMode::Eager
332332
} else {
333333
MonoItemCollectionMode::Lazy

compiler/rustc_parse/src/lexer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct UnmatchedBrace {
2727
pub candidate_span: Option<Span>,
2828
}
2929

30-
pub struct StringReader<'a> {
30+
crate struct StringReader<'a> {
3131
sess: &'a ParseSess,
3232
/// Initial position, read-only.
3333
start_pos: BytePos,
@@ -41,7 +41,7 @@ pub struct StringReader<'a> {
4141
}
4242

4343
impl<'a> StringReader<'a> {
44-
pub fn new(
44+
crate fn new(
4545
sess: &'a ParseSess,
4646
source_file: Lrc<rustc_span::SourceFile>,
4747
override_span: Option<Span>,
@@ -66,7 +66,7 @@ impl<'a> StringReader<'a> {
6666
}
6767

6868
/// Returns the next token, including trivia like whitespace or comments.
69-
pub fn next_token(&mut self) -> Token {
69+
fn next_token(&mut self) -> Token {
7070
let start_src_index = self.src_index(self.pos);
7171
let text: &str = &self.src[start_src_index..self.end_src_index];
7272

compiler/rustc_session/src/config.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -1718,20 +1718,11 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
17181718
);
17191719
}
17201720

1721-
// `-Z instrument-coverage` implies:
1722-
// * `-Z symbol-mangling-version=v0` - to ensure consistent and reversible name mangling.
1723-
// Note, LLVM coverage tools can analyze coverage over multiple runs, including some
1724-
// changes to source code; so mangled names must be consistent across compilations.
1725-
// * `-C link-dead-code` - so unexecuted code is still counted as zero, rather than be
1726-
// optimized out. Note that instrumenting dead code can be explicitly disabled with:
1727-
// `-Z instrument-coverage -C link-dead-code=no`.
1721+
// `-Z instrument-coverage` implies `-Z symbol-mangling-version=v0` - to ensure consistent
1722+
// and reversible name mangling. Note, LLVM coverage tools can analyze coverage over
1723+
// multiple runs, including some changes to source code; so mangled names must be consistent
1724+
// across compilations.
17281725
debugging_opts.symbol_mangling_version = SymbolManglingVersion::V0;
1729-
if cg.link_dead_code == None {
1730-
// FIXME(richkadel): Investigate if the `instrument-coverage` implementation can
1731-
// inject ["zero counters"](https://llvm.org/docs/CoverageMappingFormat.html#counter)
1732-
// in the coverage map when "dead code" is removed, rather than forcing `link-dead-code`.
1733-
cg.link_dead_code = Some(true);
1734-
}
17351726
}
17361727

17371728
if !cg.embed_bitcode {

compiler/rustc_session/src/options.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
885885
"instrument the generated code to support LLVM source-based code coverage \
886886
reports (note, the compiler build config must include `profiler = true`, \
887887
and is mutually exclusive with `-C profile-generate`/`-C profile-use`); \
888-
implies `-C link-dead-code` (unless explicitly disabled)` and \
889-
`-Z symbol-mangling-version=v0`; and disables/overrides some optimization \
890-
options (default: no)"),
888+
implies `-C link-dead-code` (unless targeting MSVC, or explicitly disabled) \
889+
and `-Z symbol-mangling-version=v0`; disables/overrides some Rust \
890+
optimizations (default: no)"),
891891
instrument_mcount: bool = (false, parse_bool, [TRACKED],
892892
"insert function instrument code for mcount-based tracing (default: no)"),
893893
keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_session/src/session.rs

+34-14
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,40 @@ impl Session {
10241024
|| self.opts.debugging_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY)
10251025
}
10261026

1027+
pub fn link_dead_code(&self) -> bool {
1028+
match self.opts.cg.link_dead_code {
1029+
Some(explicitly_set) => explicitly_set,
1030+
None => {
1031+
self.opts.debugging_opts.instrument_coverage
1032+
&& !self.target.target.options.is_like_msvc
1033+
// Issue #76038: (rustc `-Clink-dead-code` causes MSVC linker to produce invalid
1034+
// binaries when LLVM InstrProf counters are enabled). As described by this issue,
1035+
// the "link dead code" option produces incorrect binaries when compiled and linked
1036+
// under MSVC. The resulting Rust programs typically crash with a segmentation
1037+
// fault, or produce an empty "*.profraw" file (profiling counter results normally
1038+
// generated during program exit).
1039+
//
1040+
// If not targeting MSVC, `-Z instrument-coverage` implies `-C link-dead-code`, so
1041+
// unexecuted code is still counted as zero, rather than be optimized out. Note that
1042+
// instrumenting dead code can be explicitly disabled with:
1043+
//
1044+
// `-Z instrument-coverage -C link-dead-code=no`.
1045+
//
1046+
// FIXME(richkadel): Investigate if `instrument-coverage` implementation can inject
1047+
// [zero counters](https://llvm.org/docs/CoverageMappingFormat.html#counter) in the
1048+
// coverage map when "dead code" is removed, rather than forcing `link-dead-code`.
1049+
// This may not be possible, however, if (as it seems to appear) the "dead code"
1050+
// that would otherwise not be linked is only identified as "dead" by the native
1051+
// linker. If that's the case, I believe it is too late for the Rust compiler to
1052+
// leverage any information it might be able to get from the linker regarding what
1053+
// code is dead, to be able to add those counters.
1054+
//
1055+
// On the other hand, if any Rust compiler passes are optimizing out dead code blocks
1056+
// we should inject "zero" counters for those code regions.
1057+
}
1058+
}
1059+
}
1060+
10271061
pub fn mark_attr_known(&self, attr: &Attribute) {
10281062
self.known_attrs.lock().mark(attr)
10291063
}
@@ -1432,20 +1466,6 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
14321466
);
14331467
}
14341468

1435-
// FIXME(richkadel): See `src/test/run-make-fulldeps/instrument-coverage/Makefile`. After
1436-
// compiling with `-Zinstrument-coverage`, the resulting binary generates a segfault during
1437-
// the program's exit process (likely while attempting to generate the coverage stats in
1438-
// the "*.profraw" file). An investigation to resolve the problem on Windows is ongoing,
1439-
// but until this is resolved, the option is disabled on Windows, and the test is skipped
1440-
// when targeting `MSVC`.
1441-
if sess.opts.debugging_opts.instrument_coverage && sess.target.target.options.is_like_msvc {
1442-
sess.warn(
1443-
"Rust source-based code coverage instrumentation (with `-Z instrument-coverage`) \
1444-
is not yet supported on Windows when targeting MSVC. The resulting binaries will \
1445-
still be instrumented for experimentation purposes, but may not execute correctly.",
1446-
);
1447-
}
1448-
14491469
const ASAN_SUPPORTED_TARGETS: &[&str] = &[
14501470
"aarch64-fuchsia",
14511471
"aarch64-unknown-linux-gnu",

compiler/rustc_span/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ impl Span {
400400
span.with_lo(span.hi)
401401
}
402402

403+
#[inline]
404+
/// Returns true if hi == lo
405+
pub fn is_empty(&self) -> bool {
406+
let span = self.data();
407+
span.hi == span.lo
408+
}
409+
403410
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
404411
pub fn substitute_dummy(self, other: Span) -> Span {
405412
if self.is_dummy() { other } else { self }

compiler/rustc_span/src/source_map.rs

+9
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,15 @@ impl SourceMap {
487487
}
488488
}
489489

490+
/// Returns a new `Span` covering the start and end `BytePos`s of the file containing the given
491+
/// `pos`. This can be used to quickly determine if another `BytePos` or `Span` is from the same
492+
/// file.
493+
pub fn lookup_file_span(&self, pos: BytePos) -> Span {
494+
let idx = self.lookup_source_file_idx(pos);
495+
let SourceFile { start_pos, end_pos, .. } = *(*self.files.borrow().source_files)[idx];
496+
Span::with_root_ctxt(start_pos, end_pos)
497+
}
498+
490499
/// Returns `Some(span)`, a union of the LHS and RHS span. The LHS must precede the RHS. If
491500
/// there are gaps between LHS and RHS, the resulting union will cross these gaps.
492501
/// For this to work,

library/alloc/src/borrow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
217217
/// assert!(!bull.is_borrowed());
218218
/// ```
219219
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
220-
pub fn is_borrowed(&self) -> bool {
220+
pub const fn is_borrowed(&self) -> bool {
221221
match *self {
222222
Borrowed(_) => true,
223223
Owned(_) => false,
@@ -239,7 +239,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
239239
/// assert!(!bull.is_owned());
240240
/// ```
241241
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
242-
pub fn is_owned(&self) -> bool {
242+
pub const fn is_owned(&self) -> bool {
243243
!self.is_borrowed()
244244
}
245245

library/core/src/cmp.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ impl Ordering {
356356
/// ```
357357
#[inline]
358358
#[must_use]
359-
#[rustc_const_stable(feature = "const_ordering", since = "1.48.0")]
360359
#[stable(feature = "rust1", since = "1.0.0")]
361-
pub const fn reverse(self) -> Ordering {
360+
pub fn reverse(self) -> Ordering {
362361
match self {
363362
Less => Greater,
364363
Equal => Equal,
@@ -395,9 +394,8 @@ impl Ordering {
395394
/// ```
396395
#[inline]
397396
#[must_use]
398-
#[rustc_const_stable(feature = "const_ordering", since = "1.48.0")]
399397
#[stable(feature = "ordering_chaining", since = "1.17.0")]
400-
pub const fn then(self, other: Ordering) -> Ordering {
398+
pub fn then(self, other: Ordering) -> Ordering {
401399
match self {
402400
Equal => other,
403401
_ => self,

0 commit comments

Comments
 (0)