Skip to content

Commit bd90c2a

Browse files
committed
Auto merge of #134666 - matthiaskrgr:rollup-whe0chp, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #130289 (docs: Permissions.readonly() also ignores root user special permissions) - #134583 (docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code) - #134611 (Align `{i686,x86_64}-win7-windows-msvc` to their parent targets) - #134629 (compiletest: Allow using a specific debugger when running debuginfo tests) - #134642 (Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`.) - #134660 (Fix spacing of markdown code block fences in compiler rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e108481 + d05edbe commit bd90c2a

File tree

13 files changed

+125
-28
lines changed

13 files changed

+125
-28
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2720,12 +2720,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27202720
/// Check field access expressions, this works for both structs and tuples.
27212721
/// Returns the Ty of the field.
27222722
///
2723-
/// ```not_rust
2724-
/// base.field
2725-
/// ^^^^^^^^^^ expr
2726-
/// ^^^^ base
2727-
/// ^^^^^ field
2728-
/// ```
2723+
/// ```ignore (illustrative)
2724+
/// base.field
2725+
/// ^^^^^^^^^^ expr
2726+
/// ^^^^ base
2727+
/// ^^^^^ field
2728+
/// ```
27292729
fn check_expr_field(
27302730
&self,
27312731
expr: &'tcx hir::Expr<'tcx>,

compiler/rustc_resolve/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,18 @@ enum ImplTraitContext {
193193
}
194194

195195
/// Used for tracking import use types which will be used for redundant import checking.
196+
///
196197
/// ### Used::Scope Example
197-
/// ```rust,compile_fail
198+
///
199+
/// ```rust,compile_fail
198200
/// #![deny(redundant_imports)]
199201
/// use std::mem::drop;
200202
/// fn main() {
201203
/// let s = Box::new(32);
202204
/// drop(s);
203205
/// }
204206
/// ```
207+
///
205208
/// Used::Other is for other situations like module-relative uses.
206209
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
207210
enum Used {

compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::spec::{LinkerFlavor, Lld, Target, base};
1+
use crate::spec::{LinkerFlavor, Lld, SanitizerSet, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
5+
base.vendor = "win7".into();
56
base.cpu = "pentium4".into();
67
base.max_atomic_width = Some(64);
7-
base.vendor = "win7".into();
8+
base.supported_sanitizers = SanitizerSet::ADDRESS;
89

910
base.add_pre_link_args(LinkerFlavor::Msvc(Lld::No), &[
1011
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
@@ -19,7 +20,7 @@ pub(crate) fn target() -> Target {
1920
Target {
2021
llvm_target: "i686-pc-windows-msvc".into(),
2122
metadata: crate::spec::TargetMetadata {
22-
description: Some("32-bit Windows 7 support".into()),
23+
description: Some("32-bit MSVC (Windows 7+)".into()),
2324
tier: Some(3),
2425
host_tools: Some(false),
2526
std: Some(true),

compiler/rustc_target/src/spec/targets/x86_64_win7_windows_msvc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
use crate::spec::{Target, base};
1+
use crate::spec::{SanitizerSet, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
5+
base.vendor = "win7".into();
56
base.cpu = "x86-64".into();
67
base.plt_by_default = false;
78
base.max_atomic_width = Some(64);
8-
base.vendor = "win7".into();
9+
base.supported_sanitizers = SanitizerSet::ADDRESS;
910

1011
Target {
1112
llvm_target: "x86_64-pc-windows-msvc".into(),
1213
metadata: crate::spec::TargetMetadata {
13-
description: Some("64-bit Windows 7 support".into()),
14+
description: Some("64-bit MSVC (Windows 7+)".into()),
1415
tier: Some(3),
1516
host_tools: Some(false),
1617
std: Some(true),

library/core/src/cell.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, Unsize};
255+
use crate::marker::{PhantomData, PointerLike, Unsize};
256256
use crate::mem;
257257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::pin::PinCoerceUnsized;
@@ -677,6 +677,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
677677
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
678678
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
679679

680+
#[unstable(feature = "pointer_like_trait", issue = "none")]
681+
impl<T: PointerLike> PointerLike for Cell<T> {}
682+
680683
impl<T> Cell<[T]> {
681684
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
682685
///
@@ -2258,6 +2261,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22582261
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
22592262
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
22602263

2264+
#[unstable(feature = "pointer_like_trait", issue = "none")]
2265+
impl<T: PointerLike> PointerLike for UnsafeCell<T> {}
2266+
22612267
/// [`UnsafeCell`], but [`Sync`].
22622268
///
22632269
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2364,6 +2370,9 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell
23642370
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
23652371
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
23662372

2373+
#[unstable(feature = "pointer_like_trait", issue = "none")]
2374+
impl<T: PointerLike> PointerLike for SyncUnsafeCell<T> {}
2375+
23672376
#[allow(unused)]
23682377
fn assert_coerce_unsized(
23692378
a: UnsafeCell<&i32>,

library/core/src/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ pub trait PointerLike {}
10031003
marker_impls! {
10041004
#[unstable(feature = "pointer_like_trait", issue = "none")]
10051005
PointerLike for
1006+
isize,
10061007
usize,
10071008
{T} &T,
10081009
{T} &mut T,

library/core/src/mem/maybe_uninit.rs

+20
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ use crate::{fmt, intrinsics, ptr, slice};
232232
/// remain `#[repr(transparent)]`. That said, `MaybeUninit<T>` will *always* guarantee that it has
233233
/// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that
234234
/// guarantee may evolve.
235+
///
236+
/// Note that even though `T` and `MaybeUninit<T>` are ABI compatible it is still unsound to
237+
/// transmute `&mut T` to `&mut MaybeUninit<T>` and expose that to safe code because it would allow
238+
/// safe code to access uninitialized memory:
239+
///
240+
/// ```rust,no_run
241+
/// use core::mem::MaybeUninit;
242+
///
243+
/// fn unsound_transmute<T>(val: &mut T) -> &mut MaybeUninit<T> {
244+
/// unsafe { core::mem::transmute(val) }
245+
/// }
246+
///
247+
/// fn main() {
248+
/// let mut code = 0;
249+
/// let code = &mut code;
250+
/// let code2 = unsound_transmute(code);
251+
/// *code2 = MaybeUninit::uninit();
252+
/// std::process::exit(*code); // UB! Accessing uninitialized memory.
253+
/// }
254+
/// ```
235255
#[stable(feature = "maybe_uninit", since = "1.36.0")]
236256
// Lang item so we can wrap other types in it. This is useful for coroutines.
237257
#[lang = "maybe_uninit"]

library/core/src/ptr/non_null.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,10 @@ impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: U
15551555
#[stable(feature = "pin", since = "1.33.0")]
15561556
unsafe impl<T: ?Sized> PinCoerceUnsized for NonNull<T> {}
15571557

1558+
#[unstable(feature = "pointer_like_trait", issue = "none")]
1559+
#[cfg(not(bootstrap))]
1560+
impl<T> core::marker::PointerLike for NonNull<T> {}
1561+
15581562
#[stable(feature = "nonnull", since = "1.25.0")]
15591563
impl<T: ?Sized> fmt::Debug for NonNull<T> {
15601564
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/std/src/fs.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1869,8 +1869,10 @@ impl Permissions {
18691869
///
18701870
/// # Note
18711871
///
1872-
/// This function does not take Access Control Lists (ACLs) or Unix group
1873-
/// membership into account.
1872+
/// This function does not take Access Control Lists (ACLs), Unix group
1873+
/// membership and other nuances into account.
1874+
/// Therefore the return value of this function cannot be relied upon
1875+
/// to predict whether attempts to read or write the file will actually succeed.
18741876
///
18751877
/// # Windows
18761878
///
@@ -1885,10 +1887,13 @@ impl Permissions {
18851887
/// # Unix (including macOS)
18861888
///
18871889
/// On Unix-based platforms this checks if *any* of the owner, group or others
1888-
/// write permission bits are set. It does not check if the current
1889-
/// user is in the file's assigned group. It also does not check ACLs.
1890-
/// Therefore the return value of this function cannot be relied upon
1891-
/// to predict whether attempts to read or write the file will actually succeed.
1890+
/// write permission bits are set. It does not consider anything else, including:
1891+
///
1892+
/// * Whether the current user is in the file's assigned group.
1893+
/// * Permissions granted by ACL.
1894+
/// * That `root` user can write to files that do not have any write bits set.
1895+
/// * Writable files on a filesystem that is mounted read-only.
1896+
///
18921897
/// The [`PermissionsExt`] trait gives direct access to the permission bits but
18931898
/// also does not read ACLs.
18941899
///

src/tools/compiletest/src/lib.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use walkdir::WalkDir;
3737

3838
use self::header::{EarlyProps, make_test_description};
3939
use crate::common::{
40-
CompareMode, Config, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path,
40+
CompareMode, Config, Debugger, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path,
4141
output_base_dir, output_relative_path,
4242
};
4343
use crate::header::HeadersCache;
@@ -183,7 +183,13 @@ pub fn parse_config(args: Vec<String>) -> Config {
183183
"What custom diff tool to use for displaying compiletest tests.",
184184
"COMMAND",
185185
)
186-
.reqopt("", "minicore-path", "path to minicore aux library", "PATH");
186+
.reqopt("", "minicore-path", "path to minicore aux library", "PATH")
187+
.optopt(
188+
"",
189+
"debugger",
190+
"only test a specific debugger in debuginfo tests",
191+
"gdb | lldb | cdb",
192+
);
187193

188194
let (argv0, args_) = args.split_first().unwrap();
189195
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
@@ -302,7 +308,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
302308
stage_id: matches.opt_str("stage-id").unwrap(),
303309
mode,
304310
suite: matches.opt_str("suite").unwrap(),
305-
debugger: None,
311+
debugger: matches.opt_str("debugger").map(|debugger| {
312+
debugger
313+
.parse::<Debugger>()
314+
.unwrap_or_else(|_| panic!("unknown `--debugger` option `{debugger}` given"))
315+
}),
306316
run_ignored,
307317
with_rustc_debug_assertions,
308318
with_std_debug_assertions,
@@ -475,9 +485,16 @@ pub fn run_tests(config: Arc<Config>) {
475485
if let Mode::DebugInfo = config.mode {
476486
// Debugging emscripten code doesn't make sense today
477487
if !config.target.contains("emscripten") {
478-
configs.extend(debuggers::configure_cdb(&config));
479-
configs.extend(debuggers::configure_gdb(&config));
480-
configs.extend(debuggers::configure_lldb(&config));
488+
match config.debugger {
489+
Some(Debugger::Cdb) => configs.extend(debuggers::configure_cdb(&config)),
490+
Some(Debugger::Gdb) => configs.extend(debuggers::configure_gdb(&config)),
491+
Some(Debugger::Lldb) => configs.extend(debuggers::configure_lldb(&config)),
492+
None => {
493+
configs.extend(debuggers::configure_cdb(&config));
494+
configs.extend(debuggers::configure_gdb(&config));
495+
configs.extend(debuggers::configure_lldb(&config));
496+
}
497+
}
481498
}
482499
} else {
483500
configs.push(config.clone());

tests/ui/dyn-star/cell.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test with Cell also indirectly exercises UnsafeCell in dyn*.
2+
//
3+
//@ run-pass
4+
5+
#![feature(dyn_star)]
6+
#![allow(incomplete_features)]
7+
8+
use std::cell::Cell;
9+
10+
trait Rw<T> {
11+
fn read(&self) -> T;
12+
fn write(&self, v: T);
13+
}
14+
15+
impl<T: Copy> Rw<T> for Cell<T> {
16+
fn read(&self) -> T {
17+
self.get()
18+
}
19+
fn write(&self, v: T) {
20+
self.set(v)
21+
}
22+
}
23+
24+
fn make_dyn_star() -> dyn* Rw<usize> {
25+
Cell::new(42usize) as dyn* Rw<usize>
26+
}
27+
28+
fn main() {
29+
let x = make_dyn_star();
30+
31+
assert_eq!(x.read(), 42);
32+
x.write(24);
33+
assert_eq!(x.read(), 24);
34+
}

tests/ui/dyn-star/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::Debug;
66
trait Foo {}
77

88
fn make_dyn_star() {
9-
let i = 42;
9+
let i = 42usize;
1010
let dyn_i: dyn* Foo = i; //~ ERROR trait bound `usize: Foo` is not satisfied
1111
}
1212

tests/ui/dyn-star/float-as-dyn-star.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ LL | f32::from_bits(0x1) as f64
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `f64` needs to be a pointer-like type
1515
|
1616
= help: the trait `PointerLike` is not implemented for `f64`
17-
= help: the trait `PointerLike` is implemented for `usize`
17+
= help: the following other types implement trait `PointerLike`:
18+
isize
19+
usize
1820

1921
error: aborting due to 1 previous error; 1 warning emitted
2022

0 commit comments

Comments
 (0)