Skip to content

Commit 0c0c585

Browse files
committed
Auto merge of #57761 - Centril:rollup, r=Centril
Rollup of 4 pull requests Successful merges: - #57452 (Improve docs for Formatter) - #57689 (Redo `hir::Stmt`) - #57723 (Point at cause for expectation in return type type error) - #57736 (Remove delay_span_bug from qualify_min_const_fn) Failed merges: r? @ghost
2 parents 52fec81 + d27224e commit 0c0c585

32 files changed

+437
-369
lines changed

src/libcore/fmt/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,18 @@ impl<W: Write + ?Sized> Write for &mut W {
211211
}
212212
}
213213

214-
/// A struct to represent both where to emit formatting strings to and how they
215-
/// should be formatted. A mutable version of this is passed to all formatting
216-
/// traits.
214+
/// Configuration for formatting.
215+
///
216+
/// A `Formatter` represents various options related to formatting. Users do not
217+
/// construct `Formatter`s directly; a mutable reference to one is passed to
218+
/// the `fmt` method of all formatting traits, like [`Debug`] and [`Display`].
219+
///
220+
/// To interact with a `Formatter`, you'll call various methods to change the
221+
/// various options related to formatting. For examples, please see the
222+
/// documentation of the methods defined on `Formatter` below.
223+
///
224+
/// [`Debug`]: trait.Debug.html
225+
/// [`Display`]: trait.Display.html
217226
#[allow(missing_debug_implementations)]
218227
#[stable(feature = "rust1", since = "1.0.0")]
219228
pub struct Formatter<'a> {

src/librustc/cfg/construct.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,21 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
9999
}
100100

