Skip to content

Commit eb07728

Browse files
committed
Auto merge of #67396 - Mark-Simulacrum:rollup-85lxz7h, r=Mark-Simulacrum
Rollup of 5 pull requests Successful merges: - #66716 (Implement `DebugStruct::non_exhaustive`.) - #67286 (Fix the configure.py TOML field for a couple LLVM options) - #67321 (make htons const fn) - #67351 (Set release channel on non-dist builders) - #67382 (Remove some unnecessary `ATTR_*` constants.) Failed merges: r? @ghost
2 parents 19bd934 + f9d80cd commit eb07728

File tree

11 files changed

+183
-60
lines changed

11 files changed

+183
-60
lines changed

src/bootstrap/configure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ def v(*args):
5959
o("lld", "rust.lld", "build lld")
6060
o("lldb", "rust.lldb", "build lldb")
6161
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
62-
o("use-libcxx", "llvm.use_libcxx", "build LLVM with libc++")
62+
o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++")
6363

6464
o("cflags", "llvm.cflags", "build LLVM with these extra compiler flags")
6565
o("cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
6666
o("ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")
6767

68-
o("llvm-libunwind", "rust.llvm_libunwind", "use LLVM libunwind")
68+
o("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")
6969

7070
# Optimization and debugging options. These may be overridden by the release
7171
# channel, etc.

src/ci/run.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ fi
4444
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
4545
# either automatically or manually.
4646
export RUST_RELEASE_CHANNEL=nightly
47+
48+
# Always set the release channel for bootstrap; this is normally not important (i.e., only dist
49+
# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting
50+
# master, beta, or stable with a build to determine whether to run some checks (notably toolstate).
51+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
52+
4753
if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
48-
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
4954
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
5055
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
5156
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"

src/libcore/fmt/builders.rs

+63-6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,62 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
165165
self
166166
}
167167

168+
/// Marks the struct as non-exhaustive, indicating to the reader that there are some other
169+
/// fields that are not shown in the debug representation.
170+
///
171+
/// # Examples
172+
///
173+
/// ```
174+
/// # #![feature(debug_non_exhaustive)]
175+
/// use std::fmt;
176+
///
177+
/// struct Bar {
178+
/// bar: i32,
179+
/// hidden: f32,
180+
/// }
181+
///
182+
/// impl fmt::Debug for Bar {
183+
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
184+
/// fmt.debug_struct("Bar")
185+
/// .field("bar", &self.bar)
186+
/// .finish_non_exhaustive() // Show that some other field(s) exist.
187+
/// }
188+
/// }
189+
///
190+
/// assert_eq!(
191+
/// format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
192+
/// "Bar { bar: 10, .. }",
193+
/// );
194+
/// ```
195+
#[unstable(feature = "debug_non_exhaustive", issue = "67364")]
196+
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
197+
self.result = self.result.and_then(|_| {
198+
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).
199+
if self.is_pretty() {
200+
if !self.has_fields {
201+
self.fmt.write_str(" {\n")?;
202+
}
203+
let mut slot = None;
204+
let mut state = Default::default();
205+
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
206+
writer.write_str("..\n")?;
207+
} else {
208+
if self.has_fields {
209+
self.fmt.write_str(", ..")?;
210+
} else {
211+
self.fmt.write_str(" { ..")?;
212+
}
213+
}
214+
if self.is_pretty() {
215+
self.fmt.write_str("}")?
216+
} else {
217+
self.fmt.write_str(" }")?;
218+
}
219+
Ok(())
220+
});
221+
self.result
222+
}
223+
168224
/// Finishes output and returns any error encountered.
169225
///
170226
/// # Examples
@@ -194,15 +250,16 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
194250
/// ```
195251
#[stable(feature = "debug_builders", since = "1.2.0")]
196252
pub fn finish(&mut self) -> fmt::Result {
197-
if self.has_fields {
198-
self.result = self.result.and_then(|_| {
253+
self.result = self.result.and_then(|_| {
254+
if self.has_fields {
199255
if self.is_pretty() {
200-
self.fmt.write_str("}")
256+
self.fmt.write_str("}")?
201257
} else {
202-
self.fmt.write_str(" }")
258+
self.fmt.write_str(" }")?;
203259
}
204-
});
205-
}
260+
}
261+
Ok(())
262+
});
206263
self.result
207264
}
208265

src/libcore/tests/fmt/builders.rs

