Skip to content

Commit d297b19

Browse files
committed
Auto merge of #67721 - JohnTitor:rollup-o8zm4r9, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #64273 (Stabilize attribute macros on inline modules) - #67287 (typeck: note other end-point when checking range pats) - #67564 (docs: Iterator adapters have unspecified results after a panic) - #67622 (Some keyword documentation.) - #67657 (Clean up const-hack PRs now that const if / match exist.) - #67677 (resolve: Minor cleanup of duplicate macro reexports) - #67687 (Do not ICE on lifetime error involving closures) - #67698 (Move reachable_set and diagnostic_items to librustc_passes.) - #67701 (tidy: Enforce formatting rather than just check it if `--bless` is specified) - #67715 (Typo fix) Failed merges: r? @ghost
2 parents 214548b + dcc30ac commit d297b19

40 files changed

+333
-262
lines changed

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl Step for Tidy {
736736

737737
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
738738
builder.info("fmt check");
739-
crate::format::format(&builder.build, true);
739+
crate::format::format(&builder.build, !builder.config.cmd.bless());
740740
}
741741
}
742742

src/libcore/iter/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@
216216
//! Common iterator adapters include [`map`], [`take`], and [`filter`].
217217
//! For more, see their documentation.
218218
//!
219+
//! If an iterator adapter panics, the iterator will be in an unspecified (but
220+
//! memory safe) state. This state is also not guaranteed to stay the same
221+
//! across versions of Rust, so you should avoid relying on the exact values
222+
//! returned by an iterator which panicked.
223+
//!
219224
//! [`map`]: trait.Iterator.html#method.map
220225
//! [`take`]: trait.Iterator.html#method.take
221226
//! [`filter`]: trait.Iterator.html#method.filter

src/libcore/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#![feature(cfg_target_has_atomic)]
7272
#![feature(concat_idents)]
7373
#![feature(const_fn)]
74+
#![feature(const_if_match)]
75+
#![feature(const_panic)]
7476
#![feature(const_fn_union)]
7577
#![feature(const_generics)]
7678
#![feature(const_ptr_offset_from)]

