Skip to content

Rollup of 5 pull requests #97537

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

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
66ffdde
Make `from{,_mut}_ptr_range` const
WaffleLapkin May 26, 2022
80cbeb0
Add reexport of slice::from{,_mut}_ptr_range to alloc & std
WaffleLapkin May 27, 2022
8024fd6
Add ui tests for `slice::from_{ptr_range,raw_parts}`
WaffleLapkin May 27, 2022
e1efb5e
Rename slice_from_ptr_range_const -> const_slice_from_ptr_range
WaffleLapkin May 27, 2022
5a6fd10
Use `// error-pattern:` header in `forbidden_slices.rs` test
WaffleLapkin May 29, 2022
f4fff04
--bless
WaffleLapkin May 29, 2022
9f68b99
Fix order of closing HTML elements in rustdoc output
badboy May 29, 2022
3414c03
test forbidden slices on all two usizesizes
WaffleLapkin May 29, 2022
6b4191f
Add "no-const-assign" eslint rule
GuillaumeGomez May 29, 2022
4bb728d
Add "no-debugger" eslint rule
GuillaumeGomez May 29, 2022
9f79a03
Add "no-dup-args" eslint rule
GuillaumeGomez May 29, 2022
397ad82
Add "no-dupe-else-if" eslint rule
GuillaumeGomez May 29, 2022
88c3d70
Add "no-dupe-keys" eslint rule
GuillaumeGomez May 29, 2022
d39703a
Add "no-duplicate-case" eslint rule
GuillaumeGomez May 29, 2022
f1a95b8
Add "no-ex-assign" eslint rule
GuillaumeGomez May 29, 2022
46d34cc
Use type_is_copy_modulo_regions check in intrisicck
compiler-errors May 28, 2022
311aacf
Remove unused lifetimes from expand_macro
est31 May 29, 2022
98b134b
Rollup merge of #97419 - WaffleLapkin:const_from_ptr_range, r=oli-obk
compiler-errors May 29, 2022
86523e9
Rollup merge of #97493 - compiler-errors:issue-97490, r=oli-obk
compiler-errors May 29, 2022
bc1c83f
Rollup merge of #97518 - badboy:rustdoc-ul-div-fix, r=notriddle
compiler-errors May 29, 2022
9d584c7
Rollup merge of #97530 - GuillaumeGomez:more-eslint-checks, r=jsha
compiler-errors May 29, 2022
6dfa8be
Rollup merge of #97536 - est31:remove_unused_lifetimes, r=compiler-er…
compiler-errors May 29, 2022
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
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span,

/// Expands the rules based macro defined by `lhses` and `rhses` for a given
/// input `arg`.
fn expand_macro<'cx, 'tt>(
fn expand_macro<'cx>(
cx: &'cx mut ExtCtxt<'_>,
sp: Span,
def_span: Span,
node_id: NodeId,
name: Ident,
transparency: Transparency,
arg: TokenStream,
lhses: &'tt [Vec<MatcherLoc>],
rhses: &'tt [mbe::TokenTree],
lhses: &[Vec<MatcherLoc>],
rhses: &[mbe::TokenTree],
) -> Box<dyn MacResult + 'cx> {
let sess = &cx.sess.parse_sess;
// Macros defined in the current crate have a real node id,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_session::lint;
use rustc_span::{Span, Symbol, DUMMY_SP};
use rustc_target::abi::{Pointer, VariantIdx};
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
use rustc_trait_selection::infer::InferCtxtExt;

use super::FnCtxt;

Expand Down Expand Up @@ -210,7 +211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Check that the type implements Copy. The only case where this can
// possibly fail is for SIMD types which don't #[derive(Copy)].
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, DUMMY_SP) {
let msg = "arguments for inline assembly must be copyable";
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(&format!("`{ty}` does not implement the Copy trait"));
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
#![feature(ptr_sub_ptr)]
#![feature(receiver_trait)]
#![feature(set_ptr_value)]
#![feature(slice_from_ptr_range)]
#![feature(slice_group_by)]
#![feature(slice_ptr_get)]
#![feature(slice_ptr_len)]
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub use core::slice::EscapeAscii;
pub use core::slice::SliceIndex;
#[stable(feature = "from_ref", since = "1.28.0")]
pub use core::slice::{from_mut, from_ref};
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
pub use core::slice::{from_mut_ptr_range, from_ptr_range};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
///
/// [valid]: ptr#safety
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
#[rustc_const_unstable(feature = "const_slice_from_ptr_range", issue = "89792")]
pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
// SAFETY: the caller must uphold the safety contract for `from_ptr_range`.
unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
}
Expand Down Expand Up @@ -263,7 +264,8 @@ pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
///
/// [valid]: ptr#safety
#[unstable(feature = "slice_from_ptr_range", issue = "89792")]
pub unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] {
#[rustc_const_unstable(feature = "slice_from_mut_ptr_range_const", issue = "89792")]
pub const unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] {
// SAFETY: the caller must uphold the safety contract for `from_mut_ptr_range`.
unsafe { from_raw_parts_mut(range.start, range.end.sub_ptr(range.start)) }
}
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
write!(buffer, "<li class=\"version\">Version {}</li>", Escape(version));
}
write!(buffer, "<li><a id=\"all-types\" href=\"all.html\">All Items</a></li>");
buffer.write_str("</div></ul>");
buffer.write_str("</ul></div>");
}

