Skip to content

Commit 06c94ee

Browse files
committed
Auto merge of #64491 - Centril:rollup-21wkl69, r=Centril
Rollup of 3 pull requests Successful merges: - #63872 (Document platform-specific behavior of the iterator returned by std::fs::read_dir) - #64250 (save-analysis: Nest typeck tables when processing functions/methods) - #64472 (Don't mark expression with attributes as not needing parentheses) Failed merges: r? @ghost
2 parents 96d07e0 + 0592d13 commit 06c94ee

File tree

8 files changed

+140
-101
lines changed

8 files changed

+140
-101
lines changed

src/librustc/ty/context.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,24 @@ pub struct LocalTableInContext<'a, V> {
205205
fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
206206
hir_id: hir::HirId,
207207
mut_access: bool) {
208-
if cfg!(debug_assertions) {
209-
if let Some(local_id_root) = local_id_root {
210-
if hir_id.owner != local_id_root.index {
211-
ty::tls::with(|tcx| {
212-
bug!("node {} with HirId::owner {:?} cannot be placed in \
213-
TypeckTables with local_id_root {:?}",
214-
tcx.hir().node_to_string(hir_id),
215-
DefId::local(hir_id.owner),
216-
local_id_root)
217-
});
218-
}
219-
} else {
220-
// We use "Null Object" TypeckTables in some of the analysis passes.
221-
// These are just expected to be empty and their `local_id_root` is
222-
// `None`. Therefore we cannot verify whether a given `HirId` would
223-
// be a valid key for the given table. Instead we make sure that
224-
// nobody tries to write to such a Null Object table.
225-
if mut_access {
226-
bug!("access to invalid TypeckTables")
227-
}
208+
if let Some(local_id_root) = local_id_root {
209+
if hir_id.owner != local_id_root.index {
210+
ty::tls::with(|tcx| {
211+
bug!("node {} with HirId::owner {:?} cannot be placed in \
212+
TypeckTables with local_id_root {:?}",
213+
tcx.hir().node_to_string(hir_id),
214+
DefId::local(hir_id.owner),
215+
local_id_root)
216+
});
217+
}
218+
} else {
219+
// We use "Null Object" TypeckTables in some of the analysis passes.
220+
// These are just expected to be empty and their `local_id_root` is
221+
// `None`. Therefore we cannot verify whether a given `HirId` would
222+
// be a valid key for the given table. Instead we make sure that
223+
// nobody tries to write to such a Null Object table.
224+
if mut_access {
225+
bug!("access to invalid TypeckTables")
228226
}
229227
}
230228
}

src/librustc_lint/unused.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ impl UnusedParens {
370370
right_pos: Option<BytePos>) {
371371
match value.node {
372372
ast::ExprKind::Paren(ref inner) => {
373-
if !Self::is_expr_parens_necessary(inner, followed_by_block) {
373+
if !Self::is_expr_parens_necessary(inner, followed_by_block) &&
374+
value.attrs.is_empty() {
374375
let expr_text = if let Ok(snippet) = cx.sess().source_map()
375376
.span_to_snippet(value.span) {
376377
snippet

src/librustc_save_analysis/dump_visitor.rs

+63-56
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
130130
self.save_ctxt.span_from_span(span)
131131
}
132132

133+
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
134+
self.save_ctxt.lookup_def_id(ref_id)
135+
}
136+
133137
pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
134138
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
135139
let crate_root = source_file.map(|source_file| {
@@ -223,13 +227,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
223227
}
224228
}
225229

226-
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
227-
match self.save_ctxt.get_path_res(ref_id) {
228-
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
229-
def => Some(def.def_id()),
230-
}
231-
}
232-
233230
fn process_formals(&mut self, formals: &'l [ast::Param], qualname: &str) {
234231
for arg in formals {
235232
self.visit_pat(&arg.pat);
@@ -283,36 +280,32 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
283280
) {
284281
debug!("process_method: {}:{}", id, ident);
285282

286-
if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident, span) {
287-
let sig_str = crate::make_signature(&sig.decl, &generics);
288-
if body.is_some() {
289-
self.nest_tables(
290-
id,
291-
|v| v.process_formals(&sig.decl.inputs, &method_data.qualname),
292-
);
293-
}
283+
let hir_id = self.tcx.hir().node_to_hir_id(id);
284+
self.nest_tables(id, |v| {
285+
if let Some(mut method_data) = v.save_ctxt.get_method_data(id, ident, span) {
286+
v.process_formals(&sig.decl.inputs, &method_data.qualname);
287+
v.process_generic_params(&generics, &method_data.qualname, id);
294288

295-
self.process_generic_params(&generics, &method_data.qualname, id);
289+
method_data.value = crate::make_signature(&sig.decl, &generics);
290+
method_data.sig = sig::method_signature(id, ident, generics, sig, &v.save_ctxt);
296291

297-
method_data.value = sig_str;
298-
method_data.sig = sig::method_signature(id, ident, generics, sig, &self.save_ctxt);
299-
let hir_id = self.tcx.hir().node_to_hir_id(id);
300-
self.dumper.dump_def(&access_from_vis!(self.save_ctxt, vis, hir_id), method_data);
301-
}
292+
v.dumper.dump_def(&access_from_vis!(v.save_ctxt, vis, hir_id), method_data);
293+
}
302294

303-
// walk arg and return types
304-
for arg in &sig.decl.inputs {
305-
self.visit_ty(&arg.ty);
306-
}
295+
// walk arg and return types
296+
for arg in &sig.decl.inputs {
297+
v.visit_ty(&arg.ty);
298+
}
307299

308-
if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output {
309-
self.visit_ty(ret_ty);
310-
}
300+
if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output {
301+
v.visit_ty(ret_ty);
302+
}
311303

312-
// walk the fn body
313-
if let Some(body) = body {
314-
self.nest_tables(id, |v| v.visit_block(body));
315-
}
304+
// walk the fn body
305+
if let Some(body) = body {
306+
v.visit_block(body);
307+
}
308+
});
316309
}
317310

318311
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
@@ -377,26 +370,31 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
377370
ty_params: &'l ast::Generics,
378371
body: &'l ast::Block,
379372
) {
380-
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
381-
down_cast_data!(fn_data, DefData, item.span);
382-
self.nest_tables(
383-
item.id,
384-
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
385-
);
386-
self.process_generic_params(ty_params, &fn_data.qualname, item.id);
387-
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
388-
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), fn_data);
389-
}
373+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
374+
self.nest_tables(item.id, |v| {
375+
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
376+
down_cast_data!(fn_data, DefData, item.span);
377+
v.process_formals(&decl.inputs, &fn_data.qualname);
378+
v.process_generic_params(ty_params, &fn_data.qualname, item.id);
390379

391-
for arg in &decl.inputs {
392-
self.visit_ty(&arg.ty);
393-
}
380+
v.dumper.dump_def(&access_from!(v.save_ctxt, item, hir_id), fn_data);
381+
}
394382

395-
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
396-
self.visit_ty(&ret_ty);
397-
}
383+
for arg in &decl.inputs {
384+
v.visit_ty(&arg.ty)
385+
}
386+
387+
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
388+
if let ast::TyKind::ImplTrait(..) = ret_ty.node {
389+
// FIXME: Opaque type desugaring prevents us from easily
390+
// processing trait bounds. See `visit_ty` for more details.
391+
} else {
392+
v.visit_ty(&ret_ty);
393+
}
394+
}
398395

399-
self.nest_tables(item.id, |v| v.visit_block(&body));
396+
v.visit_block(&body);
397+
});
400398
}
401399

