Skip to content

Commit cc946fc

Browse files
committed
Auto merge of #91019 - JohnTitor:rollup-q95ra7r, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #90386 (Add `-Zassert-incr-state` to assert state of incremental cache) - #90438 (Clean up mess for --show-coverage documentation) - #90480 (Mention `Vec::remove` in `Vec::swap_remove`'s docs) - #90607 (Make slice->str conversion and related functions `const`) - #90750 (rustdoc: Replace where-bounded Clean impl with simple function) - #90895 (require full validity when determining the discriminant of a value) - #90989 (Avoid suggesting literal formatting that turns into member access) - #91002 (rustc: Remove `#[rustc_synthetic]`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b6f580a + 08c1639 commit cc946fc

File tree

36 files changed

+310
-251
lines changed

36 files changed

+310
-251
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13381338
pure_wrt_drop: false,
13391339
bounds: hir_bounds,
13401340
span: self.lower_span(span),
1341-
kind: hir::GenericParamKind::Type {
1342-
default: None,
1343-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1344-
},
1341+
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
13451342
});
13461343

13471344
hir::TyKind::Path(hir::QPath::Resolved(
@@ -1954,12 +1951,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19541951
default: default.as_ref().map(|x| {
19551952
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
19561953
}),
1957-
synthetic: param
1958-
.attrs
1959-
.iter()
1960-
.filter(|attr| attr.has_name(sym::rustc_synthetic))
1961-
.map(|_| hir::SyntheticTyParamKind::FromAttr)
1962-
.next(),
1954+
synthetic: false,
19631955
};
19641956

19651957
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
265265
}
266266
sym::discriminant_value => {
267267
let place = self.deref_operand(&args[0])?;
268+
if M::enforce_validity(self) {
269+
// This is 'using' the value, so make sure the validity invariant is satisfied.
270+
// (Also see https://github.com/rust-lang/rust/pull/89764.)
271+
self.validate_operand(&place.into())?;
272+
}
273+
268274
let discr_val = self.read_discriminant(&place.into())?.0;
269275
self.write_scalar(discr_val, dest)?;
270276
}

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
304304

305305
Discriminant(place) => {
306306
let op = self.eval_place_to_op(place, None)?;
307+
if M::enforce_validity(self) {
308+
// This is 'using' the value, so make sure the validity invariant is satisfied.
309+
// (Also see https://github.com/rust-lang/rust/pull/89764.)
310+
self.validate_operand(&op)?;
311+
}
312+
307313
let discr_val = self.read_discriminant(&op)?.0;
308314
self.write_scalar(discr_val, &dest)?;
309315
}

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
601601
TEST, rustc_expected_cgu_reuse, Normal,
602602
template!(List: r#"cfg = "...", module = "...", kind = "...""#),
603603
),
604-
rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)),
605604
rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)),
606605
rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)),
607606
rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)),

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> {
504504
},
505505
Type {
506506
default: Option<&'hir Ty<'hir>>,
507-
synthetic: Option<SyntheticTyParamKind>,
507+
synthetic: bool,
508508
},
509509
Const {
510510
ty: &'hir Ty<'hir>,
@@ -577,16 +577,6 @@ impl Generics<'hir> {
577577
}
578578
}
579579

580-
/// Synthetic type parameters are converted to another form during lowering; this allows
581-
/// us to track the original form they had, and is useful for error messages.
582-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)]
583-
#[derive(HashStable_Generic)]
584-
pub enum SyntheticTyParamKind {
585-
ImplTrait,
586-
// Created by the `#[rustc_synthetic]` attribute.
587-
FromAttr,
588-
}
589-
590580
/// A where-clause in a definition.
591581
#[derive(Debug, HashStable_Generic)]
592582
pub struct WhereClause<'hir> {

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
66
use rustc_middle::ty::OnDiskCache;
77
use rustc_serialize::opaque::Decoder;
88
use rustc_serialize::Decodable;
9+
use rustc_session::config::IncrementalStateAssertion;
910
use rustc_session::Session;
1011
use std::path::Path;
1112

@@ -16,6 +17,7 @@ use super::work_product;
1617

1718
type WorkProductMap = FxHashMap<WorkProductId, WorkProduct>;
1819

