Skip to content

Commit 07a63e6

Browse files
committed
Auto merge of rust-lang#78270 - JohnTitor:rollup-bldrjh5, r=JohnTitor
Rollup of 17 pull requests Successful merges: - rust-lang#77268 (Link to "Contributing to Rust" rather than "Getting Started".) - rust-lang#77339 (Implement TryFrom between NonZero types.) - rust-lang#77488 (Mark `repr128` as `incomplete_features`) - rust-lang#77890 (Fixing escaping to ensure generation of welformed json.) - rust-lang#77918 (Cleanup network tests) - rust-lang#77920 (Avoid extraneous space between visibility kw and ident for statics) - rust-lang#77969 (Doc formating consistency between slice sort and sort_unstable, and big O notation consistency) - rust-lang#78098 (Clean up and improve some docs) - rust-lang#78116 (Make inline const work in range patterns) - rust-lang#78153 (Sync LLVM submodule if it has been initialized) - rust-lang#78163 (Clean up lib docs) - rust-lang#78169 (Update cargo) - rust-lang#78231 (Make closures inherit the parent function's target features) - rust-lang#78235 (Explain where the closure return type was inferred) - rust-lang#78255 (Reduce diagram mess in 'match arms have incompatible types' error) - rust-lang#78263 (Add regression test of issue-77668) - rust-lang#78265 (Add some inference-related regression tests about incorrect diagnostics) Failed merges: r? `@ghost`
2 parents a9cd294 + b5d2ff0 commit 07a63e6

File tree

53 files changed

+523
-111
lines changed

Some content is hidden

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

53 files changed

+523
-111
lines changed

Diff for: CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Thank you for your interest in contributing to Rust!
44

5-
To get started, read the [Getting Started] guide in the [rustc-dev-guide].
5+
To get started, read the [Contributing to Rust] chapter of the [rustc-dev-guide].
66

77
## Bug reports
88

99
Did a compiler error message tell you to come here? If you want to create an ICE report,
1010
refer to [this section][contributing-bug-reports] and [open an issue][issue template].
1111

