Skip to content

Commit

Permalink
Auto merge of #71079 - Dylan-DPC:rollup-g7yh3sn, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #67766 (Fix warning for unused variables in or pattern (issue #67691))
 - #71013 (Pass the `PlaceElem::Index` local to `visit_local`)
 - #71064 (fix issue 69130)
 - #71069 (Remove some usage of `DUMMY_HIR_ID`)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 12, 2020
2 parents 3712e11 + 69862b7 commit 9fed360
Show file tree
Hide file tree
Showing 25 changed files with 328 additions and 164 deletions.
5 changes: 4 additions & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ impl CodeSuggestion {
}
}
if let Some(cur_line) = sf.get_line(cur_lo.line - 1) {
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
let end = match cur_line.char_indices().nth(cur_lo.col.to_usize()) {
Some((i, _)) => i,
None => cur_line.len(),
};
buf.push_str(&cur_line[..end]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ pub(super) fn note_and_explain_region(
let unknown_scope =
|| format!("{}unknown scope: {:?}{}. Please report a bug.", prefix, scope, suffix);
let span = scope.span(tcx, region_scope_tree);
let tag = match tcx.hir().find(scope.hir_id(region_scope_tree)) {
let hir_id = scope.hir_id(region_scope_tree);
let tag = match hir_id.and_then(|hir_id| tcx.hir().find(hir_id)) {
Some(Node::Block(_)) => "block",
Some(Node::Expr(expr)) => match expr.kind {
hir::ExprKind::Call(..) => "call",
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_middle/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,20 @@ impl Scope {
self.id
}

pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId {
match scope_tree.root_body {
Some(hir_id) => hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() },
None => hir::DUMMY_HIR_ID,
}
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> {
scope_tree
.root_body
.map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() })
}

/// Returns the span of this `Scope`. Note that in general the
/// returned span may not correspond to the span of any `NodeId` in
/// the AST.
pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
let hir_id = self.hir_id(scope_tree);
if hir_id == hir::DUMMY_HIR_ID {
return DUMMY_SP;
}
let hir_id = match self.hir_id(scope_tree) {
Some(hir_id) => hir_id,
None => return DUMMY_SP,
};
let span = tcx.hir().span(hir_id);
if let ScopeData::Remainder(first_statement_index) = self.data {
if let Node::Block(ref blk) = tcx.hir().get(hir_id) {
Expand Down
59 changes: 33 additions & 26 deletions src/librustc_middle/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
}

macro_rules! visit_place_fns {
(mut) => (
(mut) => {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;

fn super_place(
Expand All @@ -849,20 +849,21 @@ macro_rules! visit_place_fns {
) {
self.visit_place_base(&mut place.local, context, location);

if let Some(new_projection) = self.process_projection(&place.projection) {
if let Some(new_projection) = self.process_projection(&place.projection, location) {
place.projection = self.tcx().intern_place_elems(&new_projection);
}
}

fn process_projection(
&mut self,
projection: &'a [PlaceElem<'tcx>],
location: Location,
) -> Option<Vec<PlaceElem<'tcx>>> {
let mut projection = Cow::Borrowed(projection);

for i in 0..projection.len() {
if let Some(elem) = projection.get(i) {
if let Some(elem) = self.process_projection_elem(elem) {
if let Some(elem) = self.process_projection_elem(elem, location) {
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
// clone of the projection so we can mutate and reintern later.
let vec = projection.to_mut();
Expand All @@ -879,13 +880,30 @@ macro_rules! visit_place_fns {

fn process_projection_elem(
&mut self,
_elem: &PlaceElem<'tcx>,
elem: &PlaceElem<'tcx>,
location: Location,
) -> Option<PlaceElem<'tcx>> {
None
match elem {
PlaceElem::Index(local) => {
let mut new_local = *local;
self.visit_local(
&mut new_local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location,
);

if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Deref
| PlaceElem::Field(..)
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
}
}
);
};

() => (
() => {
fn visit_projection(
&mut self,
local: Local,
Expand All @@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
self.super_projection_elem(local, proj_base, elem, context, location);
}

fn super_place(
&mut self,
place: &Place<'tcx>,
context: PlaceContext,
location: Location,
) {
fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
let mut context = context;

if !place.projection.is_empty() {
Expand All @@ -925,10 +938,7 @@ macro_rules! visit_place_fns {

self.visit_place_base(&place.local, context, location);

self.visit_projection(place.local,
&place.projection,
context,
location);
self.visit_projection(place.local, &place.projection, context, location);
}

fn super_projection(
Expand Down Expand Up @@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
self.visit_local(
local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location
location,
);
}
ProjectionElem::Deref |
ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
ProjectionElem::ConstantIndex { offset: _,
min_length: _,
from_end: _ } |
ProjectionElem::Downcast(_, _) => {
}
ProjectionElem::Deref
| ProjectionElem::Subslice { from: _, to: _, from_end: _ }
| ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
| ProjectionElem::Downcast(_, _) => {}
}
}
);
};
}

make_mir_visitor!(Visitor,);
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/borrow_check/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
debug!("visit_ty: ty={:?}", ty);
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
fn process_projection_elem(
&mut self,
elem: &PlaceElem<'tcx>,
_: Location,
) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Field(field, ty) = elem {
let new_ty = self.renumber_regions(ty);

Expand Down
7 changes: 0 additions & 7 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
*local = self.to;
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.from => Some(PlaceElem::Index(self.to)),
_ => None,
}
}
}

struct DerefArgVisitor<'tcx> {
Expand Down
12 changes: 0 additions & 12 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,18 +706,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
self.super_place(place, context, location)
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Index(local) = elem {
let new_local = self.make_integrate_local(*local);

if new_local != *local {
return Some(PlaceElem::Index(new_local));
}
}

None
}

fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
self.in_cleanup_block = data.is_cleanup;
self.super_basic_block_data(block, data);
Expand Down
9 changes: 0 additions & 9 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,15 +1036,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
*local = self.promote_temp(*local);
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
Some(PlaceElem::Index(self.promote_temp(*local)))
}
_ => None,
}
}
}

pub fn promote_candidates<'tcx>(
Expand Down
7 changes: 0 additions & 7 deletions src/librustc_mir/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,4 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
*l = self.map[*l].unwrap();
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) => Some(PlaceElem::Index(self.map[*local].unwrap())),
_ => None,
}
}
}
13 changes: 1 addition & 12 deletions src/librustc_mir/util/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