match *it.kind {
Expand Down
7 changes: 7 additions & 0 deletions src/librustdoc/html/static/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,12 @@ module.exports = {
}
],
"eqeqeq": "error",
"no-const-assign": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-ex-assign": "error",
}
};
12 changes: 12 additions & 0 deletions src/test/ui/asm/issue-97490.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check-pass
// only-x86_64
// needs-asm-support

pub type Yes = extern "sysv64" fn(&'static u8) -> !;

fn main() {
unsafe {
let yes = &6 as *const _ as *const Yes;
core::arch::asm!("call {}", in(reg) yes, options(noreturn));
}
}
106 changes: 106 additions & 0 deletions src/test/ui/const-ptr/allowed_slices.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// run-pass
#![feature(
const_slice_from_raw_parts,
slice_from_ptr_range,
const_slice_from_ptr_range,
pointer_byte_offsets,
const_pointer_byte_offsets
)]
use std::{
mem::MaybeUninit,
ptr,
slice::{from_ptr_range, from_raw_parts},
};

// Dangling is ok, as long as it's either for ZST reads or for no reads
pub static S0: &[u32] = unsafe { from_raw_parts(dangling(), 0) };
pub static S1: &[()] = unsafe { from_raw_parts(dangling(), 3) };

// References are always valid of reads of a single element (basically `slice::from_ref`)
pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 1) };
pub static S3: &[MaybeUninit<&u32>] = unsafe { from_raw_parts(&D1, 1) };

// Reinterpreting data is fine, as long as layouts match
pub static S4: &[u8] = unsafe { from_raw_parts((&D0) as *const _ as _, 3) };
// This is only valid because D1 has uninitialized bytes, if it was an initialized pointer,
// that would reinterpret pointers as integers which is UB in CTFE.
pub static S5: &[MaybeUninit<u8>] = unsafe { from_raw_parts((&D1) as *const _ as _, 2) };
// Even though u32 and [bool; 4] have different layouts, D0 has a value that
// is valid as [bool; 4], so this is not UB (it's basically a transmute)
pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) };

// Structs are considered single allocated objects,
// as long as you don't reinterpret padding as initialized
// data everything is ok.
pub static S7: &[u16] = unsafe {
let ptr = (&D2 as *const Struct as *const u16).byte_add(4);

from_raw_parts(ptr, 3)
};
pub static S8: &[MaybeUninit<u16>] = unsafe {
let ptr = &D2 as *const Struct as *const MaybeUninit<u16>;

from_raw_parts(ptr, 6)
};

pub static R0: &[u32] = unsafe { from_ptr_range(dangling()..dangling()) };
// from_ptr_range panics on zst
//pub static R1: &[()] = unsafe { from_ptr_range(dangling(), dangling().byte_add(3)) };
pub static R2: &[u32] = unsafe {
let ptr = &D0 as *const u32;
from_ptr_range(ptr..ptr.add(1))
};
pub static R3: &[MaybeUninit<&u32>] = unsafe {
let ptr = &D1 as *const MaybeUninit<&u32>;
from_ptr_range(ptr..ptr.add(1))
};
pub static R4: &[u8] = unsafe {
let ptr = &D0 as *const u32 as *const u8;
from_ptr_range(ptr..ptr.add(3))
};
pub static R5: &[MaybeUninit<u8>] = unsafe {
let ptr = &D1 as *const MaybeUninit<&u32> as *const MaybeUninit<u8>;
from_ptr_range(ptr..ptr.add(2))
};
pub static R6: &[bool] = unsafe {
let ptr = &D0 as *const u32 as *const bool;
from_ptr_range(ptr..ptr.add(4))
};
pub static R7: &[u16] = unsafe {
let d2 = &D2;
let l = &d2.b as *const u32 as *const u16;
let r = &d2.d as *const u8 as *const u16;

from_ptr_range(l..r)
};
pub static R8: &[MaybeUninit<u16>] = unsafe {
let d2 = &D2;
let l = d2 as *const Struct as *const MaybeUninit<u16>;
let r = &d2.d as *const u8 as *const MaybeUninit<u16>;

from_ptr_range(l..r)
};

// Using valid slice is always valid
pub static R9: &[u32] = unsafe { from_ptr_range(R0.as_ptr_range()) };
pub static R10: &[u32] = unsafe { from_ptr_range(R2.as_ptr_range()) };

const D0: u32 = (1 << 16) | 1;
const D1: MaybeUninit<&u32> = MaybeUninit::uninit();
const D2: Struct = Struct { a: 1, b: 2, c: 3, d: 4 };

const fn dangling<T>() -> *const T {
ptr::NonNull::dangling().as_ptr() as _
}

#[repr(C)]
struct Struct {
a: u8,
// _pad: [MaybeUninit<u8>; 3]
b: u32,
c: u16,
d: u8,
// _pad: [MaybeUninit<u8>; 1]
}

fn main() {}
Loading