402400
fn process_static_or_const_item(
@@ -1113,11 +1111,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11131111
// FIXME: uses of the assoc type should ideally point to this
11141112
// 'def' and the name here should be a ref to the def in the
11151113
// trait.
1116-
for bound in bounds.iter() {
1117-
if let ast::GenericBound::Trait(trait_ref, _) = bound {
1118-
self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path)
1119-
}
1120-
}
1114+
self.process_bounds(&bounds);
11211115
}
11221116
ast::ImplItemKind::Macro(_) => {}
11231117
}
@@ -1364,10 +1358,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
13641358
self.visit_ty(&ty);
13651359
self.process_generic_params(ty_params, &qualname, item.id);
13661360
}
1367-
OpaqueTy(ref _bounds, ref ty_params) => {
1361+
OpaqueTy(ref bounds, ref ty_params) => {
13681362
let qualname = format!("::{}",
13691363
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id)));
1370-
// FIXME do something with _bounds
1364+
13711365
let value = String::new();
13721366
if !self.span.filter_generated(item.ident.span) {
13731367
let span = self.span_from_span(item.ident.span);
@@ -1393,6 +1387,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
13931387
);
13941388
}
13951389

1390+
self.process_bounds(bounds);
13961391
self.process_generic_params(ty_params, &qualname, item.id);
13971392
}
13981393
Mac(_) => (),
@@ -1449,6 +1444,18 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
14491444
self.visit_ty(element);
14501445
self.nest_tables(length.id, |v| v.visit_expr(&length.value));
14511446
}
1447+
ast::TyKind::ImplTrait(id, ref bounds) => {
1448+
// FIXME: As of writing, the opaque type lowering introduces
1449+
// another DefPath scope/segment (used to declare the resulting
1450+
// opaque type item).
1451+
// However, the synthetic scope does *not* have associated
1452+
// typeck tables, which means we can't nest it and we fire an
1453+
// assertion when resolving the qualified type paths in trait
1454+
// bounds...
1455+
// This will panic if called on return type `impl Trait`, which
1456+
// we guard against in `process_fn`.
1457+
self.nest_tables(id, |v| v.process_bounds(bounds));
1458+
}
14521459
_ => visit::walk_ty(self, t),
14531460
}
14541461
}

