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
This commit is contained in:
commit
cc946fcd32
36 changed files with 310 additions and 251 deletions
|
@ -1338,10 +1338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
pure_wrt_drop: false,
|
||||
bounds: hir_bounds,
|
||||
span: self.lower_span(span),
|
||||
kind: hir::GenericParamKind::Type {
|
||||
default: None,
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
},
|
||||
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
|
||||
});
|
||||
|
||||
hir::TyKind::Path(hir::QPath::Resolved(
|
||||
|
@ -1954,12 +1951,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
default: default.as_ref().map(|x| {
|
||||
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
|
||||
}),
|
||||
synthetic: param
|
||||
.attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.has_name(sym::rustc_synthetic))
|
||||
.map(|_| hir::SyntheticTyParamKind::FromAttr)
|
||||
.next(),
|
||||
synthetic: false,
|
||||
};
|
||||
|
||||
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
||||
|
|
|
@ -265,6 +265,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
sym::discriminant_value => {
|
||||
let place = self.deref_operand(&args[0])?;
|
||||
if M::enforce_validity(self) {
|
||||
// This is 'using' the value, so make sure the validity invariant is satisfied.
|
||||
// (Also see https://github.com/rust-lang/rust/pull/89764.)
|
||||
self.validate_operand(&place.into())?;
|
||||
}
|
||||
|
||||
let discr_val = self.read_discriminant(&place.into())?.0;
|
||||
self.write_scalar(discr_val, dest)?;
|
||||
}
|
||||
|
|
|
@ -304,6 +304,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
Discriminant(place) => {
|
||||
let op = self.eval_place_to_op(place, None)?;
|
||||
if M::enforce_validity(self) {
|
||||
// This is 'using' the value, so make sure the validity invariant is satisfied.
|
||||
// (Also see https://github.com/rust-lang/rust/pull/89764.)
|
||||
self.validate_operand(&op)?;
|
||||
}
|
||||
|
||||
let discr_val = self.read_discriminant(&op)?.0;
|
||||
self.write_scalar(discr_val, &dest)?;
|
||||
}
|
||||
|
|
|
@ -601,7 +601,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
|||
TEST, rustc_expected_cgu_reuse, Normal,
|
||||
template!(List: r#"cfg = "...", module = "...", kind = "...""#),
|
||||
),
|
||||
rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)),
|
||||
|
|
|
@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> {
|
|||
},
|
||||
Type {
|
||||
default: Option<&'hir Ty<'hir>>,
|
||||
synthetic: Option<SyntheticTyParamKind>,
|
||||
synthetic: bool,
|
||||
},
|
||||
Const {
|
||||
ty: &'hir Ty<'hir>,
|
||||
|
@ -577,16 +577,6 @@ impl Generics<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Synthetic type parameters are converted to another form during lowering; this allows
|
||||
/// us to track the original form they had, and is useful for error messages.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum SyntheticTyParamKind {
|
||||
ImplTrait,
|
||||
// Created by the `#[rustc_synthetic]` attribute.
|
||||
FromAttr,
|
||||
}
|
||||
|
||||
/// A where-clause in a definition.
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct WhereClause<'hir> {
|
||||
|
|
|
@ -6,6 +6,7 @@ use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
|
|||
use rustc_middle::ty::OnDiskCache;
|
||||
use rustc_serialize::opaque::Decoder;
|
||||
use rustc_serialize::Decodable;
|
||||
use rustc_session::config::IncrementalStateAssertion;
|
||||
use rustc_session::Session;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -16,6 +17,7 @@ use super::work_product;
|
|||
|
||||
type WorkProductMap = FxHashMap<WorkProductId, WorkProduct>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LoadResult<T> {
|
||||
Ok { data: T },
|
||||
DataOutOfDate,
|
||||
|
@ -24,6 +26,26 @@ pub enum LoadResult<T> {
|
|||
|
||||
impl<T: Default> LoadResult<T> {
|
||||
pub fn open(self, sess: &Session) -> T {
|
||||
// Check for errors when using `-Zassert-incremental-state`
|
||||
match (sess.opts.assert_incr_state, &self) {
|
||||
(Some(IncrementalStateAssertion::NotLoaded), LoadResult::Ok { .. }) => {
|
||||
sess.fatal(
|
||||
"We asserted that the incremental cache should not be loaded, \
|
||||
but it was loaded.",
|
||||
);
|
||||
}
|
||||
(
|
||||
Some(IncrementalStateAssertion::Loaded),
|
||||
LoadResult::Error { .. } | LoadResult::DataOutOfDate,
|
||||
) => {
|
||||
sess.fatal(
|
||||
"We asserted that an existing incremental cache directory should \
|
||||
be successfully loaded, but it was not.",
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
match self {
|
||||
LoadResult::Error { message } => {
|
||||
sess.warn(&message);
|
||||
|
@ -33,7 +55,7 @@ impl<T: Default> LoadResult<T> {
|
|||
if let Err(err) = delete_all_session_dir_contents(sess) {
|
||||
sess.err(&format!(
|
||||
"Failed to delete invalidated or incompatible \
|
||||
incremental compilation session directory contents `{}`: {}.",
|
||||
incremental compilation session directory contents `{}`: {}.",
|
||||
dep_graph_path(sess).display(),
|
||||
err
|
||||
));
|
||||
|
|
|
@ -636,6 +636,7 @@ fn test_debugging_options_tracking_hash() {
|
|||
|
||||
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
|
||||
// This list is in alphabetical order.
|
||||
untracked!(assert_incr_state, Some(String::from("loaded")));
|
||||
untracked!(ast_json, true);
|
||||
untracked!(ast_json_noexpand, true);
|
||||
untracked!(borrowck, String::from("other"));
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::ty;
|
|||
use crate::ty::subst::{Subst, SubstsRef};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
|
@ -13,14 +12,8 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
|
|||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
pub enum GenericParamDefKind {
|
||||
Lifetime,
|
||||
Type {
|
||||
has_default: bool,
|
||||
object_lifetime_default: ObjectLifetimeDefault,
|
||||
synthetic: Option<hir::SyntheticTyParamKind>,
|
||||
},
|
||||
Const {
|
||||
has_default: bool,
|
||||
},
|
||||
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
|
||||
Const { has_default: bool },
|
||||
}
|
||||
|
||||
impl GenericParamDefKind {
|
||||
|
@ -202,15 +195,7 @@ impl<'tcx> Generics {
|
|||
/// Returns `true` if `params` has `impl Trait`.
|
||||
pub fn has_impl_trait(&'tcx self) -> bool {
|
||||
self.params.iter().any(|param| {
|
||||
matches!(
|
||||
param.kind,
|
||||
ty::GenericParamDefKind::Type {
|
||||
synthetic: Some(
|
||||
hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr,
|
||||
),
|
||||
..
|
||||
}
|
||||
)
|
||||
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1810,12 +1810,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| {
|
||||
!matches!(
|
||||
p.kind,
|
||||
hir::GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} | hir::GenericParamKind::Lifetime {
|
||||
kind: hir::LifetimeParamKind::Elided,
|
||||
}
|
||||
hir::GenericParamKind::Type { synthetic: true, .. }
|
||||
| hir::GenericParamKind::Lifetime {
|
||||
kind: hir::LifetimeParamKind::Elided,
|
||||
}
|
||||
)
|
||||
}) {
|
||||
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
|
||||
|
@ -2042,12 +2040,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
if let Some(param) = generics.params.iter().find(|p| {
|
||||
!matches!(
|
||||
p.kind,
|
||||
hir::GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} | hir::GenericParamKind::Lifetime {
|
||||
kind: hir::LifetimeParamKind::Elided
|
||||
}
|
||||
hir::GenericParamKind::Type { synthetic: true, .. }
|
||||
| hir::GenericParamKind::Lifetime {
|
||||
kind: hir::LifetimeParamKind::Elided
|
||||
}
|
||||
)
|
||||
}) {
|
||||
(param.span.shrink_to_lo(), "'a, ".to_string())
|
||||
|
|
|
@ -165,6 +165,18 @@ pub enum LinkerPluginLto {
|
|||
Disabled,
|
||||
}
|
||||
|
||||
/// Used with `-Z assert-incr-state`.
|
||||
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||
pub enum IncrementalStateAssertion {
|
||||
/// Found and loaded an existing session directory.
|
||||
///
|
||||
/// Note that this says nothing about whether any particular query
|
||||
/// will be found to be red or green.
|
||||
Loaded,
|
||||
/// Did not load an existing session directory.
|
||||
NotLoaded,
|
||||
}
|
||||
|
||||
impl LinkerPluginLto {
|
||||
pub fn enabled(&self) -> bool {
|
||||
match *self {
|
||||
|
@ -704,6 +716,7 @@ pub fn host_triple() -> &'static str {
|
|||
impl Default for Options {
|
||||
fn default() -> Options {
|
||||
Options {
|
||||
assert_incr_state: None,
|
||||
crate_types: Vec::new(),
|
||||
optimize: OptLevel::No,
|
||||
debuginfo: DebugInfo::None,
|
||||
|
@ -1626,6 +1639,21 @@ fn select_debuginfo(
|
|||
}
|
||||
}
|
||||
|
||||
crate fn parse_assert_incr_state(
|
||||
opt_assertion: &Option<String>,
|
||||
error_format: ErrorOutputType,
|
||||
) -> Option<IncrementalStateAssertion> {
|
||||
match opt_assertion {
|
||||
Some(s) if s.as_str() == "loaded" => Some(IncrementalStateAssertion::Loaded),
|
||||
Some(s) if s.as_str() == "not-loaded" => Some(IncrementalStateAssertion::NotLoaded),
|
||||
Some(s) => early_error(
|
||||
error_format,
|
||||
&format!("unexpected incremental state assertion value: {}", s),
|
||||
),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_native_lib_kind(
|
||||
matches: &getopts::Matches,
|
||||
kind: &str,
|
||||
|
@ -2015,6 +2043,9 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||
|
||||
let incremental = cg.incremental.as_ref().map(PathBuf::from);
|
||||
|
||||
let assert_incr_state =
|
||||
parse_assert_incr_state(&debugging_opts.assert_incr_state, error_format);
|
||||
|
||||
if debugging_opts.profile && incremental.is_some() {
|
||||
early_error(
|
||||
error_format,
|
||||
|
@ -2179,6 +2210,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||
};
|
||||
|
||||
Options {
|
||||
assert_incr_state,
|
||||
crate_types,
|
||||
optimize: opt_level,
|
||||
debuginfo,
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::early_error;
|
|||
use crate::lint;
|
||||
use crate::search_paths::SearchPath;
|
||||
use crate::utils::NativeLib;
|
||||
|
||||
use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy, SanitizerSet};
|
||||
use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TargetTriple, TlsModel};
|
||||
|
||||
|
@ -150,6 +149,7 @@ top_level_options!(
|
|||
/// If `Some`, enable incremental compilation, using the given
|
||||
/// directory to store intermediate results.
|
||||
incremental: Option<PathBuf> [UNTRACKED],
|
||||
assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
|
||||
|
||||
debugging_opts: DebuggingOptions [SUBSTRUCT],
|
||||
prints: Vec<PrintRequest> [UNTRACKED],
|
||||
|
@ -1046,6 +1046,9 @@ options! {
|
|||
"make cfg(version) treat the current version as incomplete (default: no)"),
|
||||
asm_comments: bool = (false, parse_bool, [TRACKED],
|
||||
"generate comments into the assembly (may change behavior) (default: no)"),
|
||||
assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
|
||||
"assert that the incremental cache is in given state: \
|
||||
either `loaded` or `not-loaded`."),
|
||||
ast_json: bool = (false, parse_bool, [UNTRACKED],
|
||||
"print the AST as JSON and halt (default: no)"),
|
||||
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
|
||||
|
|
|
@ -1148,7 +1148,6 @@ symbols! {
|
|||
rustc_std_internal_symbol,
|
||||
rustc_strict_coherence,
|
||||
rustc_symbol_name,
|
||||
rustc_synthetic,
|
||||
rustc_test_marker,
|
||||
rustc_then_this_would_need,
|
||||
rustc_trivial_field_reads,
|
||||
|
|
|
@ -290,9 +290,10 @@ fn suggest_restriction(
|
|||
} else {
|
||||
// Trivial case: `T` needs an extra bound: `T: Bound`.
|
||||
let (sp, suggestion) = match (
|
||||
generics.params.iter().find(|p| {
|
||||
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
|
||||
}),
|
||||
generics
|
||||
.params
|
||||
.iter()
|
||||
.find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
|
||||
super_traits,
|
||||
) {
|
||||
(_, None) => predicate_constraint(
|
||||
|
|
|
@ -464,16 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.params
|
||||
.iter()
|
||||
.filter(|param| {
|
||||
matches!(
|
||||
param.kind,
|
||||
ty::GenericParamDefKind::Type {
|
||||
synthetic: Some(
|
||||
hir::SyntheticTyParamKind::ImplTrait
|
||||
| hir::SyntheticTyParamKind::FromAttr
|
||||
),
|
||||
..
|
||||
}
|
||||
)
|
||||
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
|
||||
})
|
||||
.count()
|
||||
} else {
|
||||
|
|
|
@ -607,10 +607,7 @@ fn compare_number_of_generics<'tcx>(
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|p| match p.kind {
|
||||
GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} => Some(p.span),
|
||||
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
@ -627,10 +624,7 @@ fn compare_number_of_generics<'tcx>(
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|p| match p.kind {
|
||||
GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} => Some(p.span),
|
||||
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
@ -823,7 +817,7 @@ fn compare_synthetic_generics<'tcx>(
|
|||
match (impl_synthetic, trait_synthetic) {
|
||||
// The case where the impl method uses `impl Trait` but the trait method uses
|
||||
// explicit generics
|
||||
(Some(hir::SyntheticTyParamKind::ImplTrait), None) => {
|
||||
(true, false) => {
|
||||
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
|
||||
(|| {
|
||||
// try taking the name from the trait impl
|
||||
|
@ -864,7 +858,7 @@ fn compare_synthetic_generics<'tcx>(
|
|||
}
|
||||
// The case where the trait method uses `impl Trait`, but the impl method uses
|
||||
// explicit generics.
|
||||
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
|
||||
(false, true) => {
|
||||
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
||||
(|| {
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
|
|
|
@ -2025,7 +2025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
|
||||
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
|
||||
let generic_param = generics.type_param(¶m, self.tcx);
|
||||
if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind {
|
||||
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
|
||||
return;
|
||||
}
|
||||
let param_def_id = generic_param.def_id;
|
||||
|
|
|
@ -317,6 +317,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
.span_to_snippet(lit.span)
|
||||
.unwrap_or_else(|_| "<numeric literal>".to_owned());
|
||||
|
||||
// If this is a floating point literal that ends with '.',
|
||||
// get rid of it to stop this from becoming a member access.
|
||||
let snippet = snippet.strip_suffix('.').unwrap_or(&snippet);
|
||||
|
||||
err.span_suggestion(
|
||||
lit.span,
|
||||
&format!(
|
||||
|
@ -324,7 +328,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
like `{}`",
|
||||
concrete_type
|
||||
),
|
||||
format!("{}_{}", snippet, concrete_type),
|
||||
format!("{snippet}_{concrete_type}"),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
@ -1490,7 +1494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
Node::GenericParam(param) => {
|
||||
let mut impl_trait = false;
|
||||
let has_bounds =
|
||||
if let hir::GenericParamKind::Type { synthetic: Some(_), .. } =
|
||||
if let hir::GenericParamKind::Type { synthetic: true, .. } =
|
||||
¶m.kind
|
||||
{
|
||||
// We've found `fn foo(x: impl Trait)` instead of
|
||||
|
|
|
@ -1543,7 +1543,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
kind: ty::GenericParamDefKind::Type {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
synthetic: None,
|
||||
synthetic: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -1673,7 +1673,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
kind: ty::GenericParamDefKind::Type {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
synthetic: None,
|
||||
synthetic: false,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
@ -1690,7 +1690,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
kind: ty::GenericParamDefKind::Type {
|
||||
has_default: false,
|
||||
object_lifetime_default: rl::Set1::Empty,
|
||||
synthetic: None,
|
||||
synthetic: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue