Skip to content

Rollup of 8 pull requests #141366

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

Merged
merged 16 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b735dce
docs: Specify that common sort functions sort in an ascending direction
Natr1x Apr 30, 2025
d8a22a2
limit impls of `VaArgSafe` to just types that are actually safe
folkertdev May 21, 2025
5d9141c
fix better_any breakage by making the solver more unsound
lcnr May 21, 2025
46a5c91
std: fix doctest and explain for as_slices and as_mut_slices in VecDeque
xizheyin May 18, 2025
96ac571
Move -Zcrate-attr injection to just after crate root parsing
bjorn3 Feb 19, 2025
2a403dc
lower bodies' params to thir before the body's value
dianne May 21, 2025
f2d94c1
`unpretty=thir-tree`: don't require the final expr to be the entrypoint
dianne May 18, 2025
6d6259f
Document why we allow escaping bound vars in LTA norm
BoxyUwU May 21, 2025
d4b7915
Rollup merge of #140526 - Natr1x:sort-direction-documentation, r=dtolnay
matthiaskrgr May 21, 2025
b5edec2
Rollup merge of #141230 - xizheyin:issue-141217, r=tgross35
matthiaskrgr May 21, 2025
b9c6b33
Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=working…
matthiaskrgr May 21, 2025
69b13e4
Rollup merge of #141347 - lcnr:lets-make-it-unsound-3, r=compiler-errors
matthiaskrgr May 21, 2025
eff339b
Rollup merge of #141351 - bjorn3:attr_handling_changes, r=Nadrieril
matthiaskrgr May 21, 2025
fea2e5c
Rollup merge of #141356 - dianne:thir-lower-params-before-body-expr, …
matthiaskrgr May 21, 2025
2663ea3
Rollup merge of #141357 - dianne:unhardcode-unpretty-thir-tree-body-e…
matthiaskrgr May 21, 2025
de4055f
Rollup merge of #141363 - BoxyUwU:doc_lta_norm_binders, r=lcnr
matthiaskrgr May 21, 2025
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
16 changes: 8 additions & 8 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::interface::Compiler;
use crate::{errors, limits, proc_macro_decls, util};

pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
let krate = sess
let mut krate = sess
.time("parse_crate", || {
let mut parser = unwrap_or_emit_fatal(match &sess.io.input {
Input::File(file) => new_parser_from_file(&sess.psess, file, None),
Expand All @@ -64,6 +64,12 @@ pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
input_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
}

rustc_builtin_macros::cmdline_attrs::inject(
&mut krate,
&sess.psess,
&sess.opts.unstable_opts.crate_attr,
);

krate
}

Expand Down Expand Up @@ -805,17 +811,11 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {

pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
compiler: &Compiler,
mut krate: rustc_ast::Crate,
krate: rustc_ast::Crate,
f: F,
) -> T {
let sess = &compiler.sess;

rustc_builtin_macros::cmdline_attrs::inject(
&mut krate,
&sess.psess,
&sess.opts.unstable_opts.crate_attr,
);

let pre_configured_attrs = rustc_expand::config::pre_configure_attrs(sess, &krate.attrs);

let crate_name = get_crate_name(sess, &pre_configured_attrs);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_build/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ fn construct_fn<'tcx>(
let span = tcx.def_span(fn_def);
let fn_id = tcx.local_def_id_to_hir_id(fn_def);

// The representation of thir for `-Zunpretty=thir-tree` relies on
// the entry expression being the last element of `thir.exprs`.
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);

// Figure out what primary body this item has.
let body = tcx.hir_body_owned_by(fn_def);
let span_with_body = tcx.hir_span_with_body(fn_id);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_build/src/thir/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub(crate) fn thir_body(
if let Some(reported) = cx.typeck_results.tainted_by_errors {
return Err(reported);
}
let expr = cx.mirror_expr(body.value);

// Lower the params before the body's expression so errors from params are shown first.
let owner_id = tcx.local_def_id_to_hir_id(owner_def);
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(owner_id) {
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
Expand All @@ -48,6 +48,7 @@ pub(crate) fn thir_body(
}
}

let expr = cx.mirror_expr(body.value);
Ok((tcx.alloc_steal_thir(cx.thir), expr))
}

Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_mir_build/src/thir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use rustc_span::def_id::LocalDefId;
/// Create a THIR tree for debugging.
pub fn thir_tree(tcx: TyCtxt<'_>, owner_def: LocalDefId) -> String {
match super::cx::thir_body(tcx, owner_def) {
Ok((thir, _)) => {
Ok((thir, expr)) => {
let thir = thir.steal();
let mut printer = ThirPrinter::new(&thir);
printer.print();
printer.print(expr);
printer.into_buffer()
}
Err(_) => "error".into(),
Expand Down Expand Up @@ -58,16 +58,15 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
}
}

fn print(&mut self) {
fn print(&mut self, body_expr: ExprId) {
print_indented!(self, "params: [", 0);
for param in self.thir.params.iter() {
self.print_param(param, 1);
}
print_indented!(self, "]", 0);

print_indented!(self, "body:", 0);
let expr = ExprId::from_usize(self.thir.exprs.len() - 1);
self.print_expr(expr, 1);
self.print_expr(body_expr, 1);
}

fn into_buffer(self) -> String {
Expand Down
44 changes: 42 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use rustc_type_ir::{
self as ty, Interner, Movability, TraitPredicate, TypeVisitableExt as _, TypingMode,
Upcast as _, elaborate,
};
use tracing::{instrument, trace};
use tracing::{debug, instrument, trace};

use crate::delegate::SolverDelegate;
use crate::solve::assembly::structural_traits::{self, AsyncCallableRelevantTypes};
use crate::solve::assembly::{self, AllowInferenceConstraints, AssembleCandidatesFrom, Candidate};
use crate::solve::inspect::ProbeKind;
use crate::solve::{
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeCause,
NoSolution, ParamEnvSource, QueryResult,
NoSolution, ParamEnvSource, QueryResult, has_only_region_constraints,
};

impl<D, I> assembly::GoalKind<D> for TraitPredicate<I>
Expand Down Expand Up @@ -1253,6 +1253,45 @@ where
D: SolverDelegate<Interner = I>,
I: Interner,
{
/// FIXME(#57893): For backwards compatability with the old trait solver implementation,
/// we need to handle overlap between builtin and user-written impls for trait objects.
///
/// This overlap is unsound in general and something which we intend to fix separately.
/// To avoid blocking the stabilization of the trait solver, we add this hack to avoid
/// breakage in cases which are *mostly fine*™. Importantly, this preference is strictly
/// weaker than the old behavior.
///
/// We only prefer builtin over user-written impls if there are no inference constraints.
/// Importantly, we also only prefer the builtin impls for trait goals, and not during
/// normalization. This means the only case where this special-case results in exploitable
/// unsoundness should be lifetime dependent user-written impls.
pub(super) fn unsound_prefer_builtin_dyn_impl(&mut self, candidates: &mut Vec<Candidate<I>>) {
match self.typing_mode() {
TypingMode::Coherence => return,
TypingMode::Analysis { .. }
| TypingMode::Borrowck { .. }
| TypingMode::PostBorrowckAnalysis { .. }
| TypingMode::PostAnalysis => {}
}

if candidates
.iter()
.find(|c| {
matches!(c.source, CandidateSource::BuiltinImpl(BuiltinImplSource::Object(_)))
})
.is_some_and(|c| has_only_region_constraints(c.result))
{
candidates.retain(|c| {
if matches!(c.source, CandidateSource::Impl(_)) {
debug!(?c, "unsoundly dropping impl in favor of builtin dyn-candidate");
false
} else {
true
}
});
}
}

#[instrument(level = "debug", skip(self), ret)]
pub(super) fn merge_trait_candidates(
&mut self,
Expand Down Expand Up @@ -1313,6 +1352,7 @@ where
}

self.filter_specialized_impls(AllowInferenceConstraints::No, &mut candidates);
self.unsound_prefer_builtin_dyn_impl(&mut candidates);

// If there are *only* global where bounds, then make sure to return that this
// is still reported as being proven-via the param-env so that rigid projections
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,21 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
);
}

// We don't replace bound vars in the generic arguments of the free alias with
// placeholders. This doesn't cause any issues as instantiating parameters with
// bound variables is special-cased to rewrite the debruijn index to be higher
// whenever we fold through a binder.
//
// However, we do replace any escaping bound vars in the resulting goals with
// placeholders as the trait solver does not expect to encounter escaping bound
// vars in obligations.
//
// FIXME(lazy_type_alias): Check how much this actually matters for perf before
// stabilization. This is a bit weird and generally not how we handle binders in
// the compiler so ideally we'd do the same boundvar->placeholder->boundvar dance
// that other kinds of normalization do.
let infcx = self.selcx.infcx;
self.obligations.extend(
// FIXME(BoxyUwU):
// FIXME(lazy_type_alias):
// It seems suspicious to instantiate the predicates with arguments that might be bound vars,
// we might wind up instantiating one of these bound vars underneath a hrtb.
infcx.tcx.predicates_of(free.def_id).instantiate_own(infcx.tcx, free.args).map(
|(mut predicate, span)| {
if free.has_escaping_bound_vars() {
Expand Down
33 changes: 28 additions & 5 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// If [`make_contiguous`] was previously called, all elements of the
/// deque will be in the first slice and the second slice will be empty.
/// Otherwise, the exact split point depends on implementation details
/// and is not guaranteed.
///
/// [`make_contiguous`]: VecDeque::make_contiguous
///
Expand All @@ -1326,12 +1328,18 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// deque.push_back(1);
/// deque.push_back(2);
///
/// assert_eq!(deque.as_slices(), (&[0, 1, 2][..], &[][..]));
/// let expected = [0, 1, 2];
/// let (front, back) = deque.as_slices();
/// assert_eq!(&expected[..front.len()], front);
/// assert_eq!(&expected[front.len()..], back);
///
/// deque.push_front(10);
/// deque.push_front(9);
///
/// assert_eq!(deque.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
/// let expected = [9, 10, 0, 1, 2];
/// let (front, back) = deque.as_slices();
/// assert_eq!(&expected[..front.len()], front);
/// assert_eq!(&expected[front.len()..], back);
/// ```
#[inline]
#[stable(feature = "deque_extras_15", since = "1.5.0")]
Expand All @@ -1347,6 +1355,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// If [`make_contiguous`] was previously called, all elements of the
/// deque will be in the first slice and the second slice will be empty.
/// Otherwise, the exact split point depends on implementation details
/// and is not guaranteed.
///
/// [`make_contiguous`]: VecDeque::make_contiguous
///
Expand All @@ -1363,9 +1373,22 @@ impl<T, A: Allocator> VecDeque<T, A> {
/// deque.push_front(10);
/// deque.push_front(9);
///
/// deque.as_mut_slices().0[0] = 42;
/// deque.as_mut_slices().1[0] = 24;
/// assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
/// // Since the split point is not guaranteed, we may need to update
/// // either slice.
/// let mut update_nth = |index: usize, val: u32| {
/// let (front, back) = deque.as_mut_slices();
/// if index > front.len() - 1 {
/// back[index - front.len()] = val;
/// } else {
/// front[index] = val;
/// }
/// };
///
/// update_nth(0, 42);
/// update_nth(2, 24);
///
/// let v: Vec<_> = deque.into();
/// assert_eq!(v, [42, 10, 24, 1]);
/// ```
#[inline]
#[stable(feature = "deque_extras_15", since = "1.5.0")]
Expand Down
11 changes: 7 additions & 4 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use crate::boxed::Box;
use crate::vec::Vec;

impl<T> [T] {
/// Sorts the slice, preserving initial order of equal elements.
/// Sorts the slice in ascending order, preserving initial order of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
/// worst-case.
Expand Down Expand Up @@ -137,7 +137,8 @@ impl<T> [T] {
stable_sort(self, T::lt);
}

/// Sorts the slice with a comparison function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a comparison function, preserving initial order of
/// equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*))
/// worst-case.
Expand Down Expand Up @@ -197,7 +198,8 @@ impl<T> [T] {
stable_sort(self, |a, b| compare(a, b) == Less);
}

/// Sorts the slice with a key extraction function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a key extraction function, preserving initial order
/// of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* \* log(*n*))
/// worst-case, where the key function is *O*(*m*).
Expand Down Expand Up @@ -252,7 +254,8 @@ impl<T> [T] {
stable_sort(self, |a, b| f(a).lt(&f(b)));
}

/// Sorts the slice with a key extraction function, preserving initial order of equal elements.
/// Sorts the slice in ascending order with a key extraction function, preserving initial order
/// of equal elements.
///
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* + *n* \*
/// log(*n*)) worst-case, where the key function is *O*(*m*).
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod c_str;
issue = "44930",
reason = "the `c_variadic` feature has not been properly tested on all supported platforms"
)]
pub use self::va_list::{VaList, VaListImpl};
pub use self::va_list::{VaArgSafe, VaList, VaListImpl};

#[unstable(
feature = "c_variadic",
Expand Down
Loading
Loading