Skip to content

Commit 9fed360

Browse files
committed
Auto merge of rust-lang#71079 - Dylan-DPC:rollup-g7yh3sn, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - rust-lang#67766 (Fix warning for unused variables in or pattern (issue rust-lang#67691)) - rust-lang#71013 (Pass the `PlaceElem::Index` local to `visit_local`) - rust-lang#71064 (fix issue 69130) - rust-lang#71069 (Remove some usage of `DUMMY_HIR_ID`) Failed merges: r? @ghost
2 parents 3712e11 + 69862b7 commit 9fed360

25 files changed

+328
-164
lines changed

src/librustc_errors/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ impl CodeSuggestion {
231231
}
232232
}
233233
if let Some(cur_line) = sf.get_line(cur_lo.line - 1) {
234-
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
234+
let end = match cur_line.char_indices().nth(cur_lo.col.to_usize()) {
235+
Some((i, _)) => i,
236+
None => cur_line.len(),
237+
};
235238
buf.push_str(&cur_line[..end]);
236239
}
237240
}

src/librustc_infer/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ pub(super) fn note_and_explain_region(
9393
let unknown_scope =
9494
|| format!("{}unknown scope: {:?}{}. Please report a bug.", prefix, scope, suffix);
9595
let span = scope.span(tcx, region_scope_tree);
96-
let tag = match tcx.hir().find(scope.hir_id(region_scope_tree)) {
96+
let hir_id = scope.hir_id(region_scope_tree);
97+
let tag = match hir_id.and_then(|hir_id| tcx.hir().find(hir_id)) {
9798
Some(Node::Block(_)) => "block",
9899
Some(Node::Expr(expr)) => match expr.kind {
99100
hir::ExprKind::Call(..) => "call",

src/librustc_middle/middle/region.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,20 @@ impl Scope {
159159
self.id
160160
}
161161

162-
pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId {
163-
match scope_tree.root_body {
164-
Some(hir_id) => hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() },
165-
None => hir::DUMMY_HIR_ID,
166-
}
162+
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> {
163+
scope_tree
164+
.root_body
165+
.map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() })
167166
}
168167

169168
/// Returns the span of this `Scope`. Note that in general the
170169
/// returned span may not correspond to the span of any `NodeId` in
171170
/// the AST.
172171
pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
173-
let hir_id = self.hir_id(scope_tree);
174-
if hir_id == hir::DUMMY_HIR_ID {
175-
return DUMMY_SP;
176-
}
172+
let hir_id = match self.hir_id(scope_tree) {
173+
Some(hir_id) => hir_id,
174+
None => return DUMMY_SP,
175+
};
177176
let span = tcx.hir().span(hir_id);
178177
if let ScopeData::Remainder(first_statement_index) = self.data {
179178
if let Node::Block(ref blk) = tcx.hir().get(hir_id) {

src/librustc_middle/mir/visit.rs

+33-26
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
838838
}
839839

840840
macro_rules! visit_place_fns {
841-
(mut) => (
841+
(mut) => {
842842
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
843843

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

852-
if let Some(new_projection) = self.process_projection(&place.projection) {
852+
if let Some(new_projection) = self.process_projection(&place.projection, location) {
853853
place.projection = self.tcx().intern_place_elems(&new_projection);
854854
}
855855
}
856856

857857
fn process_projection(
858858
&mut self,
859859
projection: &'a [PlaceElem<'tcx>],
860+
location: Location,
860861
) -> Option<Vec<PlaceElem<'tcx>>> {
861862
let mut projection = Cow::Borrowed(projection);
862863

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

880881
fn process_projection_elem(
881882
&mut self,
882-
_elem: &PlaceElem<'tcx>,
883+
elem: &PlaceElem<'tcx>,
884+
location: Location,
883885
) -> Option<PlaceElem<'tcx>> {
884-
None
886+
match elem {
887+
PlaceElem::Index(local) => {
888+
let mut new_local = *local;
889+
self.visit_local(
890+
&mut new_local,
891+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
892+
location,
893+
);
894+
895+
if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
896+
}
897+
PlaceElem::Deref
898+
| PlaceElem::Field(..)
899+
| PlaceElem::ConstantIndex { .. }
900+
| PlaceElem::Subslice { .. }
901+
| PlaceElem::Downcast(..) => None,
902+
}
885903
}
886-
);
904+
};
887905

888-
() => (
906+
() => {
889907
fn visit_projection(
890908
&mut self,
891909
local: Local,
@@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
907925
self.super_projection_elem(local, proj_base, elem, context, location);
908926
}
909927

910-
fn super_place(
911-
&mut self,
912-
place: &Place<'tcx>,
913-
context: PlaceContext,
914-
location: Location,
915-
) {
928+
fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
916929
let mut context = context;
917930

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

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

928-
self.visit_projection(place.local,
929-
&place.projection,
930-
context,
931-
location);
941+
self.visit_projection(place.local, &place.projection, context, location);
932942
}
933943

934944
fn super_projection(
@@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
961971
self.visit_local(
962972
local,
963973
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
964-
location
974+
location,
965975
);
966976
}
967-
ProjectionElem::Deref |
968-
ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
969-
ProjectionElem::ConstantIndex { offset: _,
970-
min_length: _,
971-
from_end: _ } |
972-
ProjectionElem::Downcast(_, _) => {
973-
}
977+
ProjectionElem::Deref
978+
| ProjectionElem::Subslice { from: _, to: _, from_end: _ }
979+
| ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
980+
| ProjectionElem::Downcast(_, _) => {}
974981
}
975982
}
976-
);
983+
};
977984
}
978985