+83
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,89 @@ mod debug_struct {
9393
}",
9494
format!("{:#?}", Bar));
9595
}
96+
97+
#[test]
98+
fn test_only_non_exhaustive() {
99+
struct Foo;
100+
101+
impl fmt::Debug for Foo {
102+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
103+
fmt.debug_struct("Foo")
104+
.finish_non_exhaustive()
105+
}
106+
}
107+
108+
109+
assert_eq!("Foo { .. }", format!("{:?}", Foo));
110+
assert_eq!(
111+
"Foo {
112+
..
113+
}",
114+
format!("{:#?}", Foo));
115+
}
116+
117+
#[test]
118+
fn test_multiple_and_non_exhaustive() {
119+
struct Foo;
120+
121+
impl fmt::Debug for Foo {
122+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
123+
fmt.debug_struct("Foo")
124+
.field("bar", &true)
125+
.field("baz", &format_args!("{}/{}", 10, 20))
126+
.finish_non_exhaustive()
127+
}
128+
}
129+
130+
assert_eq!("Foo { bar: true, baz: 10/20, .. }", format!("{:?}", Foo));
131+
assert_eq!(
132+
"Foo {
133+
bar: true,
134+
baz: 10/20,
135+
..
136+
}",
137+
format!("{:#?}", Foo));
138+
}
139+
140+
#[test]
141+
fn test_nested_non_exhaustive() {
142+
struct Foo;
143+
144+
impl fmt::Debug for Foo {
145+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
146+
fmt.debug_struct("Foo")
147+
.field("bar", &true)
148+
.field("baz", &format_args!("{}/{}", 10, 20))
149+
.finish_non_exhaustive()
150+
}
151+
}
152+
153+
struct Bar;
154+
155+
impl fmt::Debug for Bar {
156+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
157+
fmt.debug_struct("Bar")
158+
.field("foo", &Foo)
159+
.field("hello", &"world")
160+
.finish_non_exhaustive()
161+
}
162+
}
163+
164+
assert_eq!("Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \"world\", .. }",
165+
format!("{:?}", Bar));
166+
assert_eq!(
167+
"Bar {
168+
foo: Foo {
169+
bar: true,
170+
baz: 10/20,
171+
..
172+
},
173+
hello: \"world\",
174+
..
175+
}",
176+
format!("{:#?}", Bar));
177+
}
178+
96179
}
97180

98181
mod debug_tuple {

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(core_private_bignum)]
66
#![feature(core_private_diy_float)]
77
#![feature(debug_map_key_value)]
8+
#![feature(debug_non_exhaustive)]
89
#![feature(dec2flt)]
910
#![feature(exact_size_is_empty)]
1011
#![feature(fixed_size_array)]

src/librustc/ich/mod.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@ mod impls_hir;
1212
mod impls_ty;
1313
mod impls_syntax;
1414

15-
pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
16-
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
17-
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
18-
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
19-
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
20-
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
21-
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;
22-
2315
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
2416
sym::cfg,
25-
ATTR_IF_THIS_CHANGED,
26-
ATTR_THEN_THIS_WOULD_NEED,
27-
ATTR_DIRTY,
28-
ATTR_CLEAN,
29-
ATTR_PARTITION_REUSED,
30-
ATTR_PARTITION_CODEGENED,
31-
ATTR_EXPECTED_CGU_REUSE,
17+
sym::rustc_if_this_changed,
18+
sym::rustc_then_this_would_need,
19+
sym::rustc_dirty,
20+
sym::rustc_clean,
21+
sym::rustc_partition_reused,
22+
sym::rustc_partition_codegened,
23+
sym::rustc_expected_cgu_reuse,
3224
];

src/librustc_incremental/assert_dep_graph.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ use rustc_data_structures::graph::implementation::{
4444
};
4545
use rustc::hir;
4646
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
47-
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
4847
use std::env;
4948
use std::fs::{self, File};
5049
use std::io::Write;
51-
use syntax::ast;
50+
use syntax::{ast, symbol::sym};
5251
use syntax_pos::Span;
5352

5453
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
@@ -78,7 +77,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
7877
assert!(tcx.sess.opts.debugging_opts.query_dep_graph,
7978
"cannot use the `#[{}]` or `#[{}]` annotations \
8079
without supplying `-Z query-dep-graph`",
81-
ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED);
80+
sym::rustc_if_this_changed, sym::rustc_then_this_would_need);
8281
}
8382

