Skip to content

Commit 1773f14

Browse files
committed
Auto merge of rust-lang#85014 - Dylan-DPC:rollup-jzpbkdu, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#84409 (Ensure TLS destructors run before thread joins in SGX) - rust-lang#84500 (Add --run flag to compiletest) - rust-lang#84728 (Add test for suggestion to borrow unsized function parameters) - rust-lang#84734 (Add `needs-unwind` and beginning of support for testing `panic=abort` std to compiletest) - rust-lang#84755 (Allow using `core::` in intra-doc links within core itself) - rust-lang#84871 (Disallows `#![feature(no_coverage)]` on stable and beta (using standard crate-level gating)) - rust-lang#84872 (Wire up tidy dependency checks for cg_clif) - rust-lang#84896 (Handle incorrect placement of parentheses in trait bounds more gracefully) - rust-lang#84905 (CTFE engine: rename copy → copy_intrinsic, move to intrinsics.rs) - rust-lang#84953 (Remove unneeded call to with_default_session_globals in rustdoc highlight) - rust-lang#84987 (small nits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 777bb2f + 01e9d09 commit 1773f14

Some content is hidden

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

50 files changed

+763
-258
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@ pub fn expand_deriving_eq(
1515
item: &Annotatable,
1616
push: &mut dyn FnMut(Annotatable),
1717
) {
18+
let span = cx.with_def_site_ctxt(span);
1819
let inline = cx.meta_word(span, sym::inline);
19-
let no_coverage_ident =
20-
rustc_ast::attr::mk_nested_word_item(Ident::new(sym::no_coverage, span));
21-
let no_coverage_feature =
22-
rustc_ast::attr::mk_list_item(Ident::new(sym::feature, span), vec![no_coverage_ident]);
23-
let no_coverage = cx.meta_word(span, sym::no_coverage);
2420
let hidden = rustc_ast::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
2521
let doc = rustc_ast::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
26-
let attrs = vec![
27-
cx.attribute(inline),
28-
cx.attribute(no_coverage_feature),
29-
cx.attribute(no_coverage),
30-
cx.attribute(doc),
31-
];
22+
let no_coverage = cx.meta_word(span, sym::no_coverage);
23+
let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)];
3224
let trait_def = TraitDef {
3325
span,
3426
attributes: Vec::new(),

compiler/rustc_feature/src/builtin_attrs.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
273273
template!(List: "address, memory, thread"),
274274
experimental!(no_sanitize)
275275
),
276-
ungated!(
277-
// Not exclusively gated at the crate level (though crate-level is
278-
// supported). The feature can alternatively be enabled on individual
279-
// functions.
280-
no_coverage, AssumedUsed,
281-
template!(Word),
282-
),
276+
gated!(no_coverage, AssumedUsed, template!(Word), experimental!(no_coverage)),
283277

284278
// FIXME: #14408 assume docs are used since rustdoc looks at them.
285279
ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2398,9 +2398,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23982398
self.tcx.associated_item(def_id).ident
23992399
),
24002400
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
2401-
infer::BoundRegionInCoherence(name) => {
2402-
format!(" for lifetime parameter `{}` in coherence check", name)
2403-
}
24042401
infer::UpvarRegion(ref upvar_id, _) => {
24052402
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
24062403
format!(" for capture of `{}` by closure", var_name)

compiler/rustc_infer/src/infer/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ pub enum RegionVariableOrigin {
453453

454454
UpvarRegion(ty::UpvarId, Span),
455455

456-
BoundRegionInCoherence(Symbol),
457-
458456
/// This origin is used for the inference variables that we create
459457
/// during NLL region processing.
460458
Nll(NllRegionVariableOrigin),
@@ -1749,7 +1747,6 @@ impl RegionVariableOrigin {
17491747
| EarlyBoundRegion(a, ..)
17501748
| LateBoundRegion(a, ..)
17511749
| UpvarRegion(_, a) => a,
1752-
BoundRegionInCoherence(_) => rustc_span::DUMMY_SP,
17531750
Nll(..) => bug!("NLL variable used with `span`"),
17541751
}
17551752
}

compiler/rustc_mir/src/interpret/intrinsics.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
323323
self.write_scalar(result, dest)?;
324324
}
325325
sym::copy => {
326-
self.copy(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
326+
self.copy_intrinsic(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
327327
}
328328
sym::offset => {
329329
let ptr = self.read_scalar(&args[0])?.check_init()?;
@@ -530,4 +530,36 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
530530
)?;
531531
Ok(offset_ptr)
532532
}
533+
534+
/// Copy `count*size_of::<T>()` many bytes from `*src` to `*dst`.
535+
pub(crate) fn copy_intrinsic(
536+
&mut self,
537+
src: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
538+
dst: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
539+
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
540+
nonoverlapping: bool,
541+
) -> InterpResult<'tcx> {
542+
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
543+
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
544+
let (size, align) = (layout.size, layout.align.abi);
545+
let size = size.checked_mul(count, self).ok_or_else(|| {
546+
err_ub_format!(
547+
"overflow computing total size of `{}`",
548+
if nonoverlapping { "copy_nonoverlapping" } else { "copy" }
549+
)
550+
})?;
551+
552+
// Make sure we check both pointers for an access of the total size and aligment,
553+
// *even if* the total size is 0.
554+
let src =
555+
self.memory.check_ptr_access(self.read_scalar(&src)?.check_init()?, size, align)?;
556+
557+
let dst =
558+
self.memory.check_ptr_access(self.read_scalar(&dst)?.check_init()?, size, align)?;
559+
560+
if let (Some(src), Some(dst)) = (src, dst) {
561+
self.memory.copy(src, dst, size, nonoverlapping)?;
562+
}
563+
Ok(())
564+
}
533565
}

