Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #133359

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cbe428d
use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback o…
thomcc Aug 19, 2022
6d075dc
Prefer `target_vendor = "apple"` on confstr
madsmtm Oct 10, 2024
b62ee10
Use with_capacity(0) because we're reading the capacity later on
madsmtm Oct 10, 2024
204b228
Allow disabling ASan instrumentation for globals
BertalanD Jul 8, 2024
d318878
Reduce integer `Display` implementation size
GuillaumeGomez Nov 20, 2024
5d30436
Re-delay a resolve `bug`
jieyouxu Nov 21, 2024
9a30362
Update TRPL to latest, including new Chapter 17: Async and Await
chriskrycho Oct 17, 2024
34b4518
Update messages which reference book chs. 17-20
chriskrycho Oct 17, 2024
85c582c
Add support for `--library-path` to `rustbook test`
chriskrycho Oct 18, 2024
e0d7cf0
Update bootstrap tests to support book dependencies
chriskrycho Oct 18, 2024
99832cb
rustbook: fix two small typos
chriskrycho Oct 18, 2024
21dd59f
Update tests for new TRPL chapter order
chriskrycho Oct 30, 2024
30f9f60
Vendor `trpl` crate so The Book tests work offline
chriskrycho Nov 20, 2024
f98d9dd
Don't try to use confstr in Miri
madsmtm Oct 10, 2024
c85a742
Mark '<[T; N]>::as_mut_slice' as 'const';
bjoernager Nov 22, 2024
30c7df6
Improve code by using `unsigned_abs`
GuillaumeGomez Nov 20, 2024
38bf073
Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle
compiler-errors Nov 23, 2024
d9d0d29
Rollup merge of #131505 - madsmtm:darwin_user_temp_dir, r=dtolnay
compiler-errors Nov 23, 2024
ed6e729
Rollup merge of #131859 - chriskrycho:update-trpl, r=onur-ozkan
compiler-errors Nov 23, 2024
1f950f6
Rollup merge of #133247 - GuillaumeGomez:reduce-integer-display-impl,…
compiler-errors Nov 23, 2024
be5815d
Rollup merge of #133286 - jieyouxu:bug-ourselves, r=compiler-errors
compiler-errors Nov 23, 2024
e8bafa3
Rollup merge of #133332 - bjoernager:const-array-as-mut-slice, r=jhpratt
compiler-errors Nov 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,12 @@ pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
Visibility::Protected => llvm::Visibility::Protected,
}
}

pub(crate) fn set_variable_sanitizer_attrs(llval: &Value, attrs: &CodegenFnAttrs) {
if attrs.no_sanitize.contains(SanitizerSet::ADDRESS) {
unsafe { llvm::LLVMRustSetNoSanitizeAddress(llval) };
}
if attrs.no_sanitize.contains(SanitizerSet::HWADDRESS) {
unsafe { llvm::LLVMRustSetNoSanitizeHWAddress(llval) };
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ impl<'ll> CodegenCx<'ll, '_> {
base::set_link_section(g, attrs);
}

base::set_variable_sanitizer_attrs(g, attrs);

if attrs.flags.contains(CodegenFnAttrFlags::USED) {
// `USED` and `USED_LINKER` can't be used together.
assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER));
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,4 +2460,7 @@ unsafe extern "C" {
pub fn LLVMRustIs64BitSymbolicFile(buf_ptr: *const u8, buf_len: usize) -> bool;

pub fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool;

pub fn LLVMRustSetNoSanitizeAddress(Global: &Value);
pub fn LLVMRustSetNoSanitizeHWAddress(Global: &Value);
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn report_unexpected_variant_res(
.with_code(err_code);
match res {
Res::Def(DefKind::Fn | DefKind::AssocFn, _) if err_code == E0164 => {
let patterns_url = "https://doc.rust-lang.org/book/ch18-00-patterns.html";
let patterns_url = "https://doc.rust-lang.org/book/ch19-00-patterns.html";
err.with_span_label(span, "`fn` calls are not allowed in patterns")
.with_help(format!("for more information, visit {patterns_url}"))
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,25 @@ extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
return llvm::compression::zstd::isAvailable();
}

extern "C" void LLVMRustSetNoSanitizeAddress(LLVMValueRef Global) {
GlobalValue &GV = *unwrap<GlobalValue>(Global);
GlobalValue::SanitizerMetadata MD;
if (GV.hasSanitizerMetadata())
MD = GV.getSanitizerMetadata();
MD.NoAddress = true;
MD.IsDynInit = false;
GV.setSanitizerMetadata(MD);
}

extern "C" void LLVMRustSetNoSanitizeHWAddress(LLVMValueRef Global) {
GlobalValue &GV = *unwrap<GlobalValue>(Global);
GlobalValue::SanitizerMetadata MD;
if (GV.hasSanitizerMetadata())
MD = GV.getSanitizerMetadata();
MD.NoHWAddress = true;
GV.setSanitizerMetadata(MD);
}

// Operations on composite constants.
// These are clones of LLVM api functions that will become available in future
// releases. They can be removed once Rust's minimum supported LLVM version
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper =

mir_build_lower_range_bound_must_be_less_than_upper = lower range bound must be less than upper

mir_build_more_information = for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
mir_build_more_information = for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html

mir_build_moved = value is moved into `{$name}` here

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ parse_unexpected_expr_in_pat =
}, found an expression

.label = not a pattern
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>

parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const`

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ passes_no_mangle_foreign =
passes_no_patterns =
patterns not allowed in naked function parameters

passes_no_sanitize =
`#[no_sanitize({$attr_str})]` should be applied to {$accepted_kind}
.label = not {$accepted_kind}

passes_non_exported_macro_invalid_attrs =
attribute should be applied to function or closure
.label = not a function or closure
Expand Down
37 changes: 34 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
[sym::coverage, ..] => self.check_coverage(attr, span, target),
[sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target),
[sym::no_sanitize, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::no_sanitize, ..] => self.check_no_sanitize(attr, span, target),
[sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target),
[sym::marker, ..] => self.check_marker(hir_id, attr, span, target),
[sym::target_feature, ..] => {
Expand Down Expand Up @@ -450,6 +448,39 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
let sym = item.name_or_empty();
match sym {
sym::address | sym::hwaddress => {
let is_valid =
matches!(target, Target::Fn | Target::Method(..) | Target::Static);
if !is_valid {
self.dcx().emit_err(errors::NoSanitize {
attr_span: item.span(),
defn_span: span,
accepted_kind: "a function or static",
attr_str: sym.as_str(),
});
}
}
_ => {
let is_valid = matches!(target, Target::Fn | Target::Method(..));
if !is_valid {
self.dcx().emit_err(errors::NoSanitize {
attr_span: item.span(),
defn_span: span,
accepted_kind: "a function",
attr_str: sym.as_str(),
});
}
}
}
}
}
}

