Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 13 pull requests #80503

Merged
merged 29 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6e852cc
remove redundant clones (clippy::redundant_clone)
matthiaskrgr Dec 24, 2020
a8775d4
Edit rustc_span documentation
pierwill Dec 24, 2020
8d5dc8c
Add missing commas to `rustc_ast_pretty::pp` docs
camelid Dec 28, 2020
8041ccf
Add llvm-libunwind change to bootstrap CHANGELOG
tmandry Dec 28, 2020
5718cc2
Make forget intrinsic safe
tmiasko Dec 29, 2020
3dae414
Use Option::map_or instead of open coding it
LingMan Dec 29, 2020
02db77c
Fix typo in ffi-pure.md
eltociear Dec 29, 2020
5449a42
Fix small typo in time comment
BlackHoleFox Dec 29, 2020
893c626
Use sans-serif font for the "all items" page links
GuillaumeGomez Dec 29, 2020
7a41532
More uses of the matches! macro
LingMan Dec 29, 2020
17a8c10
don't clone copy types
matthiaskrgr Dec 29, 2020
0c3af22
don't redundantly repeat field names
matthiaskrgr Dec 29, 2020
c857cbe
Lint on redundant trailing semicolon after item
Aaron1011 Dec 7, 2020
21ed141
Remove trailing semicolon in librustdoc
Aaron1011 Dec 8, 2020
4c4700d
Remove unnecessary semicolon from Rustdoc-generated code
Aaron1011 Dec 28, 2020
6bef37c
Remove unnecessary semicolon from Clippy test
Aaron1011 Dec 29, 2020
3fe4236
Rollup merge of #79812 - Aaron1011:lint-item-trailing-semi, r=oli-obk
JohnTitor Dec 30, 2020
a309468
Rollup merge of #80348 - matthiaskrgr:less_clones, r=Dylan-DPC
JohnTitor Dec 30, 2020
6064be7
Rollup merge of #80358 - pierwill:edit_rustc_span, r=lcnr
JohnTitor Dec 30, 2020
d8cabe1
Rollup merge of #80457 - camelid:pretty-docs-commas, r=jonas-schievink
JohnTitor Dec 30, 2020
7c57d51
Rollup merge of #80461 - rust-lang:tmandry-patch-1, r=Mark-Simulacrum
JohnTitor Dec 30, 2020
30ddc91
Rollup merge of #80464 - LingMan:map_or, r=oli-obk
JohnTitor Dec 30, 2020
b050261
Rollup merge of #80465 - eltociear:patch-3, r=jyn514
JohnTitor Dec 30, 2020
231727d
Rollup merge of #80467 - LingMan:more_matches, r=oli-obk
JohnTitor Dec 30, 2020
c50800b
Rollup merge of #80469 - BlackHoleFox:fix-time-typo, r=jonas-schievink
JohnTitor Dec 30, 2020
bdc215a
Rollup merge of #80472 - GuillaumeGomez:sans-serif-for-all-items-page…
JohnTitor Dec 30, 2020
9576ee9
Rollup merge of #80477 - tmiasko:safe-forget, r=oli-obk
JohnTitor Dec 30, 2020
039b62e
Rollup merge of #80482 - matthiaskrgr:cl0ne_on_copy, r=jyn514
JohnTitor Dec 30, 2020
3812909
Rollup merge of #80487 - matthiaskrgr:field_names, r=jyn514
JohnTitor Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1806,12 +1806,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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("_")
}
Loading