use rustc_index::vec::IndexVec;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::{
Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo,
};
use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo};
use rustc_middle::ty::TyCtxt;
use std::mem;

Expand Down Expand Up @@ -157,13 +155,4 @@ impl MutVisitor<'tcx> for MutateUseVisitor<'tcx> {
*local = self.new_local;
}
}

fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.query => {
Some(PlaceElem::Index(self.new_local))
}
_ => None,
}
}
}
5 changes: 2 additions & 3 deletions src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::DUMMY_HIR_ID;
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
use rustc_hir::{MethodKind, Target};
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
Expand Down Expand Up @@ -360,7 +359,7 @@ impl CheckAttrVisitor<'tcx> {
if let hir::StmtKind::Local(ref l) = stmt.kind {
for attr in l.attrs.iter() {
if attr.check_name(sym::inline) {
self.check_inline(DUMMY_HIR_ID, attr, &stmt.span, Target::Statement);
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
}
if attr.check_name(sym::repr) {
self.emit_repr_error(
Expand All @@ -381,7 +380,7 @@ impl CheckAttrVisitor<'tcx> {
};
for attr in expr.attrs.iter() {
if attr.check_name(sym::inline) {
self.check_inline(DUMMY_HIR_ID, attr, &expr.span, target);
self.check_inline(expr.hir_id, attr, &expr.span, target);
}
if attr.check_name(sym::repr) {
self.emit_repr_error(
Expand Down
Loading

0 comments on commit 9fed360

Please sign in to comment.