Skip to content

Commit c20d7ee

Browse files
committed
Auto merge of rust-lang#69919 - Centril:rollup-fxo33zs, r=Centril
Rollup of 8 pull requests Successful merges: - rust-lang#66472 (--show-coverage json) - rust-lang#69603 (tidy: replace `make check` with `./x.py test` in documentation) - rust-lang#69760 (Improve expression & attribute parsing) - rust-lang#69828 (fix memory leak when vec::IntoIter panics during drop) - rust-lang#69850 (panic_bounds_check: use caller_location, like PanicFnLangItem) - rust-lang#69876 (Add long error explanation for E0739) - rust-lang#69888 ([Miri] Use a session variable instead of checking for an env var always) - rust-lang#69893 (librustc_codegen_llvm: Use slices instead of 0-terminated strings) Failed merges: r? @ghost
2 parents 303d8af + a77206f commit c20d7ee

File tree

92 files changed

+1262
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1262
-511
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ the issue in question.
142142
Please make sure your pull request is in compliance with Rust's style
143143
guidelines by running
144144

145-
$ python x.py test src/tools/tidy
145+
$ python x.py test tidy
146146

147147
Make this check before every pull request (and every new commit in a pull
148148
request); you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)

src/bootstrap/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ The script accepts commands, flags, and arguments to determine what to do:
5555
# run all unit tests
5656
./x.py test
5757
58+
# execute tool tests
59+
./x.py test tidy
60+
5861
# execute the UI test suite
5962
./x.py test src/test/ui
6063

src/bootstrap/flags.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Arguments:
359359
subcommand_help.push_str(
360360
"\n
361361
Arguments:
362-
This subcommand accepts a number of paths to directories to tests that
362+
This subcommand accepts a number of paths to test directories that
363363
should be compiled and run. For example:
364364
365365
./x.py test src/test/ui
@@ -372,6 +372,10 @@ Arguments:
372372
just like `build src/libstd --stage N` it tests the compiler produced by the previous
373373
stage.
374374
375+
Execute tool tests with a tool name argument:
376+
377+
./x.py test tidy
378+
375379
If no arguments are passed then the complete artifacts for that stage are
376380
compiled and tested.
377381

src/liballoc/vec.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -2626,13 +2626,21 @@ impl<T: Clone> Clone for IntoIter<T> {
26262626
#[stable(feature = "rust1", since = "1.0.0")]
26272627
unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
26282628
fn drop(&mut self) {
2629+
struct DropGuard<'a, T>(&'a mut IntoIter<T>);
2630+
2631+
impl<T> Drop for DropGuard<'_, T> {
2632+
fn drop(&mut self) {
2633+
// RawVec handles deallocation
2634+
let _ = unsafe { RawVec::from_raw_parts(self.0.buf.as_ptr(), self.0.cap) };
2635+
}
2636+
}
2637+
2638+
let guard = DropGuard(self);
26292639
// destroy the remaining elements
26302640
unsafe {
2631-
ptr::drop_in_place(self.as_mut_slice());
2641+
ptr::drop_in_place(guard.0.as_mut_slice());
26322642
}
2633-
2634-
// RawVec handles deallocation
2635-
let _ = unsafe { RawVec::from_raw_parts(self.buf.as_ptr(), self.cap) };
2643+
// now `guard` will be dropped and do the rest
26362644
}
26372645
}
26382646

src/libcore/macros/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(bootstrap)]
12
#[doc(include = "panic.md")]
23
#[macro_export]
34
#[allow_internal_unstable(core_panic, track_caller)]
@@ -20,6 +21,26 @@ macro_rules! panic {
2021
);
2122
}
2223

24+
#[cfg(not(bootstrap))]
25+
#[doc(include = "panic.md")]
26+
#[macro_export]
27+
#[allow_internal_unstable(core_panic, track_caller)]
28+
#[stable(feature = "core", since = "1.6.0")]
29+
macro_rules! panic {
30+
() => (
31+
$crate::panic!("explicit panic")
32+
);
33+
($msg:expr) => (
34+
$crate::panicking::panic($msg)
35+
);
36+
($msg:expr,) => (
37+
$crate::panic!($msg)
38+
);
39+
($fmt:expr, $($arg:tt)+) => (
40+
$crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+))
41+
);
42+
}
43+
2344
/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
2445
///
2546
/// On panic, this macro will print the values of the expressions with their

src/libcore/panicking.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use crate::fmt;
3333
use crate::panic::{Location, PanicInfo};
3434

35+
/// The underlying implementation of libcore's `panic!` macro when no formatting is used.
3536
#[cold]
3637
// never inline unless panic_immediate_abort to avoid code
3738
// bloat at the call sites as much as possible
@@ -49,9 +50,28 @@ pub fn panic(expr: &str) -> ! {
4950
// truncation and padding (even though none is used here). Using
5051
// Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
5152
// output binary, saving up to a few kilobytes.
52-
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller())
53+
#[cfg(not(bootstrap))]
54+
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]));
55+
#[cfg(bootstrap)]
56+
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller());
5357
}
5458

