Skip to content

Commit

Permalink
Auto merge of rust-lang#78212 - JohnTitor:rollup-j5r6xuy, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#77420 (Unify const-checking structured errors for `&mut` and `&raw mut`)
 - rust-lang#77554 (Support signed integers and `char` in v0 mangling)
 - rust-lang#77976 (Mark inout asm! operands as used in liveness pass)
 - rust-lang#78009 (Haiku: explicitly set CMAKE_SYSTEM_NAME when cross-compiling)
 - rust-lang#78084 (Greatly improve display for small mobile devices screens)
 - rust-lang#78155 (Fix two small issues in compiler/rustc_lint/src/types.rs)
 - rust-lang#78156 (Fixed build failure of `rustfmt`)
 - rust-lang#78172 (Add test case for rust-lang#77062)
 - rust-lang#78188 (Add tracking issue number for pin_static_ref)
 - rust-lang#78200 (Add `ControlFlow::is_{break,continue}` methods)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Oct 22, 2020
2 parents c4fe25d + 69e0658 commit ef3e386
Show file tree
Hide file tree
Showing 25 changed files with 411 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3276,9 +3276,9 @@ dependencies = [

[[package]]
name = "rustc-demangle"
version = "0.1.16"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ measureme = "0.7.1"
snap = "1"
tracing = "0.1"
rustc_middle = { path = "../rustc_middle" }
rustc-demangle = "0.1"
rustc-demangle = "0.1.18"
rustc_attr = { path = "../rustc_attr" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
35 changes: 18 additions & 17 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ fn lint_overflowing_range_endpoint<'tcx>(
// We need to preserve the literal's suffix,
// as it may determine typing information.
let suffix = match lit.node {
LitKind::Int(_, LitIntType::Signed(s)) => s.name_str().to_string(),
LitKind::Int(_, LitIntType::Unsigned(s)) => s.name_str().to_string(),
LitKind::Int(_, LitIntType::Unsuffixed) => "".to_string(),
LitKind::Int(_, LitIntType::Signed(s)) => s.name_str(),
LitKind::Int(_, LitIntType::Unsigned(s)) => s.name_str(),
LitKind::Int(_, LitIntType::Unsuffixed) => "",
_ => bug!(),
};
let suggestion = format!("{}..={}{}", start, lit_val - 1, suffix);
Expand All @@ -170,24 +170,25 @@ fn lint_overflowing_range_endpoint<'tcx>(
// warnings are consistent between 32- and 64-bit platforms.
fn int_ty_range(int_ty: ast::IntTy) -> (i128, i128) {
match int_ty {
ast::IntTy::Isize => (i64::MIN as i128, i64::MAX as i128),
ast::IntTy::I8 => (i8::MIN as i64 as i128, i8::MAX as i128),
ast::IntTy::I16 => (i16::MIN as i64 as i128, i16::MAX as i128),
ast::IntTy::I32 => (i32::MIN as i64 as i128, i32::MAX as i128),
ast::IntTy::I64 => (i64::MIN as i128, i64::MAX as i128),
ast::IntTy::I128 => (i128::MIN as i128, i128::MAX),
ast::IntTy::Isize => (i64::MIN.into(), i64::MAX.into()),
ast::IntTy::I8 => (i8::MIN.into(), i8::MAX.into()),
ast::IntTy::I16 => (i16::MIN.into(), i16::MAX.into()),
ast::IntTy::I32 => (i32::MIN.into(), i32::MAX.into()),
ast::IntTy::I64 => (i64::MIN.into(), i64::MAX.into()),
ast::IntTy::I128 => (i128::MIN, i128::MAX),
}
}

fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) {
match uint_ty {
ast::UintTy::Usize => (u64::MIN as u128, u64::MAX as u128),
ast::UintTy::U8 => (u8::MIN as u128, u8::MAX as u128),
ast::UintTy::U16 => (u16::MIN as u128, u16::MAX as u128),
ast::UintTy::U32 => (u32::MIN as u128, u32::MAX as u128),
ast::UintTy::U64 => (u64::MIN as u128, u64::MAX as u128),
ast::UintTy::U128 => (u128::MIN, u128::MAX),
}
let max = match uint_ty {
ast::UintTy::Usize => u64::MAX.into(),
ast::UintTy::U8 => u8::MAX.into(),
ast::UintTy::U16 => u16::MAX.into(),
ast::UintTy::U32 => u32::MAX.into(),
ast::UintTy::U64 => u64::MAX.into(),
ast::UintTy::U128 => u128::MAX,
};
(0, max)
}

fn get_bin_hex_repr(cx: &LateContext<'_>, lit: &hir::Lit) -> Option<String> {
Expand Down
38 changes: 11 additions & 27 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ impl NonConstOp for CellBorrow {
}

#[derive(Debug)]
pub struct MutBorrow;
pub struct MutBorrow(pub hir::BorrowKind);

impl NonConstOp for MutBorrow {
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
// Forbid everywhere except in const fn with a feature gate
Expand All @@ -236,22 +237,28 @@ impl NonConstOp for MutBorrow {
}

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
let raw = match self.0 {
hir::BorrowKind::Raw => "raw ",
hir::BorrowKind::Ref => "",
};

let mut err = if ccx.const_kind() == hir::ConstContext::ConstFn {
feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_mut_refs,
span,
&format!("mutable references are not allowed in {}s", ccx.const_kind()),
&format!("{}mutable references are not allowed in {}s", raw, ccx.const_kind()),
)
} else {
let mut err = struct_span_err!(
ccx.tcx.sess,
span,
E0764,
"mutable references are not allowed in {}s",
"{}mutable references are not allowed in {}s",
raw,
ccx.const_kind(),
);
err.span_label(span, format!("`&mut` is only allowed in `const fn`"));
err.span_label(span, format!("`&{}mut` is only allowed in `const fn`", raw));
err
};
if ccx.tcx.sess.teach(&err.get_code().unwrap()) {
Expand All @@ -270,29 +277,6 @@ impl NonConstOp for MutBorrow {
}
}

// FIXME(ecstaticmorse): Unify this with `MutBorrow`. It has basically the same issues.
#[derive(Debug)]
pub struct MutAddressOf;
impl NonConstOp for MutAddressOf {
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
// Forbid everywhere except in const fn with a feature gate
if ccx.const_kind() == hir::ConstContext::ConstFn {
Status::Unstable(sym::const_mut_refs)
} else {
Status::Forbidden
}
}

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_mut_refs,
span,
&format!("`&raw mut` is not allowed in {}s", ccx.const_kind()),
)
}
}

