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

+2-10
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

+6
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

+6
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

-1
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

+1-11
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

+23-1
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

+1
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

+3-18
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

+8-12
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

+32
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,

compiler/rustc_session/src/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::early_error;
44
use crate::lint;
55
use crate::search_paths::SearchPath;
66
use crate::utils::NativeLib;
7-
87
use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy, SanitizerSet};
98
use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TargetTriple, TlsModel};
109

@@ -150,6 +149,7 @@ top_level_options!(
150149
/// If `Some`, enable incremental compilation, using the given
151150
/// directory to store intermediate results.
152151
incremental: Option<PathBuf> [UNTRACKED],
152+
assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
153153

154154
debugging_opts: DebuggingOptions [SUBSTRUCT],
155155
prints: Vec<PrintRequest> [UNTRACKED],
@@ -1046,6 +1046,9 @@ options! {
10461046
"make cfg(version) treat the current version as incomplete (default: no)"),
10471047
asm_comments: bool = (false, parse_bool, [TRACKED],
10481048
"generate comments into the assembly (may change behavior) (default: no)"),
1049+
assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
1050+
"assert that the incremental cache is in given state: \
1051+
either `loaded` or `not-loaded`."),
10491052
ast_json: bool = (false, parse_bool, [UNTRACKED],
10501053
"print the AST as JSON and halt (default: no)"),
10511054
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ symbols! {
11481148
rustc_std_internal_symbol,
11491149
rustc_strict_coherence,
11501150
rustc_symbol_name,
1151-
rustc_synthetic,
11521151
rustc_test_marker,
11531152
rustc_then_this_would_need,
11541153
rustc_trivial_field_reads,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ fn suggest_restriction(
290290
} else {
291291
// Trivial case: `T` needs an extra bound: `T: Bound`.
292292
let (sp, suggestion) = match (
293-
generics.params.iter().find(|p| {
294-
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
295-
}),
293+
generics
294+
.params
295+
.iter()
296+
.find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
296297
super_traits,
297298
) {
298299
(_, None) => predicate_constraint(

compiler/rustc_typeck/src/astconv/generics.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
464464
.params
465465
.iter()
466466
.filter(|param| {
467-
matches!(
468-
param.kind,
469-
ty::GenericParamDefKind::Type {
470-
synthetic: Some(
471-
hir::SyntheticTyParamKind::ImplTrait
472-
| hir::SyntheticTyParamKind::FromAttr
473-
),
474-
..
475-
}
476-
)
467+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
477468
})
478469
.count()
479470
} else {

compiler/rustc_typeck/src/check/compare_method.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,7 @@ fn compare_number_of_generics<'tcx>(
607607
.params
608608
.iter()
609609
.filter_map(|p| match p.kind {
610-
GenericParamKind::Type {
611-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
612-
..
613-
} => Some(p.span),
610+
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
614611
_ => None,
615612
})
616613
.collect();
@@ -627,10 +624,7 @@ fn compare_number_of_generics<'tcx>(
627624
.params
628625
.iter()
629626
.filter_map(|p| match p.kind {
630-
GenericParamKind::Type {
631-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
632-
..
633-
} => Some(p.span),
627+
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
634628
_ => None,
635629
})
636630
.collect();
@@ -823,7 +817,7 @@ fn compare_synthetic_generics<'tcx>(
823817
match (impl_synthetic, trait_synthetic) {
824818
// The case where the impl method uses `impl Trait` but the trait method uses
825819
// explicit generics
826-
(Some(hir::SyntheticTyParamKind::ImplTrait), None) => {
820+
(true, false) => {
827821
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
828822
(|| {
829823
// try taking the name from the trait impl
@@ -864,7 +858,7 @@ fn compare_synthetic_generics<'tcx>(
864858
}
865859
// The case where the trait method uses `impl Trait`, but the impl method uses
866860
// explicit generics.
867-
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
861+
(false, true) => {
868862
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
869863
(|| {
870864
let impl_m = impl_m.def_id.as_local()?;

0 commit comments

Comments
 (0)