Skip to content

Commit

Permalink
Auto merge of rust-lang#71255 - Dylan-DPC:rollup-u5yl04z, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#69642 (Use query to determine whether function needs const checking)
 - rust-lang#71239 (Rename `asm` test directory in favor of `llvm_asm`)
 - rust-lang#71246 (Implement `Clone` for `liballoc::collections::linked_list::Cursor`.)
 - rust-lang#71247 (Remove unnecessary variable intialization)
 - rust-lang#71254 (Minor fix and addition to doc comments)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 17, 2020
2 parents 8d67f57 + 4132642 commit ce93331
Show file tree
Hide file tree
Showing 30 changed files with 87 additions and 56 deletions.
8 changes: 8 additions & 0 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,14 @@ pub struct Cursor<'a, T: 'a> {
list: &'a LinkedList<T>,
}

#[unstable(feature = "linked_list_cursors", issue = "58533")]
impl<T> Clone for Cursor<'_, T> {
fn clone(&self) -> Self {
let Cursor { index, current, list } = *self;
Cursor { index, current, list }
}
}

#[unstable(feature = "linked_list_cursors", issue = "58533")]
impl<T: fmt::Debug> fmt::Debug for Cursor<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,14 +2611,14 @@ impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
type Iter = iter::Cloned<Successors<'b>>;
}

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

/// The location is the position of the start of the statement; or, if
/// `statement_index` equals the number of statements, then the start of the
/// terminator.
pub statement_index: usize,
}

Expand Down
27 changes: 10 additions & 17 deletions src/librustc_mir/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {

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

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

/// Const evaluability whitelist is here to check evaluability at the
/// top level beforehand.
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
if tcx.is_closure(def_id) {
return None;
}

match tcx.fn_sig(def_id).abi() {
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
Some(tcx.lookup_const_stability(def_id).is_some())
}
_ => None,
}
}

/// Checks whether the given item is an `impl` that has a `const` modifier.
fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ pub fn write_mir_pretty<'tcx>(
Ok(())
}

/// Write out a human-readable textual representation for the given function.
pub fn write_mir_fn<'tcx, F>(
tcx: TyCtxt<'tcx>,
src: MirSource<'tcx>,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_passes/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ enum ConstKind {
}

impl ConstKind {
fn for_body(body: &hir::Body<'_>, hir_map: Map<'_>) -> Option<Self> {
let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const();

let owner = hir_map.body_owner(body.id());
let const_kind = match hir_map.body_owner_kind(owner) {
fn for_body(body: &hir::Body<'_>, tcx: TyCtxt<'_>) -> Option<Self> {
let owner = tcx.hir().body_owner(body.id());
let const_kind = match tcx.hir().body_owner_kind(owner) {
hir::BodyOwnerKind::Const => Self::Const,
hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut,
hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static,

hir::BodyOwnerKind::Fn if is_const_fn(owner) => Self::ConstFn,
hir::BodyOwnerKind::Fn if tcx.is_const_fn_raw(tcx.hir().local_def_id(owner)) => {
Self::ConstFn
}
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None,
};

Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
}

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

Expand Down
21 changes: 11 additions & 10 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,18 +975,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Expectation<'tcx>,
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
let uty = expected.to_option(self).and_then(|uty| match uty.kind {
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
_ => None,
});

let element_ty = if !args.is_empty() {
let coerce_to = uty.unwrap_or_else(|| {
self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference,
span: expr.span,
let coerce_to = expected
.to_option(self)
.and_then(|uty| match uty.kind {
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
_ => None,
})
});
.unwrap_or_else(|| {
self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference,
span: expr.span,
})
});
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
assert_eq!(self.diverges.get(), Diverges::Maybe);
for e in args {
Expand Down
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.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0664]: clobber should not be surrounded by braces
--> $DIR/asm-bad-clobber.rs:22:42
--> $DIR/llvm-asm-bad-clobber.rs:22:42
|
LL | llvm_asm!("xor %eax, %eax" : : : "{eax}");
| ^^^^^^^
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0662]: input operand constraint contains '='
--> $DIR/asm-in-bad-modifier.rs:23:44
--> $DIR/llvm-asm-in-bad-modifier.rs:23:44
|
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "=r"(5));
| ^^^^

error[E0663]: input operand constraint contains '+'
--> $DIR/asm-in-bad-modifier.rs:24:44
--> $DIR/llvm-asm-in-bad-modifier.rs:24:44
|
LL | llvm_asm!("mov $1, $0" : "=r"(y) : "+r"(5));
| ^^^^
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
warning: unrecognized option
--> $DIR/asm-misplaced-option.rs:24:69
--> $DIR/llvm-asm-misplaced-option.rs:24:69
|
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(5_usize), "0"(x) : : "cc");
| ^^^^

warning: expected a clobber, found an option
--> $DIR/asm-misplaced-option.rs:31:85
--> $DIR/llvm-asm-misplaced-option.rs:31:85
|
LL | llvm_asm!("add $2, $1; mov $1, $0" : "=r"(x) : "r"(x), "r"(8_usize) : "cc", "volatile");
| ^^^^^^^^^^
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/asm-out-assign-imm.rs:24:39
--> $DIR/llvm-asm-out-assign-imm.rs:24:39
|
LL | let x: isize;
| - help: make this binding mutable: `mut x`
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0661]: output operand constraint lacks '=' or '+'
--> $DIR/asm-out-no-modifier.rs:22:34
--> $DIR/llvm-asm-out-no-modifier.rs:22:34
|
LL | llvm_asm!("mov $1, $0" : "r"(x) : "r"(5));
| ^^^
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/asm-out-read-uninit.rs:22:48
--> $DIR/llvm-asm-out-read-uninit.rs:22:48
|
LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(x));
| ^ use of possibly-uninitialized `x`
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
error: macro requires a string literal as an argument
--> $DIR/asm-parse-errors.rs:4:5
--> $DIR/llvm-asm-parse-errors.rs:4:5
|
LL | llvm_asm!();
| ^^^^^^^^^^^^ string literal required

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

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

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

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

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

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

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

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

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

error: inline assembly must be a string literal
--> $DIR/asm-parse-errors.rs:14:15
--> $DIR/llvm-asm-parse-errors.rs:14:15
|
LL | llvm_asm!(123);
| ^^^
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Regression test for #69615.

#![feature(const_trait_impl, const_fn)]
#![allow(incomplete_features)]

pub trait MyTrait {
fn method(&self);
}

impl const MyTrait for () {
fn method(&self) {
match *self {} //~ ERROR `match` is not allowed in a `const fn`
}
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0658]: `match` is not allowed in a `const fn`
--> $DIR/hir-const-check.rs:12:9
|
LL | match *self {}
| ^^^^^^^^^^^^^^
|
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
= help: add `#![feature(const_if_match)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

0 comments on commit ce93331

Please sign in to comment.