Skip to content

Commit 4fac5c9

Browse files
committed
Auto merge of #59590 - Centril:rollup, r=Centril
Rollup of 7 pull requests Successful merges: - #58805 (Lint for redundant imports) - #59506 (Use platform dependent mcount function) - #59519 (rustc_target: factor out common fields of non-Single Variants.) - #59580 (Allow closure to unsafe fn coercion) - #59581 (Stabilize refcell_replace_swap feature) - #59583 (match match match match match) - #59587 (Remove #[doc(hidden)] from Error::type_id) Failed merges: r? @ghost
2 parents a89c03a + 3445445 commit 4fac5c9

File tree

110 files changed

+599
-251
lines changed

Some content is hidden

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

110 files changed

+599
-251
lines changed

src/liballoc/borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<T> ToOwned for T
135135
/// Another example showing how to keep `Cow` in a struct:
136136
///
137137
/// ```
138-
/// use std::borrow::{Cow, ToOwned};
138+
/// use std::borrow::Cow;
139139
///
140140
/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned = Vec<X>> {
141141
/// values: Cow<'a, [X]>,

src/libcore/cell.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -702,24 +702,21 @@ impl<T> RefCell<T> {
702702
/// Replaces the wrapped value with a new one computed from `f`, returning
703703
/// the old value, without deinitializing either one.
704704
///
705-
/// This function corresponds to [`std::mem::replace`](../mem/fn.replace.html).
706-
///
707705
/// # Panics
708706
///
709707
/// Panics if the value is currently borrowed.
710708
///
711709
/// # Examples
712710
///
713711
/// ```
714-
/// #![feature(refcell_replace_swap)]
715712
/// use std::cell::RefCell;
716713
/// let cell = RefCell::new(5);
717714
/// let old_value = cell.replace_with(|&mut old| old + 1);
718715
/// assert_eq!(old_value, 5);
719716
/// assert_eq!(cell, RefCell::new(6));
720717
/// ```
721718
#[inline]
722-
#[unstable(feature = "refcell_replace_swap", issue="43570")]
719+
#[stable(feature = "refcell_replace_swap", since="1.35.0")]
723720
pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T {
724721
let mut_borrow = &mut *self.borrow_mut();
725722
let replacement = f(mut_borrow);
@@ -1421,7 +1418,6 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
14211418
///
14221419
/// ```
14231420
/// use std::cell::UnsafeCell;
1424-
/// use std::marker::Sync;
14251421
///
14261422
/// # #[allow(dead_code)]
14271423
/// struct NotThreadSafe<T> {

src/libcore/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#![feature(pattern)]
1717
#![feature(range_is_empty)]
1818
#![feature(raw)]
19-
#![feature(refcell_replace_swap)]
2019
#![feature(slice_patterns)]
2120
#![feature(sort_internals)]
2221
#![feature(specialization)]

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#![feature(proc_macro_internals)]
4646
#![feature(optin_builtin_traits)]
4747
#![feature(range_is_empty)]
48-
#![feature(refcell_replace_swap)]
4948
#![feature(rustc_diagnostic_macros)]
5049
#![feature(rustc_attrs)]
5150
#![feature(slice_patterns)]

src/librustc/lint/builtin.rs

+10
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ pub enum BuiltinLintDiagnostics {
483483
UnknownCrateTypes(Span, String, String),
484484
UnusedImports(String, Vec<(Span, String)>),
485485
NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
486+
RedundantImport(Vec<(Span, bool)>, ast::Ident),
486487
}
487488

488489
impl BuiltinLintDiagnostics {
@@ -579,6 +580,15 @@ impl BuiltinLintDiagnostics {
579580
db.span_label(outer_impl_trait_span, "outer `impl Trait`");
580581
db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
581582
}
583+
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
584+
for (span, is_imported) in spans {
585+
let introduced = if is_imported { "imported" } else { "defined" };
586+
db.span_label(
587+
span,
588+
format!("the item `{}` is already {} here", ident, introduced)
589+
);
590+
}
591+
}
582592
}
583593
}
584594
}

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
707707
adjustment::Adjust::NeverToAny |
708708
adjustment::Adjust::ReifyFnPointer |
709709
adjustment::Adjust::UnsafeFnPointer |
710-
adjustment::Adjust::ClosureFnPointer |
710+
adjustment::Adjust::ClosureFnPointer(_) |
711711
adjustment::Adjust::MutToConstPointer |
712712
adjustment::Adjust::Unsize => {
713713
// Creating a closure/fn-pointer or unsizing consumes

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
621621
adjustment::Adjust::NeverToAny |
622622
adjustment::Adjust::ReifyFnPointer |
623623
adjustment::Adjust::UnsafeFnPointer |
624-
adjustment::Adjust::ClosureFnPointer |
624+
adjustment::Adjust::ClosureFnPointer(_) |
625625
adjustment::Adjust::MutToConstPointer |
626626
adjustment::Adjust::Borrow(_) |
627627
adjustment::Adjust::Unsize => {

src/librustc/mir/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2247,8 +2247,9 @@ pub enum CastKind {
22472247
/// Converts unique, zero-sized type for a fn to fn()
22482248
ReifyFnPointer,
22492249

2250-
/// Converts non capturing closure to fn()
2251-
ClosureFnPointer,
2250+
/// Converts non capturing closure to fn() or unsafe fn().
2251+
/// It cannot convert a closure that requires unsafe.
2252+
ClosureFnPointer(hir::Unsafety),
22522253

22532254
/// Converts safe fn() to unsafe fn()
22542255
UnsafeFnPointer,

src/librustc/ty/adjustment.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ pub enum Adjust<'tcx> {
6262
/// Go from a safe fn pointer to an unsafe fn pointer.
6363
UnsafeFnPointer,
6464

65-
/// Go from a non-capturing closure to an fn pointer.
66-
ClosureFnPointer,
65+
/// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
66+
/// It cannot convert a closure that requires unsafe.
67+
ClosureFnPointer(hir::Unsafety),
6768

6869
/// Go from a mut raw pointer to a const raw pointer.
6970
MutToConstPointer,

src/librustc/ty/context.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24412441
/// type with the same signature. Detuples and so forth -- so
24422442
/// e.g., if we have a sig with `Fn<(u32, i32)>` then you would get
24432443
/// a `fn(u32, i32)`.
2444-
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
2444+
/// `unsafety` determines the unsafety of the `fn` type. If you pass
2445+
/// `hir::Unsafety::Unsafe` in the previous example, then you would get
2446+
/// an `unsafe fn (u32, i32)`.
2447+
/// It cannot convert a closure that requires unsafe.
2448+
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>, unsafety: hir::Unsafety) -> Ty<'tcx> {
24452449
let converted_sig = sig.map_bound(|s| {
24462450
let params_iter = match s.inputs()[0].sty {
24472451
ty::Tuple(params) => {
@@ -2453,7 +2457,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24532457
params_iter,
24542458
s.output(),
24552459
s.c_variadic,
2456-
hir::Unsafety::Normal,
2460+
unsafety,
24572461
abi::Abi::Rust,
24582462
)
24592463
});

src/librustc/ty/layout.rs

+34-23
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,13 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
913913
}
914914

915915
return Ok(tcx.intern_layout(LayoutDetails {
916-
variants: Variants::NicheFilling {
917-
dataful_variant: i,
918-
niche_variants,
919-
niche: niche_scalar,
920-
niche_start,
916+
variants: Variants::Multiple {
917+
discr: niche_scalar,
918+
discr_kind: DiscriminantKind::Niche {
919+
dataful_variant: i,
920+
niche_variants,
921+
niche_start,
922+
},
921923
variants: st,
922924
},
923925
fields: FieldPlacement::Arbitrary {
@@ -1137,8 +1139,9 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11371139
}
11381140

11391141
tcx.intern_layout(LayoutDetails {
1140-
variants: Variants::Tagged {
1141-
tag,
1142+
variants: Variants::Multiple {
1143+
discr: tag,
1144+
discr_kind: DiscriminantKind::Tag,
11421145
variants: layout_variants,
11431146
},
11441147
fields: FieldPlacement::Arbitrary {
@@ -1293,8 +1296,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
12931296
}
12941297
}
12951298

1296-
Variants::NicheFilling { .. } |
1297-
Variants::Tagged { .. } => {
1299+
Variants::Multiple { ref discr, ref discr_kind, .. } => {
12981300
debug!("print-type-size `{:#?}` adt general variants def {}",
12991301
layout.ty, adt_def.variants.len());
13001302
let variant_infos: Vec<_> =
@@ -1306,8 +1308,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
13061308
layout.for_variant(self, i))
13071309
})
13081310
.collect();
1309-
record(adt_kind.into(), adt_packed, match layout.variants {
1310-
Variants::Tagged { ref tag, .. } => Some(tag.value.size(self)),
1311+
record(adt_kind.into(), adt_packed, match discr_kind {
1312+
DiscriminantKind::Tag => Some(discr.value.size(self)),
13111313
_ => None
13121314
}, variant_infos);
13131315
}
@@ -1627,8 +1629,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16271629
})
16281630
}
16291631

1630-
Variants::NicheFilling { ref variants, .. } |
1631-
Variants::Tagged { ref variants, .. } => {
1632+
Variants::Multiple { ref variants, .. } => {
16321633
&variants[variant_index]
16331634
}
16341635
};
@@ -1735,8 +1736,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
17351736
}
17361737

17371738
// Discriminant field for enums (where applicable).
1738-
Variants::Tagged { tag: ref discr, .. } |
1739-
Variants::NicheFilling { niche: ref discr, .. } => {
1739+
Variants::Multiple { ref discr, .. } => {
17401740
assert_eq!(i, 0);
17411741
let layout = LayoutDetails::scalar(cx, discr.clone());
17421742
return MaybeResult::from_ok(TyLayout {
@@ -1881,26 +1881,37 @@ impl<'a> HashStable<StableHashingContext<'a>> for Variants {
18811881
Single { index } => {
18821882
index.hash_stable(hcx, hasher);
18831883
}
1884-
Tagged {
1885-
ref tag,
1884+
Multiple {
1885+
ref discr,
1886+
ref discr_kind,
18861887
ref variants,
18871888
} => {
1888-
tag.hash_stable(hcx, hasher);
1889+
discr.hash_stable(hcx, hasher);
1890+
discr_kind.hash_stable(hcx, hasher);
18891891
variants.hash_stable(hcx, hasher);
18901892
}
1891-
NicheFilling {
1893+
}
1894+
}
1895+
}
1896+
1897+
impl<'a> HashStable<StableHashingContext<'a>> for DiscriminantKind {
1898+
fn hash_stable<W: StableHasherResult>(&self,
1899+
hcx: &mut StableHashingContext<'a>,
1900+
hasher: &mut StableHasher<W>) {
1901+
use crate::ty::layout::DiscriminantKind::*;
1902+
mem::discriminant(self).hash_stable(hcx, hasher);
1903+
1904+
match *self {
1905+
Tag => {}
1906+
Niche {
18921907
dataful_variant,
18931908
ref niche_variants,
1894-
ref niche,
18951909
niche_start,
1896-
ref variants,
18971910
} => {
18981911
dataful_variant.hash_stable(hcx, hasher);
18991912
niche_variants.start().hash_stable(hcx, hasher);
19001913
niche_variants.end().hash_stable(hcx, hasher);
1901-
niche.hash_stable(hcx, hasher);
19021914
niche_start.hash_stable(hcx, hasher);
1903-
variants.hash_stable(hcx, hasher);
19041915
}
19051916
}
19061917
}

src/librustc/ty/query/on_disk_cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E>
777777
value: &V)
778778
-> Result<(), E::Error>
779779
{
780-
use crate::ty::codec::TyEncoder;
781780
let start_pos = self.position();
782781

783782
tag.encode(self)?;

src/librustc/ty/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
630630
Some(ty::adjustment::Adjust::ReifyFnPointer),
631631
ty::adjustment::Adjust::UnsafeFnPointer =>
632632
Some(ty::adjustment::Adjust::UnsafeFnPointer),
633-
ty::adjustment::Adjust::ClosureFnPointer =>
634-
Some(ty::adjustment::Adjust::ClosureFnPointer),
633+
ty::adjustment::Adjust::ClosureFnPointer(unsafety) =>
634+
Some(ty::adjustment::Adjust::ClosureFnPointer(unsafety)),
635635
ty::adjustment::Adjust::MutToConstPointer =>
636636
Some(ty::adjustment::Adjust::MutToConstPointer),
637637
ty::adjustment::Adjust::Unsize =>
@@ -1187,7 +1187,7 @@ EnumTypeFoldableImpl! {
11871187
(ty::adjustment::Adjust::NeverToAny),
11881188
(ty::adjustment::Adjust::ReifyFnPointer),
11891189
(ty::adjustment::Adjust::UnsafeFnPointer),
1190-
(ty::adjustment::Adjust::ClosureFnPointer),
1190+
(ty::adjustment::Adjust::ClosureFnPointer)(a),
11911191
(ty::adjustment::Adjust::MutToConstPointer),
11921192
(ty::adjustment::Adjust::Unsize),
11931193
(ty::adjustment::Adjust::Deref)(a),

src/librustc_codegen_llvm/attributes.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ pub fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
7777
if cx.sess().instrument_mcount() {
7878
// Similar to `clang -pg` behavior. Handled by the
7979
// `post-inline-ee-instrument` LLVM pass.
80+
81+
// The function name varies on platforms.
82+
// See test/CodeGen/mcount.c in clang.
83+
let mcount_name = CString::new(
84+
cx.sess().target.target.options.target_mcount.as_str().as_bytes()).unwrap();
85+
8086
llvm::AddFunctionAttrStringValue(
8187
llfn, llvm::AttributePlace::Function,
82-
const_cstr!("instrument-function-entry-inlined"), const_cstr!("mcount"));
88+
const_cstr!("instrument-function-entry-inlined"), &mcount_name);
8389
}
8490
}
8591

src/librustc_codegen_llvm/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
372372
// Returns a Value of the "eh_unwind_resume" lang item if one is defined,
373373
// otherwise declares it as an external function.
374374
fn eh_unwind_resume(&self) -> &'ll Value {
375-
use crate::attributes;
376375
let unwresume = &self.eh_unwind_resume;
377376
if let Some(llfn) = unwresume.get() {
378377
return llfn;

0 commit comments

Comments
 (0)