Skip to content

Commit 7e9a36f

Browse files
committed
Auto merge of #78810 - JohnTitor:rollup-8fhtvxu, r=JohnTitor
Rollup of 15 pull requests Successful merges: - #74979 (`#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit) - #78006 (Use Intra-doc links for std::io::buffered) - #78167 (Fix unreachable sub-branch detection in or-patterns) - #78514 (Allow using 1/2/3/4 for `x.py setup` options) - #78538 (BTreeMap: document a curious assumption in test cases) - #78559 (Add LLVM upgrades from 7 to 10 to RELEASES.md) - #78666 (Fix shellcheck error) - #78705 (Print a summary of which test suite failed) - #78726 (Add link to rust website) - #78730 (Expand explanation of reverse_bits) - #78760 (`deny(invalid_codeblock_attributes)` for rustc_error_codes) - #78771 (inliner: Copy unevaluated constants only after successful inlining) - #78794 (rustc_expand: use collect_bang helper instead of manual reimplementation) - #78795 (The renumber pass is long gone) - #78798 (Fixing Spelling Typos) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dc06a36 + af50c79 commit 7e9a36f

File tree

66 files changed

+251
-95
lines changed

Some content is hidden

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

66 files changed

+251
-95
lines changed

RELEASES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ Compiler
297297
- [Added the `tiny` value to the `code-model` codegen flag.][72397]
298298
- [Added tier 3 support\* for the `mipsel-sony-psp` target.][72062]
299299
- [Added tier 3 support for the `thumbv7a-uwp-windows-msvc` target.][72133]
300+
- [Upgraded to LLVM 10.][67759]
300301

301302
\* Refer to Rust's [platform support page][forge-platform-support] for more
302303
information on Rust's tiered platform support.
@@ -396,6 +397,7 @@ Internals Only
396397
[72062]: https://github.com/rust-lang/rust/pull/72062/
397398
[72094]: https://github.com/rust-lang/rust/pull/72094/
398399
[72133]: https://github.com/rust-lang/rust/pull/72133/
400+
[67759]: https://github.com/rust-lang/rust/pull/67759/
399401
[71900]: https://github.com/rust-lang/rust/pull/71900/
400402
[71928]: https://github.com/rust-lang/rust/pull/71928/
401403
[71662]: https://github.com/rust-lang/rust/pull/71662/
@@ -1270,6 +1272,7 @@ Compiler
12701272
`armv7-unknown-linux-musleabi` targets.][63107]
12711273
- [Added tier 3 support for the `hexagon-unknown-linux-musl` target.][62814]
12721274
- [Added tier 3 support for the `riscv32i-unknown-none-elf` target.][62784]
1275+
- [Upgraded to LLVM 9.][62592]
12731276

12741277
\* Refer to Rust's [platform support page][forge-platform-support] for more
12751278
information on Rust's tiered platform support.
@@ -1336,6 +1339,7 @@ Compatibility Notes
13361339
[62735]: https://github.com/rust-lang/rust/pull/62735/
13371340
[62766]: https://github.com/rust-lang/rust/pull/62766/
13381341
[62784]: https://github.com/rust-lang/rust/pull/62784/
1342+
[62592]: https://github.com/rust-lang/rust/pull/62592/
13391343
[62785]: https://github.com/rust-lang/rust/issues/62785/
13401344
[62814]: https://github.com/rust-lang/rust/pull/62814/
13411345
[62896]: https://github.com/rust-lang/rust/issues/62896/
@@ -2431,6 +2435,7 @@ Compiler
24312435
--------
24322436
- [Added the `riscv32imc-unknown-none-elf` target.][53822]
24332437
- [Added the `aarch64-unknown-netbsd` target][53165]
2438+
- [Upgraded to LLVM 8.][53611]
24342439

24352440
Libraries
24362441
---------
@@ -2479,6 +2484,7 @@ Misc
24792484
[53033]: https://github.com/rust-lang/rust/pull/53033/
24802485
[53044]: https://github.com/rust-lang/rust/pull/53044/
24812486
[53165]: https://github.com/rust-lang/rust/pull/53165/
2487+
[53611]: https://github.com/rust-lang/rust/pull/53611/
24822488
[53213]: https://github.com/rust-lang/rust/pull/53213/
24832489
[53236]: https://github.com/rust-lang/rust/pull/53236/
24842490
[53272]: https://github.com/rust-lang/rust/pull/53272/
@@ -2537,6 +2543,7 @@ Compiler
25372543
- [Bumped minimum LLVM version to 5.0.][51899]
25382544
- [Added `powerpc64le-unknown-linux-musl` target.][51619]
25392545
- [Added `aarch64-unknown-hermit` and `x86_64-unknown-hermit` targets.][52861]
2546+
- [Upgraded to LLVM 7.][51966]
25402547

