Skip to content

Commit 6867dd2

Browse files
committed
Auto merge of rust-lang#89230 - workingjubilee:rollup-1swktdq, r=workingjubilee
Rollup of 8 pull requests Successful merges: - rust-lang#88893 (Add 1.56.0 release notes) - rust-lang#89001 (Be explicit about using Binder::dummy) - rust-lang#89072 (Avoid a couple of Symbol::as_str calls in cg_llvm ) - rust-lang#89104 (Simplify scoped_thread) - rust-lang#89208 ([rfc 2229] Drop fully captured upvars in the same order as the regular drop code) - rust-lang#89210 (Add missing time complexities to linked_list.rs) - rust-lang#89217 (Enable "generate-link-to-definition" option on rust tools docs as well) - rust-lang#89221 (Give better error for `macro_rules! name!`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 043972f + 6f31fa5 commit 6867dd2

File tree

52 files changed

+863
-153
lines changed

Some content is hidden

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

52 files changed

+863
-153
lines changed

RELEASES.md

+185
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,188 @@
1+
Rust 1.56.0 (2021-10-21)
2+
========================
3+
4+
Language
5+
--------
6+
7+
- [The 2021 Edition is now stable.][rust#88100]
8+
See [the edition guide][rust-2021-edition-guide] for more details.
9+
- [You can now specify explicit discriminant values on any Rust enum.][rust#86860]
10+
- [The pattern in `binding @ pattern` can now also introduce new bindings.][rust#85305]
11+
- [Union field access is permitted in `const fn`.][rust#85769]
12+
13+
[rust-2021-edition-guide]: https://doc.rust-lang.org/nightly/edition-guide/rust-2021/index.html
14+
15+
Compiler
16+
--------
17+
18+
- [Upgrade to LLVM 13.][rust#87570]
19+
- [Support memory, address, and thread sanitizers on aarch64-unknown-freebsd.][rust#88023]
20+
- [Allow specifying an deployment target version for all iOS targets][rust#87699]
21+
- [Warnings can be forced on with `--force-warn`.][rust#87472]
22+
This feature is primarily intended for usage by `cargo fix`, rather than end users.
23+
- [Promote `aarch64-apple-ios-sim` to Tier 2\*.][rust#87760]
24+
- [Add `powerpc-unknown-freebsd` at Tier 3\*.][rust#87370]
25+
26+
\* Refer to Rust's [platform support page][platform-support-doc] for more
27+
information on Rust's tiered platform support.
28+
29+
Libraries
30+
---------
31+
32+
- [Allow writing of incomplete UTF-8 sequences via stdout/stderr on Windows.][rust#83342]
33+
The Windows console still requires valid Unicode, but this change allows
34+
splitting a UTF-8 character across multiple write calls. This allows, for
35+
instance, programs that just read and write data buffers (e.g. copying a file
36+
to stdout) without regard for Unicode or character boundaries.
37+
- [Prefer `AtomicU{64,128}` over Mutex for Instant backsliding protection.][rust#83093]
38+
For this use case, atomics scale much better under contention.
39+
- [Implement `Extend<(A, B)>` for `(Extend<A>, Extend<B>)`][rust#85835]
40+
- [impl Default, Copy, Clone for std::io::Sink and std::io::Empty][rust#86744]
41+
- [`impl From<[(K, V); N]>` for all collections.][rust#84111]
42+
- [Remove `P: Unpin` bound on impl Future for Pin.][rust#81363]
43+
- [Treat invalid environment variable names as non-existent.][rust#86183]
44+
Previously, the environment functions would panic if given a variable name
45+
with an internal null character or equal sign (`=`). Now, these functions will
46+
just treat such names as non-existent variables, since the OS cannot represent
47+
the existence of a variable with such a name.
48+
49+
Stabilised APIs
50+
---------------
51+
52+
- [`std::os::unix::fs::chroot`]
53+
- [`Iterator::intersperse`]
54+
- [`Iterator::intersperse_with`]
55+
- [`UnsafeCell::raw_get`]
56+
- [`BufWriter::into_parts`]
57+
- [`core::panic::{UnwindSafe, RefUnwindSafe, AssertUnwindSafe}`]
58+
These APIs were previously stable in `std`, but are now also available in `core`.
59+
- [`Vec::shrink_to`]
60+
- [`String::shrink_to`]
61+
- [`OsString::shrink_to`]
62+
- [`PathBuf::shrink_to`]
63+
- [`BinaryHeap::shrink_to`]
64+
- [`VecDeque::shrink_to`]
65+
- [`HashMap::shrink_to`]
66+
- [`HashSet::shrink_to`]
67+
- [`task::ready!`]
68+
69+
These APIs are now usable in const contexts:
70+
71+
- [`std::mem::transmute`]
72+
- [`[T]::first`][`slice::first`]
73+
- [`[T]::split_first`][`slice::split_first`]
74+
- [`[T]::last`][`slice::last`]
75+
- [`[T]::split_last`][`slice::split_last`]
76+
77+
Cargo
78+
-----
79+
80+
- [Cargo supports specifying a minimum supported Rust version in Cargo.toml.][`rust-version`]
81+
This has no effect at present on dependency version selection.
82+
We encourage crates to specify their minimum supported Rust version, and we encourage CI systems
83+
that support Rust code to include a crate's specified minimum version in the text matrix for that
84+
crate by default.
85+
86+
Compatibility notes
87+
-------------------
88+
89+
- [Update to new argument parsing rules on Windows.][rust#87580]
90+
This adjusts Rust's standard library to match the behavior of the standard
91+
libraries for C/C++. The rules have changed slightly over time, and this PR
92+
brings us to the latest set of rules (changed in 2008).
93+
- [Disallow the aapcs calling convention on aarch64][rust#88399]
94+
This was already not supported by LLVM; this change surfaces this lack of
95+
support with a better error message.
96+
- [Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default][rust#87385]
97+
- [Warn when an escaped newline skips multiple lines.][rust#87671]
98+
- [Calls to `libc::getpid` / `std::process::id` from `Command::pre_exec`
99+
may return different values on glibc <= 2.24.][rust#81825]
100+
Rust now invokes the `clone3` system call directly, when available, to use new functionality
101+
available via that system call. Older versions of glibc cache the result of `getpid`, and only
102+
update that cache when calling glibc's clone/fork functions, so a direct system call bypasses
103+
that cache update. glibc 2.25 and newer no longer cache `getpid` for exactly this reason.
104+
105+
Internal changes
106+
----------------
107+
These changes provide no direct user facing benefits, but represent significant
108+
improvements to the internals and overall performance of rustc
109+
and related tools.
110+
111+
- [LLVM is compiled with PGO in published x86_64-unknown-linux-gnu artifacts.][rust#88069]
112+
This improves the performance of most Rust builds.
113+
- [Unify representation of macros in internal data structures.][rust#88019]
114+
This change fixes a host of bugs with the handling of macros by the compiler,
115+
as well as rustdoc.
116+
117+
[`std::os::unix::fs::chroot`]: https://doc.rust-lang.org/stable/std/os/unix/fs/fn.chroot.html
118+
[`Iterator::intersperse`]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.intersperse
119+
[`Iterator::intersperse_with`]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.intersperse
120+
[`UnsafeCell::raw_get`]: https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html#method.raw_get
121+
[`BufWriter::into_parts`]: https://doc.rust-lang.org/stable/std/io/struct.BufWriter.html#method.into_parts
122+
[`core::panic::{UnwindSafe, RefUnwindSafe, AssertUnwindSafe}`]: https://github.com/rust-lang/rust/pull/84662
123+
[`Vec::shrink_to`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.shrink_to
124+
[`String::shrink_to`]: https://doc.rust-lang.org/stable/std/string/struct.String.html#method.shrink_to
125+
[`OsString::shrink_to`]: https://doc.rust-lang.org/stable/std/ffi/struct.OsString.html#method.shrink_to
126+
[`PathBuf::shrink_to`]: https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#method.shrink_to
127+
[`BinaryHeap::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html#method.shrink_to
128+
[`VecDeque::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.shrink_to
129+
[`HashMap::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.shrink_to
130+
[`HashSet::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_set/struct.HashSet.html#method.shrink_to
131+
[`task::ready!`]: https://doc.rust-lang.org/stable/std/task/macro.ready.html
132+
[`std::mem::transmute`]: https://doc.rust-lang.org/stable/std/mem/fn.transmute.html
133+
[`slice::first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first
134+
[`slice::split_first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first
135+
[`slice::last`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.last
136+
[`slice::split_last`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last
137+
[`rust-version`]: https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field
138+
[rust#87671]: https://github.com/rust-lang/rust/pull/87671
139+
[rust#86183]: https://github.com/rust-lang/rust/pull/86183
140+
[rust#87385]: https://github.com/rust-lang/rust/pull/87385
141+
[rust#88100]: https://github.com/rust-lang/rust/pull/88100
142+
[rust#86860]: https://github.com/rust-lang/rust/pull/86860
143+
[rust#84039]: https://github.com/rust-lang/rust/pull/84039
144+
[rust#86492]: https://github.com/rust-lang/rust/pull/86492
145+
[rust#88363]: https://github.com/rust-lang/rust/pull/88363
146+
[rust#85305]: https://github.com/rust-lang/rust/pull/85305
147+
[rust#87832]: https://github.com/rust-lang/rust/pull/87832
148+
[rust#88069]: https://github.com/rust-lang/rust/pull/88069
149+
[rust#87472]: https://github.com/rust-lang/rust/pull/87472
150+
[rust#87699]: https://github.com/rust-lang/rust/pull/87699
151+
[rust#87570]: https://github.com/rust-lang/rust/pull/87570
152+
[rust#88023]: https://github.com/rust-lang/rust/pull/88023
153+
[rust#87760]: https://github.com/rust-lang/rust/pull/87760
154+
[rust#87370]: https://github.com/rust-lang/rust/pull/87370
155+
[rust#87580]: https://github.com/rust-lang/rust/pull/87580
156+
[rust#83342]: https://github.com/rust-lang/rust/pull/83342
157+
[rust#83093]: https://github.com/rust-lang/rust/pull/83093
158+
[rust#88177]: https://github.com/rust-lang/rust/pull/88177
159+
[rust#88548]: https://github.com/rust-lang/rust/pull/88548
160+
[rust#88551]: https://github.com/rust-lang/rust/pull/88551
161+
[rust#88299]: https://github.com/rust-lang/rust/pull/88299
162+
[rust#88220]: https://github.com/rust-lang/rust/pull/88220
163+
[rust#85835]: https://github.com/rust-lang/rust/pull/85835
164+
[rust#86879]: https://github.com/rust-lang/rust/pull/86879
165+
[rust#86744]: https://github.com/rust-lang/rust/pull/86744
166+
[rust#84662]: https://github.com/rust-lang/rust/pull/84662
167+
[rust#86593]: https://github.com/rust-lang/rust/pull/86593
168+
[rust#81050]: https://github.com/rust-lang/rust/pull/81050
169+
[rust#81363]: https://github.com/rust-lang/rust/pull/81363
170+
[rust#84111]: https://github.com/rust-lang/rust/pull/84111
171+
[rust#85769]: https://github.com/rust-lang/rust/pull/85769#issuecomment-854363720
172+
[rust#88490]: https://github.com/rust-lang/rust/pull/88490
173+
[rust#88269]: https://github.com/rust-lang/rust/pull/88269
174+
[rust#84176]: https://github.com/rust-lang/rust/pull/84176
175+
[rust#88399]: https://github.com/rust-lang/rust/pull/88399
176+
[rust#88227]: https://github.com/rust-lang/rust/pull/88227
177+
[rust#88200]: https://github.com/rust-lang/rust/pull/88200
178+
[rust#82776]: https://github.com/rust-lang/rust/pull/82776
179+
[rust#88077]: https://github.com/rust-lang/rust/pull/88077
180+
[rust#87728]: https://github.com/rust-lang/rust/pull/87728
181+
[rust#87050]: https://github.com/rust-lang/rust/pull/87050
182+
[rust#87619]: https://github.com/rust-lang/rust/pull/87619
183+
[rust#81825]: https://github.com/rust-lang/rust/pull/81825#issuecomment-808406918
184+
[rust#88019]: https://github.com/rust-lang/rust/pull/88019
185+
1186
Version 1.55.0 (2021-09-09)
2187
============================
3188

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8989
category: ConstraintCategory,
9090
) {
9191
self.prove_predicates(
92-
Some(ty::PredicateKind::Trait(ty::TraitPredicate {
92+
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
9393
trait_ref,
9494
constness: ty::BoundConstness::NotConst,
95-
})),
95+
}))),
9696
locations,
9797
category,
9898
);

compiler/rustc_borrowck/src/type_check/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10801080
}
10811081

10821082
self.prove_predicate(
1083-
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
1083+
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into()))
1084+
.to_predicate(self.tcx()),
10841085
Locations::All(span),
10851086
ConstraintCategory::TypeAnnotation,
10861087
);
@@ -1316,7 +1317,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13161317
obligations.obligations.push(traits::Obligation::new(
13171318
ObligationCause::dummy(),
13181319
param_env,
1319-
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
1320+
ty::Binder::dummy(ty::PredicateKind::WellFormed(revealed_ty.into()))
1321+
.to_predicate(infcx.tcx),
13201322
));
13211323
obligations.add(
13221324
infcx
@@ -1599,7 +1601,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15991601
self.check_call_dest(body, term, &sig, destination, term_location);
16001602

16011603
self.prove_predicates(
1602-
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
1604+
sig.inputs_and_output
1605+
.iter()
1606+
.map(|ty| ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))),
16031607
term_location.to_locations(),
16041608
ConstraintCategory::Boring,
16051609
);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9696
let arg_tys = sig.inputs();
9797
let ret_ty = sig.output();
9898
let name = tcx.item_name(def_id);
99-
let name_str = &*name.as_str();
10099

101100
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
102101
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
@@ -230,9 +229,14 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
230229
&[args[0].immediate(), y],
231230
)
232231
}
233-
sym::ctlz_nonzero | sym::cttz_nonzero => {
232+
sym::ctlz_nonzero => {
234233
let y = self.const_bool(true);
235-
let llvm_name = &format!("llvm.{}.i{}", &name_str[..4], width);
234+
let llvm_name = &format!("llvm.ctlz.i{}", width);
235+
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
236+
}
237+
sym::cttz_nonzero => {
238+
let y = self.const_bool(true);
239+
let llvm_name = &format!("llvm.cttz.i{}", width);
236240
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
237241
}
238242
sym::ctpop => self.call_intrinsic(
@@ -353,7 +357,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
353357
return;
354358
}
355359

356-
_ if name_str.starts_with("simd_") => {
360+
_ if name.as_str().starts_with("simd_") => {
357361
match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) {
358362
Ok(llval) => llval,
359363
Err(()) => return,
@@ -843,7 +847,6 @@ fn generic_simd_intrinsic(
843847
let sig =
844848
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
845849
let arg_tys = sig.inputs();
846-
let name_str = &*name.as_str();
847850

848851
if name == sym::simd_select_bitmask {
849852
let in_ty = arg_tys[0];
@@ -917,7 +920,7 @@ fn generic_simd_intrinsic(
917920
));
918921
}
919922

920-
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
923+
if let Some(stripped) = name.as_str().strip_prefix("simd_shuffle") {
921924
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
922925
// If there is no suffix, use the index array length.
923926
let n: u64 = if stripped.is_empty() {

compiler/rustc_expand/src/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl server::Literal for Rustc<'_> {
577577
}
578578

579579
// Synthesize a new symbol that includes the minus sign.
580-
let symbol = Symbol::intern(&s[..1 + lit.symbol.len()]);
580+
let symbol = Symbol::intern(&s[..1 + lit.symbol.as_str().len()]);
581581
lit = token::Lit::new(lit.kind, symbol, lit.suffix);
582582
}
583583

compiler/rustc_infer/src/infer/canonical/query_response.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,10 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
669669
self.obligations.push(Obligation {
670670
cause: self.cause.clone(),
671671
param_env: self.param_env,
672-
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
673-
.to_predicate(self.infcx.tcx),
672+
predicate: ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
673+
sup, sub,
674+
)))
675+
.to_predicate(self.infcx.tcx),
674676
recursion_depth: 0,
675677
});
676678
}

compiler/rustc_infer/src/infer/combine.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
360360
self.obligations.push(Obligation::new(
361361
self.trace.cause.clone(),
362362
self.param_env,
363-
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
363+
ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into()))
364+
.to_predicate(self.infcx.tcx),
364365
));
365366
}
366367

@@ -463,7 +464,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
463464
self.obligations.push(Obligation::new(
464465
self.trace.cause.clone(),
465466
self.param_env,
466-
predicate.to_predicate(self.tcx()),
467+
ty::Binder::dummy(predicate).to_predicate(self.tcx()),
467468
));
468469
}
469470
}

compiler/rustc_infer/src/infer/sub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
9797
self.fields.obligations.push(Obligation::new(
9898
self.fields.trace.cause.clone(),
9999
self.fields.param_env,
100-
ty::PredicateKind::Subtype(ty::SubtypePredicate {
100+
ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate {
101101
a_is_expected: self.a_is_expected,
102102
a,
103103
b,
104-
})
104+
}))
105105
.to_predicate(self.tcx()),
106106
));
107107

compiler/rustc_infer/src/traits/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
3535
cause,
3636
recursion_depth: 0,
3737
param_env,
38-
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
38+
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
3939
},
4040
);
4141
}

compiler/rustc_infer/src/traits/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl Elaborator<'tcx> {
231231
None
232232
}
233233
})
234+
.map(ty::Binder::dummy)
234235
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
235236
.filter(|&predicate| visited.insert(predicate))
236237
.map(|predicate| {

compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(bool_to_option)]
22
#![feature(box_patterns)]
33
#![feature(internal_output_capture)]
4+
#![feature(thread_spawn_unchecked)]
45
#![feature(nll)]
56
#![feature(once_cell)]
67
#![recursion_limit = "256"]

compiler/rustc_interface/src/util.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,11 @@ fn get_stack_size() -> Option<usize> {
115115
/// for `'static` bounds.
116116
#[cfg(not(parallel_compiler))]
117117
pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
118-
struct Ptr(*mut ());
119-
unsafe impl Send for Ptr {}
120-
unsafe impl Sync for Ptr {}
121-
122-
let mut f = Some(f);
123-
let run = Ptr(&mut f as *mut _ as *mut ());
124-
let mut result = None;
125-
let result_ptr = Ptr(&mut result as *mut _ as *mut ());
126-
127-
let thread = cfg.spawn(move || {
128-
let _ = (&run, &result_ptr);
129-
let run = unsafe { (*(run.0 as *mut Option<F>)).take().unwrap() };
130-
let result = unsafe { &mut *(result_ptr.0 as *mut Option<R>) };
131-
*result = Some(run());
132-
});
133-
134-
match thread.unwrap().join() {
135-
Ok(()) => result.unwrap(),
136-
Err(p) => panic::resume_unwind(p),
118+
// SAFETY: join() is called immediately, so any closure captures are still
119+
// alive.
120+
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
121+
Ok(v) => v,
122+
Err(e) => panic::resume_unwind(e),
137123
}
138124
}
139125

0 commit comments

Comments
 (0)