Skip to content

Commit 3ed6c1d

Browse files
committed
Auto merge of rust-lang#88556 - m-ou-se:rollup-q636wyd, r=m-ou-se
Rollup of 9 pull requests Successful merges: - rust-lang#86376 (Emit specific warning to clarify that `#[no_mangle]` should not be applied on foreign statics or functions) - rust-lang#88040 (BTree: remove Ord bound from new) - rust-lang#88053 (Fix the flock fallback implementation) - rust-lang#88350 (add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPC) - rust-lang#88410 (Remove bolding on associated constants) - rust-lang#88525 (fix(rustc_typeck): produce better errors for dyn auto trait) - rust-lang#88542 (Use the return value of readdir_r() instead of errno) - rust-lang#88548 (Stabilize `Iterator::intersperse()`) - rust-lang#88551 (Stabilize `UnsafeCell::raw_get()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 608b5e1 + d313529 commit 3ed6c1d

File tree

33 files changed

+401
-81
lines changed

33 files changed

+401
-81
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+8
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
616616
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
617617
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
618618
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
619+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
620+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
621+
unreachable!("clobber-only")
622+
}
619623
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
620624
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
621625
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
@@ -755,6 +759,10 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
755759
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => cx.type_i32(),
756760
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => cx.type_i32(),
757761
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => cx.type_f64(),
762+
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
763+
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
764+
unreachable!("clobber-only")
765+
}
758766
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
759767
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
760768
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {

compiler/rustc_data_structures/src/flock.rs

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ cfg_if! {
222222
let msg = "file locks not supported on this platform";
223223
Err(io::Error::new(io::ErrorKind::Other, msg))
224224
}
225+
226+
pub fn error_unsupported(_err: &io::Error) -> bool {
227+
true
228+
}
225229
}
226230
}
227231
}

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ E0781: include_str!("./error_codes/E0781.md"),
480480
E0782: include_str!("./error_codes/E0782.md"),
481481
E0783: include_str!("./error_codes/E0783.md"),
482482
E0784: include_str!("./error_codes/E0784.md"),
483+
E0785: include_str!("./error_codes/E0785.md"),
483484
;
484485
// E0006, // merged with E0005
485486
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
An inherent `impl` was written on a dyn auto trait.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0785
6+
#![feature(auto_traits)]
7+
8+
auto trait AutoTrait {}
9+
10+
impl dyn AutoTrait {}
11+
```
12+
13+
Dyn objects allow any number of auto traits, plus at most one non-auto trait.
14+
The non-auto trait becomes the "principal trait".
15+
16+
When checking if an impl on a dyn trait is coherent, the principal trait is
17+
normally the only one considered. Since the erroneous code has no principal
18+
trait, it cannot be implemented at all.
19+
20+
Working example:
21+
22+
```
23+
#![feature(auto_traits)]
24+
25+
trait PrincipalTrait {}
26+
27+
auto trait AutoTrait {}
28+
29+
impl dyn PrincipalTrait + AutoTrait + Send {}
30+
```

compiler/rustc_passes/src/check_attr.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,36 @@ impl CheckAttrVisitor<'tcx> {
13311331
Target::Field | Target::Arm | Target::MacroDef => {
13321332
self.inline_attr_str_error_with_macro_def(hir_id, attr, "no_mangle");
13331333
}
1334+
// FIXME: #[no_mangle] was previously allowed on non-functions/statics, this should be an error
1335+
// The error should specify that the item that is wrong is specifically a *foreign* fn/static
1336+
// otherwise the error seems odd
1337+
Target::ForeignFn | Target::ForeignStatic => {
1338+
let foreign_item_kind = match target {
1339+
Target::ForeignFn => "function",
1340+
Target::ForeignStatic => "static",
1341+
_ => unreachable!(),
1342+
};
1343+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1344+
lint.build(&format!(
1345+
"`#[no_mangle]` has no effect on a foreign {}",
1346+
foreign_item_kind
1347+
))
1348+
.warn(
1349+
"this was previously accepted by the compiler but is \
1350+
being phased out; it will become a hard error in \
1351+
a future release!",
1352+
)
1353+
.span_label(*span, format!("foreign {}", foreign_item_kind))
1354+
.note("symbol names in extern blocks are not mangled")
1355+
.span_suggestion(
1356+
attr.span,
1357+
"remove this attribute",
1358+
String::new(),
1359+
Applicability::MachineApplicable,
1360+
)
1361+
.emit();
1362+
});
1363+
}
13341364
_ => {
13351365
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
13361366
// crates used this, so only emit a warning.

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ symbols! {
479479
core_panic_macro,
480480
cosf32,
481481
cosf64,
482+
cr,
482483
crate_id,
483484
crate_in_paths,
484485
crate_local,
@@ -1418,6 +1419,7 @@ symbols! {
14181419
wreg,
14191420
write_bytes,
14201421
x87_reg,
1422+
xer,
14211423
xmm_reg,
14221424
ymm_reg,
14231425
zmm_reg,

compiler/rustc_target/src/asm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl InlineAsmReg {
355355
Self::Arm(r) => r.overlapping_regs(|r| cb(Self::Arm(r))),
356356
Self::AArch64(_) => cb(self),
357357
Self::RiscV(_) => cb(self),
358-
Self::PowerPC(_) => cb(self),
358+
Self::PowerPC(r) => r.overlapping_regs(|r| cb(Self::PowerPC(r))),
359359
Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))),
360360
Self::Mips(_) => cb(self),
361361
Self::S390x(_) => cb(self),

compiler/rustc_target/src/asm/powerpc.rs

+60-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def_reg_class! {
77
reg,
88
reg_nonzero,
99
freg,
10+
cr,
11+
xer,
1012
}
1113
}
1214