979986
make_mir_visitor!(Visitor,);

src/librustc_mir/borrow_check/renumber.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
6464
debug!("visit_ty: ty={:?}", ty);
6565
}
6666

67-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
67+
fn process_projection_elem(
68+
&mut self,
69+
elem: &PlaceElem<'tcx>,
70+
_: Location,
71+
) -> Option<PlaceElem<'tcx>> {
6872
if let PlaceElem::Field(field, ty) = elem {
6973
let new_ty = self.renumber_regions(ty);
7074

src/librustc_mir/transform/generator.rs

-7
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
8989
*local = self.to;
9090
}
9191
}
92-
93-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
94-
match elem {
95-
PlaceElem::Index(local) if *local == self.from => Some(PlaceElem::Index(self.to)),
96-
_ => None,
97-
}
98-
}
9992
}
10093

10194
struct DerefArgVisitor<'tcx> {

src/librustc_mir/transform/inline.rs

-12
Original file line numberDiff line numberDiff line change
@@ -706,18 +706,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
706706
self.super_place(place, context, location)
707707
}
708708

709-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
710-
if let PlaceElem::Index(local) = elem {
711-
let new_local = self.make_integrate_local(*local);
712-
713-
if new_local != *local {
714-
return Some(PlaceElem::Index(new_local));
715-
}
716-
}
717-
718-
None
719-
}
720-
721709
fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
722710
self.in_cleanup_block = data.is_cleanup;
723711
self.super_basic_block_data(block, data);

src/librustc_mir/transform/promote_consts.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1036,15 +1036,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
10361036
*local = self.promote_temp(*local);
10371037
}
10381038
}
1039-
1040-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
1041-
match elem {
1042-
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
1043-
Some(PlaceElem::Index(self.promote_temp(*local)))
1044-
}
1045-
_ => None,
1046-
}
1047-
}
10481039
}
10491040

10501041
pub fn promote_candidates<'tcx>(

src/librustc_mir/transform/simplify.rs

-7
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,4 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
417417
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
418418
*l = self.map[*l].unwrap();
419419
}
420-
421-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
422-
match elem {
423-
PlaceElem::Index(local) => Some(PlaceElem::Index(self.map[*local].unwrap())),
424-
_ => None,
425-
}
426-
}
427420
}

src/librustc_mir/util/def_use.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
33
use rustc_index::vec::IndexVec;
44
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
5-
use rustc_middle::mir::{
6-
Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo,
7-
};
5+
use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo};
86
use rustc_middle::ty::TyCtxt;
97
use std::mem;
108

@@ -157,13 +155,4 @@ impl MutVisitor<'tcx> for MutateUseVisitor<'tcx> {
157155
*local = self.new_local;
158156
}
159157
}
160-
161-
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
162-
match elem {
163-
PlaceElem::Index(local) if *local == self.query => {
164-
Some(PlaceElem::Index(self.new_local))
165-
}
166-
_ => None,
167-
}
168-
}
169158
}

src/librustc_passes/check_attr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_errors::struct_span_err;
1414
use rustc_hir as hir;
1515
use rustc_hir::def_id::DefId;
1616
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
17-
use rustc_hir::DUMMY_HIR_ID;
1817
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
1918
use rustc_hir::{MethodKind, Target};
2019
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
@@ -360,7 +359,7 @@ impl CheckAttrVisitor<'tcx> {
360359
if let hir::StmtKind::Local(ref l) = stmt.kind {
361360
for attr in l.attrs.iter() {
362361
if attr.check_name(sym::inline) {
363-
self.check_inline(DUMMY_HIR_ID, attr, &stmt.span, Target::Statement);
362+
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
364363
}
365364
if attr.check_name(sym::repr) {
366365
self.emit_repr_error(
@@ -381,7 +380,7 @@ impl CheckAttrVisitor<'tcx> {
381380
};
382381
for attr in expr.attrs.iter() {
383382
if attr.check_name(sym::inline) {
384-
self.check_inline(DUMMY_HIR_ID, attr, &expr.span, target);
383+
self.check_inline(expr.hir_id, attr, &expr.span, target);
385384
}
386385
if attr.check_name(sym::repr) {
387386
self.emit_repr_error(

0 commit comments

Comments
 (0)