Skip to content

Commit 8ccab7e

Browse files
committed
Auto merge of #47900 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests - Successful merges: #47838, #47840, #47844, #47874, #47875, #47876, #47884, #47886, #47889, #47890, #47891, #47795, #47677, #47893, #47895, #47552 - Failed merges:
2 parents 560a2f4 + af95302 commit 8ccab7e

Some content is hidden

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

43 files changed

+320
-48
lines changed

src/bootstrap/builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ impl<'a> Builder<'a> {
377377
self.ensure(Libdir { compiler, target })
378378
}
379379

380+
pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
381+
self.sysroot_libdir(compiler, compiler.host)
382+
.with_file_name("codegen-backends")
383+
}
384+
380385
/// Returns the compiler's libdir where it stores the dynamic libraries that
381386
/// it itself links against.
382387
///

src/bootstrap/compile.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,7 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
724724
//
725725
// Here we're looking for the output dylib of the `CodegenBackend` step and
726726
// we're copying that into the `codegen-backends` folder.
727-
let libdir = builder.sysroot_libdir(target_compiler, target);
728-
let dst = libdir.join("codegen-backends");
727+
let dst = builder.sysroot_codegen_backends(target_compiler);
729728
t!(fs::create_dir_all(&dst));
730729

731730
for backend in builder.config.rust_codegen_backends.iter() {

src/bootstrap/dist.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,9 @@ impl Step for Rustc {
435435
}
436436

437437
// Copy over the codegen backends
438-
let backends_src = builder.sysroot_libdir(compiler, host)
439-
.join("codegen-backends");
440-
let backends_dst = image.join("lib/rustlib")
441-
.join(&*host)
442-
.join("lib/codegen-backends");
438+
let backends_src = builder.sysroot_codegen_backends(compiler);
439+
let backends_rel = backends_src.strip_prefix(&src).unwrap();
440+
let backends_dst = image.join(&backends_rel);
443441
t!(fs::create_dir_all(&backends_dst));
444442
cp_r(&backends_src, &backends_dst);
445443

src/libcore/fmt/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ impl Display for ! {
15861586

15871587
#[stable(feature = "rust1", since = "1.0.0")]
15881588
impl Debug for bool {
1589+
#[inline]
15891590
fn fmt(&self, f: &mut Formatter) -> Result {
15901591
Display::fmt(self, f)
15911592
}
@@ -1748,6 +1749,7 @@ impl<T: Debug> Debug for [T] {
17481749

17491750
#[stable(feature = "rust1", since = "1.0.0")]
17501751
impl Debug for () {
1752+
#[inline]
17511753
fn fmt(&self, f: &mut Formatter) -> Result {
17521754
f.pad("()")
17531755
}

src/libcore/fmt/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ macro_rules! debug {
157157
($T:ident) => {
158158
#[stable(feature = "rust1", since = "1.0.0")]
159159
impl fmt::Debug for $T {
160+
#[inline]
160161
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161162
fmt::Display::fmt(self, f)
162163
}

src/libcore/iter/mod.rs

+44
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ use fmt;
307307
use iter_private::TrustedRandomAccess;
308308
use ops::Try;
309309
use usize;
310+
use intrinsics;
310311

311312
#[stable(feature = "rust1", since = "1.0.0")]
312313
pub use self::iterator::Iterator;
@@ -694,6 +695,49 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
694695
(f(inner_hint.0), inner_hint.1.map(f))
695696
}
696697
}
698+
699+
#[inline]
700+
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
701+
if self.first_take {
702+
self.first_take = false;
703+
let first = self.iter.next();
704+
if n == 0 {
705+
return first;
706+
}
707+
n -= 1;
708+
}
709+
// n and self.step are indices, we need to add 1 to get the amount of elements
710+
// When calling `.nth`, we need to subtract 1 again to convert back to an index
711+
// step + 1 can't overflow because `.step_by` sets `self.step` to `step - 1`
712+
let mut step = self.step + 1;
713+
// n + 1 could overflow
714+
// thus, if n is usize::MAX, instead of adding one, we call .nth(step)
715+
if n == usize::MAX {
716+
self.iter.nth(step - 1);
717+
} else {
718+
n += 1;
719+
}
720+
721+
// overflow handling
722+
loop {
723+
let mul = n.checked_mul(step);
724+
if unsafe { intrinsics::likely(mul.is_some()) } {
725+
return self.iter.nth(mul.unwrap() - 1);
726+
}
727+
let div_n = usize::MAX / n;
728+
let div_step = usize::MAX / step;
729+
let nth_n = div_n * n;
730+
let nth_step = div_step * step;
731+
let nth = if nth_n > nth_step {
732+
step -= div_n;
733+
nth_n
734+
} else {
735+
n -= div_step;
736+
nth_step
737+
};
738+
self.iter.nth(nth - 1);
739+
}
740+
}
697741
}
698742

699743
// StepBy can only make the iterator shorter, so the len will still fit.

src/libcore/tests/iter.rs

+62
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,68 @@ fn test_iterator_step_by() {
161161
assert_eq!(it.next(), None);
162162
}
163163

164+
#[test]
165+
fn test_iterator_step_by_nth() {
166+
let mut it = (0..16).step_by(5);
167+
assert_eq!(it.nth(0), Some(0));
168+
assert_eq!(it.nth(0), Some(5));
169+
assert_eq!(it.nth(0), Some(10));
170+
assert_eq!(it.nth(0), Some(15));
171+
assert_eq!(it.nth(0), None);
172+
173+
let it = (0..18).step_by(5);
174+
assert_eq!(it.clone().nth(0), Some(0));
175+
assert_eq!(it.clone().nth(1), Some(5));
176+
assert_eq!(it.clone().nth(2), Some(10));
177+
assert_eq!(it.clone().nth(3), Some(15));
178+
assert_eq!(it.clone().nth(4), None);
179+
assert_eq!(it.clone().nth(42), None);
180+
}
181+
182+
#[test]
183+
fn test_iterator_step_by_nth_overflow() {
184+
#[cfg(target_pointer_width = "8")]
185+
type Bigger = u16;
186+
#[cfg(target_pointer_width = "16")]
187+
type Bigger = u32;
188+
#[cfg(target_pointer_width = "32")]
189+
type Bigger = u64;
190+
#[cfg(target_pointer_width = "64")]
191+
type Bigger = u128;
192+
193+
#[derive(Clone)]
194+
struct Test(Bigger);
195+
impl<'a> Iterator for &'a mut Test {
196+
type Item = i32;
197+
fn next(&mut self) -> Option<Self::Item> { Some(21) }
198+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
199+
self.0 += n as Bigger + 1;
200+
Some(42)
201+
}
202+
}
203+
204+
let mut it = Test(0);
205+
let root = usize::MAX >> (::std::mem::size_of::<usize>() * 8 / 2);
206+
let n = root + 20;
207+
(&mut it).step_by(n).nth(n);
208+
assert_eq!(it.0, n as Bigger * n as Bigger);
209+
210+
// large step
211+
let mut it = Test(0);
212+
(&mut it).step_by(usize::MAX).nth(5);
213+
assert_eq!(it.0, (usize::MAX as Bigger) * 5);
214+
215+
// n + 1 overflows
216+
let mut it = Test(0);
217+
(&mut it).step_by(2).nth(usize::MAX);
218+
assert_eq!(it.0, (usize::MAX as Bigger) * 2);
219+
220+
// n + 1 overflows
221+
let mut it = Test(0);
222+
(&mut it).step_by(1).nth(usize::MAX);
223+
assert_eq!(it.0, (usize::MAX as Bigger) * 1);
224+
}
225+
164226
#[test]
165227
#[should_panic]
166228
fn test_iterator_step_by_zero() {

src/libpanic_abort/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#![feature(libc)]
2828
#![feature(panic_runtime)]
2929
#![feature(staged_api)]
30+
#![feature(rustc_attrs)]
3031

3132
// Rust's "try" function, but if we're aborting on panics we just call the
3233
// function as there's nothing else we need to do here.
3334
#[no_mangle]
35+
#[rustc_std_internal_symbol]
3436
pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
3537
data: *mut u8,
3638
_data_ptr: *mut usize,
@@ -50,6 +52,7 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
5052
// will kill us with an illegal instruction, which will do a good enough job for
5153
// now hopefully.
5254
#[no_mangle]
55+
#[rustc_std_internal_symbol]
5356
pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
5457
abort();
5558

src/librustc/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pointers for understanding them better.
176176
- `'gcx` -- the lifetime of the global arena (see `librustc/ty`).
177177
- generics -- the set of generic type parameters defined on a type or item
178178
- ICE -- internal compiler error. When the compiler crashes.
179+
- ICH -- incremental compilation hash.
179180
- infcx -- the inference context (see `librustc/infer`)
180181
- MIR -- the **Mid-level IR** that is created after type-checking for use by borrowck and trans.
181182
Defined in the `src/librustc/mir/` module, but much of the code that manipulates it is

src/librustc/dep_graph/dep_node.rs

+3
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ define_dep_nodes!( <'tcx>
639639
[] TargetFeaturesEnabled(DefId),
640640

641641
[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
642+
643+
[] GetSymbolExportLevel(DefId),
644+
642645
);
643646

644647
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/traits/error_reporting.rs

+5
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
831831
span,
832832
node: hir::ImplItemKind::Method(hir::MethodSig { ref decl, .. }, _),
833833
..
834+
}) |
835+
hir::map::NodeTraitItem(&hir::TraitItem {
836+
span,
837+
node: hir::TraitItemKind::Method(hir::MethodSig { ref decl, .. }, _),
838+
..
834839
}) => {
835840
(self.tcx.sess.codemap().def_span(span), decl.inputs.iter()
836841
.map(|arg| match arg.clone().into_inner().node {

src/librustc/ty/maps/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ define_maps! { <'tcx>
343343
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
344344
[] fn export_name: ExportName(DefId) -> Option<Symbol>,
345345
[] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
346+
[] fn symbol_export_level: GetSymbolExportLevel(DefId) -> SymbolExportLevel,
346347
[] fn is_translated_function: IsTranslatedFunction(DefId) -> bool,
347348
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
348349
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,

src/librustc/ty/maps/plumbing.rs

+2
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
921921

922922
DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
923923
DepKind::TargetFeaturesEnabled => { force!(target_features_enabled, def_id!()); }
924+
925+
DepKind::GetSymbolExportLevel => { force!(symbol_export_level, def_id!()); }
924926
}
925927

926928
true

src/librustc_back/target/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ pub struct TargetOptions {
468468

469469
/// The codegen backend to use for this target, typically "llvm"
470470
pub codegen_backend: String,
471+
472+
/// The default visibility for symbols in this target should be "hidden"
473+
/// rather than "default"
474+
pub default_hidden_visibility: bool,
471475
}
472476

473477
impl Default for TargetOptions {
@@ -538,6 +542,7 @@ impl Default for TargetOptions {
538542
no_builtins: false,
539543
i128_lowering: false,
540544
codegen_backend: "llvm".to_string(),
545+
default_hidden_visibility: false,
541546
}
542547
}
543548
}
@@ -785,6 +790,7 @@ impl Target {
785790
key!(singlethread, bool);
786791
key!(no_builtins, bool);
787792
key!(codegen_backend);
793+
key!(default_hidden_visibility, bool);
788794

789795
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
790796
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -982,6 +988,7 @@ impl ToJson for Target {
982988
target_option_val!(singlethread);
983989
target_option_val!(no_builtins);
984990
target_option_val!(codegen_backend);
991+
target_option_val!(default_hidden_visibility);
985992

986993
if default.abi_blacklist != self.options.abi_blacklist {
987994
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

src/librustc_back/target/msp430_none_elf.rs

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ pub fn target() -> TargetResult {
5353
// don't want to invoke that many gcc instances.
5454
default_codegen_units: Some(1),
5555

56+
// Since MSP430 doesn't meaningfully support faulting on illegal
57+
// instructions, LLVM generates a call to abort() function instead
58+
// of a trap instruction. Such calls are 4 bytes long, and that is
59+
// too much overhead for such small target.
60+
trap_unreachable: false,
61+
5662
.. Default::default( )
5763
}
5864
})

src/librustc_back/target/wasm32_unknown_unknown.rs

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub fn target() -> Result<Target, String> {
8383
// performing LTO with compiler-builtins.
8484
no_builtins: true,
8585

86+
// no dynamic linking, no need for default visibility!
87+
default_hidden_visibility: true,
88+
8689
.. Default::default()
8790
};
8891
Ok(Target {

src/librustc_const_eval/check_match.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,27 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
127127
}
128128
}
129129

130+
130131
impl<'a, 'tcx> PatternContext<'a, 'tcx> {
131132
fn report_inlining_errors(&self, pat_span: Span) {
132133
for error in &self.errors {
133134
match *error {
134135
PatternError::StaticInPattern(span) => {
135-
span_err!(self.tcx.sess, span, E0158,
136-
"statics cannot be referenced in patterns");
136+
self.span_e0158(span, "statics cannot be referenced in patterns")
137+
}
138+
PatternError::AssociatedConstInPattern(span) => {
139+
self.span_e0158(span, "associated consts cannot be referenced in patterns")
137140
}
138141
PatternError::ConstEval(ref err) => {
139142
err.report(self.tcx, pat_span, "pattern");
140143
}
141144
}
142145
}
143146
}
147+
148+
fn span_e0158(&self, span: Span, text: &str) {
149+
span_err!(self.tcx.sess, span, E0158, "{}", text)
150+
}
144151
}
145152

146153
impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {

src/librustc_const_eval/pattern.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use syntax_pos::Span;
2727

2828
#[derive(Clone, Debug)]
2929
pub enum PatternError<'tcx> {
30+
AssociatedConstInPattern(Span),
3031
StaticInPattern(Span),
3132
ConstEval(ConstEvalErr<'tcx>),
3233
}
@@ -635,6 +636,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
635636
-> Pattern<'tcx> {
636637
let ty = self.tables.node_id_to_type(id);
637638
let def = self.tables.qpath_def(qpath, id);
639+
let is_associated_const = match def {
640+
Def::AssociatedConst(_) => true,
641+
_ => false,
642+
};
638643
let kind = match def {
639644
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
640645
let substs = self.tables.node_substs(id);
@@ -656,7 +661,11 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
656661
return pat;
657662
}
658663
None => {
659-
self.errors.push(PatternError::StaticInPattern(span));
664+
self.errors.push(if is_associated_const {
665+
PatternError::AssociatedConstInPattern(span)
666+
} else {
667+
PatternError::StaticInPattern(span)
668+
});
660669
PatternKind::Wild
661670
}
662671
}

0 commit comments

Comments
 (0)