Skip to content

Commit

Permalink
Auto merge of #80364 - Dylan-DPC:rollup-0y96okz, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 25, 2020
2 parents cae1f4d + 7c7812d commit 9a40539
Show file tree
Hide file tree
Showing 32 changed files with 203 additions and 105 deletions.
22 changes: 12 additions & 10 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use rustc_hir::{intravisit, HirId};
use rustc_middle::hir::map::Map;
use rustc_middle::lint::LevelSource;
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::lint::{struct_lint_level, LintLevelMap, LintLevelSets, LintSet, LintSource};
use rustc_middle::lint::{
struct_lint_level, LintLevelMap, LintLevelSets, LintLevelSource, LintSet,
};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{builtin, Level, Lint, LintId};
Expand Down Expand Up @@ -91,7 +93,7 @@ impl<'s> LintLevelsBuilder<'s> {
};
for id in ids {
self.check_gated_lint(id, DUMMY_SP);
let src = LintSource::CommandLine(lint_flag_val, orig_level);
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
specs.insert(id, (level, src));
}
}
Expand Down Expand Up @@ -128,19 +130,19 @@ impl<'s> LintLevelsBuilder<'s> {
);
diag_builder.span_label(src.span(), "overruled by previous forbid");
match old_src {
LintSource::Default => {
LintLevelSource::Default => {
diag_builder.note(&format!(
"`forbid` lint level is the default for {}",
id.to_string()
));
}
LintSource::Node(_, forbid_source_span, reason) => {
LintLevelSource::Node(_, forbid_source_span, reason) => {
diag_builder.span_label(forbid_source_span, "`forbid` level set here");
if let Some(rationale) = reason {
diag_builder.note(&rationale.as_str());
}
}
LintSource::CommandLine(_, _) => {
LintLevelSource::CommandLine(_, _) => {
diag_builder.note("`forbid` lint level was set on command line");
}
}
Expand Down Expand Up @@ -276,7 +278,7 @@ impl<'s> LintLevelsBuilder<'s> {
let name = meta_item.path.segments.last().expect("empty lint name").ident.name;
match store.check_lint_name(&name.as_str(), tool_name) {
CheckLintNameResult::Ok(ids) => {
let src = LintSource::Node(name, li.span(), reason);
let src = LintLevelSource::Node(name, li.span(), reason);
for &id in ids {
self.check_gated_lint(id, attr.span);
self.insert_spec(&mut specs, id, (level, src));
Expand All @@ -287,7 +289,7 @@ impl<'s> LintLevelsBuilder<'s> {
match result {
Ok(ids) => {
let complete_name = &format!("{}::{}", tool_name.unwrap(), name);
let src = LintSource::Node(
let src = LintLevelSource::Node(
Symbol::intern(complete_name),
li.span(),
reason,
Expand Down Expand Up @@ -324,7 +326,7 @@ impl<'s> LintLevelsBuilder<'s> {
},
);

let src = LintSource::Node(
let src = LintLevelSource::Node(
Symbol::intern(&new_lint_name),
li.span(),
reason,
Expand Down Expand Up @@ -403,7 +405,7 @@ impl<'s> LintLevelsBuilder<'s> {
}

let (lint_attr_name, lint_attr_span) = match *src {
LintSource::Node(name, span, _) => (name, span),
LintLevelSource::Node(name, span, _) => (name, span),
_ => continue,
};

Expand Down Expand Up @@ -460,7 +462,7 @@ impl<'s> LintLevelsBuilder<'s> {
}

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

Expand Down
33 changes: 17 additions & 16 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_span::{symbol, Span, Symbol, DUMMY_SP};

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

impl LintSource {
impl LintLevelSource {
pub fn name(&self) -> Symbol {
match *self {
LintSource::Default => symbol::kw::Default,
LintSource::Node(name, _, _) => name,
LintSource::CommandLine(name, _) => name,
LintLevelSource::Default => symbol::kw::Default,
LintLevelSource::Node(name, _, _) => name,
LintLevelSource::CommandLine(name, _) => name,
}
}

pub fn span(&self) -> Span {
match *self {
LintSource::Default => DUMMY_SP,
LintSource::Node(_, span, _) => span,
LintSource::CommandLine(_, _) => DUMMY_SP,
LintLevelSource::Default => DUMMY_SP,
LintLevelSource::Node(_, span, _) => span,
LintLevelSource::CommandLine(_, _) => DUMMY_SP,
}
}
}

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

pub struct LintLevelSets {
pub list: Vec<LintSet>,
Expand Down Expand Up @@ -113,7 +114,7 @@ impl LintLevelSets {
id: LintId,
mut idx: u32,
aux: Option<&FxHashMap<LintId, LevelSource>>,
) -> (Option<Level>, LintSource) {
) -> (Option<Level>, LintLevelSource) {
if let Some(specs) = aux {
if let Some(&(level, src)) = specs.get(&id) {
return (Some(level), src);
Expand All @@ -125,7 +126,7 @@ impl LintLevelSets {
if let Some(&(level, src)) = specs.get(&id) {
return (Some(level), src);
}
return (None, LintSource::Default);
return (None, LintLevelSource::Default);
}
LintSet::Node { ref specs, parent } => {
if let Some(&(level, src)) = specs.get(&id) {
Expand Down Expand Up @@ -213,7 +214,7 @@ pub fn struct_lint_level<'s, 'd>(
sess: &'s Session,
lint: &'static Lint,
level: Level,
src: LintSource,
src: LintLevelSource,
span: Option<MultiSpan>,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>) + 'd,
) {
Expand All @@ -223,7 +224,7 @@ pub fn struct_lint_level<'s, 'd>(
sess: &'s Session,
lint: &'static Lint,
level: Level,
src: LintSource,
src: LintLevelSource,
span: Option<MultiSpan>,
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
) {
Expand Down Expand Up @@ -274,14 +275,14 @@ pub fn struct_lint_level<'s, 'd>(

let name = lint.name_lower();
match src {
LintSource::Default => {
LintLevelSource::Default => {
sess.diag_note_once(
&mut err,
DiagnosticMessageId::from(lint),
&format!("`#[{}({})]` on by default", level.as_str(), name),
);
}
LintSource::CommandLine(lint_flag_val, orig_level) => {
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
let flag = match orig_level {
Level::Warn => "-W",
Level::Deny => "-D",
Expand Down Expand Up @@ -310,7 +311,7 @@ pub fn struct_lint_level<'s, 'd>(
);
}
}
LintSource::Node(lint_attr_name, src, reason) => {
LintLevelSource::Node(lint_attr_name, src, reason) => {
if let Some(rationale) = reason {
err.note(&rationale.as_str());
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::dep_graph::{self, DepGraph, DepKind, DepNode, DepNodeExt};
use crate::hir::exports::ExportMap;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
use crate::middle;
use crate::middle::cstore::{CrateStoreDyn, EncodedMetadata};
use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault};
Expand Down Expand Up @@ -2559,7 +2559,7 @@ impl<'tcx> TyCtxt<'tcx> {
self,
lint: &'static Lint,
mut id: hir::HirId,
) -> (Level, LintSource) {
) -> (Level, LintLevelSource) {
let sets = self.lint_levels(LOCAL_CRATE);
loop {
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
/// This means we can use pointer for both
/// equality comparisons and hashing.
///
/// Unlike slices, The types contained in `List` are expected to be `Copy`
/// Unlike slices, the types contained in `List` are expected to be `Copy`
/// and iterating over a `List` returns `T` instead of a reference.
///
/// Note: `Slice` was already taken by the `Ty`.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ pub enum TyKind<'tcx> {
impl TyKind<'tcx> {
#[inline]
pub fn is_primitive(&self) -> bool {
match self {
Bool | Char | Int(_) | Uint(_) | Float(_) => true,
_ => false,
}
matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
}

/// Get the article ("a" or "an") to use with this type.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/simplify_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn optimization_applies<'tcx>(
return false;
}

// Verify the assigment chain consists of the form b = a; c = b; d = c; etc...
// Verify the assignment chain consists of the form b = a; c = b; d = c; etc...
if opt_info.field_tmp_assignments.is_empty() {
trace!("NO: no assignments found");
return false;
Expand Down
28 changes: 17 additions & 11 deletions compiler/rustc_mir/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_middle::mir::interpret::{
};
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_middle::ty::{self, TyCtxt, TyS, TypeFoldable, TypeVisitor};
use rustc_target::abi::Size;
use std::ops::ControlFlow;

Expand Down Expand Up @@ -408,6 +408,18 @@ impl ExtraComments<'tcx> {
}
}

fn use_verbose(ty: &&TyS<'tcx>) -> bool {
match ty.kind() {
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
// Unit type
ty::Tuple(g_args) if g_args.is_empty() => false,
ty::Tuple(g_args) => g_args.iter().any(|g_arg| use_verbose(&g_arg.expect_ty())),
ty::Array(ty, _) => use_verbose(ty),
ty::FnDef(..) => false,
_ => true,
}
}

impl Visitor<'tcx> for ExtraComments<'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
self.super_constant(constant, location);
Expand All @@ -430,16 +442,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
self.super_const(constant);
let ty::Const { ty, val, .. } = constant;
match ty.kind() {
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => {}
// Unit type
ty::Tuple(tys) if tys.is_empty() => {}
ty::FnDef(..) => {}
_ => {
self.push("ty::Const");
self.push(&format!("+ ty: {:?}", ty));
self.push(&format!("+ val: {:?}", val));
}
if use_verbose(ty) {
self.push("ty::Const");
self.push(&format!("+ ty: {:?}", ty));
self.push(&format!("+ val: {:?}", val));
}
}

Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,4 +1912,22 @@ impl<'a> Parser<'a> {
*self = snapshot;
Err(err)
}

/// Get the diagnostics for the cases where `move async` is found.
///
/// `move_async_span` starts at the 'm' of the move keyword and ends with the 'c' of the async keyword
pub(super) fn incorrect_move_async_order_found(
&self,
move_async_span: Span,
) -> DiagnosticBuilder<'a> {
let mut err =
self.struct_span_err(move_async_span, "the order of `move` and `async` is incorrect");
err.span_suggestion_verbose(
move_async_span,
"try switching the order",
"async move".to_owned(),
Applicability::MaybeIncorrect,
);
err
}
}
18 changes: 14 additions & 4 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ impl<'a> Parser<'a> {
self.sess.gated_spans.gate(sym::async_closure, span);
}

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

/// Parses an optional `move` prefix to a closure-like construct.
fn parse_capture_clause(&mut self) -> CaptureBy {
if self.eat_keyword(kw::Move) { CaptureBy::Value } else { CaptureBy::Ref }
fn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy> {
if self.eat_keyword(kw::Move) {
// Check for `move async` and recover
if self.check_keyword(kw::Async) {
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
Err(self.incorrect_move_async_order_found(move_async_span))
} else {
Ok(CaptureBy::Value)
}
} else {
Ok(CaptureBy::Ref)
}
}

/// Parses the `|arg, arg|` header of a closure.
Expand Down Expand Up @@ -2019,7 +2029,7 @@ impl<'a> Parser<'a> {
fn parse_async_block(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
self.expect_keyword(kw::Async)?;
let capture_clause = self.parse_capture_clause();
let capture_clause = self.parse_capture_clause()?;
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
let kind = ExprKind::Async(capture_clause, DUMMY_NODE_ID, body);
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<K, V> BTreeMap<K, V> {

impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
fn assert_min_len(self, min_len: usize) {
assert!(self.len() >= min_len, "{} < {}", self.len(), min_len);
assert!(self.len() >= min_len, "node len {} < {}", self.len(), min_len);
if let node::ForceResult::Internal(node) = self.force() {
for idx in 0..=node.len() {
let edge = unsafe { Handle::new_edge(node, idx) };
Expand Down
12 changes: 8 additions & 4 deletions library/alloc/src/collections/btree/node/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
let depth = self.height();
let indent = " ".repeat(depth);
result += &format!("\n{}", indent);
for idx in 0..leaf.len() {
if idx > 0 {
result += ", ";
if leaf.len() == 0 {
result += "(empty node)";
} else {
for idx in 0..leaf.len() {
if idx > 0 {
result += ", ";
}
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
}
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
}
}
navigate::Position::Internal(_) => {}
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2581,14 +2581,12 @@ impl<T> [T] {
/// # Examples
///
/// ```
/// #![feature(slice_fill)]
///
/// let mut buf = vec![0; 10];
/// buf.fill(1);
/// assert_eq!(buf, vec![1; 10]);
/// ```
#[doc(alias = "memset")]
#[unstable(feature = "slice_fill", issue = "70758")]
#[stable(feature = "slice_fill", since = "1.50.0")]
pub fn fill(&mut self, value: T)
where
T: Clone,
Expand Down
Loading

0 comments on commit 9a40539

Please sign in to comment.