fn check_generic_attr(
&self,
hir_id: HirId,
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,3 +1846,14 @@ pub(crate) struct AttrCrateLevelOnlySugg {
#[primary_span]
pub attr: Span,
}

#[derive(Diagnostic)]
#[diag(passes_no_sanitize)]
pub(crate) struct NoSanitize<'a> {
#[primary_span]
pub attr_span: Span,
#[label]
pub defn_span: Span,
pub accepted_kind: &'a str,
pub attr_str: &'a str,
}
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3940,12 +3940,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
Res::SelfCtor(_) => {
// We resolve `Self` in pattern position as an ident sometimes during recovery,
// so delay a bug instead of ICEing. (Note: is this no longer true? We now ICE. If
// this triggers, please convert to a delayed bug and add a test.)
self.r.dcx().span_bug(
// so delay a bug instead of ICEing.
self.r.dcx().span_delayed_bug(
ident.span,
"unexpected `SelfCtor` in pattern, expected identifier"
);
None
}
_ => span_bug!(
ident.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
let PathSource::TupleStruct(_, _) = source else { return };
let Some(Res::Def(DefKind::Fn, _)) = res else { return };
err.primary_message("expected a pattern, found a function call");
err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>");
err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>");
}

fn suggest_changing_type_to_const_param(
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ impl<T, const N: usize> [T; N] {
/// Returns a mutable slice containing the entire array. Equivalent to
/// `&mut s[..]`.
#[stable(feature = "array_as_slice", since = "1.57.0")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
#[rustc_const_unstable(feature = "const_array_as_mut_slice", issue = "133333")]
pub const fn as_mut_slice(&mut self) -> &mut [T] {
self
}

Expand Down
80 changes: 32 additions & 48 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,12 @@ static DEC_DIGITS_LUT: &[u8; 200] = b"0001020304050607080910111213141516171819\
8081828384858687888990919293949596979899";

macro_rules! impl_Display {
($($t:ident $(as $positive:ident)? named $name:ident,)* ; as $u:ident via $conv_fn:ident named $gen_name:ident) => {
($($signed:ident, $unsigned:ident,)* ; as $u:ident via $conv_fn:ident named $gen_name:ident) => {

$(
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for $t {
impl fmt::Display for $unsigned {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// If it's a signed integer.
$(
let is_nonnegative = *self >= 0;

#[cfg(not(feature = "optimize_for_size"))]
{
if !is_nonnegative {
// convert the negative num to positive by summing 1 to its 2s complement
return (!self as $positive).wrapping_add(1)._fmt(false, f);
}
}
#[cfg(feature = "optimize_for_size")]
{
if !is_nonnegative {
// convert the negative num to positive by summing 1 to its 2s complement
return $gen_name((!self.$conv_fn()).wrapping_add(1), false, f);
}
}
)?
// If it's a positive integer.
#[cfg(not(feature = "optimize_for_size"))]
{
self._fmt(true, f)
Expand All @@ -236,10 +216,24 @@ macro_rules! impl_Display {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for $signed {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(not(feature = "optimize_for_size"))]
{
return self.unsigned_abs()._fmt(*self >= 0, f);
}
#[cfg(feature = "optimize_for_size")]
{
return $gen_name((!self.unsigned_abs().$conv_fn()), *self >= 0, f);
}
}
}

#[cfg(not(feature = "optimize_for_size"))]
impl $t {
fn _fmt(mut self: $t, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
const SIZE: usize = $t::MAX.ilog(10) as usize + 1;
impl $unsigned {
fn _fmt(mut self, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
const SIZE: usize = $unsigned::MAX.ilog(10) as usize + 1;
let mut buf = [MaybeUninit::<u8>::uninit(); SIZE];
let mut curr = SIZE;
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
Expand All @@ -258,7 +252,7 @@ macro_rules! impl_Display {
#[allow(unused_comparisons)]
// This block will be removed for smaller types at compile time and in the worst
// case, it will prevent to have the `10000` literal to overflow for `i8` and `u8`.
if core::mem::size_of::<$t>() >= 2 {
if core::mem::size_of::<$unsigned>() >= 2 {
// eagerly decode 4 characters at a time
while self >= 10000 {
let rem = (self % 10000) as usize;
Expand Down Expand Up @@ -312,8 +306,8 @@ macro_rules! impl_Display {

#[cfg(feature = "optimize_for_size")]
fn $gen_name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
const SIZE: usize = $u::MAX.ilog(10) as usize + 1;
let mut buf = [MaybeUninit::<u8>::uninit(); SIZE];
let mut curr = buf.len();
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);

Expand Down Expand Up @@ -523,16 +517,11 @@ impl_Debug! {
mod imp {
use super::*;
impl_Display!(
i8 as u8 named fmt_i8,
u8 named fmt_u8,
i16 as u16 named fmt_i16,
u16 named fmt_u16,
i32 as u32 named fmt_i32,
u32 named fmt_u32,
i64 as u64 named fmt_i64,
u64 named fmt_u64,
isize as usize named fmt_isize,
usize named fmt_usize,
i8, u8,
i16, u16,
i32, u32,
i64, u64,
isize, usize,
; as u64 via to_u64 named fmt_u64
);
impl_Exp!(
Expand All @@ -545,18 +534,13 @@ mod imp {
mod imp {
use super::*;
impl_Display!(
i8 as u8 named fmt_i8,
u8 named fmt_u8,
i16 as u16 named fmt_i16,
u16 named fmt_u16,
i32 as u32 named fmt_i32,
u32 named fmt_u32,
isize as usize named fmt_isize,
usize named fmt_usize,
i8, u8,
i16, u16,
i32, u32,
isize, usize,
; as u32 via to_u32 named fmt_u32);
impl_Display!(
i64 as u64 named fmt_i64,
u64 named fmt_u64,
i64, u64,
; as u64 via to_u64 named fmt_u64);

impl_Exp!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named exp_u32);
Expand Down
15 changes: 12 additions & 3 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,19 +653,28 @@ pub fn home_dir() -> Option<PathBuf> {
/// may result in "insecure temporary file" security vulnerabilities. Consider
/// using a crate that securely creates temporary files or directories.
///
/// Note that the returned value may be a symbolic link, not a directory.
///
/// # Platform-specific behavior
///
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
/// set, otherwise for non-Android it returns `/tmp`. On Android, since there
/// is no global temporary folder (it is usually allocated per-app), it returns
/// `/data/local/tmp`.
/// set, otherwise the value is OS-specific:
/// - On Android, there is no global temporary folder (it is usually allocated
/// per-app), it returns `/data/local/tmp`.
/// - On Darwin-based OSes (macOS, iOS, etc) it returns the directory provided
/// by `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)`, as recommended by [Apple's
/// security guidelines][appledoc].
/// - On all other unix-based OSes, it returns `/tmp`.
///
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
/// [`GetTempPath`][GetTempPath], which this function uses internally.
///
/// Note that, this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
/// [GetTempPath2]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
/// [GetTempPath]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
/// [appledoc]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585-SW10
///
/// ```no_run
/// use std::env;
Expand Down
Loading
Loading