compiler/rustc_mir/src/interpret/step.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! The main entry point is the `step` method.
44
5-
use crate::interpret::OpTy;
65
use rustc_middle::mir;
76
use rustc_middle::mir::interpret::{InterpResult, Scalar};
87
use rustc_target::abi::LayoutOf;
@@ -119,7 +118,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
119118
let src = self.eval_operand(src, None)?;
120119
let dst = self.eval_operand(dst, None)?;
121120
let count = self.eval_operand(count, None)?;
122-
self.copy(&src, &dst, &count, /* nonoverlapping */ true)?;
121+
self.copy_intrinsic(&src, &dst, &count, /* nonoverlapping */ true)?;
123122
}
124123

125124
// Statements we do not track.
@@ -149,37 +148,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
149148
Ok(())
150149
}
151150

152-
pub(crate) fn copy(
153-
&mut self,
154-
src: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
155-
dst: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
156-
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
157-
nonoverlapping: bool,
158-
) -> InterpResult<'tcx> {
159-
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
160-
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
161-
let (size, align) = (layout.size, layout.align.abi);
162-
let size = size.checked_mul(count, self).ok_or_else(|| {
163-
err_ub_format!(
164-
"overflow computing total size of `{}`",
165-
if nonoverlapping { "copy_nonoverlapping" } else { "copy" }
166-
)
167-
})?;
168-
169-
// Make sure we check both pointers for an access of the total size and aligment,
170-
// *even if* the total size is 0.
171-
let src =
172-
self.memory.check_ptr_access(self.read_scalar(&src)?.check_init()?, size, align)?;
173-
174-
let dst =
175-
self.memory.check_ptr_access(self.read_scalar(&dst)?.check_init()?, size, align)?;
176-
177-
if let (Some(src), Some(dst)) = (src, dst) {
178-
self.memory.copy(src, dst, size, nonoverlapping)?;
179-
}
180-
Ok(())
181-
}
182-
183151
/// Evaluate an assignment statement.
184152
///
185153
/// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue

