Skip to content

Commit ce93331

Browse files
committed
Auto merge of #71255 - Dylan-DPC:rollup-u5yl04z, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #69642 (Use query to determine whether function needs const checking) - #71239 (Rename `asm` test directory in favor of `llvm_asm`) - #71246 (Implement `Clone` for `liballoc::collections::linked_list::Cursor`.) - #71247 (Remove unnecessary variable intialization) - #71254 (Minor fix and addition to doc comments) Failed merges: r? @ghost
2 parents 8d67f57 + 4132642 commit ce93331

30 files changed

+87
-56
lines changed

src/liballoc/collections/linked_list.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,14 @@ pub struct Cursor<'a, T: 'a> {
11971197
list: &'a LinkedList<T>,
11981198
}
11991199

1200+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1201+
impl<T> Clone for Cursor<'_, T> {
1202+
fn clone(&self) -> Self {
1203+
let Cursor { index, current, list } = *self;
1204+
Cursor { index, current, list }
1205+
}
1206+
}
1207+
12001208
#[unstable(feature = "linked_list_cursors", issue = "58533")]
12011209
impl<T: fmt::Debug> fmt::Debug for Cursor<'_, T> {
12021210
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/librustc_middle/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,14 +2611,14 @@ impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
26112611
type Iter = iter::Cloned<Successors<'b>>;
26122612
}
26132613

2614+
/// `Location` represents the position of the start of the statement; or, if
2615+
/// `statement_index` equals the number of statements, then the start of the
2616+
/// terminator.
26142617
#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, HashStable)]
26152618
pub struct Location {
26162619
/// The block that the location is within.
26172620
pub block: BasicBlock,
26182621

2619-
/// The location is the position of the start of the statement; or, if
2620-
/// `statement_index` equals the number of statements, then the start of the
2621-
/// terminator.
26222622
pub statement_index: usize,
26232623
}
26242624

src/librustc_mir/const_eval/fn_queries.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
9595

9696
let node = tcx.hir().get(hir_id);
9797

98-
if let Some(whitelisted) = is_const_intrinsic(tcx, def_id) {
99-
whitelisted
98+
if let hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) =
99+
node
100+
{
101+
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
102+
// foreign items cannot be evaluated at compile-time.
103+
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = tcx.hir().get_foreign_abi(hir_id) {
104+
tcx.lookup_const_stability(def_id).is_some()
105+
} else {
106+
false
107+
}
100108
} else if let Some(fn_like) = FnLikeNode::from_node(node) {
101109
if fn_like.constness() == hir::Constness::Const {
102110
return true;
@@ -112,21 +120,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
112120
}
113121
}
114122

115-
/// Const evaluability whitelist is here to check evaluability at the
116-
/// top level beforehand.
117-
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
118-
if tcx.is_closure(def_id) {
119-
return None;
120-
}
121-
122-
match tcx.fn_sig(def_id).abi() {
123-
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
124-
Some(tcx.lookup_const_stability(def_id).is_some())
125-
}
126-
_ => None,
127-
}
128-
}
129-
130123
/// Checks whether the given item is an `impl` that has a `const` modifier.
131124
fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
132125
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

src/librustc_mir/util/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ pub fn write_mir_pretty<'tcx>(
254254
Ok(())
255255
}
256256

257+
/// Write out a human-readable textual representation for the given function.
257258
pub fn write_mir_fn<'tcx, F>(
258259
tcx: TyCtxt<'tcx>,
259260
src: MirSource<'tcx>,

src/librustc_passes/check_const.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ enum ConstKind {
7474
}
7575

7676
impl ConstKind {
77-
fn for_body(body: &hir::Body<'_>, hir_map: Map<'_>) -> Option<Self> {
78-
let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const();
79-
80-
let owner = hir_map.body_owner(body.id());
81-
let const_kind = match hir_map.body_owner_kind(owner) {
77+
fn for_body(body: &hir::Body<'_>, tcx: TyCtxt<'_>) -> Option<Self> {
78+
let owner = tcx.hir().body_owner(body.id());
79+
let const_kind = match tcx.hir().body_owner_kind(owner) {
8280
hir::BodyOwnerKind::Const => Self::Const,
8381
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
8482
hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static,
8583

86-
hir::BodyOwnerKind::Fn if is_const_fn(owner) => Self::ConstFn,
84+
hir::BodyOwnerKind::Fn if tcx.is_const_fn_raw(tcx.hir().local_def_id(owner)) => {
85+
Self::ConstFn
86+
}
8787
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None,
8888
};
8989

@@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
211211
}
212212

213213
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
214-
let kind = ConstKind::for_body(body, self.tcx.hir());
214+
let kind = ConstKind::for_body(body, self.tcx);
215215
self.recurse_into(kind, |this| intravisit::walk_body(this, body));
216216
}
217217

src/librustc_typeck/check/expr.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -975,18 +975,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
975975
expected: Expectation<'tcx>,
976976
expr: &'tcx hir::Expr<'tcx>,
977977
) -> Ty<'tcx> {
978-
let uty = expected.to_option(self).and_then(|uty| match uty.kind {
979-
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
980-
_ => None,
981-
});
982-
983978
let element_ty = if !args.is_empty() {
984-
let coerce_to = uty.unwrap_or_else(|| {
985-
self.next_ty_var(TypeVariableOrigin {
986-
kind: TypeVariableOriginKind::TypeInference,
987-
span: expr.span,
979+
let coerce_to = expected
980+
.to_option(self)
981+
.and_then(|uty| match uty.kind {
982+
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
983+
_ => None,
988984
})
989-
});
985+
.unwrap_or_else(|| {
986+
self.next_ty_var(TypeVariableOrigin {
987+
kind: TypeVariableOriginKind::TypeInference,
988+
span: expr.span,
989+
})
990+
});
990991
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
991992
assert_eq!(self.diverges.get(), Diverges::Maybe);
992993
for e in args {
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)