src/libcore/mem/manually_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<T: ?Sized> ManuallyDrop<T> {
121121
/// This function runs the destructor of the contained value and thus the wrapped value
122122
/// now represents uninitialized data. It is up to the user of this method to ensure the
123123
/// uninitialized data is not actually used.
124-
/// In particular, this function can only be called called at most once
124+
/// In particular, this function can only be called at most once
125125
/// for a given instance of `ManuallyDrop<T>`.
126126
///
127127
/// [`ManuallyDrop::into_inner`]: #method.into_inner

src/libcore/num/mod.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1416,18 +1416,14 @@ $EndFeature, "
14161416
```"),
14171417
#[stable(feature = "no_panic_abs", since = "1.13.0")]
14181418
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
1419+
#[allow_internal_unstable(const_if_match)]
14191420
#[inline]
14201421
pub const fn wrapping_abs(self) -> Self {
1421-
// sign is -1 (all ones) for negative numbers, 0 otherwise.
1422-
let sign = self >> ($BITS - 1);
1423-
// For positive self, sign == 0 so the expression is simply
1424-
// (self ^ 0).wrapping_sub(0) == self == abs(self).
1425-
//
1426-
// For negative self, self ^ sign == self ^ all_ones.
1427-
// But all_ones ^ self == all_ones - self == -1 - self.
1428-
// So for negative numbers, (self ^ sign).wrapping_sub(sign) is
1429-
// (-1 - self).wrapping_sub(-1) == -self == abs(self).
1430-
(self ^ sign).wrapping_sub(sign)
1422+
if self.is_negative() {
1423+
self.wrapping_neg()
1424+
} else {
1425+
self
1426+
}
14311427
}
14321428
}
14331429

@@ -1713,8 +1709,13 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self
17131709
#[inline]
17141710
#[stable(feature = "wrapping", since = "1.7.0")]
17151711
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
1712+
#[allow_internal_unstable(const_if_match)]
17161713
pub const fn overflowing_neg(self) -> (Self, bool) {
1717-
((!self).wrapping_add(1), self == Self::min_value())
1714+
if self == Self::min_value() {
1715+
(Self::min_value(), true)
1716+
} else {
1717+
(-self, false)
1718+
}
17181719
}
17191720
}
17201721

@@ -2041,7 +2042,11 @@ $EndFeature, "
20412042
#[rustc_const_unstable(feature = "const_int_sign", issue = "53718")]
20422043
#[inline]
20432044
pub const fn signum(self) -> Self {
2044-
(self > 0) as Self - (self < 0) as Self
2045+
match self {
2046+
n if n > 0 => 1,
2047+
0 => 0,
2048+
_ => -1,
2049+
}
20452050
}
20462051
}
20472052

src/libcore/ptr/const_ptr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,7 @@ impl<T: ?Sized> *const T {
288288
T: Sized,
289289
{
290290
let pointee_size = mem::size_of::<T>();
291-
let ok = 0 < pointee_size && pointee_size <= isize::max_value() as usize;
292-
// assert that the pointee size is valid in a const eval compatible way
293-
// FIXME: do this with a real assert at some point
294-
[()][(!ok) as usize];
291+
assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize);
295292
intrinsics::ptr_offset_from(self, origin)
296293
}
297294

src/librustc/lib.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,7 @@ pub mod hir;
9595
pub mod ich;
9696
pub mod infer;
9797
pub mod lint;
98-
99-
pub mod middle {
100-
pub mod cstore;
101-
pub mod dependency_format;
102-
pub mod diagnostic_items;
103-
pub mod exported_symbols;
104-
pub mod free_region;
105-
pub mod lang_items;
106-
pub mod lib_features;
107-
pub mod privacy;
108-
pub mod reachable;
109-
pub mod recursion_limit;
110-
pub mod region;
111-
pub mod resolve_lifetime;
112-
pub mod stability;
113-
pub mod weak_lang_items;
114-
}
115-
98+
pub mod middle;
11699
pub mod mir;
117100
pub use rustc_session as session;
118101
pub mod traits;

src/librustc/middle/mod.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pub mod cstore;
2+
pub mod dependency_format;
3+
pub mod exported_symbols;
4+
pub mod free_region;
5+
pub mod lang_items;
6+
pub mod lib_features {
7+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use syntax::symbol::Symbol;
9+
10+
#[derive(HashStable)]
11+
pub struct LibFeatures {
12+
// A map from feature to stabilisation version.
13+
pub stable: FxHashMap<Symbol, Symbol>,
14+
pub unstable: FxHashSet<Symbol>,
15+
}
16+
17+
impl LibFeatures {
18+
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
19+
let mut all_features: Vec<_> = self
20+
.stable
21+
.iter()
22+
.map(|(f, s)| (*f, Some(*s)))
23+
.chain(self.unstable.iter().map(|f| (*f, None)))
24+
.collect();
25+
all_features.sort_unstable_by_key(|f| f.0.as_str());
26+
all_features
27+
}
28+
}
29+
}
30+
pub mod privacy;
31+
pub mod recursion_limit;
32+
pub mod region;
33+
pub mod resolve_lifetime;
34+
pub mod stability;
35+
pub mod weak_lang_items;

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ rustc_queries! {
510510
}
511511

512512
Other {
513-
query reachable_set(_: CrateNum) -> ReachableSet {
513+
query reachable_set(_: CrateNum) -> Lrc<HirIdSet> {
514514
desc { "reachability" }
515515
}
516516

src/librustc/ty/context.rs

-12
Original file line numberDiff line numberDiff line change
@@ -2751,22 +2751,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
27512751
assert_eq!(id, LOCAL_CRATE);
27522752
tcx.crate_name
27532753
};
2754-
providers.get_lib_features = |tcx, id| {
2755-
assert_eq!(id, LOCAL_CRATE);
2756-
tcx.arena.alloc(middle::lib_features::collect(tcx))
2757-
};
27582754
providers.get_lang_items = |tcx, id| {
27592755
assert_eq!(id, LOCAL_CRATE);
27602756
tcx.arena.alloc(middle::lang_items::collect(tcx))
27612757
};
2762-
providers.diagnostic_items = |tcx, id| {
2763-
assert_eq!(id, LOCAL_CRATE);
2764-
middle::diagnostic_items::collect(tcx)
2765-
};
2766-
providers.all_diagnostic_items = |tcx, id| {
2767-
assert_eq!(id, LOCAL_CRATE);
2768-
middle::diagnostic_items::collect_all(tcx)
2769-
};
27702758
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
27712759
providers.maybe_unused_extern_crates = |tcx, cnum| {
27722760
assert_eq!(cnum, LOCAL_CRATE);

src/librustc/ty/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
1010
use crate::middle::lang_items::{LangItem, LanguageItems};
1111
use crate::middle::lib_features::LibFeatures;
1212
use crate::middle::privacy::AccessLevels;
13-
use crate::middle::reachable::ReachableSet;
1413
use crate::middle::region;
1514
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
1615
use crate::middle::stability::{self, DeprecationEntry};
@@ -37,7 +36,7 @@ use crate::ty::subst::SubstsRef;
3736
use crate::ty::util::NeedsDrop;
3837
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
3938
use crate::util::common::ErrorReported;
40-
use crate::util::nodemap::{DefIdMap, DefIdSet};
39+
use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdSet};
4140
use rustc_data_structures::profiling::ProfileCategory::*;
4241

4342
use rustc_data_structures::fingerprint::Fingerprint;

src/librustc_codegen_ssa/back/symbol_export.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ fn reachable_non_generics_provider(
6565

6666
let mut reachable_non_generics: DefIdMap<_> = tcx
6767
.reachable_set(LOCAL_CRATE)
68-
.0
6968
.iter()
7069
.filter_map(|&hir_id| {
7170
// We want to ignore some FFI functions that are not exposed from
@@ -313,7 +312,7 @@ fn upstream_monomorphizations_for_provider(
313312

314313
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
315314
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
316-
!tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id)
315+
!tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
317316
} else {
318317
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
319318
}

src/librustc_interface/passes.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
1010
use rustc::hir::lowering::lower_crate;
1111
use rustc::lint;
1212
use rustc::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn};
13-
use rustc::middle::{self, reachable, resolve_lifetime, stability};
13+
use rustc::middle::{self, resolve_lifetime, stability};
1414
use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType};
1515
use rustc::session::config::{PpMode, PpSourceMode};
1616
use rustc::session::search_paths::PathKind;
@@ -678,14 +678,12 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
678678
plugin::build::provide(providers);
679679
hir::provide(providers);
680680
mir::provide(providers);
681-
reachable::provide(providers);
682681
resolve_lifetime::provide(providers);
683682
rustc_privacy::provide(providers);
684683
typeck::provide(providers);
685684
ty::provide(providers);
686685
traits::provide(providers);
687686
stability::provide(providers);
688-
reachable::provide(providers);
689687
rustc_passes::provide(providers);
690688
rustc_traits::provide(providers);
691689
middle::region::provide(providers);

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
882882
err.span_label(
883883
drop_span,
884884
format!(
885-
"...but `{}` will be dropped here, when the function `{}` returns",
885+
"...but `{}` will be dropped here, when the {} returns",
886886
name,
887-
self.infcx.tcx.hir().name(fn_hir_id),
887+
self.infcx
888+
.tcx
889+
.hir()
890+
.opt_name(fn_hir_id)
891+
.map(|name| format!("function `{}`", name))
892+
.unwrap_or_else(|| {
893+
match &self
894+
.infcx
895+
.tcx
896+
.typeck_tables_of(self.mir_def_id)
897+
.node_type(fn_hir_id)
898+
.kind
899+
{
900+
ty::Closure(..) => "enclosing closure",
901+
ty::Generator(..) => "enclosing generator",
902+
kind => bug!("expected closure or generator, found {:?}", kind),
903+
}
904+
.to_string()
905+
})
888906
),
889907
);
890908

src/librustc/middle/diagnostic_items.rs src/librustc_passes/diagnostic_items.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
//!
1010
//! * Compiler internal types like `Ty` and `TyCtxt`
1111
12-
use crate::hir::def_id::{DefId, LOCAL_CRATE};
13-
use crate::ty::TyCtxt;
14-
use crate::util::nodemap::FxHashMap;
12+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
13+
use rustc::ty::query::Providers;
14+
use rustc::ty::TyCtxt;
15+
use rustc::util::nodemap::FxHashMap;
1516

16-
use crate::hir;
17-
use crate::hir::itemlikevisit::ItemLikeVisitor;
17+
use rustc::hir;
18+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1819
use syntax::ast;
1920
use syntax::symbol::{sym, Symbol};
2021

@@ -93,7 +94,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
9394
}
9495

9596
/// Traverse and collect the diagnostic items in the current
96-
pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
97+
fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
9798
// Initialize the collector.
9899
let mut collector = DiagnosticItemCollector::new(tcx);
99100

@@ -104,7 +105,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
104105
}
105106

106107
/// Traverse and collect all the diagnostic items in all crates.
107-
pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
108+
fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
108109
// Initialize the collector.
109110
let mut collector = FxHashMap::default();
110111

@@ -117,3 +118,14 @@ pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap<Symbol, DefId> {
117118

118119
tcx.arena.alloc(collector)
119120
}
121+
122+
pub fn provide(providers: &mut Providers<'_>) {
123+
providers.diagnostic_items = |tcx, id| {
124+
assert_eq!(id, LOCAL_CRATE);
125+
collect(tcx)
126+
};
127+
providers.all_diagnostic_items = |tcx, id| {
128+
assert_eq!(id, LOCAL_CRATE);
129+
collect_all(tcx)
130+
};
131+
}

src/librustc_passes/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@ use rustc::ty::query::Providers;
2222
pub mod ast_validation;
2323
mod check_const;
2424
pub mod dead;
25+
mod diagnostic_items;
2526
pub mod entry;
2627
pub mod hir_stats;
2728
mod intrinsicck;
2829
pub mod layout_test;
30+
mod lib_features;
2931
mod liveness;
3032
pub mod loops;
33+
mod reachable;
3134

3235
pub fn provide(providers: &mut Providers<'_>) {
3336
check_const::provide(providers);
37+
diagnostic_items::provide(providers);
3438
entry::provide(providers);
39+
lib_features::provide(providers);
3540
loops::provide(providers);
3641
liveness::provide(providers);
3742
intrinsicck::provide(providers);
43+
reachable::provide(providers);
3844
}

0 commit comments

Comments
 (0)