Skip to content

Commit

Permalink
Auto merge of #80503 - JohnTitor:rollup-b26vglu, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 13 pull requests

Successful merges:

 - #79812 (Lint on redundant trailing semicolon after item)
 - #80348 (remove redundant clones (clippy::redundant_clone))
 - #80358 (Edit rustc_span documentation)
 - #80457 (Add missing commas to `rustc_ast_pretty::pp` docs)
 - #80461 (Add llvm-libunwind change to bootstrap CHANGELOG)
 - #80464 (Use Option::map_or instead of open coding it)
 - #80465 (Fix typo in ffi-pure.md)
 - #80467 (More uses of the matches! macro)
 - #80469 (Fix small typo in time comment)
 - #80472 (Use sans-serif font for the "all items" page links)
 - #80477 (Make forget intrinsic safe)
 - #80482 (don't clone copy types)
 - #80487 (don't redundantly repeat field names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 30, 2020
2 parents b9c403b + 3812909 commit d107a87
Show file tree
Hide file tree
Showing 39 changed files with 164 additions and 142 deletions.
14 changes: 4 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Expand Up @@ -1092,15 +1092,9 @@ impl Expr {
if let ExprKind::Block(ref block, _) = self.kind {
match block.stmts.last().map(|last_stmt| &last_stmt.kind) {
// Implicit return
Some(&StmtKind::Expr(_)) => true,
Some(&StmtKind::Semi(ref expr)) => {
if let ExprKind::Ret(_) = expr.kind {
// Last statement is explicit return.
true
} else {
false
}
}
Some(StmtKind::Expr(_)) => true,
// Last statement is an explicit return?
Some(StmtKind::Semi(expr)) => matches!(expr.kind, ExprKind::Ret(_)),
// This is a block that doesn't end in either an implicit or explicit return.
_ => false,
}
Expand Down Expand Up @@ -1950,7 +1944,7 @@ impl TyKind {
}

pub fn is_unit(&self) -> bool {
if let TyKind::Tup(ref tys) = *self { tys.is_empty() } else { false }
matches!(self, TyKind::Tup(tys) if tys.is_empty())
}
}

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -1857,12 +1857,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output,
c_variadic,
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
let is_mutable_pat = match arg.pat.kind {
PatKind::Ident(BindingMode::ByValue(mt) | BindingMode::ByRef(mt), _, _) => {
mt == Mutability::Mut
}
_ => false,
};
use BindingMode::{ByRef, ByValue};
let is_mutable_pat = matches!(
arg.pat.kind,
PatKind::Ident(ByValue(Mutability::Mut) | ByRef(Mutability::Mut), ..)
);

match arg.ty.kind {
TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -397,10 +397,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
match i.kind {
ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => {
let link_name = self.sess.first_attr_value_str_by_name(&i.attrs, sym::link_name);
let links_to_llvm = match link_name {
Some(val) => val.as_str().starts_with("llvm."),
_ => false,
};
let links_to_llvm =
link_name.map_or(false, |val| val.as_str().starts_with("llvm."));
if links_to_llvm {
gate_feature_post!(
&self,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pp.rs
Expand Up @@ -75,15 +75,15 @@
//! breaking inconsistently to become
//!
//! ```
//! foo(hello, there
//! foo(hello, there,
//! good, friends);
//! ```
//!
//! whereas a consistent breaking would yield:
//!
//! ```
//! foo(hello,
//! there
//! there,
//! good,
//! friends);
//! ```
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Expand Up @@ -116,7 +116,7 @@ pub struct NativeLib {

impl From<&cstore::NativeLib> for NativeLib {
fn from(lib: &cstore::NativeLib) -> Self {
NativeLib { kind: lib.kind.clone(), name: lib.name.clone(), cfg: lib.cfg.clone() }
NativeLib { kind: lib.kind, name: lib.name, cfg: lib.cfg.clone() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/scc/mod.rs
Expand Up @@ -523,7 +523,7 @@ where
successors_len: 0,
min_depth: depth,
min_cycle_root: successor_node,
successor_node: successor_node,
successor_node,
});
continue 'recurse;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Expand Up @@ -1317,7 +1317,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
T: TypeFoldable<'tcx>,
{
if !value.needs_infer() {
return value.clone(); // Avoid duplicated subst-folding.
return value; // Avoid duplicated subst-folding.
}
let mut r = resolve::OpportunisticVarResolver::new(self);
value.fold_with(&mut r)
Expand Down
20 changes: 3 additions & 17 deletions compiler/rustc_lint/src/redundant_semicolon.rs
Expand Up @@ -28,40 +28,26 @@ declare_lint_pass!(RedundantSemicolons => [REDUNDANT_SEMICOLONS]);

impl EarlyLintPass for RedundantSemicolons {
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
let mut after_item_stmt = false;
let mut seq = None;
for stmt in block.stmts.iter() {
match (&stmt.kind, &mut seq) {
(StmtKind::Empty, None) => seq = Some((stmt.span, false)),
(StmtKind::Empty, Some(seq)) => *seq = (seq.0.to(stmt.span), true),
(_, seq) => {
maybe_lint_redundant_semis(cx, seq, after_item_stmt);
after_item_stmt = matches!(stmt.kind, StmtKind::Item(_));
}
(_, seq) => maybe_lint_redundant_semis(cx, seq),
}
}
maybe_lint_redundant_semis(cx, &mut seq, after_item_stmt);
maybe_lint_redundant_semis(cx, &mut seq);
}
}

fn maybe_lint_redundant_semis(
cx: &EarlyContext<'_>,
seq: &mut Option<(Span, bool)>,
after_item_stmt: bool,
) {
fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
if let Some((span, multiple)) = seq.take() {
// FIXME: Find a better way of ignoring the trailing
// semicolon from macro expansion
if span == rustc_span::DUMMY_SP {
return;
}

// FIXME: Lint on semicolons after item statements
// once doing so doesn't break bootstrapping
if after_item_stmt {
return;
}

cx.struct_span_lint(REDUNDANT_SEMICOLONS, span, |lint| {
let (msg, rem) = if multiple {
("unnecessary trailing semicolons", "remove these semicolons")
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/hir/place.rs
Expand Up @@ -110,10 +110,7 @@ impl<'tcx> PlaceWithHirId<'tcx> {
base: PlaceBase,
projections: Vec<Projection<'tcx>>,
) -> PlaceWithHirId<'tcx> {
PlaceWithHirId {
hir_id: hir_id,
place: Place { base_ty: base_ty, base: base, projections: projections },
}
PlaceWithHirId { hir_id, place: Place { base_ty, base, projections } }
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/visit.rs
Expand Up @@ -306,13 +306,13 @@ macro_rules! make_mir_visitor {

let mut index = 0;
for statement in statements {
let location = Location { block: block, statement_index: index };
let location = Location { block, statement_index: index };
self.visit_statement(statement, location);
index += 1;
}

if let Some(terminator) = terminator {
let location = Location { block: block, statement_index: index };
let location = Location { block, statement_index: index };
self.visit_terminator(terminator, location);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Expand Up @@ -1634,7 +1634,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

let layout = tcx.intern_layout(Layout {
variants: Variants::Multiple {
tag: tag,
tag,
tag_encoding: TagEncoding::Direct,
tag_field: tag_index,
variants,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Expand Up @@ -328,8 +328,8 @@ struct SplitIntRange {
}

impl SplitIntRange {
fn new(r: IntRange) -> Self {
SplitIntRange { range: r.clone(), borders: Vec::new() }
fn new(range: IntRange) -> Self {
SplitIntRange { range, borders: Vec::new() }
}

/// Internal use
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_span/src/edition.rs
Expand Up @@ -4,24 +4,25 @@ use std::str::FromStr;

use rustc_macros::HashStable_Generic;

/// The edition of the compiler (RFC 2052)
/// The edition of the compiler. (See [RFC 2052](https://github.com/rust-lang/rfcs/blob/master/text/2052-epochs.md).)
#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, Encodable, Decodable, Eq)]
#[derive(HashStable_Generic)]
pub enum Edition {
// editions must be kept in order, oldest to newest
// When adding new editions, be sure to do the following:
//
// - update the `ALL_EDITIONS` const
// - update the `EDITION_NAME_LIST` const
// - add a `rust_####()` function to the session
// - update the enum in Cargo's sources as well
//
// Editions *must* be kept in order, oldest to newest.
/// The 2015 edition
Edition2015,
/// The 2018 edition
Edition2018,
// when adding new editions, be sure to update:
//
// - Update the `ALL_EDITIONS` const
// - Update the EDITION_NAME_LIST const
// - add a `rust_####()` function to the session
// - update the enum in Cargo's sources as well
}

// must be in order from oldest to newest
// Must be in order from oldest to newest.
pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];

pub const EDITION_NAME_LIST: &str = "2015|2018";
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_span/src/lev_distance.rs
@@ -1,10 +1,16 @@
//! Levenshtein distances.
//!
//! The [Levenshtein distance] is a metric for measuring the difference between two strings.
//!
//! [Levenshtein distance]: https://en.wikipedia.org/wiki/Levenshtein_distance

use crate::symbol::Symbol;
use std::cmp;

#[cfg(test)]
mod tests;

/// Finds the Levenshtein distance between two strings
/// Finds the Levenshtein distance between two strings.
pub fn lev_distance(a: &str, b: &str) -> usize {
// cases which don't require further computation
if a.is_empty() {
Expand Down Expand Up @@ -35,14 +41,14 @@ pub fn lev_distance(a: &str, b: &str) -> usize {
dcol[t_last + 1]
}

/// Finds the best match for a given word in the given iterator
/// Finds the best match for a given word in the given iterator.
///
/// As a loose rule to avoid the obviously incorrect suggestions, it takes
/// an optional limit for the maximum allowable edit distance, which defaults
/// to one-third of the given word.
///
/// Besides Levenshtein, we use case insensitive comparison to improve accuracy on an edge case with
/// a lower(upper)case letters mismatch.
/// Besides Levenshtein, we use case insensitive comparison to improve accuracy
/// on an edge case with a lower(upper)case letters mismatch.
#[cold]
pub fn find_best_match_for_name(
name_vec: &[Symbol],
Expand Down Expand Up @@ -98,7 +104,7 @@ fn find_match_by_sorted_words(iter_names: &[Symbol], lookup: &str) -> Option<Sym

fn sort_by_words(name: &str) -> String {
let mut split_words: Vec<&str> = name.split('_').collect();
// We are sorting primitive &strs and can use unstable sort here
// We are sorting primitive &strs and can use unstable sort here.
split_words.sort_unstable();
split_words.join("_")
}

0 comments on commit d107a87

Please sign in to comment.