20+
#[derive(Debug)]
1921
pub enum LoadResult<T> {
2022
Ok { data: T },
2123
DataOutOfDate,
@@ -24,6 +26,26 @@ pub enum LoadResult<T> {
2426

2527
impl<T: Default> LoadResult<T> {
2628
pub fn open(self, sess: &Session) -> T {
29+
// Check for errors when using `-Zassert-incremental-state`
30+
match (sess.opts.assert_incr_state, &self) {
31+
(Some(IncrementalStateAssertion::NotLoaded), LoadResult::Ok { .. }) => {
32+
sess.fatal(
33+
"We asserted that the incremental cache should not be loaded, \
34+
but it was loaded.",
35+
);
36+
}
37+
(
38+
Some(IncrementalStateAssertion::Loaded),
39+
LoadResult::Error { .. } | LoadResult::DataOutOfDate,
40+
) => {
41+
sess.fatal(
42+
"We asserted that an existing incremental cache directory should \
43+
be successfully loaded, but it was not.",
44+
);
45+
}
46+
_ => {}
47+
};
48+
2749
match self {
2850
LoadResult::Error { message } => {
2951
sess.warn(&message);
@@ -33,7 +55,7 @@ impl<T: Default> LoadResult<T> {
3355
if let Err(err) = delete_all_session_dir_contents(sess) {
3456
sess.err(&format!(
3557
"Failed to delete invalidated or incompatible \
36-
incremental compilation session directory contents `{}`: {}.",
58+
incremental compilation session directory contents `{}`: {}.",
3759
dep_graph_path(sess).display(),
3860
err
3961
));

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ fn test_debugging_options_tracking_hash() {
636636

637637
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
638638
// This list is in alphabetical order.
639+
untracked!(assert_incr_state, Some(String::from("loaded")));
639640
untracked!(ast_json, true);
640641
untracked!(ast_json_noexpand, true);
641642
untracked!(borrowck, String::from("other"));

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::ty;
33
use crate::ty::subst::{Subst, SubstsRef};
44
use rustc_ast as ast;
55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_hir as hir;
76
use rustc_hir::def_id::DefId;
87
use rustc_span::symbol::Symbol;
98
use rustc_span::Span;
@@ -13,14 +12,8 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
1312
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
1413
pub enum GenericParamDefKind {
1514
Lifetime,
16-
Type {
17-
has_default: bool,
18-
object_lifetime_default: ObjectLifetimeDefault,
19-
synthetic: Option<hir::SyntheticTyParamKind>,
20-
},
21-
Const {
22-
has_default: bool,
23-
},
15+
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
16+
Const { has_default: bool },
2417
}
2518

2619
impl GenericParamDefKind {
@@ -202,15 +195,7 @@ impl<'tcx> Generics {
202195
/// Returns `true` if `params` has `impl Trait`.
203196
pub fn has_impl_trait(&'tcx self) -> bool {
204197
self.params.iter().any(|param| {
205-
matches!(
206-
param.kind,
207-
ty::GenericParamDefKind::Type {
208-
synthetic: Some(
209-
hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr,
210-
),
211-
..
212-
}
213-
)
198+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
214199
})
215200
}
216201
}

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,12 +1810,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
18101810
let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| {
18111811
!matches!(
18121812
p.kind,
1813-
hir::GenericParamKind::Type {
1814-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1815-
..
1816-
} | hir::GenericParamKind::Lifetime {
1817-
kind: hir::LifetimeParamKind::Elided,
1818-
}
1813+
hir::GenericParamKind::Type { synthetic: true, .. }
1814+
| hir::GenericParamKind::Lifetime {
1815+
kind: hir::LifetimeParamKind::Elided,
1816+
}
18191817
)
18201818
}) {
18211819
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
@@ -2042,12 +2040,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
20422040
if let Some(param) = generics.params.iter().find(|p| {
20432041
!matches!(
20442042
p.kind,
2045-
hir::GenericParamKind::Type {
2046-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
2047-
..
2048-
} | hir::GenericParamKind::Lifetime {
2049-
kind: hir::LifetimeParamKind::Elided
2050-
}
2043+
hir::GenericParamKind::Type { synthetic: true, .. }
2044+
| hir::GenericParamKind::Lifetime {
2045+
kind: hir::LifetimeParamKind::Elided
2046+
}
20512047
)
20522048
}) {
20532049
(param.span.shrink_to_lo(), "'a, ".to_string())

compiler/rustc_session/src/config.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ pub enum LinkerPluginLto {
165165
Disabled,
166166
}
167167

168+
/// Used with `-Z assert-incr-state`.
169+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
170+
pub enum IncrementalStateAssertion {
171+
/// Found and loaded an existing session directory.
172+
///
173+
/// Note that this says nothing about whether any particular query
174+
/// will be found to be red or green.
175+
Loaded,
176+
/// Did not load an existing session directory.
177+
NotLoaded,
178+
}
179+
168180
impl LinkerPluginLto {
169181
pub fn enabled(&self) -> bool {
170182
match *self {
@@ -704,6 +716,7 @@ pub fn host_triple() -> &'static str {
704716
impl Default for Options {
705717
fn default() -> Options {
706718
Options {
719+
assert_incr_state: None,
707720
crate_types: Vec::new(),
708721
optimize: OptLevel::No,
709722
debuginfo: DebugInfo::None,
@@ -1626,6 +1639,21 @@ fn select_debuginfo(
16261639
}
16271640
}
16281641

1642+
crate fn parse_assert_incr_state(
1643+
opt_assertion: &Option<String>,
1644+
error_format: ErrorOutputType,
1645+
) -> Option<IncrementalStateAssertion> {
1646+
match opt_assertion {
1647+
Some(s) if s.as_str() == "loaded" => Some(IncrementalStateAssertion::Loaded),
1648+
Some(s) if s.as_str() == "not-loaded" => Some(IncrementalStateAssertion::NotLoaded),
1649+
Some(s) => early_error(
1650+
error_format,
1651+
&format!("unexpected incremental state assertion value: {}", s),
1652+
),
1653+
None => None,
1654+
}
1655+
}
1656+
16291657
fn parse_native_lib_kind(
16301658
matches: &getopts::Matches,
16311659
kind: &str,
@@ -2015,6 +2043,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
20152043

20162044
let incremental = cg.incremental.as_ref().map(PathBuf::from);
20172045

2046+
let assert_incr_state =
2047+
parse_assert_incr_state(&debugging_opts.assert_incr_state, error_format);
2048+
20182049
if debugging_opts.profile && incremental.is_some() {
20192050
early_error(
20202051
error_format,
@@ -2179,6 +2210,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
21792210
};
21802211

21812212
Options {
2213+
assert_incr_state,
21822214
crate_types,
21832215
optimize: opt_level,
21842216
debuginfo,

0 commit comments

Comments
 (0)