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

+8
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

+3-3
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

+10-17
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

+1
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

+7-7
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

+11-10
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/test/ui/asm/asm-bad-clobber.stderr src/test/ui/llvm-asm/llvm-asm-bad-clobber.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0664]: clobber should not be surrounded by braces
2-
--> $DIR/asm-bad-clobber.rs:22:42
2+
--> $DIR/llvm-asm-bad-clobber.rs:22:42
33
|
44
LL | llvm_asm!("xor %eax, %eax" : : : "{eax}");
55
| ^^^^^^^

src/test/ui/asm/asm-in-bad-modifier.stderr src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0662]: input operand constraint contains '='
2-
--> $DIR/asm-in-bad-modifier.rs:23:44
2+
--> $DIR/llvm-asm-in-bad-modifier.rs:23:44
33
|
44
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "=r"(5));
55
| ^^^^
66

77
error[E0663]: input operand constraint contains '+'
8-
--> $DIR/asm-in-bad-modifier.rs:24:44
8+
--> $DIR/llvm-asm-in-bad-modifier.rs:24:44
99
|
1010
LL | llvm_asm!("mov $1, $0" : "=r"(y) : "+r"(5));
1111
| ^^^^

src/test/ui/asm/asm-misplaced-option.stderr src/test/ui/llvm-asm/llvm-asm-misplaced-option.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: unrecognized option
2-
--> $DIR/asm-misplaced-option.rs:24:69
2+
--> $DIR/llvm-asm-misplaced-option.rs:24:69
33
|
44
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(5_usize), "0"(x) : : "cc");
55
| ^^^^
66

77
warning: expected a clobber, found an option
8-
--> $DIR/asm-misplaced-option.rs:31:85
8+
--> $DIR/llvm-asm-misplaced-option.rs:31:85
99
|
1010
LL | llvm_asm!("add $2, $1; mov $1, $0" : "=r"(x) : "r"(x), "r"(8_usize) : "cc", "volatile");
1111
| ^^^^^^^^^^

src/test/ui/asm/asm-out-assign-imm.stderr src/test/ui/llvm-asm/llvm-asm-out-assign-imm.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0384]: cannot assign twice to immutable variable `x`
2-
--> $DIR/asm-out-assign-imm.rs:24:39
2+
--> $DIR/llvm-asm-out-assign-imm.rs:24:39
33
|
44
LL | let x: isize;
55
| - help: make this binding mutable: `mut x`

src/test/ui/asm/asm-out-no-modifier.stderr src/test/ui/llvm-asm/llvm-asm-out-no-modifier.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0661]: output operand constraint lacks '=' or '+'
2-
--> $DIR/asm-out-no-modifier.rs:22:34
2+
--> $DIR/llvm-asm-out-no-modifier.rs:22:34
33
|
44
LL | llvm_asm!("mov $1, $0" : "r"(x) : "r"(5));
55
| ^^^

src/test/ui/asm/asm-out-read-uninit.stderr src/test/ui/llvm-asm/llvm-asm-out-read-uninit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0381]: use of possibly-uninitialized variable: `x`
2-
--> $DIR/asm-out-read-uninit.rs:22:48
2+
--> $DIR/llvm-asm-out-read-uninit.rs:22:48
33
|
44
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(x));
55
| ^ use of possibly-uninitialized `x`

src/test/ui/asm/asm-parse-errors.stderr src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
error: macro requires a string literal as an argument
2-
--> $DIR/asm-parse-errors.rs:4:5
2+
--> $DIR/llvm-asm-parse-errors.rs:4:5
33
|
44
LL | llvm_asm!();
55
| ^^^^^^^^^^^^ string literal required
66

77
error: expected string literal
8-
--> $DIR/asm-parse-errors.rs:5:23
8+
--> $DIR/llvm-asm-parse-errors.rs:5:23
99
|
1010
LL | llvm_asm!("nop" : struct);
1111
| ^^^^^^ not a string literal
1212

1313
error: expected string literal
14-
--> $DIR/asm-parse-errors.rs:6:35
14+
--> $DIR/llvm-asm-parse-errors.rs:6:35
1515
|
1616
LL | llvm_asm!("mov %eax, $$0x2" : struct);
1717
| ^^^^^^ not a string literal
1818

1919
error: expected `(`, found keyword `struct`
20-
--> $DIR/asm-parse-errors.rs:7:44
20+
--> $DIR/llvm-asm-parse-errors.rs:7:44
2121
|
2222
LL | llvm_asm!("mov %eax, $$0x2" : "={eax}" struct);
2323
| ^^^^^^ expected `(`
2424

2525
error: expected expression, found keyword `struct`
26-
--> $DIR/asm-parse-errors.rs:8:44
26+
--> $DIR/llvm-asm-parse-errors.rs:8:44
2727
|
2828
LL | llvm_asm!("mov %eax, $$0x2" : "={eax}"(struct));
2929
| ^^^^^^ expected expression
3030

3131
error: expected string literal
32-
--> $DIR/asm-parse-errors.rs:9:49
32+
--> $DIR/llvm-asm-parse-errors.rs:9:49
3333
|
3434
LL | llvm_asm!("in %dx, %al" : "={al}"(result) : struct);
3535
| ^^^^^^ not a string literal
3636

3737
error: expected `(`, found keyword `struct`
38-
--> $DIR/asm-parse-errors.rs:10:56
38+
--> $DIR/llvm-asm-parse-errors.rs:10:56
3939
|
4040
LL | llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}" struct);
4141
| ^^^^^^ expected `(`
4242

4343
error: expected expression, found keyword `struct`
44-
--> $DIR/asm-parse-errors.rs:11:56
44+
--> $DIR/llvm-asm-parse-errors.rs:11:56
4545
|
4646
LL | llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(struct));
4747
| ^^^^^^ expected expression
4848

4949
error: expected string literal
50-
--> $DIR/asm-parse-errors.rs:12:41
50+
--> $DIR/llvm-asm-parse-errors.rs:12:41
5151
|
5252
LL | llvm_asm!("mov $$0x200, %eax" : : : struct);
5353
| ^^^^^^ not a string literal
5454

5555
error: expected string literal
56-
--> $DIR/asm-parse-errors.rs:13:50
56+
--> $DIR/llvm-asm-parse-errors.rs:13:50
5757
|
5858
LL | llvm_asm!("mov eax, 2" : "={eax}"(foo) : : : struct);
5959
| ^^^^^^ not a string literal
6060

6161
error: inline assembly must be a string literal
62-
--> $DIR/asm-parse-errors.rs:14:15
62+
--> $DIR/llvm-asm-parse-errors.rs:14:15
6363
|
6464
LL | llvm_asm!(123);
6565
| ^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for #69615.
2+
3+
#![feature(const_trait_impl, const_fn)]
4+
#![allow(incomplete_features)]
5+
6+
pub trait MyTrait {
7+
fn method(&self);
8+
}
9+
10+
impl const MyTrait for () {
11+
fn method(&self) {
12+
match *self {} //~ ERROR `match` is not allowed in a `const fn`
13+
}
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: `match` is not allowed in a `const fn`
2+
--> $DIR/hir-const-check.rs:12:9
3+
|
4+
LL | match *self {}
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
8+
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)