src/librustc_save_analysis/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
312312
let impl_id = self.next_impl_id();
313313
let span = self.span_from_span(sub_span);
314314

315-
let type_data = self.lookup_ref_id(typ.id);
315+
let type_data = self.lookup_def_id(typ.id);
316316
type_data.map(|type_data| {
317317
Data::RelationData(Relation {
318318
kind: RelationKind::Impl {
@@ -322,7 +322,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
322322
from: id_from_def_id(type_data),
323323
to: trait_ref
324324
.as_ref()
325-
.and_then(|t| self.lookup_ref_id(t.ref_id))
325+
.and_then(|t| self.lookup_def_id(t.ref_id))
326326
.map(id_from_def_id)
327327
.unwrap_or_else(|| null_id()),
328328
},
@@ -495,7 +495,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
495495
}
496496

497497
pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option<Ref> {
498-
self.lookup_ref_id(trait_ref.ref_id).and_then(|def_id| {
498+
self.lookup_def_id(trait_ref.ref_id).and_then(|def_id| {
499499
let span = trait_ref.path.span;
500500
if generated_code(span) {
501501
return None;
@@ -870,7 +870,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
870870
})
871871
}
872872

873-
fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> {
873+
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
874874
match self.get_path_res(ref_id) {
875875
Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
876876
def => Some(def.def_id()),

src/libstd/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,8 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
19561956
/// # Platform-specific behavior
19571957
///
19581958
/// This function currently corresponds to the `opendir` function on Unix
1959-
/// and the `FindFirstFile` function on Windows.
1959+
/// and the `FindFirstFile` function on Windows. Advancing the iterator
1960+
/// currently corresponds to `readdir` on Unix and `FindNextFile` on Windows.
19601961
/// Note that, this [may change in the future][changes].
19611962
///
19621963
/// [changes]: ../io/index.html#platform-specific-behavior

src/test/ui/lint/issue-54538-unused-parens-lint.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(box_patterns)]
1+
#![feature(box_patterns, stmt_expr_attributes)]
22

33
#![feature(or_patterns)]
44
//~^ WARN the feature `or_patterns` is incomplete
@@ -17,6 +17,10 @@ fn lint_on_top_level() {
1717
let _ = |(a): u8| 0; //~ ERROR unnecessary parentheses around pattern
1818
}
1919

20+
fn _no_lint_attr() {
21+
let _x = #[allow(dead_code)] (1 + 2);
22+
}
23+
2024
// Don't lint in these cases (#64106).
2125
fn or_patterns_no_lint() {
2226
match Box::new(0) {

0 commit comments

Comments
 (0)