25412548
Libraries
25422549
---------
@@ -2588,6 +2595,7 @@ Compatibility Notes
25882595

25892596
[53893]: https://github.com/rust-lang/rust/pull/53893/
25902597
[52861]: https://github.com/rust-lang/rust/pull/52861/
2598+
[51966]: https://github.com/rust-lang/rust/pull/51966/
25912599
[52656]: https://github.com/rust-lang/rust/pull/52656/
25922600
[52239]: https://github.com/rust-lang/rust/pull/52239/
25932601
[52330]: https://github.com/rust-lang/rust/pull/52330/

compiler/rustc_ast/src/node_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId);
1313
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
1414

1515
/// When parsing and doing expansions, we initially give all AST nodes this AST
16-
/// node value. Then later, in the renumber pass, we renumber them to have
17-
/// small, positive ids.
16+
/// node value. Then later, during expansion, we renumber them to have small,
17+
/// positive ids.
1818
pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
1919

2020
impl NodeId {

compiler/rustc_codegen_cranelift/scripts/cargo.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cmd=$1
1010
shift || true
1111

1212
if [[ "$cmd" = "jit" ]]; then
13-
cargo +${TOOLCHAIN} rustc $@ -- --jit
13+
cargo +${TOOLCHAIN} rustc "$@" -- --jit
1414
else
15-
cargo +${TOOLCHAIN} $cmd $@
15+
cargo +${TOOLCHAIN} $cmd "$@"
1616
fi

compiler/rustc_codegen_cranelift/scripts/config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env bash
12
set -e
23

34
unamestr=`uname`

compiler/rustc_codegen_cranelift/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ set -e
33

44
export RUSTFLAGS="-Zrun_dsymutil=no"
55

6-
./build.sh --without-sysroot $@
6+
./build.sh --without-sysroot "$@"
77

88
rm -r target/out || true
99

1010
scripts/tests.sh no_sysroot
1111

12-
./build.sh $@
12+
./build.sh "$@"
1313

1414
scripts/tests.sh base_sysroot
1515
scripts/tests.sh extended_sysroot

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(invalid_codeblock_attributes)]
12
//! This library is used to gather all error codes into one place,
23
//! the goal being to make their maintenance easier.
34

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
14361436
item.attrs = attrs;
14371437
self.check_attributes(&item.attrs);
14381438
item.and_then(|item| match item.kind {
1439-
ItemKind::MacCall(mac) => self
1440-
.collect(AstFragmentKind::Items, InvocationKind::Bang { mac, span })
1441-
.make_items(),
1439+
ItemKind::MacCall(mac) => {
1440+
self.collect_bang(mac, span, AstFragmentKind::Items).make_items()
1441+
}
14421442
_ => unreachable!(),
14431443
})
14441444
}

compiler/rustc_mir/src/transform/check_unsafety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
693693
// should only issue a warning for the sake of backwards compatibility.
694694
//
695695
// The solution those 2 expectations is to always take the minimum of both lints.
696-
// This prevent any new errors (unless both lints are explicitely set to `deny`).
696+
// This prevent any new errors (unless both lints are explicitly set to `deny`).
697697
let lint = if tcx.lint_level_at_node(SAFE_PACKED_BORROWS, lint_root).0
698698
<= tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, lint_root).0
699699
{

compiler/rustc_mir/src/transform/inline.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,6 @@ impl Inliner<'tcx> {
140140
continue;
141141
};
142142

143-
// Copy only unevaluated constants from the callee_body into the caller_body.
144-
// Although we are only pushing `ConstKind::Unevaluated` consts to
145-
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
146-
// because we are calling `subst_and_normalize_erasing_regions`.
147-
caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter(
148-
|&constant| matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)),
149-
));
150-
151143
let start = caller_body.basic_blocks().len();
152144
debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
153145
if !self.inline_call(callsite, caller_body, callee_body) {
@@ -522,6 +514,16 @@ impl Inliner<'tcx> {
522514
kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) },
523515
});
524516