12-
[Getting Started]: https://rustc-dev-guide.rust-lang.org/getting-started.html
12+
[Contributing to Rust]: https://rustc-dev-guide.rust-lang.org/contributing.html#contributing-to-rust
1313
[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
1414
[contributing-bug-reports]: https://rustc-dev-guide.rust-lang.org/contributing.html#bug-reports
1515
[issue template]: https://github.com/rust-lang/rust/issues/new/choose

Diff for: Cargo.lock

+14-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ dependencies = [
310310
"crypto-hash",
311311
"curl",
312312
"curl-sys",
313-
"env_logger 0.7.1",
313+
"env_logger 0.8.1",
314314
"filetime",
315315
"flate2",
316316
"fwdansi",
@@ -1035,6 +1035,19 @@ dependencies = [
10351035
"termcolor",
10361036
]
10371037

1038+
[[package]]
1039+
name = "env_logger"
1040+
version = "0.8.1"
1041+
source = "registry+https://github.com/rust-lang/crates.io-index"
1042+
checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd"
1043+
dependencies = [
1044+
"atty",
1045+
"humantime 2.0.1",
1046+
"log",
1047+
"regex",
1048+
"termcolor",
1049+
]
1050+
10381051
[[package]]
10391052
name = "error_index_generator"
10401053
version = "0.0.0"

Diff for: compiler/rustc_feature/src/active.rs

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
622622
sym::lazy_normalization_consts,
623623
sym::specialization,
624624
sym::inline_const,
625+
sym::repr128,
625626
];
626627

627628
/// Some features are not allowed to be used together at the same time, if

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
619619
scrut_hir_id,
620620
opt_suggest_box_span,
621621
arm_span,
622+
scrut_span,
622623
..
623624
}) => match source {
624625
hir::MatchSource::IfLetDesugar { .. } => {
@@ -664,18 +665,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
664665
Some(ty::error::ExpectedFound { expected, .. }) => expected,
665666
_ => last_ty,
666667
});
667-
let msg = "`match` arms have incompatible types";
668-
err.span_label(cause.span, msg);
668+
let source_map = self.tcx.sess.source_map();
669+
let mut any_multiline_arm = source_map.is_multiline(arm_span);
669670
if prior_arms.len() <= 4 {
670671
for sp in prior_arms {
672+
any_multiline_arm |= source_map.is_multiline(*sp);
671673
err.span_label(*sp, format!("this is found to be of type `{}`", t));
672674
}
673675
} else if let Some(sp) = prior_arms.last() {
676+
any_multiline_arm |= source_map.is_multiline(*sp);
674677
err.span_label(
675678
*sp,
676679
format!("this and all prior arms are found to be of type `{}`", t),
677680
);
678681
}
682+
let outer_error_span = if any_multiline_arm {
683+
// Cover just `match` and the scrutinee expression, not
684+
// the entire match body, to reduce diagram noise.
685+
cause.span.shrink_to_lo().to(scrut_span)
686+
} else {
687+
cause.span
688+
};
689+
let msg = "`match` arms have incompatible types";
690+
err.span_label(outer_error_span, msg);
679691
if let Some(sp) = semi_span {
680692
err.span_suggestion_short(
681693
sp,

Diff for: compiler/rustc_middle/src/middle/region.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,20 @@ pub struct ScopeTree {
292292
///
293293
/// Then:
294294
///
295-
/// 1. From the ordering guarantee of HIR visitors (see
296-
/// `rustc_hir::intravisit`), `D` does not dominate `U`.
295+
/// 1. From the ordering guarantee of HIR visitors (see
296+
/// `rustc_hir::intravisit`), `D` does not dominate `U`.
297297
///
298-
/// 2. Therefore, `D` is *potentially* storage-dead at `U` (because
299-
/// we might visit `U` without ever getting to `D`).
298+
/// 2. Therefore, `D` is *potentially* storage-dead at `U` (because
299+
/// we might visit `U` without ever getting to `D`).
300300
///
301-
/// 3. However, we guarantee that at each HIR point, each
302-
/// binding/temporary is always either always storage-live
303-
/// or always storage-dead. This is what is being guaranteed
304-
/// by `terminating_scopes` including all blocks where the
305-
/// count of executions is not guaranteed.
301+
/// 3. However, we guarantee that at each HIR point, each
302+
/// binding/temporary is always either always storage-live
303+
/// or always storage-dead. This is what is being guaranteed
304+
/// by `terminating_scopes` including all blocks where the
305+
/// count of executions is not guaranteed.
306306
///
307-
/// 4. By `2.` and `3.`, `D` is *statically* storage-dead at `U`,
308-
/// QED.
307+
/// 4. By `2.` and `3.`, `D` is *statically* storage-dead at `U`,
308+
/// QED.
309309
///
310310
/// This property ought to not on (3) in an essential way -- it
311311
/// is probably still correct even if we have "unrestricted" terminating

Diff for: compiler/rustc_middle/src/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static_assert_size!(ObligationCauseCode<'_>, 32);
343343
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
344344
pub struct MatchExpressionArmCause<'tcx> {
345345
pub arm_span: Span,
346+
pub scrut_span: Span,
346347
pub semi_span: Option<Span>,
347348
pub source: hir::MatchSource,
348349
pub prior_arms: Vec<Span>,

Diff for: compiler/rustc_mir_build/src/thir/pattern/_match.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,26 @@
7878
//! new pattern `p`.
7979
//!
8080
//! For example, say we have the following:
81+
//!
8182
//! ```
82-
//! // x: (Option<bool>, Result<()>)
83-
//! match x {
84-
//! (Some(true), _) => {}
85-
//! (None, Err(())) => {}
86-
//! (None, Err(_)) => {}
87-
//! }
83+
//! // x: (Option<bool>, Result<()>)
84+
//! match x {
85+
//! (Some(true), _) => {}
86+
//! (None, Err(())) => {}
87+
//! (None, Err(_)) => {}
88+
//! }
8889
//! ```
90+
//!
8991
//! Here, the matrix `P` starts as:
92+
//!
93+
//! ```
9094
//! [
9195
//! [(Some(true), _)],
9296
//! [(None, Err(()))],
9397
//! [(None, Err(_))],
9498
//! ]
99+
//! ```
100+
//!
95101
//! We can tell it's not exhaustive, because `U(P, _)` is true (we're not covering
96102
//! `[(Some(false), _)]`, for instance). In addition, row 3 is not useful, because
97103
//! all the values it covers are already covered by row 2.
@@ -178,10 +184,14 @@
178184
//! This special case is handled in `is_useful_specialized`.
179185
//!
180186
//! For example, if `P` is:
187+
//!
188+
//! ```
181189
//! [
182-
//! [Some(true), _],
183-
//! [None, 0],
190+
//! [Some(true), _],
191+
//! [None, 0],
184192
//! ]
193+
//! ```
194+
//!
185195
//! and `p` is [Some(false), 0], then we don't care about row 2 since we know `p` only
186196
//! matches values that row 2 doesn't. For row 1 however, we need to dig into the
187197
//! arguments of `Some` to know whether some new value is covered. So we compute
@@ -198,10 +208,14 @@
198208
//! `U(P, p) := U(D(P), D(p))`
199209
//!
200210
//! For example, if `P` is:
211+
//!
212+
//! ```
201213
//! [
202214
//! [_, true, _],
203215
//! [None, false, 1],
204216
//! ]
217+
//! ```
218+
//!
205219
//! and `p` is [_, false, _], the `Some` constructor doesn't appear in `P`. So if we
206220
//! only had row 2, we'd know that `p` is useful. However row 1 starts with a
207221
//! wildcard, so we need to check whether `U([[true, _]], [false, 1])`.
@@ -215,10 +229,14 @@
215229
//! `U(P, p) := ∃(k ϵ constructors) U(S(k, P), S(k, p))`
216230
//!
217231
//! For example, if `P` is:
232+
//!
233+
//! ```
218234
//! [
219235
//! [Some(true), _],
220236
//! [None, false],
221237
//! ]
238+
//! ```
239+
//!
222240
//! and `p` is [_, false], both `None` and `Some` constructors appear in the first
223241
//! components of `P`. We will therefore try popping both constructors in turn: we
224242
//! compute `U([[true, _]], [_, false])` for the `Some` constructor, and `U([[false]],
@@ -1496,6 +1514,7 @@ struct PatCtxt<'tcx> {
14961514
/// multiple patterns.
14971515
///
14981516
/// For example, if we are constructing a witness for the match against
1517+
///
14991518
/// ```
15001519
/// struct Pair(Option<(u32, u32)>, bool);
15011520
///
@@ -1619,12 +1638,14 @@ fn all_constructors<'a, 'tcx>(
16191638
// actually match against them all themselves. So we always return only the fictitious
16201639
// constructor.
16211640
// E.g., in an example like:
1641+
//
16221642
// ```
16231643
// let err: io::ErrorKind = ...;
16241644
// match err {
16251645
// io::ErrorKind::NotFound => {},
16261646
// }
16271647
// ```
1648+
//
16281649
// we don't want to show every possible IO error, but instead have only `_` as the
16291650
// witness.
16301651
let is_declared_nonexhaustive = cx.is_foreign_non_exhaustive_enum(pcx.ty);
@@ -2017,6 +2038,7 @@ crate fn is_useful<'p, 'tcx>(
20172038
let mut unreachable_branches = Vec::new();
20182039
// Subpatterns that are unreachable from all branches. E.g. in the following case, the last
20192040
// `true` is unreachable only from one branch, so it is overall reachable.
2041+
//
20202042
// ```
20212043
// match (true, true) {
20222044
// (true, true) => {}
@@ -2161,10 +2183,12 @@ crate fn is_useful<'p, 'tcx>(
21612183
// to do this and instead report a single `_` witness:
21622184
// if the user didn't actually specify a constructor
21632185
// in this arm, e.g., in
2186+
//
21642187
// ```
21652188
// let x: (Direction, Direction, bool) = ...;
21662189
// let (_, _, false) = x;
21672190
// ```
2191+
//
21682192
// we don't want to show all 16 possible witnesses
21692193
// `(<direction-1>, <direction-2>, true)` - we are
21702194
// satisfied with `(_, _, true)`. In this case,

Diff for: compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,8 @@ impl<'a> Parser<'a> {
10621062
})
10631063
} else if self.eat_keyword(kw::Unsafe) {
10641064
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
1065-
} else if self.check_inline_const() {
1066-
self.parse_const_expr(lo.to(self.token.span))
1065+
} else if self.check_inline_const(0) {
1066+
self.parse_const_block(lo.to(self.token.span))
10671067
} else if self.is_do_catch_block() {
10681068
self.recover_do_catch(attrs)
10691069
} else if self.is_try_block() {

Diff for: compiler/rustc_parse/src/parser/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,9 @@ impl<'a> Parser<'a> {
522522
self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const)
523523
}
524524

525-
fn check_inline_const(&mut self) -> bool {
526-
self.check_keyword(kw::Const)
527-
&& self.look_ahead(1, |t| match t.kind {
525+
fn check_inline_const(&self, dist: usize) -> bool {
526+
self.is_keyword_ahead(dist, &[kw::Const])
527+
&& self.look_ahead(dist + 1, |t| match t.kind {
528528
token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)),
529529
token::OpenDelim(DelimToken::Brace) => true,
530530
_ => false,
@@ -864,7 +864,7 @@ impl<'a> Parser<'a> {
864864
}
865865

866866
/// Parses inline const expressions.
867-
fn parse_const_expr(&mut self, span: Span) -> PResult<'a, P<Expr>> {
867+
fn parse_const_block(&mut self, span: Span) -> PResult<'a, P<Expr>> {
868868
self.sess.gated_spans.gate(sym::inline_const, span);
869869
self.eat_keyword(kw::Const);
870870
let blk = self.parse_block()?;

Diff for: compiler/rustc_parse/src/parser/pat.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,15 @@ impl<'a> Parser<'a> {
313313
let pat = self.parse_pat_with_range_pat(false, None)?;
314314
self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
315315
PatKind::Box(pat)
316-
} else if self.check_inline_const() {
316+
} else if self.check_inline_const(0) {
317317
// Parse `const pat`
318-
PatKind::Lit(self.parse_const_expr(lo.to(self.token.span))?)
318+
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
319+
320+
if let Some(re) = self.parse_range_end() {
321+
self.parse_pat_range_begin_with(const_expr, re)?
322+
} else {
323+
PatKind::Lit(const_expr)
324+
}
319325
} else if self.can_be_ident_pat() {
320326
// Parse `ident @ pat`
321327
// This can give false positives and parse nullary enums,
@@ -717,16 +723,19 @@ impl<'a> Parser<'a> {
717723

718724
/// Is the token `dist` away from the current suitable as the start of a range patterns end?
719725
fn is_pat_range_end_start(&self, dist: usize) -> bool {
720-
self.look_ahead(dist, |t| {
721-
t.is_path_start() // e.g. `MY_CONST`;
726+
self.check_inline_const(dist)
727+
|| self.look_ahead(dist, |t| {
728+
t.is_path_start() // e.g. `MY_CONST`;
722729
|| t.kind == token::Dot // e.g. `.5` for recovery;
723730
|| t.can_begin_literal_maybe_minus() // e.g. `42`.
724731
|| t.is_whole_expr()
725-
})
732+
})
726733
}
727734

728735
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
729-
if self.check_path() {
736+
if self.check_inline_const(0) {
737+
self.parse_const_block(self.token.span)
738+
} else if self.check_path() {
730739
let lo = self.token.span;
731740
let (qself, path) = if self.eat_lt() {
732741
// Parse a qualified path

Diff for: compiler/rustc_typeck/src/check/_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
201201
expr.span,
202202
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
203203
arm_span,
204+
scrut_span: scrut.span,
204205
semi_span,
205206
source: match_src,
206207
prior_arms: other_arms.clone(),

Diff for: compiler/rustc_typeck/src/check/coercion.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,28 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14751475
if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.borrow().as_ref(), fn_output) {
14761476
self.add_impl_trait_explanation(&mut err, cause, fcx, expected, *sp, fn_output);
14771477
}
1478+
1479+
if let Some(sp) = fcx.ret_coercion_span.borrow().as_ref() {
1480+
// If the closure has an explicit return type annotation,
1481+
// then a type error may occur at the first return expression we
1482+
// see in the closure (if it conflicts with the declared
1483+
// return type). Skip adding a note in this case, since it
1484+
// would be incorrect.
1485+
if !err.span.primary_spans().iter().any(|span| span == sp) {
1486+
let hir = fcx.tcx.hir();
1487+
let body_owner = hir.body_owned_by(hir.enclosing_body_owner(fcx.body_id));
1488+
if fcx.tcx.is_closure(hir.body_owner_def_id(body_owner).to_def_id()) {
1489+
err.span_note(
1490+
*sp,
1491+
&format!(
1492+
"return type inferred to be `{}` here",
1493+
fcx.resolve_vars_if_possible(&expected)
1494+
),
1495+
);
1496+
}
1497+
}
1498+
}
1499+
14781500
err
14791501
}
14801502

Diff for: compiler/rustc_typeck/src/collect.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_middle::ty::query::Providers;
4040
use rustc_middle::ty::subst::InternalSubsts;
4141
use rustc_middle::ty::util::Discr;
4242
use rustc_middle::ty::util::IntTypeExt;
43-
use rustc_middle::ty::{self, AdtKind, Const, ToPolyTraitRef, Ty, TyCtxt};
43+
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, ToPolyTraitRef, Ty, TyCtxt};
4444
use rustc_middle::ty::{ReprOptions, ToPredicate, WithConstness};
4545
use rustc_session::config::SanitizerSet;
4646
use rustc_session::lint;
@@ -2786,6 +2786,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27862786
}
27872787
});
27882788

2789+
// #73631: closures inherit `#[target_feature]` annotations
2790+
if tcx.features().target_feature_11 && tcx.is_closure(id) {
2791+
let owner_id = tcx.parent(id).expect("closure should have a parent");
2792+
codegen_fn_attrs
2793+
.target_features
2794+
.extend(tcx.codegen_fn_attrs(owner_id).target_features.iter().copied())
2795+
}
2796+
27892797
// If a function uses #[target_feature] it can't be inlined into general
27902798
// purpose functions as they wouldn't have the right target features
27912799
// enabled. For that reason we also forbid #[inline(always)] as it can't be

0 commit comments

Comments
 (0)