8483
// Check paths.
@@ -114,7 +113,7 @@ impl IfThisChanged<'tcx> {
114113
let def_id = self.tcx.hir().local_def_id(hir_id);
115114
let def_path_hash = self.tcx.def_path_hash(def_id);
116115
for attr in attrs {
117-
if attr.check_name(ATTR_IF_THIS_CHANGED) {
116+
if attr.check_name(sym::rustc_if_this_changed) {
118117
let dep_node_interned = self.argument(attr);
119118
let dep_node = match dep_node_interned {
120119
None => def_path_hash.to_dep_node(DepKind::Hir),
@@ -130,7 +129,7 @@ impl IfThisChanged<'tcx> {
130129
}
131130
};
132131
self.if_this_changed.push((attr.span, def_id, dep_node));
133-
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
132+
} else if attr.check_name(sym::rustc_then_this_would_need) {
134133
let dep_node_interned = self.argument(attr);
135134
let dep_node = match dep_node_interned {
136135
Some(n) => {

src/librustc_incremental/assert_module_sources.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use rustc::ty::TyCtxt;
2828
use std::collections::BTreeSet;
2929
use syntax::ast;
3030
use syntax::symbol::{Symbol, sym};
31-
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
32-
ATTR_EXPECTED_CGU_REUSE};
3331

3432
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3533
tcx.dep_graph.with_ignore(|| {
@@ -62,11 +60,11 @@ struct AssertModuleSource<'tcx> {
6260

6361
impl AssertModuleSource<'tcx> {
6462
fn check_attr(&self, attr: &ast::Attribute) {
65-
let (expected_reuse, comp_kind) = if attr.check_name(ATTR_PARTITION_REUSED) {
63+
let (expected_reuse, comp_kind) = if attr.check_name(sym::rustc_partition_reused) {
6664
(CguReuse::PreLto, ComparisonKind::AtLeast)
67-
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
65+
} else if attr.check_name(sym::rustc_partition_codegened) {
6866
(CguReuse::No, ComparisonKind::Exact)
69-
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
67+
} else if attr.check_name(sym::rustc_expected_cgu_reuse) {
7068
match &*self.field(attr, sym::kind).as_str() {
7169
"no" => (CguReuse::No, ComparisonKind::Exact),
7270
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),

src/librustc_incremental/persist/dirty_clean.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc::hir::Node as HirNode;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2424
use rustc::hir::intravisit;
25-
use rustc::ich::{ATTR_DIRTY, ATTR_CLEAN};
2625
use rustc::ty::TyCtxt;
2726
use rustc_data_structures::fingerprint::Fingerprint;
2827
use rustc_data_structures::fx::FxHashSet;
@@ -224,7 +223,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
224223

225224
let mut all_attrs = FindAllAttrs {
226225
tcx,
227-
attr_names: vec![ATTR_DIRTY, ATTR_CLEAN],
226+
attr_names: vec![sym::rustc_dirty, sym::rustc_clean],
228227
found_attrs: vec![],
229228
};
230229
intravisit::walk_crate(&mut all_attrs, krate);
@@ -246,9 +245,9 @@ impl DirtyCleanVisitor<'tcx> {
246245
fn assertion_maybe(&mut self, item_id: hir::HirId, attr: &Attribute)
247246
-> Option<Assertion>
248247
{
249-
let is_clean = if attr.check_name(ATTR_DIRTY) {
248+
let is_clean = if attr.check_name(sym::rustc_dirty) {
250249
false
251-
} else if attr.check_name(ATTR_CLEAN) {
250+
} else if attr.check_name(sym::rustc_clean) {
252251
true
253252
} else {
254253
// skip: not rustc_clean/dirty

src/libstd/net/addr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hash;
44
use crate::io;
55
use crate::iter;
66
use crate::mem;
7-
use crate::net::{hton, ntoh, IpAddr, Ipv4Addr, Ipv6Addr};
7+
use crate::net::{htons, ntohs, IpAddr, Ipv4Addr, Ipv6Addr};
88
use crate::option;
99
use crate::slice;
1010
use crate::sys::net::netc as c;
@@ -276,7 +276,7 @@ impl SocketAddrV4 {
276276
SocketAddrV4 {
277277
inner: c::sockaddr_in {
278278
sin_family: c::AF_INET as c::sa_family_t,
279-
sin_port: hton(port),
279+
sin_port: htons(port),
280280
sin_addr: *ip.as_inner(),
281281
..unsafe { mem::zeroed() }
282282
},
@@ -326,7 +326,7 @@ impl SocketAddrV4 {
326326
/// ```
327327
#[stable(feature = "rust1", since = "1.0.0")]
328328
pub fn port(&self) -> u16 {
329-
ntoh(self.inner.sin_port)
329+
ntohs(self.inner.sin_port)
330330
}
331331

332332
/// Changes the port number associated with this socket address.
@@ -342,7 +342,7 @@ impl SocketAddrV4 {
342342
/// ```
343343
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
344344
pub fn set_port(&mut self, new_port: u16) {
345-
self.inner.sin_port = hton(new_port);
345+
self.inner.sin_port = htons(new_port);
346346
}
347347
}
348348

@@ -368,7 +368,7 @@ impl SocketAddrV6 {
368368
SocketAddrV6 {
369369
inner: c::sockaddr_in6 {
370370
sin6_family: c::AF_INET6 as c::sa_family_t,
371-
sin6_port: hton(port),
371+
sin6_port: htons(port),
372372
sin6_addr: *ip.as_inner(),
373373
sin6_flowinfo: flowinfo,
374374
sin6_scope_id: scope_id,
@@ -420,7 +420,7 @@ impl SocketAddrV6 {
420420
/// ```
421421
#[stable(feature = "rust1", since = "1.0.0")]
422422
pub fn port(&self) -> u16 {
423-
ntoh(self.inner.sin6_port)
423+
ntohs(self.inner.sin6_port)
424424
}
425425

426426
/// Changes the port number associated with this socket address.
@@ -436,7 +436,7 @@ impl SocketAddrV6 {
436436
/// ```
437437
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
438438
pub fn set_port(&mut self, new_port: u16) {
439-
self.inner.sin6_port = hton(new_port);
439+
self.inner.sin6_port = htons(new_port);
440440
}
441441

442442
/// Returns the flow information associated with this address.

0 commit comments

Comments
 (0)