59+
#[cfg(not(bootstrap))]
60+
#[cold]
61+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
62+
#[track_caller]
63+
#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access
64+
fn panic_bounds_check(index: usize, len: usize) -> ! {
65+
if cfg!(feature = "panic_immediate_abort") {
66+
unsafe { super::intrinsics::abort() }
67+
}
68+
69+
panic!("index out of bounds: the len is {} but the index is {}", len, index)
70+
}
71+
72+
// For bootstrap, we need a variant with the old argument order, and a corresponding
73+
// `panic_fmt`.
74+
#[cfg(bootstrap)]
5575
#[cold]
5676
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
5777
#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access
@@ -66,10 +86,12 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
6686
)
6787
}
6888

89+
/// The underlying implementation of libcore's `panic!` macro when formatting is used.
6990
#[cold]
7091
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
7192
#[cfg_attr(feature = "panic_immediate_abort", inline)]
72-
pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
93+
#[cfg_attr(not(bootstrap), track_caller)]
94+
pub fn panic_fmt(fmt: fmt::Arguments<'_>, #[cfg(bootstrap)] location: &Location<'_>) -> ! {
7395
if cfg!(feature = "panic_immediate_abort") {
7496
unsafe { super::intrinsics::abort() }
7597
}
@@ -81,6 +103,10 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
81103
fn panic_impl(pi: &PanicInfo<'_>) -> !;
82104
}
83105

106+
#[cfg(bootstrap)]
84107
let pi = PanicInfo::internal_constructor(Some(&fmt), location);
108+
#[cfg(not(bootstrap))]
109+
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller());
110+
85111
unsafe { panic_impl(&pi) }
86112
}

src/librustc/mir/interpret/error.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ use crate::mir;
55
use crate::mir::interpret::ConstValue;
66
use crate::ty::layout::{Align, LayoutError, Size};
77
use crate::ty::query::TyCtxtAt;
8+
use crate::ty::tls;
89
use crate::ty::{self, layout, Ty};
910

1011
use backtrace::Backtrace;
12+
use rustc_data_structures::sync::Lock;
1113
use rustc_errors::{struct_span_err, DiagnosticBuilder};
1214
use rustc_hir as hir;
1315
use rustc_macros::HashStable;
16+
use rustc_session::CtfeBacktrace;
1417
use rustc_span::{Pos, Span};
1518
use rustc_target::spec::abi::Abi;
16-
use std::{any::Any, env, fmt};
19+
use std::{any::Any, fmt};
1720

1821
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
1922
pub enum ErrorHandled {
@@ -257,21 +260,25 @@ impl From<ErrorHandled> for InterpErrorInfo<'_> {
257260

258261
impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
259262
fn from(kind: InterpError<'tcx>) -> Self {
260-
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {
261-
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
262-
Ok(ref val) if val != "0" => {
263-
let mut backtrace = Backtrace::new_unresolved();
263+
let capture_backtrace = tls::with_context_opt(|ctxt| {
264+
if let Some(ctxt) = ctxt {
265+
*Lock::borrow(&ctxt.tcx.sess.ctfe_backtrace)
266+
} else {
267+
CtfeBacktrace::Disabled
268+
}
269+
});
264270

265-
if val == "immediate" {
266-
// Print it now.
267-
print_backtrace(&mut backtrace);
268-
None
269-
} else {
270-
Some(Box::new(backtrace))
271-
}
271+
let backtrace = match capture_backtrace {
272+
CtfeBacktrace::Disabled => None,
273+
CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),
274+
CtfeBacktrace::Immediate => {
275+
// Print it now.
276+
let mut backtrace = Backtrace::new_unresolved();
277+
print_backtrace(&mut backtrace);
278+
None
272279
}
273-
_ => None,
274280
};
281+
275282
InterpErrorInfo { kind, backtrace }
276283
}
277284
}

src/librustc_ast/token.rs

+10
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,16 @@ impl Token {
535535
false
536536
}
537537

538+
// Is the token an interpolated block (`$b:block`)?
539+
pub fn is_whole_block(&self) -> bool {
540+
if let Interpolated(ref nt) = self.kind {
541+
if let NtBlock(..) = **nt {
542+
return true;
543+
}
544+
}
545+
false
546+
}
547+
538548
/// Returns `true` if the token is either the `mut` or `const` keyword.
539549
pub fn is_mutability(&self) -> bool {
540550
self.is_keyword(kw::Mut) || self.is_keyword(kw::Const)

src/librustc_codegen_llvm/allocator.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ffi::CString;
2-
31
use crate::attributes;
42
use libc::c_uint;
53
use rustc::bug;
@@ -50,8 +48,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
5048
args.len() as c_uint,
5149
False,
5250
);
53-
let name = CString::new(format!("__rust_{}", method.name)).unwrap();
54-
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr(), ty);
51+
let name = format!("__rust_{}", method.name);
52+
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);
5553