517+
// Copy only unevaluated constants from the callee_body into the caller_body.
518+
// Although we are only pushing `ConstKind::Unevaluated` consts to
519+
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
520+
// because we are calling `subst_and_normalize_erasing_regions`.
521+
caller_body.required_consts.extend(
522+
callee_body.required_consts.iter().copied().filter(|&constant| {
523+
matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
524+
}),
525+
);
526+
525527
true
526528
}
527529
kind => {

compiler/rustc_mir_build/src/thir/pattern/_match.rs

Lines changed: 88 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
//! Note: most of the tests relevant to this file can be found (at the time of writing) in
2-
//! src/tests/ui/pattern/usefulness.
1+
//! Note: tests specific to this file can be found in:
2+
//! - ui/pattern/usefulness
3+
//! - ui/or-patterns
4+
//! - ui/consts/const_in_pattern
5+
//! - ui/rfc-2008-non-exhaustive
6+
//! - probably many others
7+
//! I (Nadrieril) prefer to put new tests in `ui/pattern/usefulness` unless there's a specific
8+
//! reason not to, for example if they depend on a particular feature like or_patterns.
39
//!
410
//! This file includes the logic for exhaustiveness and usefulness checking for
511
//! pattern-matching. Specifically, given a list of patterns for a type, we can
@@ -1361,8 +1367,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
13611367

13621368
#[derive(Clone, Debug)]
13631369
crate enum Usefulness<'tcx> {
1364-
/// Carries a list of unreachable subpatterns. Used only in the presence of or-patterns.
1365-
Useful(Vec<Span>),
1370+
/// Carries, for each column in the matrix, a set of sub-branches that have been found to be
1371+
/// unreachable. Used only in the presence of or-patterns, otherwise it stays empty.
1372+
Useful(Vec<FxHashSet<Span>>),
13661373
/// Carries a list of witnesses of non-exhaustiveness.
13671374
UsefulWithWitness(Vec<Witness<'tcx>>),
13681375
NotUseful,
@@ -1410,6 +1417,23 @@ impl<'tcx> Usefulness<'tcx> {
14101417
};
14111418
UsefulWithWitness(new_witnesses)
14121419
}
1420+
Useful(mut unreachables) => {
1421+
if !unreachables.is_empty() {
1422+
// When we apply a constructor, there are `arity` columns of the matrix that
1423+
// corresponded to its arguments. All the unreachables found in these columns
1424+
// will, after `apply`, come from the first column. So we take the union of all
1425+
// the corresponding sets and put them in the first column.
1426+
// Note that `arity` may be 0, in which case we just push a new empty set.
1427+
let len = unreachables.len();
1428+
let arity = ctor_wild_subpatterns.len();
1429+
let mut unioned = FxHashSet::default();
1430+
for set in unreachables.drain((len - arity)..) {
1431+
unioned.extend(set)
1432+
}
1433+
unreachables.push(unioned);
1434+
}
1435+
Useful(unreachables)
1436+
}
14131437
x => x,
14141438
}
14151439
}
@@ -2091,55 +2115,87 @@ crate fn is_useful<'p, 'tcx>(
20912115

20922116
// If the first pattern is an or-pattern, expand it.
20932117
if let Some(vs) = v.expand_or_pat() {
2094-
// We need to push the already-seen patterns into the matrix in order to detect redundant
2095-
// branches like `Some(_) | Some(0)`. We also keep track of the unreachable subpatterns.
2096-
let mut matrix = matrix.clone();
2097-
// `Vec` of all the unreachable branches of the current or-pattern.
2098-
let mut unreachable_branches = Vec::new();
2099-
// Subpatterns that are unreachable from all branches. E.g. in the following case, the last
2100-
// `true` is unreachable only from one branch, so it is overall reachable.
2118+
// We expand the or pattern, trying each of its branches in turn and keeping careful track
2119+
// of possible unreachable sub-branches.
2120+
//
2121+
// If two branches have detected some unreachable sub-branches, we need to be careful. If
2122+
// they were detected in columns that are not the current one, we want to keep only the
2123+
// sub-branches that were unreachable in _all_ branches. Eg. in the following, the last
2124+
// `true` is unreachable in the second branch of the first or-pattern, but not otherwise.
2125+
// Therefore we don't want to lint that it is unreachable.
21012126
//
21022127
// ```
21032128
// match (true, true) {
21042129
// (true, true) => {}
21052130
// (false | true, false | true) => {}
21062131
// }
21072132
// ```
2108-
let mut unreachable_subpats = FxHashSet::default();
2109-
// Whether any branch at all is useful.
2133+
// If however the sub-branches come from the current column, they come from the inside of
2134+
// the current or-pattern, and we want to keep them all. Eg. in the following, we _do_ want
2135+
// to lint that the last `false` is unreachable.
2136+
// ```
2137+
// match None {
2138+
// Some(false) => {}
2139+
// None | Some(true | false) => {}
2140+
// }
2141+
// ```
2142+
2143+
let mut matrix = matrix.clone();
2144+
// We keep track of sub-branches separately depending on whether they come from this column
2145+
// or from others.
2146+
let mut unreachables_this_column: FxHashSet<Span> = FxHashSet::default();
2147+
let mut unreachables_other_columns: Vec<FxHashSet<Span>> = Vec::default();
2148+
// Whether at least one branch is reachable.
21102149
let mut any_is_useful = false;
21112150

21122151
for v in vs {
21132152
let res = is_useful(cx, &matrix, &v, witness_preference, hir_id, is_under_guard, false);
21142153
match res {
2115-
Useful(pats) => {
2116-
if !any_is_useful {
2117-
any_is_useful = true;
2118-
// Initialize with the first set of unreachable subpatterns encountered.
2119-
unreachable_subpats = pats.into_iter().collect();
2120-
} else {
2121-
// Keep the patterns unreachable from both this and previous branches.
2122-
unreachable_subpats =
2123-
pats.into_iter().filter(|p| unreachable_subpats.contains(p)).collect();
2154+
Useful(unreachables) => {
2155+
if let Some((this_column, other_columns)) = unreachables.split_last() {
2156+
// We keep the union of unreachables found in the first column.
2157+
unreachables_this_column.extend(this_column);
2158+
// We keep the intersection of unreachables found in other columns.
2159+
if unreachables_other_columns.is_empty() {
2160+
unreachables_other_columns = other_columns.to_vec();
2161+
} else {
2162+
unreachables_other_columns = unreachables_other_columns
2163+
.into_iter()
2164+
.zip(other_columns)
2165+
.map(|(x, y)| x.intersection(&y).copied().collect())
2166+
.collect();
2167+
}
21242168
}
2169+
any_is_useful = true;
21252170
}
2126-
NotUseful => unreachable_branches.push(v.head().span),
2127-
UsefulWithWitness(_) => {
2128-
bug!("Encountered or-pat in `v` during exhaustiveness checking")
2171+
NotUseful => {
2172+
unreachables_this_column.insert(v.head().span);
21292173
}
2174+
UsefulWithWitness(_) => bug!(
2175+
"encountered or-pat in the expansion of `_` during exhaustiveness checking"
2176+
),
21302177
}
2131-
// If pattern has a guard don't add it to the matrix
2178+
2179+
// If pattern has a guard don't add it to the matrix.
21322180
if !is_under_guard {
2181+
// We push the already-seen patterns into the matrix in order to detect redundant
2182+
// branches like `Some(_) | Some(0)`.
21332183
matrix.push(v);
21342184
}
21352185
}
2136-
if any_is_useful {
2137-
// Collect all the unreachable patterns.
2138-
unreachable_branches.extend(unreachable_subpats);
2139-
return Useful(unreachable_branches);
2186+
2187+
return if any_is_useful {
2188+
let mut unreachables = if unreachables_other_columns.is_empty() {
2189+
let n_columns = v.len();
2190+
(0..n_columns - 1).map(|_| FxHashSet::default()).collect()
2191+
} else {
2192+
unreachables_other_columns
2193+
};
2194+
unreachables.push(unreachables_this_column);
2195+
Useful(unreachables)
21402196
} else {
2141-
return NotUseful;
2142-
}
2197+
NotUseful
2198+
};
21432199
}
21442200

21452201
// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).

0 commit comments

Comments
 (0)