Skip to content

Commit d28e948

Browse files
committed
Auto merge of #60748 - Centril:rollup-rr63jqo, r=Centril
Rollup of 4 pull requests Successful merges: - #60720 (Remove unnecessary unwraps) - #60727 (add comment to `Rc`/`Arc`'s `Eq` specialization) - #60733 (Cleanup the .await HIR lowering with .stmt(..).) - #60741 (Remove redundant "let mut" in write_graph_label) Failed merges: r? @ghost
2 parents af98304 + f2dd97c commit d28e948

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

src/liballoc/rc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,11 @@ impl<T: ?Sized + PartialEq> RcEqIdent<T> for Rc<T> {
932932
}
933933
}
934934

935+
/// We're doing this specialization here, and not as a more general optimization on `&T`, because it
936+
/// would otherwise add a cost to all equality checks on refs. We assume that `Rc`s are used to
937+
/// store large values, that are slow to clone, but also heavy to check for equality, causing this
938+
/// cost to pay off more easily. It's also more likely to have two `Rc` clones, that point to
939+
/// the same value, than two `&T`s.
935940
#[stable(feature = "rust1", since = "1.0.0")]
936941
impl<T: ?Sized + Eq> RcEqIdent<T> for Rc<T> {
937942
#[inline]

src/liballoc/sync.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,11 @@ impl<T: ?Sized + PartialEq> ArcEqIdent<T> for Arc<T> {
13771377
}
13781378
}
13791379

1380+
/// We're doing this specialization here, and not as a more general optimization on `&T`, because it
1381+
/// would otherwise add a cost to all equality checks on refs. We assume that `Arc`s are used to
1382+
/// store large values, that are slow to clone, but also heavy to check for equality, causing this
1383+
/// cost to pay off more easily. It's also more likely to have two `Arc` clones, that point to
1384+
/// the same value, than two `&T`s.
13801385
#[stable(feature = "rust1", since = "1.0.0")]
13811386
impl<T: ?Sized + Eq> ArcEqIdent<T> for Arc<T> {
13821387
#[inline]

src/librustc/hir/lowering.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -5647,11 +5647,7 @@ impl<'a> LoweringContext<'a> {
56475647
hir_vec![ready_arm, pending_arm],
56485648
hir::MatchSource::AwaitDesugar,
56495649
));
5650-
hir::Stmt {
5651-
hir_id: self.next_id(),
5652-
node: hir::StmtKind::Expr(match_expr),
5653-
span,
5654-
}
5650+
self.stmt(span, hir::StmtKind::Expr(match_expr))
56555651
};
56565652

56575653
let yield_stmt = {
@@ -5661,11 +5657,7 @@ impl<'a> LoweringContext<'a> {
56615657
hir::ExprKind::Yield(P(unit)),
56625658
ThinVec::new(),
56635659
));
5664-
hir::Stmt {
5665-
hir_id: self.next_id(),
5666-
node: hir::StmtKind::Expr(yield_expr),
5667-
span,
5668-
}
5660+
self.stmt(span, hir::StmtKind::Expr(yield_expr))
56695661
};
56705662

56715663
let loop_block = P(self.block_all(

src/librustc_mir/util/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
167167
write!(w, r#"{:?}: {}; // {}<br align="left"/>"#,
168168
Place::Base(PlaceBase::Local(local)), escape(&decl.ty), name)?;
169169
} else {
170-
write!(w, r#"let mut {:?}: {};<br align="left"/>"#,
170+
write!(w, r#"{:?}: {};<br align="left"/>"#,
171171
Place::Base(PlaceBase::Local(local)), escape(&decl.ty))?;
172172
}
173173
}

src/librustc_typeck/check/method/suggest.rs

+34-23
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
9191
CandidateSource::ImplSource(impl_did) => {
9292
// Provide the best span we can. Use the item, if local to crate, else
9393
// the impl, if local to crate (item may be defaulted), else nothing.
94-
let item = self.associated_item(impl_did, item_name, Namespace::Value)
95-
.or_else(|| {
96-
self.associated_item(
97-
self.tcx.impl_trait_ref(impl_did).unwrap().def_id,
98-
item_name,
99-
Namespace::Value,
100-
)
101-
}).unwrap();
94+
let item = match self.associated_item(
95+
impl_did,
96+
item_name,
97+
Namespace::Value,
98+
).or_else(|| {
99+
let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
100+
self.associated_item(
101+
impl_trait_ref.def_id,
102+
item_name,
103+
Namespace::Value,
104+
)
105+
}) {
106+
Some(item) => item,
107+
None => continue,
108+
};
102109
let note_span = self.tcx.hir().span_if_local(item.def_id).or_else(|| {
103110
self.tcx.hir().span_if_local(impl_did)
104111
});
@@ -132,9 +139,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
132139
}
133140
}
134141
CandidateSource::TraitSource(trait_did) => {
135-
let item = self
136-
.associated_item(trait_did, item_name, Namespace::Value)
137-
.unwrap();
142+
let item = match self.associated_item(
143+
trait_did,
144+
item_name,
145+
Namespace::Value)
146+
{
147+
Some(item) => item,
148+
None => continue,
149+
};
138150
let item_span = self.tcx.sess.source_map()
139151
.def_span(self.tcx.def_span(item.def_id));
140152
if sources.len() > 1 {
@@ -251,8 +263,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
251263
if let &QPath::Resolved(_, ref path) = &qpath {
252264
if let hir::def::Res::Local(hir_id) = path.res {
253265
let span = tcx.hir().span_by_hir_id(hir_id);
254-
let snippet = tcx.sess.source_map().span_to_snippet(span)
255-
.unwrap();
266+
let snippet = tcx.sess.source_map().span_to_snippet(span);
256267
let filename = tcx.sess.source_map().span_to_filename(span);
257268

258269
let parent_node = self.tcx.hir().get_by_hir_id(
@@ -263,12 +274,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
263274
concrete_type,
264275
);
265276

266-
match (filename, parent_node) {
277+
match (filename, parent_node, snippet) {
267278
(FileName::Real(_), Node::Local(hir::Local {
268279
source: hir::LocalSource::Normal,
269280
ty,
270281
..
271-
})) => {
282+
}), Ok(ref snippet)) => {
272283
err.span_suggestion(
273284
// account for `let x: _ = 42;`
274285
// ^^^^
@@ -375,14 +386,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
375386
self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id),
376387
);
377388

378-
let span = call_expr.span.trim_start(item_name.span).unwrap();
379-
380-
err.span_suggestion(
381-
span,
382-
"remove the arguments",
383-
String::new(),
384-
Applicability::MaybeIncorrect,
385-
);
389+
if let Some(span) = call_expr.span.trim_start(item_name.span) {
390+
err.span_suggestion(
391+
span,
392+
"remove the arguments",
393+
String::new(),
394+
Applicability::MaybeIncorrect,
395+
);
396+
}
386397
}
387398
}
388399

0 commit comments

Comments
 (0)