Skip to content

Cleanup rustc/middle #54756

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

Merged
merged 4 commits into from
Oct 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 5 additions & 7 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {

fn mark_live_symbols(&mut self) {
let mut scanned = FxHashSet();
while !self.worklist.is_empty() {
let id = self.worklist.pop().unwrap();
if scanned.contains(&id) {
while let Some(id) = self.worklist.pop() {
if !scanned.insert(id) {
continue
}
scanned.insert(id);

if let Some(ref node) = self.tcx.hir.find(id) {
self.live_symbols.insert(id);
Expand Down Expand Up @@ -212,7 +210,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
}

fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name,
_: &hir::Generics, _: ast::NodeId, _: syntax_pos::Span) {
_: &hir::Generics, _: ast::NodeId, _: syntax_pos::Span) {
let has_repr_c = self.repr_has_repr_c;
let inherited_pub_visibility = self.inherited_pub_visibility;
let live_fields = def.fields().iter().filter(|f| {
Expand Down Expand Up @@ -494,8 +492,8 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
ctor_id: Option<ast::NodeId>)
-> bool {
if self.live_symbols.contains(&id)
|| ctor_id.map_or(false,
|ctor| self.live_symbols.contains(&ctor)) {
|| ctor_id.map_or(false, |ctor| self.live_symbols.contains(&ctor))
{
return true;
}
// If it's a type whose items are live, then it's live, too.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let src = tcx.used_crate_source(cnum);
if src.rlib.is_some() { continue }
sess.err(&format!("crate `{}` required to be available in rlib format, \
but was not found in this form",
but was not found in this form",
tcx.crate_name(cnum)));
}
return Vec::new();
Expand Down Expand Up @@ -247,13 +247,13 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => "dylib",
};
sess.err(&format!("crate `{}` required to be available in {} format, \
but was not found in this form",
but was not found in this form",
tcx.crate_name(cnum), kind));
}
}
}

return ret;
ret
}

fn add_library(tcx: TyCtxt<'_, '_, '_>,
Expand Down
10 changes: 3 additions & 7 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


use hir::map as hir_map;
use hir::def_id::{CRATE_DEF_INDEX};
use session::{config, Session};
Expand Down Expand Up @@ -131,7 +130,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
ctxt.attr_main_fn = Some((item.id, item.span));
} else {
struct_span_err!(ctxt.session, item.span, E0137,
"multiple functions with a #[main] attribute")
"multiple functions with a #[main] attribute")
.span_label(item.span, "additional #[main] function")
.span_label(ctxt.attr_main_fn.unwrap().1, "first #[main] function")
.emit();
Expand All @@ -141,11 +140,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
if ctxt.start_fn.is_none() {
ctxt.start_fn = Some((item.id, item.span));
} else {
struct_span_err!(
ctxt.session, item.span, E0138,
"multiple 'start' functions")
.span_label(ctxt.start_fn.unwrap().1,
"previous `start` function here")
struct_span_err!(ctxt.session, item.span, E0138, "multiple 'start' functions")
.span_label(ctxt.start_fn.unwrap().1, "previous `start` function here")
.span_label(item.span, "multiple `start` functions")
.emit();
}
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ impl_stable_hash_for!(enum self::SymbolExportLevel {

impl SymbolExportLevel {
pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool {
if threshold == SymbolExportLevel::Rust {
// We export everything from Rust dylibs
true
} else {
self == SymbolExportLevel::C
}
threshold == SymbolExportLevel::Rust // export everything from Rust dylibs
|| self == SymbolExportLevel::C
}
}

Expand Down
25 changes: 12 additions & 13 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::Node
}));
}));
let arg_cmt = Rc::new(self.mc.cat_rvalue(
arg.hir_id,
arg.pat.span,
Expand Down Expand Up @@ -402,20 +402,20 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
self.walk_expr(&subexpr)
}

hir::ExprKind::Unary(hir::UnDeref, ref base) => { // *base
hir::ExprKind::Unary(hir::UnDeref, ref base) => { // *base
self.select_from_expr(&base);
}

hir::ExprKind::Field(ref base, _) => { // base.f
hir::ExprKind::Field(ref base, _) => { // base.f
self.select_from_expr(&base);
}

hir::ExprKind::Index(ref lhs, ref rhs) => { // lhs[rhs]
hir::ExprKind::Index(ref lhs, ref rhs) => { // lhs[rhs]
self.select_from_expr(&lhs);
self.consume_expr(&rhs);
}

hir::ExprKind::Call(ref callee, ref args) => { // callee(args)
hir::ExprKind::Call(ref callee, ref args) => { // callee(args)
self.walk_callee(expr, &callee);
self.consume_exprs(args);
}
Expand Down Expand Up @@ -801,10 +801,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
self.walk_pat(discr_cmt.clone(), &pat, mode);
}

if let Some(ref guard) = arm.guard {
match guard {
hir::Guard::If(ref e) => self.consume_expr(e),
}
if let Some(hir::Guard::If(ref e)) = arm.guard {
self.consume_expr(e)
}

self.consume_expr(&arm.body);
Expand All @@ -826,12 +824,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
cmt_discr: mc::cmt<'tcx>,
pat: &hir::Pat,
mode: &mut TrackMatchMode) {
debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr,
pat);
debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr, pat);

return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |cmt_pat, pat| {
if let PatKind::Binding(..) = pat.node {
let bm = *self.mc.tables.pat_binding_modes().get(pat.hir_id)
.expect("missing binding mode");
let bm = *self.mc.tables.pat_binding_modes()
.get(pat.hir_id)
.expect("missing binding mode");
match bm {
ty::BindByReference(..) =>
mode.lub(BorrowingMatch),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
}
Err(LayoutError::Unknown(bad)) => {
if bad == ty {
"this type's size can vary".to_string()
"this type's size can vary".to_owned()
} else {
format!("size can vary because of {}", bad)
}
Expand All @@ -117,7 +117,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
};

struct_span_err!(self.tcx.sess, span, E0512,
"transmute called with types of different sizes")
"transmute called with types of different sizes")
.note(&format!("source type: {} ({})", from, skeleton_string(from, sk_from)))
.note(&format!("target type: {} ({})", to, skeleton_string(to, sk_to)))
.emit();
Expand Down
13 changes: 4 additions & 9 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ macro_rules! language_item_table {
$( $variant:ident, $name:expr, $method:ident; )*
) => {


enum_from_u32! {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum LangItem {
Expand Down Expand Up @@ -145,8 +144,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {

fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
// Check for duplicates.
match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => {
if let Some(original_def_id) = self.items.items[item_index] {
if original_def_id != item_def_id {
let name = LangItem::from_u32(item_index as u32).unwrap().name();
let mut err = match self.tcx.hir.span_if_local(item_def_id) {
Some(span) => struct_span_err!(
Expand All @@ -161,17 +160,13 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
name)),
};
if let Some(span) = self.tcx.hir.span_if_local(original_def_id) {
span_note!(&mut err, span,
"first defined here.");
span_note!(&mut err, span, "first defined here.");
} else {
err.note(&format!("first defined in crate `{}`.",
self.tcx.crate_name(original_def_id.krate)));
}
err.emit();
}
_ => {
// OK.
}
}

// Matched.
Expand All @@ -194,7 +189,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
}
}

return None;
None
}

pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LanguageItems {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/lib_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ impl<'a, 'tcx> LibFeatureCollector<'a, 'tcx> {
let msg = format!(
"feature `{}` is declared {}, but was previously declared {}",
feature,
if since.is_some() { "stable"} else { "unstable" },
if since.is_none() { "stable"} else { "unstable" },
if since.is_some() { "stable" } else { "unstable" },
if since.is_none() { "stable" } else { "unstable" },
);
self.tcx.sess.struct_span_err_with_code(span, &msg,
DiagnosticId::Error("E0711".into())).emit();
Expand Down
Loading