compiler/rustc_parse/src/parser/ty.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a> Parser<'a> {
470470
/// Is a `dyn B0 + ... + Bn` type allowed here?
471471
fn is_explicit_dyn_type(&mut self) -> bool {
472472
self.check_keyword(kw::Dyn)
473-
&& (self.token.uninterpolated_span().rust_2018()
473+
&& (!self.token.uninterpolated_span().rust_2015()
474474
|| self.look_ahead(1, |t| {
475475
t.can_begin_bound() && !can_continue_type_after_non_fn_ident(t)
476476
}))
@@ -539,7 +539,21 @@ impl<'a> Parser<'a> {
539539
) -> PResult<'a, GenericBounds> {
540540
let mut bounds = Vec::new();
541541
let mut negative_bounds = Vec::new();
542-
while self.can_begin_bound() {
542+
543+
while self.can_begin_bound() || self.token.is_keyword(kw::Dyn) {
544+
if self.token.is_keyword(kw::Dyn) {
545+
// Account for `&dyn Trait + dyn Other`.
546+
self.struct_span_err(self.token.span, "invalid `dyn` keyword")
547+
.help("`dyn` is only needed at the start of a trait `+`-separated list")
548+
.span_suggestion(
549+
self.token.span,
550+
"remove this keyword",
551+
String::new(),
552+
Applicability::MachineApplicable,
553+
)
554+
.emit();
555+
self.bump();
556+
}
543557
match self.parse_generic_bound()? {
544558
Ok(bound) => bounds.push(bound),
545559
Err(neg_sp) => negative_bounds.push(neg_sp),
@@ -721,7 +735,26 @@ impl<'a> Parser<'a> {
721735
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
722736
let path = self.parse_path(PathStyle::Type)?;
723737
if has_parens {
724-
self.expect(&token::CloseDelim(token::Paren))?;
738+
if self.token.is_like_plus() {
739+
// Someone has written something like `&dyn (Trait + Other)`. The correct code
740+
// would be `&(dyn Trait + Other)`, but we don't have access to the appropriate
741+
// span to suggest that. When written as `&dyn Trait + Other`, an appropriate
742+
// suggestion is given.
743+
let bounds = vec![];
744+
self.parse_remaining_bounds(bounds, true)?;
745+
self.expect(&token::CloseDelim(token::Paren))?;
746+
let sp = vec![lo, self.prev_token.span];
747+
let sugg: Vec<_> = sp.iter().map(|sp| (*sp, String::new())).collect();
748+
self.struct_span_err(sp, "incorrect braces around trait bounds")
749+
.multipart_suggestion(
750+
"remove the parentheses",
751+
sugg,
752+
Applicability::MachineApplicable,
753+
)
754+
.emit();
755+
} else {
756+
self.expect(&token::CloseDelim(token::Paren))?;
757+
}
725758
}
726759

727760
let modifier = modifiers.to_trait_bound_modifier();

compiler/rustc_trait_selection/src/traits/select/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10441044
}
10451045

10461046
/// Returns `true` if the global caches can be used.
1047-
/// Do note that if the type itself is not in the
1048-
/// global tcx, the local caches will be used.
10491047
fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
10501048
// If there are any inference variables in the `ParamEnv`, then we
10511049
// always use a cache local to this particular scope. Otherwise, we

compiler/rustc_typeck/src/collect.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
26612661
let mut inline_span = None;
26622662
let mut link_ordinal_span = None;
26632663
let mut no_sanitize_span = None;
2664-
let mut no_coverage_feature_enabled = false;
2665-
let mut no_coverage_attr = None;
26662664
for attr in attrs.iter() {
26672665
if tcx.sess.check_name(attr, sym::cold) {
26682666
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
@@ -2726,15 +2724,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27262724
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED;
27272725
} else if tcx.sess.check_name(attr, sym::no_mangle) {
27282726
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
2729-
} else if attr.has_name(sym::feature) {
2730-
if let Some(list) = attr.meta_item_list() {
2731-
if list.iter().any(|nested_meta_item| nested_meta_item.has_name(sym::no_coverage)) {
2732-
tcx.sess.mark_attr_used(attr);
2733-
no_coverage_feature_enabled = true;
2734-
}
2735-
}
27362727
} else if tcx.sess.check_name(attr, sym::no_coverage) {
2737-
no_coverage_attr = Some(attr);
2728+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
27382729
} else if tcx.sess.check_name(attr, sym::rustc_std_internal_symbol) {
27392730
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
27402731
} else if tcx.sess.check_name(attr, sym::used) {
@@ -2945,23 +2936,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29452936
}
29462937
}
29472938

2948-
if let Some(no_coverage_attr) = no_coverage_attr {
2949-
if tcx.sess.features_untracked().no_coverage || no_coverage_feature_enabled {
2950-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE
2951-
} else {
2952-
let mut err = feature_err(
2953-
&tcx.sess.parse_sess,
2954-
sym::no_coverage,
2955-
no_coverage_attr.span,
2956-
"the `#[no_coverage]` attribute is an experimental feature",
2957-
);
2958-
if tcx.sess.parse_sess.unstable_features.is_nightly_build() {
2959-
err.help("or, alternatively, add `#[feature(no_coverage)]` to the function");
2960-
}
2961-
err.emit();
2962-
}
2963-
}
2964-
29652939
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
29662940
if !attr.has_name(sym::inline) {
29672941
return ia;

library/core/src/cmp.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ pub trait Eq: PartialEq<Self> {
274274
//
275275
// This should never be implemented by hand.
276276
#[doc(hidden)]
277-
#[cfg_attr(not(bootstrap), feature(no_coverage))]
278-
#[cfg_attr(not(bootstrap), no_coverage)]
277+
#[cfg_attr(not(bootstrap), no_coverage)] // rust-lang/rust#84605
279278
#[inline]
280279
#[stable(feature = "rust1", since = "1.0.0")]
281280
fn assert_receiver_is_total_eq(&self) {}
@@ -284,7 +283,7 @@ pub trait Eq: PartialEq<Self> {
284283
/// Derive macro generating an impl of the trait `Eq`.
285284
#[rustc_builtin_macro]
286285
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
287-
#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match)]
286+
#[allow_internal_unstable(core_intrinsics, derive_eq, structural_match, no_coverage)]
288287
pub macro Eq($item:item) {
289288
/* compiler built-in */
290289
}

library/core/src/intrinsics.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ extern "rust-intrinsic" {
723723
/// macro, which panics when it is executed, it is *undefined behavior* to
724724
/// reach code marked with this function.
725725
///
726-
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`](crate::hint::unreachable_unchecked).
726+
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
727727
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
728728
pub fn unreachable() -> !;
729729

@@ -768,13 +768,13 @@ extern "rust-intrinsic" {
768768
/// More specifically, this is the offset in bytes between successive
769769
/// items of the same type, including alignment padding.
770770
///
771-
/// The stabilized version of this intrinsic is [`core::mem::size_of`](crate::mem::size_of).
771+
/// The stabilized version of this intrinsic is [`core::mem::size_of`].
772772
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
773773
pub fn size_of<T>() -> usize;
774774

775775
/// The minimum alignment of a type.
776776
///
777-
/// The stabilized version of this intrinsic is [`core::mem::align_of`](crate::mem::align_of).
777+
/// The stabilized version of this intrinsic is [`core::mem::align_of`].
778778
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
779779
pub fn min_align_of<T>() -> usize;
780780
/// The preferred alignment of a type.
@@ -790,21 +790,21 @@ extern "rust-intrinsic" {
790790
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
791791
/// The required alignment of the referenced value.
792792
///
793-
/// The stabilized version of this intrinsic is [`core::mem::align_of_val`](crate::mem::align_of_val).
793+
/// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
794794
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
795795
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
796796

797797
/// Gets a static string slice containing the name of a type.
798798
///
799-
/// The stabilized version of this intrinsic is [`core::any::type_name`](crate::any::type_name).
799+
/// The stabilized version of this intrinsic is [`core::any::type_name`].
800800
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
801801
pub fn type_name<T: ?Sized>() -> &'static str;
802802

803803
/// Gets an identifier which is globally unique to the specified type. This
804804
/// function will return the same value for a type regardless of whichever
805805
/// crate it is invoked in.
806806
///
807-
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`](crate::any::TypeId::of).
807+
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
808808
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
809809
pub fn type_id<T: ?Sized + 'static>() -> u64;
810810

@@ -829,7 +829,7 @@ extern "rust-intrinsic" {
829829

830830
/// Gets a reference to a static `Location` indicating where it was called.
831831
///
832-
/// Consider using [`core::panic::Location::caller`](crate::panic::Location::caller) instead.
832+
/// Consider using [`core::panic::Location::caller`] instead.
833833
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
834834
pub fn caller_location() -> &'static crate::panic::Location<'static>;
835835

@@ -1158,11 +1158,11 @@ extern "rust-intrinsic" {
11581158

11591159
/// Performs a volatile load from the `src` pointer.
11601160
///
1161-
/// The stabilized version of this intrinsic is [`core::ptr::read_volatile`](crate::ptr::read_volatile).
1161+
/// The stabilized version of this intrinsic is [`core::ptr::read_volatile`].
11621162
pub fn volatile_load<T>(src: *const T) -> T;
11631163
/// Performs a volatile store to the `dst` pointer.
11641164
///
1165-
/// The stabilized version of this intrinsic is [`core::ptr::write_volatile`](crate::ptr::write_volatile).
1165+
/// The stabilized version of this intrinsic is [`core::ptr::write_volatile`].
11661166
pub fn volatile_store<T>(dst: *mut T, val: T);
11671167

11681168
/// Performs a volatile load from the `src` pointer
@@ -1703,7 +1703,7 @@ extern "rust-intrinsic" {
17031703
/// Returns the value of the discriminant for the variant in 'v';
17041704
/// if `T` has no discriminant, returns `0`.
17051705
///
1706-
/// The stabilized version of this intrinsic is [`core::mem::discriminant`](crate::mem::discriminant).
1706+
/// The stabilized version of this intrinsic is [`core::mem::discriminant`].
17071707
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
17081708
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
17091709

0 commit comments

Comments
 (0)