#[derive(Debug)]
pub struct MutDeref;
impl NonConstOp for MutDeref {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {

if !is_allowed {
if let BorrowKind::Mut { .. } = kind {
self.check_op(ops::MutBorrow);
self.check_op(ops::MutBorrow(hir::BorrowKind::Ref));
} else {
self.check_op(ops::CellBorrow);
}
}
}

Rvalue::AddressOf(Mutability::Mut, _) => self.check_op(ops::MutAddressOf),
Rvalue::AddressOf(Mutability::Mut, _) => {
self.check_op(ops::MutBorrow(hir::BorrowKind::Raw))
}

Rvalue::Ref(_, BorrowKind::Shared | BorrowKind::Shallow, ref place)
| Rvalue::AddressOf(Mutability::Not, ref place) => {
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {

let func_ty = func.ty(body, tcx);
if let ty::FnDef(callee, substs) = *func_ty.kind() {
let (callee, call_substs) =
if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, callee, substs) {
(instance.def_id(), instance.substs)
} else {
(callee, substs)
};
let normalized_substs = tcx.normalize_erasing_regions(param_env, substs);
let (callee, call_substs) = if let Ok(Some(instance)) =
Instance::resolve(tcx, param_env, callee, normalized_substs)
{
(instance.def_id(), instance.substs)
} else {
(callee, normalized_substs)
};

// FIXME(#57965): Make this work across function boundaries

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
hir::InlineAsmOperand::InOut { expr, .. } => {
succ = self.write_place(expr, succ, ACC_READ | ACC_WRITE);
succ = self.write_place(expr, succ, ACC_READ | ACC_WRITE | ACC_USE);
}
hir::InlineAsmOperand::SplitInOut { out_expr, .. } => {
if let Some(expr) = out_expr {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_symbol_mangling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doctest = false
[dependencies]
tracing = "0.1"
punycode = "0.4.0"
rustc-demangle = "0.1.16"
rustc-demangle = "0.1.18"

rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
Expand Down
29 changes: 22 additions & 7 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_middle::mir::interpret::sign_extend;
use rustc_middle::ty::print::{Print, Printer};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
Expand Down Expand Up @@ -527,17 +528,31 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
}
let start = self.out.len();

match ct.ty.kind() {
ty::Uint(_) => {}
ty::Bool => {}
let mut neg = false;
let val = match ct.ty.kind() {
ty::Uint(_) | ty::Bool | ty::Char => {
ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty)
}
ty::Int(_) => {
let param_env = ty::ParamEnv::reveal_all();
ct.try_eval_bits(self.tcx, param_env, ct.ty).and_then(|b| {
let sz = self.tcx.layout_of(param_env.and(ct.ty)).ok()?.size;
let val = sign_extend(b, sz) as i128;
if val < 0 {
neg = true;
}
Some(val.wrapping_abs() as u128)
})
}
_ => {
bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct);
}
}
self = ct.ty.print(self)?;
};

if let Some(bits) = ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) {
let _ = write!(self.out, "{:x}_", bits);
if let Some(bits) = val {
// We only print the type if the const can be evaluated.
self = ct.ty.print(self)?;
let _ = write!(self.out, "{}{:x}_", if neg { "n" } else { "" }, bits);
} else {
// NOTE(eddyb) despite having the path, we need to
// encode a placeholder, as the path could refer
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ impl<C, B> Try for ControlFlow<C, B> {
}

impl<C, B> ControlFlow<C, B> {
/// Returns `true` if this is a `Break` variant.
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn is_break(&self) -> bool {
matches!(*self, ControlFlow::Break(_))
}

/// Returns `true` if this is a `Continue` variant.
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn is_continue(&self) -> bool {
matches!(*self, ControlFlow::Continue(_))
}

/// Converts the `ControlFlow` into an `Option` which is `Some` if the
/// `ControlFlow` was `Break` and `None` otherwise.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl<T: ?Sized> Pin<&'static T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "none")]
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand All @@ -800,7 +800,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "none")]
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hashbrown = { version = "0.9.0", default-features = false, features = ['rustc-de

# Dependencies of the `backtrace` crate
addr2line = { version = "0.13.0", optional = true, default-features = false }
rustc-demangle = { version = "0.1.4", features = ['rustc-dep-of-std'] }
rustc-demangle = { version = "0.1.18", features = ['rustc-dep-of-std'] }
miniz_oxide = { version = "0.4.0", optional = true, default-features = false }
[dependencies.object]
version = "0.20"
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ fn configure_cmake(
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
} else if target.contains("windows") {
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
} else if target.contains("haiku") {
cfg.define("CMAKE_SYSTEM_NAME", "Haiku");
}
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
// that case like CMake we cannot easily determine system version either.
Expand Down
35 changes: 35 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,41 @@ h4 > .notable-traits {
#titles, #titles > div {
height: 73px;
}

#main > table:not(.table-display) td {
word-break: break-word;
min-width: 10%;
}

.search-container > div {
display: block;
width: calc(100% - 37px);
}

#crate-search {
width: 100%;
border-radius: 4px;
border: 0;
}

#crate-search + .search-input {
width: calc(100% + 71px);
margin-left: -36px;
}

#theme-picker, #settings-menu {
padding: 5px;
width: 31px;
height: 31px;
}

#theme-picker {
margin-top: -2px;
}

#settings-menu {
top: 7px;
}
}

h3.notable {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/consts/const-address-of-mut.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![feature(raw_ref_op)]

const A: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed
const A: () = { let mut x = 2; &raw mut x; }; //~ mutable reference

static B: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed
static B: () = { let mut x = 2; &raw mut x; }; //~ mutable reference

static mut C: () = { let mut x = 2; &raw mut x; }; //~ ERROR `&raw mut` is not allowed
static mut C: () = { let mut x = 2; &raw mut x; }; //~ mutable reference

const fn foo() {
let mut x = 0;
let y = &raw mut x; //~ ERROR `&raw mut` is not allowed
let y = &raw mut x; //~ mutable reference
}

fn main() {}
Loading

0 comments on commit ef3e386

Please sign in to comment.