Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #107823

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c13669e
Implement `AsFd` and `AsRawFd` for `Rc`
ids1024 Jan 26, 2023
83b05ef
Stabilize feature 'cstr_from_bytes_until_nul'
tgross35 Jan 28, 2023
877e9f5
Change 'from_bytes_until_nul' to const stable
tgross35 Jan 30, 2023
f95b553
Replace a command line flag with an env var to allow tools to initial…
oli-obk Feb 7, 2023
0017822
Do not eagerly recover for bad impl-trait in macros
compiler-errors Feb 8, 2023
a516460
correctly update goals in the cache
lcnr Feb 8, 2023
4c7c5e5
add (currently ICEing) test
lcnr Feb 8, 2023
55330f6
Fix subst issue with object_ty_for_trait
compiler-errors Feb 8, 2023
a447e66
Use elaborated item bounds for alias types
compiler-errors Feb 8, 2023
09f2981
Implement a dummy drop-in-favor-of for the new solver
compiler-errors Feb 8, 2023
caa8ee9
Move winnowing to assembly
compiler-errors Feb 8, 2023
8cb5be9
rustdoc: use [svgo] to shrink `wheel.svg`
notriddle Feb 8, 2023
730470c
Set `rust-analyzer.check.invocationLocation` to `root`
clubby789 Feb 8, 2023
a70d03b
Extend `BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE`.
nnethercote Feb 6, 2023
4212d25
Rollup merge of #107317 - ids1024:asfd-rc, r=dtolnay
compiler-errors Feb 9, 2023
cda1583
Rollup merge of #107429 - tgross35:from-bytes-until-null-stabilizatio…
compiler-errors Feb 9, 2023
3e81dec
Rollup merge of #107713 - nnethercote:extend-BYTE_SLICE_IN_PACKED_STR…
compiler-errors Feb 9, 2023
43dce77
Rollup merge of #107761 - oli-obk:miri_🪵, r=TaKO8Ki
compiler-errors Feb 9, 2023
582c946
Rollup merge of #107786 - compiler-errors:new-solver-some-tweaks, r=lcnr
compiler-errors Feb 9, 2023
16709b0
Rollup merge of #107799 - lcnr:update-provisional-result, r=oli-obk
compiler-errors Feb 9, 2023
3c108ba
Rollup merge of #107813 - compiler-errors:bad-impl-trait-in-macro-is-…
compiler-errors Feb 9, 2023
6905d2c
Rollup merge of #107817 - notriddle:notriddle/wheel-svg, r=GuillaumeG…
compiler-errors Feb 9, 2023
e36673f
Rollup merge of #107819 - clubby789:x-py-root, r=jyn514
compiler-errors Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,31 +1557,46 @@ impl<'a> TraitDef<'a> {
}),
),
);
// In general, fields in packed structs are copied via a
// block, e.g. `&{self.0}`. The one exception is `[u8]`
// fields, which cannot be copied and also never cause
// unaligned references. This exception is allowed to
// handle the `FlexZeroSlice` type in the `zerovec` crate
// within `icu4x-0.9.0`.
//
// Once use of `icu4x-0.9.0` has dropped sufficiently, this
// exception should be removed.
let is_u8_slice = if let TyKind::Slice(ty) = &struct_field.ty.kind &&
let TyKind::Path(None, rustc_ast::Path { segments, .. }) = &ty.kind &&
let [seg] = segments.as_slice() &&
seg.ident.name == sym::u8 && seg.args.is_none()
{
true
} else {
false
};
if is_packed {
if is_u8_slice {
// In general, fields in packed structs are copied via a
// block, e.g. `&{self.0}`. The two exceptions are `[u8]`
// and `str` fields, which cannot be copied and also never
// cause unaligned references. These exceptions are allowed
// to handle the `FlexZeroSlice` type in the `zerovec`
// crate within `icu4x-0.9.0`.
//
// Once use of `icu4x-0.9.0` has dropped sufficiently, this
// exception should be removed.
let is_simple_path = |ty: &P<ast::Ty>, sym| {
if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind &&
let [seg] = segments.as_slice() &&
seg.ident.name == sym && seg.args.is_none()
{
true
} else {
false
}
};

let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind &&
is_simple_path(ty, sym::u8)
{
Some("byte")
} else if is_simple_path(&struct_field.ty, sym::str) {
Some("string")
} else {
None
};

if let Some(ty) = exception {
cx.sess.parse_sess.buffer_lint_with_diagnostic(
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
sp,
ast::CRATE_NODE_ID,
"byte slice in a packed struct that derives a built-in trait",
&format!(
"{} slice in a packed struct that derives a built-in trait",
ty
),
rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive
);
} else {
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ fn run_compiler(
registry: diagnostics_registry(),
};

if !tracing::dispatcher::has_been_set() {
init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace);
}

match make_input(config.opts.error_format, &matches.free) {
Err(reported) => return Err(reported),
Ok(Some(input)) => {
Expand Down Expand Up @@ -1251,16 +1247,7 @@ pub fn install_ice_hook() {
/// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version.
pub fn init_rustc_env_logger() {
init_rustc_env_logger_with_backtrace_option(&None);
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to
/// choose a target module you wish to show backtraces along with its logging.
pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) {
if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) {
early_error(ErrorOutputType::default(), &error.to_string());
}
init_env_logger("RUSTC_LOG");
}

/// This allows tools to enable rust logging without having to magically match rustc's
Expand Down Expand Up @@ -1324,6 +1311,7 @@ mod signal_handler {
pub fn main() -> ! {
let start_time = Instant::now();
let start_rss = get_resident_set_size();
init_rustc_env_logger();
signal_handler::install();
let mut callbacks = TimePassesCallbacks::default();
install_ice_hook();
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(link_only, true);
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
tracked!(log_backtrace, Some("filter".to_string()));
tracked!(maximal_hir_to_mir_coverage, true);
tracked!(merge_functions, Some(MergeFunctions::Disabled));
tracked!(mir_emit_retag, true);
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,8 @@ declare_lint! {

declare_lint! {
/// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field
/// (`[u8]`) is used in a `packed` struct that derives one or more built-in traits.
/// (`[u8]`) or string slice field (`str`) is used in a `packed` struct that derives one or
/// more built-in traits.
///
/// ### Example
///
Expand All @@ -4091,11 +4092,11 @@ declare_lint! {
/// ### Explanation
///
/// This was previously accepted but is being phased out, because fields in packed structs are
/// now required to implement `Copy` for `derive` to work. Byte slices are a temporary
/// exception because certain crates depended on them.
/// now required to implement `Copy` for `derive` to work. Byte slices and string slices are a
/// temporary exception because certain crates depended on them.
pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
Warn,
"`[u8]` slice used in a packed struct with `derive`",
"`[u8]` or `str` used in a packed struct with `derive`",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
Expand Down
21 changes: 4 additions & 17 deletions compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,12 @@ use tracing_subscriber::fmt::{
use tracing_subscriber::layer::SubscriberExt;

pub fn init_rustc_env_logger() -> Result<(), Error> {
init_rustc_env_logger_with_backtrace_option(&None)
}

pub fn init_rustc_env_logger_with_backtrace_option(
backtrace_target: &Option<String>,
) -> Result<(), Error> {
init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target)
init_env_logger("RUSTC_LOG")
}

/// In contrast to `init_rustc_env_logger` this allows you to choose an env var
/// other than `RUSTC_LOG`.
pub fn init_env_logger(env: &str) -> Result<(), Error> {
init_env_logger_with_backtrace_option(env, &None)
}

pub fn init_env_logger_with_backtrace_option(
env: &str,
backtrace_target: &Option<String>,
) -> Result<(), Error> {
let filter = match env::var(env) {
Ok(env) => EnvFilter::new(env),
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
Expand Down Expand Up @@ -106,16 +93,16 @@ pub fn init_env_logger_with_backtrace_option(
let layer = layer.with_thread_ids(true).with_thread_names(true);

let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
match backtrace_target {
Some(str) => {
match env::var(format!("{env}_BACKTRACE")) {
Ok(str) => {
let fmt_layer = tracing_subscriber::fmt::layer()
.with_writer(io::stderr)
.without_time()
.event_format(BacktraceFormatter { backtrace_target: str.to_string() });
let subscriber = subscriber.with(fmt_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
}
None => {
Err(_) => {
tracing::subscriber::set_global_default(subscriber).unwrap();
}
};
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,9 @@ impl<'a> Parser<'a> {
// `where`, so stop if it's it.
// We also continue if we find types (not traits), again for error recovery.
while self.can_begin_bound()
|| self.token.can_begin_type()
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
|| (self.may_recover()
&& (self.token.can_begin_type()
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))))
{
if self.token.is_keyword(kw::Dyn) {
// Account for `&dyn Trait + dyn Other`.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,6 @@ options! {
"what location details should be tracked when using caller_location, either \
`none`, or a comma separated list of location details, for which \
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
log_backtrace: Option<String> = (None, parse_opt_string, [TRACKED],
"add a backtrace along with logging"),
ls: bool = (false, parse_bool, [UNTRACKED],
"list the symbols defined by a library crate (default: no)"),
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
Expand Down
81 changes: 76 additions & 5 deletions compiler/rustc_trait_selection/src/solve/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::infcx_ext::InferCtxtExt;
#[cfg(doc)]
use super::trait_goals::structural_traits::*;
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult};
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
use rustc_hir::def_id::DefId;
use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::util::elaborate_predicates;
Expand Down Expand Up @@ -399,10 +399,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
ty::Alias(_, alias_ty) => alias_ty,
};

for (assumption, _) in self
.tcx()
.bound_explicit_item_bounds(alias_ty.def_id)
.subst_iter_copied(self.tcx(), alias_ty.substs)
for assumption in self.tcx().item_bounds(alias_ty.def_id).subst(self.tcx(), alias_ty.substs)
{
match G::consider_assumption(self, goal, assumption) {
Ok(result) => {
Expand Down Expand Up @@ -462,4 +459,78 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
}
}

#[instrument(level = "debug", skip(self), ret)]
pub(super) fn merge_candidates_and_discard_reservation_impls(
&mut self,
mut candidates: Vec<Candidate<'tcx>>,
) -> QueryResult<'tcx> {
match candidates.len() {
0 => return Err(NoSolution),
1 => return Ok(self.discard_reservation_impl(candidates.pop().unwrap()).result),
_ => {}
}

if candidates.len() > 1 {
let mut i = 0;
'outer: while i < candidates.len() {
for j in (0..candidates.len()).filter(|&j| i != j) {
if self.trait_candidate_should_be_dropped_in_favor_of(
&candidates[i],
&candidates[j],
) {
debug!(candidate = ?candidates[i], "Dropping candidate #{}/{}", i, candidates.len());
candidates.swap_remove(i);
continue 'outer;
}
}

debug!(candidate = ?candidates[i], "Retaining candidate #{}/{}", i, candidates.len());
i += 1;
}

// If there are *STILL* multiple candidates, give up
// and report ambiguity.
if candidates.len() > 1 {
let certainty = if candidates.iter().all(|x| {
matches!(x.result.value.certainty, Certainty::Maybe(MaybeCause::Overflow))
}) {
Certainty::Maybe(MaybeCause::Overflow)
} else {
Certainty::AMBIGUOUS
};
return self.make_canonical_response(certainty);
}
}

Ok(self.discard_reservation_impl(candidates.pop().unwrap()).result)
}

fn trait_candidate_should_be_dropped_in_favor_of(
&self,
candidate: &Candidate<'tcx>,
other: &Candidate<'tcx>,
) -> bool {
// FIXME: implement this
match (candidate.source, other.source) {
(CandidateSource::Impl(_), _)
| (CandidateSource::ParamEnv(_), _)
| (CandidateSource::AliasBound, _)
| (CandidateSource::BuiltinImpl, _) => false,
}
}

fn discard_reservation_impl(&self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
if let CandidateSource::Impl(def_id) = candidate.source {
if let ty::ImplPolarity::Reservation = self.tcx().impl_polarity(def_id) {
debug!("Selected reservation impl");
// We assemble all candidates inside of a probe so by
// making a new canonical response here our result will
// have no constraints.
candidate.result = self.make_canonical_response(Certainty::AMBIGUOUS).unwrap();
}
}

candidate
}
}
60 changes: 4 additions & 56 deletions compiler/rustc_trait_selection/src/solve/project_goals.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::traits::{specialization_graph, translate_substs};

use super::assembly::{self, Candidate, CandidateSource};
use super::assembly;
use super::infcx_ext::InferCtxtExt;
use super::trait_goals::structural_traits;
use super::{Certainty, EvalCtxt, Goal, QueryResult};
Expand Down Expand Up @@ -34,7 +34,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
// projection cache in the solver.
if self.term_is_fully_unconstrained(goal) {
let candidates = self.assemble_and_evaluate_candidates(goal);
self.merge_project_candidates(candidates)
self.merge_candidates_and_discard_reservation_impls(candidates)
} else {
let predicate = goal.predicate;
let unconstrained_rhs = match predicate.term.unpack() {
Expand Down Expand Up @@ -153,59 +153,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {

self.make_canonical_response(normalization_certainty.unify_and(rhs_certainty))
}

fn merge_project_candidates(
&mut self,
mut candidates: Vec<Candidate<'tcx>>,
) -> QueryResult<'tcx> {
match candidates.len() {
0 => return Err(NoSolution),
1 => return Ok(candidates.pop().unwrap().result),
_ => {}
}

if candidates.len() > 1 {
let mut i = 0;
'outer: while i < candidates.len() {
for j in (0..candidates.len()).filter(|&j| i != j) {
if self.project_candidate_should_be_dropped_in_favor_of(
&candidates[i],
&candidates[j],
) {
debug!(candidate = ?candidates[i], "Dropping candidate #{}/{}", i, candidates.len());
candidates.swap_remove(i);
continue 'outer;
}
}

debug!(candidate = ?candidates[i], "Retaining candidate #{}/{}", i, candidates.len());
// If there are *STILL* multiple candidates, give up
// and report ambiguity.
i += 1;
if i > 1 {
debug!("multiple matches, ambig");
// FIXME: return overflow if all candidates overflow, otherwise return ambiguity.
unimplemented!();
}
}
}

Ok(candidates.pop().unwrap().result)
}

fn project_candidate_should_be_dropped_in_favor_of(
&self,
candidate: &Candidate<'tcx>,
other: &Candidate<'tcx>,
) -> bool {
// FIXME: implement this
match (candidate.source, other.source) {
(CandidateSource::Impl(_), _)
| (CandidateSource::ParamEnv(_), _)
| (CandidateSource::BuiltinImpl, _)
| (CandidateSource::AliasBound, _) => unimplemented!(),
}
}
}

impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
Expand Down Expand Up @@ -452,7 +399,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
[ty::GenericArg::from(goal.predicate.self_ty())],
));

let is_sized_certainty = ecx.evaluate_goal(goal.with(tcx, sized_predicate))?.1;
let (_, is_sized_certainty) =
ecx.evaluate_goal(goal.with(tcx, sized_predicate))?;
return ecx.eq_term_and_make_canonical_response(
goal,
is_sized_certainty,
Expand Down
Loading