Skip to content

Commit

Permalink
Auto merge of rust-lang#91019 - JohnTitor:rollup-q95ra7r, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#90386 (Add `-Zassert-incr-state` to assert state of incremental cache)
 - rust-lang#90438 (Clean up mess for --show-coverage documentation)
 - rust-lang#90480 (Mention `Vec::remove` in `Vec::swap_remove`'s docs)
 - rust-lang#90607 (Make slice->str conversion and related functions `const`)
 - rust-lang#90750 (rustdoc: Replace where-bounded Clean impl with simple function)
 - rust-lang#90895 (require full validity when determining the discriminant of a value)
 - rust-lang#90989 (Avoid suggesting literal formatting that turns into member access)
 - rust-lang#91002 (rustc: Remove `#[rustc_synthetic]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 18, 2021
2 parents b6f580a + 08c1639 commit cc946fc
Show file tree
Hide file tree
Showing 36 changed files with 310 additions and 251 deletions.
12 changes: 2 additions & 10 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> {
},
Type {
default: Option<&'hir Ty<'hir>>,
synthetic: Option<SyntheticTyParamKind>,
synthetic: bool,
},
Const {
ty: &'hir Ty<'hir>,
Expand Down Expand Up @@ -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> {
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

type WorkProductMap = FxHashMap<WorkProductId, WorkProduct>;

#[derive(Debug)]
pub enum LoadResult<T> {
Ok { data: T },
DataOutOfDate,
Expand All @@ -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);
Expand All @@ -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
));
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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, .. })
})
}
}
Expand Down
20 changes: 8 additions & 12 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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())
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2179,6 +2210,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
};

Options {
assert_incr_state,
crate_types,
optimize: opt_level,
debuginfo,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 4 additions & 10 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()?;
Expand Down
Loading

0 comments on commit cc946fc

Please sign in to comment.