Skip to content

Commit 9a40539

Browse files
committed
Auto merge of #80364 - Dylan-DPC:rollup-0y96okz, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - #79213 (Stabilize `core::slice::fill`) - #79999 (Refactored verbose print into a function) - #80160 (Implemented a compiler diagnostic for move async mistake) - #80274 (Rename rustc_middle::lint::LintSource) - #80280 (Add installation commands to `x` tool README) - #80319 (Fix elided lifetimes shown as `'_` on async functions) - #80327 (Updated the match with the matches macro) - #80330 (Fix typo in simplify_try.rs) - #80340 (Don't unnecessarily override attrs for Module) - #80342 (Fix typo) - #80352 (BTreeMap: make test cases more explicit on failure) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cae1f4d + 7c7812d commit 9a40539

32 files changed

+203
-105
lines changed

compiler/rustc_lint/src/levels.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use rustc_hir::{intravisit, HirId};
1212
use rustc_middle::hir::map::Map;
1313
use rustc_middle::lint::LevelSource;
1414
use rustc_middle::lint::LintDiagnosticBuilder;
15-
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
15+
use rustc_middle::lint::{
16+
struct_lint_level, LintLevelMap, LintLevelSets, LintLevelSource, LintSet,
17+
};
1618
use rustc_middle::ty::query::Providers;
1719
use rustc_middle::ty::TyCtxt;
1820
use rustc_session::lint::{builtin, Level, Lint, LintId};
@@ -91,7 +93,7 @@ impl<'s> LintLevelsBuilder<'s> {
9193
};
9294
for id in ids {
9395
self.check_gated_lint(id, DUMMY_SP);
94-
let src = LintSource::CommandLine(lint_flag_val, orig_level);
96+
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
9597
specs.insert(id, (level, src));
9698
}
9799
}
@@ -128,19 +130,19 @@ impl<'s> LintLevelsBuilder<'s> {
128130
);
129131
diag_builder.span_label(src.span(), "overruled by previous forbid");
130132
match old_src {
131-
LintSource::Default => {
133+
LintLevelSource::Default => {
132134
diag_builder.note(&format!(
133135
"`forbid` lint level is the default for {}",
134136
id.to_string()
135137
));
136138
}
137-
LintSource::Node(_, forbid_source_span, reason) => {
139+
LintLevelSource::Node(_, forbid_source_span, reason) => {
138140
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
139141
if let Some(rationale) = reason {
140142
diag_builder.note(&rationale.as_str());
141143
}
142144
}
143-
LintSource::CommandLine(_, _) => {
145+
LintLevelSource::CommandLine(_, _) => {
144146
diag_builder.note("`forbid` lint level was set on command line");
145147
}
146148
}
@@ -276,7 +278,7 @@ impl<'s> LintLevelsBuilder<'s> {
276278
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
277279
match store.check_lint_name(&name.as_str(), tool_name) {
278280
CheckLintNameResult::Ok(ids) => {
279-
let src = LintSource::Node(name, li.span(), reason);
281+
let src = LintLevelSource::Node(name, li.span(), reason);
280282
for &id in ids {
281283
self.check_gated_lint(id, attr.span);
282284
self.insert_spec(&mut specs, id, (level, src));
@@ -287,7 +289,7 @@ impl<'s> LintLevelsBuilder<'s> {
287289
match result {
288290
Ok(ids) => {
289291
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
290-
let src = LintSource::Node(
292+
let src = LintLevelSource::Node(
291293
Symbol::intern(complete_name),
292294
li.span(),
293295
reason,
@@ -324,7 +326,7 @@ impl<'s> LintLevelsBuilder<'s> {
324326
},
325327
);
326328

327-
let src = LintSource::Node(
329+
let src = LintLevelSource::Node(
328330
Symbol::intern(&new_lint_name),
329331
li.span(),
330332
reason,
@@ -403,7 +405,7 @@ impl<'s> LintLevelsBuilder<'s> {
403405
}
404406

405407
let (lint_attr_name, lint_attr_span) = match *src {
406-
LintSource::Node(name, span, _) => (name, span),
408+
LintLevelSource::Node(name, span, _) => (name, span),
407409
_ => continue,
408410
};
409411

@@ -460,7 +462,7 @@ impl<'s> LintLevelsBuilder<'s> {
460462
}
461463

462464
/// Find the lint level for a lint.
463-
pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintSource) {
465+
pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintLevelSource) {
464466
self.sets.get_lint_level(lint, self.cur, None, self.sess)
465467
}
466468

compiler/rustc_middle/src/lint.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::{symbol, Span, Symbol, DUMMY_SP};
1313

1414
/// How a lint level was set.
1515
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
16-
pub enum LintSource {
16+
pub enum LintLevelSource {
1717
/// Lint is at the default level as declared
1818
/// in rustc or a plugin.
1919
Default,
@@ -27,25 +27,26 @@ pub enum LintSource {
2727
CommandLine(Symbol, Level),
2828
}
2929

30-
impl LintSource {
30+
impl LintLevelSource {
3131
pub fn name(&self) -> Symbol {
3232
match *self {
33-
LintSource::Default => symbol::kw::Default,
34-
LintSource::Node(name, _, _) => name,
35-
LintSource::CommandLine(name, _) => name,
33+
LintLevelSource::Default => symbol::kw::Default,
34+
LintLevelSource::Node(name, _, _) => name,
35+
LintLevelSource::CommandLine(name, _) => name,
3636
}
3737
}
3838

3939
pub fn span(&self) -> Span {
4040
match *self {
41-
LintSource::Default => DUMMY_SP,
42-
LintSource::Node(_, span, _) => span,
43-
LintSource::CommandLine(_, _) => DUMMY_SP,
41+
LintLevelSource::Default => DUMMY_SP,
42+
LintLevelSource::Node(_, span, _) => span,
43+
LintLevelSource::CommandLine(_, _) => DUMMY_SP,
4444
}
4545
}
4646
}
4747

48-
pub type LevelSource = (Level, LintSource);
48+
/// A tuple of a lint level and its source.
49+
pub type LevelSource = (Level, LintLevelSource);
4950

5051
pub struct LintLevelSets {
5152
pub list: Vec<LintSet>,
@@ -113,7 +114,7 @@ impl LintLevelSets {
113114
id: LintId,
114115
mut idx: u32,
115116
aux: Option<&FxHashMap<LintId, LevelSource>>,
116-
) -> (Option<Level>, LintSource) {
117+
) -> (Option<Level>, LintLevelSource) {
117118
if let Some(specs) = aux {
118119
if let Some(&(level, src)) = specs.get(&id) {
119120
return (Some(level), src);
@@ -125,7 +126,7 @@ impl LintLevelSets {
125126
if let Some(&(level, src)) = specs.get(&id) {
126127
return (Some(level), src);
127128
}
128-
return (None, LintSource::Default);
129+
return (None, LintLevelSource::Default);
129130
}
130131
LintSet::Node { ref specs, parent } => {
131132
if let Some(&(level, src)) = specs.get(&id) {
@@ -213,7 +214,7 @@ pub fn struct_lint_level<'s, 'd>(
213214
sess: &'s Session,
214215
lint: &'static Lint,
215216
level: Level,
216-
src: LintSource,
217+
src: LintLevelSource,
217218
span: Option<MultiSpan>,
218219
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>) + 'd,
219220
) {
@@ -223,7 +224,7 @@ pub fn struct_lint_level<'s, 'd>(
223224
sess: &'s Session,
224225
lint: &'static Lint,
225226
level: Level,
226-
src: LintSource,
227+
src: LintLevelSource,
227228
span: Option<MultiSpan>,
228229
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
229230
) {
@@ -274,14 +275,14 @@ pub fn struct_lint_level<'s, 'd>(
274275

275276
let name = lint.name_lower();
276277
match src {
277-
LintSource::Default => {
278+
LintLevelSource::Default => {
278279
sess.diag_note_once(
279280
&mut err,
280281
DiagnosticMessageId::from(lint),
281282
&format!("`#[{}({})]` on by default", level.as_str(), name),
282283
);
283284
}
284-
LintSource::CommandLine(lint_flag_val, orig_level) => {
285+
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
285286
let flag = match orig_level {
286287
Level::Warn => "-W",
287288
Level::Deny => "-D",
@@ -310,7 +311,7 @@ pub fn struct_lint_level<'s, 'd>(
310311
);
311312
}
312313
}
313-
LintSource::Node(lint_attr_name, src, reason) => {
314+
LintLevelSource::Node(lint_attr_name, src, reason) => {
314315
if let Some(rationale) = reason {
315316
err.note(&rationale.as_str());
316317
}

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::dep_graph::{self, DepGraph, DepKind, DepNode, DepNodeExt};
55
use crate::hir::exports::ExportMap;
66
use crate::ich::{NodeIdHashingMode, StableHashingContext};
77
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
8-
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource};
8+
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
99
use crate::middle;
1010
use crate::middle::cstore::{CrateStoreDyn, EncodedMetadata};
1111
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
@@ -2559,7 +2559,7 @@ impl<'tcx> TyCtxt<'tcx> {
25592559
self,
25602560
lint: &'static Lint,
25612561
mut id: hir::HirId,
2562-
) -> (Level, LintSource) {
2562+
) -> (Level, LintLevelSource) {
25632563
let sets = self.lint_levels(LOCAL_CRATE);
25642564
loop {
25652565
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {

compiler/rustc_middle/src/ty/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424
/// This means we can use pointer for both
2525
/// equality comparisons and hashing.
2626
///
27-
/// Unlike slices, The types contained in `List` are expected to be `Copy`
27+
/// Unlike slices, the types contained in `List` are expected to be `Copy`
2828
/// and iterating over a `List` returns `T` instead of a reference.
2929
///
3030
/// Note: `Slice` was already taken by the `Ty`.

compiler/rustc_middle/src/ty/sty.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,7 @@ pub enum TyKind<'tcx> {
215215
impl TyKind<'tcx> {
216216
#[inline]
217217
pub fn is_primitive(&self) -> bool {
218-
match self {
219-
Bool | Char | Int(_) | Uint(_) | Float(_) => true,
220-
_ => false,
221-
}
218+
matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
222219
}
223220

224221
/// Get the article ("a" or "an") to use with this type.

compiler/rustc_mir/src/transform/simplify_try.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn optimization_applies<'tcx>(
306306
return false;
307307
}
308308

309-
// Verify the assigment chain consists of the form b = a; c = b; d = c; etc...
309+
// Verify the assignment chain consists of the form b = a; c = b; d = c; etc...
310310
if opt_info.field_tmp_assignments.is_empty() {
311311
trace!("NO: no assignments found");
312312
return false;

compiler/rustc_mir/src/util/pretty.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::interpret::{
1717
};
1818
use rustc_middle::mir::visit::Visitor;
1919
use rustc_middle::mir::*;
20-
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
20+
use rustc_middle::ty::{self, TyCtxt, TyS, TypeFoldable, TypeVisitor};
2121
use rustc_target::abi::Size;
2222
use std::ops::ControlFlow;
2323

@@ -408,6 +408,18 @@ impl ExtraComments<'tcx> {
408408
}
409409
}
410410

411+
fn use_verbose(ty: &&TyS<'tcx>) -> bool {
412+
match ty.kind() {
413+
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
414+
// Unit type
415+
ty::Tuple(g_args) if g_args.is_empty() => false,
416+
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(&g_arg.expect_ty())),
417+
ty::Array(ty, _) => use_verbose(ty),
418+
ty::FnDef(..) => false,
419+
_ => true,
420+
}
421+
}
422+
411423
impl Visitor<'tcx> for ExtraComments<'tcx> {
412424
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
413425
self.super_constant(constant, location);
@@ -430,16 +442,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
430442
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
431443
self.super_const(constant);
432444
let ty::Const { ty, val, .. } = constant;
433-
match ty.kind() {
434-
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => {}
435-
// Unit type
436-
ty::Tuple(tys) if tys.is_empty() => {}
437-
ty::FnDef(..) => {}
438-
_ => {
439-
self.push("ty::Const");
440-
self.push(&format!("+ ty: {:?}", ty));
441-
self.push(&format!("+ val: {:?}", val));
442-
}
445+
if use_verbose(ty) {
446+
self.push("ty::Const");
447+
self.push(&format!("+ ty: {:?}", ty));
448+
self.push(&format!("+ val: {:?}", val));
443449
}
444450
}
445451

compiler/rustc_parse/src/parser/diagnostics.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1912,4 +1912,22 @@ impl<'a> Parser<'a> {
19121912
*self = snapshot;
19131913
Err(err)
19141914
}
1915+
1916+
/// Get the diagnostics for the cases where `move async` is found.
1917+
///
1918+
/// `move_async_span` starts at the 'm' of the move keyword and ends with the 'c' of the async keyword
1919+
pub(super) fn incorrect_move_async_order_found(
1920+
&self,
1921+
move_async_span: Span,
1922+
) -> DiagnosticBuilder<'a> {
1923+
let mut err =
1924+
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
1925+
err.span_suggestion_verbose(
1926+
move_async_span,
1927+
"try switching the order",
1928+
"async move".to_owned(),
1929+
Applicability::MaybeIncorrect,
1930+
);
1931+
err
1932+
}
19151933
}

compiler/rustc_parse/src/parser/expr.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ impl<'a> Parser<'a> {
16031603
self.sess.gated_spans.gate(sym::async_closure, span);
16041604
}
16051605

1606-
let capture_clause = self.parse_capture_clause();
1606+
let capture_clause = self.parse_capture_clause()?;
16071607
let decl = self.parse_fn_block_decl()?;
16081608
let decl_hi = self.prev_token.span;
16091609
let body = match decl.output {
@@ -1626,8 +1626,18 @@ impl<'a> Parser<'a> {
16261626
}
16271627

16281628
/// Parses an optional `move` prefix to a closure-like construct.
1629-
fn parse_capture_clause(&mut self) -> CaptureBy {
1630-
if self.eat_keyword(kw::Move) { CaptureBy::Value } else { CaptureBy::Ref }
1629+
fn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy> {
1630+
if self.eat_keyword(kw::Move) {
1631+
// Check for `move async` and recover
1632+
if self.check_keyword(kw::Async) {
1633+
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
1634+
Err(self.incorrect_move_async_order_found(move_async_span))
1635+
} else {
1636+
Ok(CaptureBy::Value)
1637+
}
1638+
} else {
1639+
Ok(CaptureBy::Ref)
1640+
}
16311641
}
16321642

16331643
/// Parses the `|arg, arg|` header of a closure.
@@ -2019,7 +2029,7 @@ impl<'a> Parser<'a> {
20192029
fn parse_async_block(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
20202030
let lo = self.token.span;
20212031
self.expect_keyword(kw::Async)?;
2022-
let capture_clause = self.parse_capture_clause();
2032+
let capture_clause = self.parse_capture_clause()?;
20232033
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
20242034
attrs.extend(iattrs);
20252035
let kind = ExprKind::Async(capture_clause, DUMMY_NODE_ID, body);

library/alloc/src/collections/btree/map/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<K, V> BTreeMap<K, V> {
115115

116116
impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
117117
fn assert_min_len(self, min_len: usize) {
118-
assert!(self.len() >= min_len, "{} < {}", self.len(), min_len);
118+
assert!(self.len() >= min_len, "node len {} < {}", self.len(), min_len);
119119
if let node::ForceResult::Internal(node) = self.force() {
120120
for idx in 0..=node.len() {
121121
let edge = unsafe { Handle::new_edge(node, idx) };

library/alloc/src/collections/btree/node/tests.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
3030
let depth = self.height();
3131
let indent = " ".repeat(depth);
3232
result += &format!("\n{}", indent);
33-
for idx in 0..leaf.len() {
34-
if idx > 0 {
35-
result += ", ";
33+
if leaf.len() == 0 {
34+
result += "(empty node)";
35+
} else {
36+
for idx in 0..leaf.len() {
37+
if idx > 0 {
38+
result += ", ";
39+
}
40+
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
3641
}
37-
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
3842
}
3943
}
4044
navigate::Position::Internal(_) => {}

library/core/src/slice/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2581,14 +2581,12 @@ impl<T> [T] {
25812581
/// # Examples
25822582
///
25832583
/// ```
2584-
/// #![feature(slice_fill)]
2585-
///
25862584
/// let mut buf = vec![0; 10];
25872585
/// buf.fill(1);
25882586
/// assert_eq!(buf, vec![1; 10]);
25892587
/// ```
25902588
#[doc(alias = "memset")]
2591-
#[unstable(feature = "slice_fill", issue = "70758")]
2589+
#[stable(feature = "slice_fill", since = "1.50.0")]
25922590
pub fn fill(&mut self, value: T)
25932591
where
25942592
T: Clone,

0 commit comments

Comments
 (0)