5654
if tcx.sess.target.target.options.default_hidden_visibility {
5755
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
@@ -60,8 +58,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
6058
attributes::emit_uwtable(llfn, true);
6159
}
6260

63-
let callee = CString::new(kind.fn_name(method.name)).unwrap();
64-
let callee = llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr(), ty);
61+
let callee = kind.fn_name(method.name);
62+
let callee =
63+
llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty);
6564
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);
6665

6766
let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, "entry\0".as_ptr().cast());
@@ -73,14 +72,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
7372
.enumerate()
7473
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
7574
.collect::<Vec<_>>();
76-
let ret = llvm::LLVMRustBuildCall(
77-
llbuilder,
78-
callee,
79-
args.as_ptr(),
80-
args.len() as c_uint,
81-
None,
82-
"\0".as_ptr().cast(),
83-
);
75+
let ret =
76+
llvm::LLVMRustBuildCall(llbuilder, callee, args.as_ptr(), args.len() as c_uint, None);
8477
llvm::LLVMSetTailCall(ret, True);
8578
if output.is_some() {
8679
llvm::LLVMBuildRet(llbuilder, ret);

src/librustc_codegen_llvm/asm.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_span::Span;
1212

1313
use libc::{c_char, c_uint};
1414
use log::debug;
15-
use std::ffi::{CStr, CString};
1615

1716
impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
1817
fn codegen_inline_asm(
@@ -80,12 +79,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
8079
_ => self.type_struct(&output_types, false),
8180
};
8281

83-
let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
84-
let constraint_cstr = CString::new(all_constraints).unwrap();
82+
let asm = ia.asm.as_str();
8583
let r = inline_asm_call(
8684
self,
8785
&asm,
88-
&constraint_cstr,
86+
&all_constraints,
8987
&inputs,
9088
output_type,
9189
ia.volatile,
@@ -125,17 +123,17 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
125123

126124
impl AsmMethods for CodegenCx<'ll, 'tcx> {
127125
fn codegen_global_asm(&self, ga: &hir::GlobalAsm) {
128-
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
126+
let asm = ga.asm.as_str();
129127
unsafe {
130-
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr());
128+
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr().cast(), asm.len());
131129
}
132130
}
133131
}
134132

135133
fn inline_asm_call(
136134
bx: &mut Builder<'a, 'll, 'tcx>,
137-
asm: &CStr,
138-
cons: &CStr,
135+
asm: &str,
136+
cons: &str,
139137
inputs: &[&'ll Value],
140138
output: &'ll llvm::Type,
141139
volatile: bool,
@@ -157,13 +155,15 @@ fn inline_asm_call(
157155
let fty = bx.cx.type_func(&argtys[..], output);
158156
unsafe {
159157
// Ask LLVM to verify that the constraints are well-formed.
160-
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
158+
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr().cast(), cons.len());
161159
debug!("constraint verification result: {:?}", constraints_ok);
162160
if constraints_ok {
163161
let v = llvm::LLVMRustInlineAsm(
164162
fty,
165-
asm.as_ptr(),
166-
cons.as_ptr(),
163+
asm.as_ptr().cast(),
164+
asm.len(),
165+
cons.as_ptr().cast(),
166+
cons.len(),
167167
volatile,
168168
alignstack,
169169
llvm::AsmDialect::from_generic(dia),

src/librustc_codegen_llvm/builder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10161016
args.as_ptr() as *const &llvm::Value,
10171017
args.len() as c_uint,
10181018
bundle,
1019-
UNNAMED,
10201019
)
10211020
}
10221021
}

src/librustc_codegen_llvm/declare.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::value::Value;
2121
use log::debug;
2222
use rustc::ty::Ty;
2323
use rustc_codegen_ssa::traits::*;
24-
use rustc_data_structures::small_c_str::SmallCStr;
2524

2625
/// Declare a function.
2726
///
@@ -34,8 +33,9 @@ fn declare_raw_fn(
3433
ty: &'ll Type,
3534
) -> &'ll Value {
3635
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
37-
let namebuf = SmallCStr::new(name);
38-
let llfn = unsafe { llvm::LLVMRustGetOrInsertFunction(cx.llmod, namebuf.as_ptr(), ty) };
36+
let llfn = unsafe {
37+
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_ptr().cast(), name.len(), ty)
38+
};
3939

4040
llvm::SetFunctionCallConv(llfn, callconv);
4141
// Function addresses in Rust are never significant, allowing functions to
@@ -83,8 +83,7 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
8383

8484
fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
8585
debug!("get_declared_value(name={:?})", name);
86-
let namebuf = SmallCStr::new(name);
87-
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, namebuf.as_ptr()) }
86+
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, name.as_ptr().cast(), name.len()) }
8887
}
8988

9089
fn get_defined_value(&self, name: &str) -> Option<&'ll Value> {

0 commit comments

Comments
 (0)