@@ -44,6 +46,7 @@ impl PowerPCInlineAsmRegClass {
4446
}
4547
}
4648
Self::freg => types! { _: F32, F64; },
49+
Self::cr | Self::xer => &[],
4750
}
4851
}
4952
}
@@ -108,6 +111,16 @@ def_regs! {
108111
f29: freg = ["f29", "fr29"],
109112
f30: freg = ["f30", "fr30"],
110113
f31: freg = ["f31", "fr31"],
114+
cr: cr = ["cr"],
115+
cr0: cr = ["cr0"],
116+
cr1: cr = ["cr1"],
117+
cr2: cr = ["cr2"],
118+
cr3: cr = ["cr3"],
119+
cr4: cr = ["cr4"],
120+
cr5: cr = ["cr5"],
121+
cr6: cr = ["cr6"],
122+
cr7: cr = ["cr7"],
123+
xer: xer = ["xer"],
111124
#error = ["r1", "1", "sp"] =>
112125
"the stack pointer cannot be used as an operand for inline asm",
113126
#error = ["r2", "2"] =>
@@ -136,17 +149,55 @@ impl PowerPCInlineAsmReg {
136149
_arch: InlineAsmArch,
137150
_modifier: Option<char>,
138151
) -> fmt::Result {
152+
macro_rules! do_emit {
153+
(
154+
$($(($reg:ident, $value:literal)),*;)*
155+
) => {
156+
out.write_str(match self {
157+
$($(Self::$reg => $value,)*)*
158+
})
159+
};
160+
}
139161
// Strip off the leading prefix.
140-
if self as u32 <= Self::r28 as u32 {
141-
let index = self as u32 - Self::r28 as u32;
142-
write!(out, "{}", index)
143-
} else if self as u32 >= Self::f0 as u32 && self as u32 <= Self::f31 as u32 {
144-
let index = self as u32 - Self::f31 as u32;
145-
write!(out, "{}", index)
146-
} else {
147-
unreachable!()
162+
do_emit! {
163+
(r0, "0"), (r3, "3"), (r4, "4"), (r5, "5"), (r6, "6"), (r7, "7");
164+
(r8, "8"), (r9, "9"), (r10, "10"), (r11, "11"), (r12, "12"), (r14, "14"), (r15, "15");
165+
(r16, "16"), (r17, "17"), (r18, "18"), (r19, "19"), (r20, "20"), (r21, "21"), (r22, "22"), (r23, "23");
166+
(r24, "24"), (r25, "25"), (r26, "26"), (r27, "27"), (r28, "28");
167+
(f0, "0"), (f1, "1"), (f2, "2"), (f3, "3"), (f4, "4"), (f5, "5"), (f6, "6"), (f7, "7");
168+
(f8, "8"), (f9, "9"), (f10, "10"), (f11, "11"), (f12, "12"), (f13, "13"), (f14, "14"), (f15, "15");
169+
(f16, "16"), (f17, "17"), (f18, "18"), (f19, "19"), (f20, "20"), (f21, "21"), (f22, "22"), (f23, "23");
170+
(f24, "24"), (f25, "25"), (f26, "26"), (f27, "27"), (f28, "28"), (f29, "29"), (f30, "30"), (f31, "31");
171+
(cr, "cr");
172+
(cr0, "0"), (cr1, "1"), (cr2, "2"), (cr3, "3"), (cr4, "4"), (cr5, "5"), (cr6, "6"), (cr7, "7");
173+
(xer, "xer");
148174
}
149175
}
150176

151-
pub fn overlapping_regs(self, mut _cb: impl FnMut(PowerPCInlineAsmReg)) {}
177+
pub fn overlapping_regs(self, mut cb: impl FnMut(PowerPCInlineAsmReg)) {
178+
macro_rules! reg_conflicts {
179+
(
180+
$(
181+
$full:ident : $($field:ident)*
182+
),*;
183+
) => {
184+
match self {
185+
$(
186+
Self::$full => {
187+
cb(Self::$full);
188+
$(cb(Self::$field);)*
189+
}
190+
$(Self::$field)|* => {
191+
cb(Self::$full);
192+
cb(self);
193+
}
194+
)*
195+
r => cb(r),
196+
}
197+
};
198+
}
199+
reg_conflicts! {
200+
cr : cr0 cr1 cr2 cr3 cr4 cr5 cr6 cr7;
201+
}
202+
}
152203
}

compiler/rustc_typeck/src/coherence/inherent_impls.rs

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
6060
ty::Dynamic(ref data, ..) if data.principal_def_id().is_some() => {
6161
self.check_def_id(item, data.principal_def_id().unwrap());
6262
}
63+
ty::Dynamic(..) => {
64+
struct_span_err!(
65+
self.tcx.sess,
66+
ty.span,
67+
E0785,
68+
"cannot define inherent `impl` for a dyn auto trait"
69+
)
70+
.span_label(ty.span, "impl requires at least one non-auto trait")
71+
.note("define and implement a new trait or type instead")
72+
.emit();
73+
}
6374
ty::Bool => {
6475
self.check_primitive_impl(
6576
item.def_id,

library/alloc/src/collections/btree/map.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
233233
}
234234

235235
if self.is_empty() {
236-
// Ideally we'd call `BTreeMap::new` here, but that has the `K:
237-
// Ord` constraint, which this method lacks.
238-
BTreeMap { root: None, length: 0 }
236+
BTreeMap::new()
239237
} else {
240238
clone_subtree(self.root.as_ref().unwrap().reborrow()) // unwrap succeeds because not empty
241239
}
@@ -499,10 +497,7 @@ impl<K, V> BTreeMap<K, V> {
499497
/// ```
500498
#[stable(feature = "rust1", since = "1.0.0")]
501499
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
502-
pub const fn new() -> BTreeMap<K, V>
503-
where
504-
K: Ord,
505-
{
500+
pub const fn new() -> BTreeMap<K, V> {
506501
BTreeMap { root: None, length: 0 }
507502
}
508503

@@ -522,7 +517,7 @@ impl<K, V> BTreeMap<K, V> {
522517
/// ```
523518
#[stable(feature = "rust1", since = "1.0.0")]
524519
pub fn clear(&mut self) {
525-
*self = BTreeMap { root: None, length: 0 };
520+
*self = BTreeMap::new();
526521
}
527522

528523
/// Returns a reference to the value corresponding to the key.
@@ -1957,7 +1952,7 @@ impl<K: Hash, V: Hash> Hash for BTreeMap<K, V> {
19571952
}
19581953

19591954
#[stable(feature = "rust1", since = "1.0.0")]
1960-
impl<K: Ord, V> Default for BTreeMap<K, V> {
1955+
impl<K, V> Default for BTreeMap<K, V> {
19611956
/// Creates an empty `BTreeMap`.
19621957
fn default() -> BTreeMap<K, V> {
19631958
BTreeMap::new()

library/alloc/src/collections/btree/map/tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ fn test_send() {
17451745
}
17461746
}
17471747

1748-
#[allow(dead_code)]
1748+
#[test]
17491749
fn test_ord_absence() {
17501750
fn map<K>(mut map: BTreeMap<K, ()>) {
17511751
map.is_empty();
@@ -1784,6 +1784,12 @@ fn test_ord_absence() {
17841784
fn map_clone<K: Clone>(mut map: BTreeMap<K, ()>) {
17851785
map.clone_from(&map.clone());
17861786
}
1787+
1788+
#[derive(Debug, Clone)]
1789+
struct NonOrd;
1790+
map(BTreeMap::<NonOrd, _>::new());
1791+
map_debug(BTreeMap::<NonOrd, _>::new());
1792+
map_clone(BTreeMap::<NonOrd, _>::default());
17871793
}
17881794

17891795
#[test]

library/alloc/src/collections/btree/set.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ impl<T> BTreeSet<T> {
246246
/// ```
247247
#[stable(feature = "rust1", since = "1.0.0")]
248248
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
249-
pub const fn new() -> BTreeSet<T>
250-
where
251-
T: Ord,
252-
{
249+
pub const fn new() -> BTreeSet<T> {
253250
BTreeSet { map: BTreeMap::new() }
254251
}
255252

@@ -1192,7 +1189,7 @@ impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BTreeSet<T> {
11921189
}
11931190

11941191
#[stable(feature = "rust1", since = "1.0.0")]
1195-
impl<T: Ord> Default for BTreeSet<T> {
1192+
impl<T> Default for BTreeSet<T> {
11961193
/// Creates an empty `BTreeSet`.
11971194
fn default() -> BTreeSet<T> {
11981195
BTreeSet::new()

library/alloc/src/collections/btree/set/tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ fn test_send() {
607607
}
608608
}
609609

610-
#[allow(dead_code)]
610+
#[test]
611611
fn test_ord_absence() {
612612
fn set<K>(mut set: BTreeSet<K>) {
613613
set.is_empty();
@@ -626,6 +626,12 @@ fn test_ord_absence() {
626626
fn set_clone<K: Clone>(mut set: BTreeSet<K>) {
627627
set.clone_from(&set.clone());
628628
}
629+
630+
#[derive(Debug, Clone)]
631+
struct NonOrd;
632+
set(BTreeSet::<NonOrd>::new());
633+
set_debug(BTreeSet::<NonOrd>::new());
634+
set_clone(BTreeSet::<NonOrd>::default());
629635
}
630636

631637
#[test]

0 commit comments

Comments
 (0)