101101
fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
102-
let hir_id = self.tcx.hir().node_to_hir_id(stmt.node.id());
103-
match stmt.node {
104-
hir::StmtKind::Decl(ref decl, _) => {
105-
let exit = self.decl(&decl, pred);
106-
self.add_ast_node(hir_id.local_id, &[exit])
107-
}
108-
109-
hir::StmtKind::Expr(ref expr, _) |
110-
hir::StmtKind::Semi(ref expr, _) => {
111-
let exit = self.expr(&expr, pred);
112-
self.add_ast_node(hir_id.local_id, &[exit])
113-
}
114-
}
115-
}
116-
117-
fn decl(&mut self, decl: &hir::Decl, pred: CFGIndex) -> CFGIndex {
118-
match decl.node {
119-
hir::DeclKind::Local(ref local) => {
102+
let hir_id = self.tcx.hir().node_to_hir_id(stmt.id);
103+
let exit = match stmt.node {
104+
hir::StmtKind::Local(ref local) => {
120105
let init_exit = self.opt_expr(&local.init, pred);
121106
self.pat(&local.pat, init_exit)
122107
}
123-
124-
hir::DeclKind::Item(_) => pred,
125-
}
108+
hir::StmtKind::Item(_) => {
109+
pred
110+
}
111+
hir::StmtKind::Expr(ref expr) |
112+
hir::StmtKind::Semi(ref expr) => {
113+
self.expr(&expr, pred)
114+
}
115+
};
116+
self.add_ast_node(hir_id.local_id, &[exit])
126117
}
127118

128119
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
283283

284284
fn check_stmt_attributes(&self, stmt: &hir::Stmt) {
285285
// When checking statements ignore expressions, they will be checked later
286-
if let hir::StmtKind::Decl(_, _) = stmt.node {
287-
for attr in stmt.node.attrs() {
286+
if let hir::StmtKind::Local(ref l) = stmt.node {
287+
for attr in l.attrs.iter() {
288288
if attr.check_name("inline") {
289289
self.check_inline(attr, &stmt.span, Target::Statement);
290290
}

src/librustc/hir/intravisit.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ pub trait Visitor<'v> : Sized {
258258
fn visit_pat(&mut self, p: &'v Pat) {
259259
walk_pat(self, p)
260260
}
261-
fn visit_decl(&mut self, d: &'v Decl) {
262-
walk_decl(self, d)
263-
}
264261
fn visit_anon_const(&mut self, c: &'v AnonConst) {
265262
walk_anon_const(self, c)
266263
}
@@ -951,26 +948,17 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
951948
}
952949

953950
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
951+
visitor.visit_id(statement.id);
954952
match statement.node {
955-
StmtKind::Decl(ref declaration, id) => {
956-
visitor.visit_id(id);
957-
visitor.visit_decl(declaration)
958-
}
959-
StmtKind::Expr(ref expression, id) |
960-
StmtKind::Semi(ref expression, id) => {
961-
visitor.visit_id(id);
953+
StmtKind::Local(ref local) => visitor.visit_local(local),
954+
StmtKind::Item(ref item) => visitor.visit_nested_item(**item),
955+
StmtKind::Expr(ref expression) |
956+
StmtKind::Semi(ref expression) => {
962957
visitor.visit_expr(expression)
963958
}
964959
}
965960
}
966961

967-
pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
968-
match declaration.node {
969-
DeclKind::Local(ref local) => visitor.visit_local(local),
970-
DeclKind::Item(item) => visitor.visit_nested_item(item),
971-
}
972-
}
973-
974962
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
975963
visitor.visit_id(constant.id);
976964
visitor.visit_nested_body(constant.body);

src/librustc/hir/lowering.rs

+35-43
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
19571957
)
19581958
}
19591959

1960-
fn lower_local(&mut self, l: &Local) -> (P<hir::Local>, SmallVec<[hir::ItemId; 1]>) {
1960+
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
19611961
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
19621962
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
19631963
if self.sess.features_untracked().impl_trait_in_bindings {
@@ -1967,7 +1967,7 @@ impl<'a> LoweringContext<'a> {
19671967
}
19681968
}
19691969
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
1970-
(P(hir::Local {
1970+
(hir::Local {
19711971
id: node_id,
19721972
hir_id,
19731973
ty: l.ty
@@ -1984,7 +1984,7 @@ impl<'a> LoweringContext<'a> {
19841984
span: l.span,
19851985
attrs: l.attrs.clone(),
19861986
source: hir::LocalSource::Normal,
1987-
}), ids)
1987+
}, ids)
19881988
}
19891989

19901990
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
@@ -4331,10 +4331,11 @@ impl<'a> LoweringContext<'a> {
43314331
ThinVec::new(),
43324332
))
43334333
};
4334-
let match_stmt = respan(
4335-
head_sp,
4336-
hir::StmtKind::Expr(match_expr, self.next_id().node_id)
4337-
);
4334+
let match_stmt = hir::Stmt {
4335+
id: self.next_id().node_id,
4336+
node: hir::StmtKind::Expr(match_expr),
4337+
span: head_sp,
4338+
};
43384339

43394340
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
43404341

@@ -4357,10 +4358,11 @@ impl<'a> LoweringContext<'a> {
43574358

43584359
let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
43594360
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
4360-
let body_stmt = respan(
4361-
body.span,
4362-
hir::StmtKind::Expr(body_expr, self.next_id().node_id)
4363-
);
4361+
let body_stmt = hir::Stmt {
4362+
id: self.next_id().node_id,
4363+
node: hir::StmtKind::Expr(body_expr),
4364+
span: body.span,
4365+
};
43644366

43654367
let loop_block = P(self.block_all(
43664368
e.span,
@@ -4533,25 +4535,15 @@ impl<'a> LoweringContext<'a> {
45334535
let (l, item_ids) = self.lower_local(l);
45344536
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
45354537
.into_iter()
4536-
.map(|item_id| Spanned {
4537-
node: hir::StmtKind::Decl(
4538-
P(Spanned {
4539-
node: hir::DeclKind::Item(item_id),
4540-
span: s.span,
4541-
}),
4542-
self.next_id().node_id,
4543-
),
4538+
.map(|item_id| hir::Stmt {
4539+
id: self.next_id().node_id,
4540+
node: hir::StmtKind::Item(P(item_id)),
45444541
span: s.span,
45454542
})
45464543
.collect();
4547-
ids.push(Spanned {
4548-
node: hir::StmtKind::Decl(
4549-
P(Spanned {
4550-
node: hir::DeclKind::Local(l),
4551-
span: s.span,
4552-
}),
4553-
self.lower_node_id(s.id).node_id,
4554-
),
4544+
ids.push(hir::Stmt {
4545+
id: self.lower_node_id(s.id).node_id,
4546+
node: hir::StmtKind::Local(P(l)),
45554547
span: s.span,
45564548
});
45574549
return ids;
@@ -4561,26 +4553,23 @@ impl<'a> LoweringContext<'a> {
45614553
let mut id = Some(s.id);
45624554
return self.lower_item_id(it)
45634555
.into_iter()
4564-
.map(|item_id| Spanned {
4565-
node: hir::StmtKind::Decl(
4566-
P(Spanned {
4567-
node: hir::DeclKind::Item(item_id),
4568-
span: s.span,
4569-
}),
4570-
id.take()
4556+
.map(|item_id| hir::Stmt {
4557+
id: id.take()
45714558
.map(|id| self.lower_node_id(id).node_id)
45724559
.unwrap_or_else(|| self.next_id().node_id),
4573-
),
4560+
node: hir::StmtKind::Item(P(item_id)),
45744561
span: s.span,
45754562
})
45764563
.collect();
45774564
}
4578-
StmtKind::Expr(ref e) => Spanned {
4579-
node: hir::StmtKind::Expr(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id),
4565+
StmtKind::Expr(ref e) => hir::Stmt {
4566+
id: self.lower_node_id(s.id).node_id,
4567+
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
45804568
span: s.span,
45814569
},
4582-
StmtKind::Semi(ref e) => Spanned {
4583-
node: hir::StmtKind::Semi(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id),
4570+
StmtKind::Semi(ref e) => hir::Stmt {
4571+
id: self.lower_node_id(s.id).node_id,
4572+
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
45844573
span: s.span,
45854574
},
45864575
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
@@ -4795,7 +4784,7 @@ impl<'a> LoweringContext<'a> {
47954784
) -> hir::Stmt {
47964785
let LoweredNodeId { node_id, hir_id } = self.next_id();
47974786

4798-
let local = P(hir::Local {
4787+
let local = hir::Local {
47994788
pat,
48004789
ty: None,
48014790
init: ex,
@@ -4804,9 +4793,12 @@ impl<'a> LoweringContext<'a> {
48044793
span: sp,
48054794
attrs: ThinVec::new(),
48064795
source,
4807-
});
4808-
let decl = respan(sp, hir::DeclKind::Local(local));
4809-
respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id))
4796+
};
4797+
hir::Stmt {
4798+
id: self.next_id().node_id,
4799+
node: hir::StmtKind::Local(P(local)),
4800+
span: sp
4801+
}
48104802
}
48114803

48124804
fn stmt_let(

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
426426
}
427427

428428
fn visit_stmt(&mut self, stmt: &'hir Stmt) {
429-
let id = stmt.node.id();
429+
let id = stmt.id;
430430
self.insert(stmt.span, id, Node::Stmt(stmt));
431431

432432
self.with_parent(id, |this| {

src/librustc/hir/mod.rs

+20-50
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use util::nodemap::{NodeMap, FxHashSet};
1717
use mir::mono::Linkage;
1818

1919
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
20-
use syntax::source_map::{self, Spanned};
20+
use syntax::source_map::Spanned;
2121
use rustc_target::spec::abi::Abi;
2222
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
2323
use syntax::ast::{Attribute, Label, Lit, StrStyle, FloatTy, IntTy, UintTy};
@@ -1134,45 +1134,41 @@ impl UnOp {
11341134
}
11351135

11361136
/// A statement
1137-
pub type Stmt = Spanned<StmtKind>;
1137+
#[derive(Clone, RustcEncodable, RustcDecodable)]
1138+
pub struct Stmt {
1139+
pub id: NodeId,
1140+
pub node: StmtKind,
1141+
pub span: Span,
1142+
}
11381143

1139-
impl fmt::Debug for StmtKind {
1144+
impl fmt::Debug for Stmt {
11401145
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1141-
// Sadness.
1142-
let spanned = source_map::dummy_spanned(self.clone());
1143-
write!(f,
1144-
"stmt({}: {})",
1145-
spanned.node.id(),
1146-
print::to_string(print::NO_ANN, |s| s.print_stmt(&spanned)))
1146+
write!(f, "stmt({}: {})", self.id,
1147+
print::to_string(print::NO_ANN, |s| s.print_stmt(self)))
11471148
}
11481149
}
11491150

11501151
#[derive(Clone, RustcEncodable, RustcDecodable)]
11511152
pub enum StmtKind {
1152-
/// Could be an item or a local (let) binding:
1153-
Decl(P<Decl>, NodeId),
1153+
/// A local (let) binding:
1154+
Local(P<Local>),
1155+
/// An item binding:
1156+
Item(P<ItemId>),
11541157

11551158
/// Expr without trailing semi-colon (must have unit type):
1156-
Expr(P<Expr>, NodeId),
1159+
Expr(P<Expr>),
11571160

11581161
/// Expr with trailing semi-colon (may have any type):
1159-
Semi(P<Expr>, NodeId),
1162+
Semi(P<Expr>),
11601163
}
11611164

11621165
impl StmtKind {
11631166
pub fn attrs(&self) -> &[Attribute] {
11641167
match *self {
1165-
StmtKind::Decl(ref d, _) => d.node.attrs(),
1166-
StmtKind::Expr(ref e, _) |
1167-
StmtKind::Semi(ref e, _) => &e.attrs,
1168-
}
1169-
}
1170-
1171-
pub fn id(&self) -> NodeId {
1172-
match *self {
1173-
StmtKind::Decl(_, id) |
1174-
StmtKind::Expr(_, id) |
1175-
StmtKind::Semi(_, id) => id,
1168+
StmtKind::Local(ref l) => &l.attrs,
1169+
StmtKind::Item(_) => &[],
1170+
StmtKind::Expr(ref e) |
1171+
StmtKind::Semi(ref e) => &e.attrs,
11761172
}
11771173
}
11781174
}
@@ -1191,32 +1187,6 @@ pub struct Local {
11911187
pub source: LocalSource,
11921188
}
11931189

1194-
pub type Decl = Spanned<DeclKind>;
1195-
1196-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1197-
pub enum DeclKind {
1198-
/// A local (let) binding:
1199-
Local(P<Local>),
1200-
/// An item binding:
1201-
Item(ItemId),
1202-
}
1203-
1204-
impl DeclKind {
1205-
pub fn attrs(&self) -> &[Attribute] {
1206-
match *self {
1207-
DeclKind::Local(ref l) => &l.attrs,
1208-
DeclKind::Item(_) => &[]
1209-
}
1210-
}
1211-
1212-
pub fn is_local(&self) -> bool {
1213-
match *self {
1214-
DeclKind::Local(_) => true,
1215-
_ => false,
1216-
}
1217-
}
1218-
}
1219-
12201190
/// represents one arm of a 'match'
12211191
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
12221192
pub struct Arm {

0 commit comments

Comments
 (0)