Skip to content

Commit 8a30a32

Browse files
committed
Auto merge of rust-lang#126369 - workingjubilee:rollup-fd21o5w, r=workingjubilee
Rollup of 11 pull requests Successful merges: - rust-lang#125165 (Migrate `run-make/pgo-branch-weights` to `rmake`) - rust-lang#125674 (Rewrite `symlinked-extern`, `symlinked-rlib` and `symlinked-libraries` `run-make` tests in `rmake.rs` format) - rust-lang#125688 (Walk into alias-eq nested goals even if normalization fails) - rust-lang#126142 (Harmonize using root or leaf obligation in trait error reporting) - rust-lang#126303 (Urls to docs in rust_hir) - rust-lang#126328 (Add Option::is_none_or) - rust-lang#126337 (Add test for walking order dependent opaque type behaviour) - rust-lang#126351 (std::unix::fs::link using direct linkat call for Solaris.) - rust-lang#126353 (Move `MatchAgainstFreshVars` to old solver) - rust-lang#126356 (docs(rustc): Improve discoverable of Cargo docs) - rust-lang#126362 (Make `try_from_target_usize` method public) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8cf5101 + f16bd4e commit 8a30a32

File tree

82 files changed

+692
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+692
-272
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10571057

10581058
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
10591059

1060-
ty::Tuple(tys) => tys.last().iter().all(|ty| is_very_trivially_sized(**ty)),
1060+
ty::Tuple(tys) => tys.last().is_none_or(|ty| is_very_trivially_sized(*ty)),
10611061

10621062
ty::Pat(ty, ..) => is_very_trivially_sized(*ty),
10631063

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
446446
let (alloc_size, _alloc_align, ret_val) = alloc_size(alloc_id, offset, prov)?;
447447
// Test bounds.
448448
// It is sufficient to check this for the end pointer. Also check for overflow!
449-
if offset.checked_add(size, &self.tcx).map_or(true, |end| end > alloc_size) {
449+
if offset.checked_add(size, &self.tcx).is_none_or(|end| end > alloc_size) {
450450
throw_ub!(PointerOutOfBounds {
451451
alloc_id,
452452
alloc_size,

compiler/rustc_const_eval/src/interpret/projection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ where
300300
) -> InterpResult<'tcx, P> {
301301
let len = base.len(self)?; // also asserts that we have a type where this makes sense
302302
let actual_to = if from_end {
303-
if from.checked_add(to).map_or(true, |to| to > len) {
303+
if from.checked_add(to).is_none_or(|to| to > len) {
304304
// This can only be reached in ConstProp and non-rustc-MIR.
305305
throw_ub!(BoundsCheckFailed { len: len, index: from.saturating_add(to) });
306306
}

compiler/rustc_const_eval/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(box_patterns)]
77
#![feature(decl_macro)]
88
#![feature(if_let_guard)]
9+
#![feature(is_none_or)]
910
#![feature(let_chains)]
1011
#![feature(never_type)]
1112
#![feature(rustdoc_internals)]

compiler/rustc_hir/src/hir.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,13 @@ pub struct ConstBlock {
16331633
}
16341634

16351635
/// An expression.
1636+
///
1637+
/// For more details, see the [rust lang reference].
1638+
/// Note that the reference does not document nightly-only features.
1639+
/// There may be also slight differences in the names and representation of AST nodes between
1640+
/// the compiler and the reference.
1641+
///
1642+
/// [rust lang reference]: https://doc.rust-lang.org/reference/expressions.html
16361643
#[derive(Debug, Clone, Copy, HashStable_Generic)]
16371644
pub struct Expr<'hir> {
16381645
pub hir_id: HirId,
@@ -3147,6 +3154,13 @@ impl ItemId {
31473154
/// An item
31483155
///
31493156
/// The name might be a dummy name in case of anonymous items
3157+
///
3158+
/// For more details, see the [rust lang reference].
3159+
/// Note that the reference does not document nightly-only features.
3160+
/// There may be also slight differences in the names and representation of AST nodes between
3161+
/// the compiler and the reference.
3162+
///
3163+
/// [rust lang reference]: https://doc.rust-lang.org/reference/items.html
31503164
#[derive(Debug, Clone, Copy, HashStable_Generic)]
31513165
pub struct Item<'hir> {
31523166
pub ident: Ident,

compiler/rustc_hir_typeck/src/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
let ret_ty = ret_coercion.borrow().expected_ty();
235235
let ret_ty = self.infcx.shallow_resolve(ret_ty);
236236
self.can_coerce(arm_ty, ret_ty)
237-
&& prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty))
237+
&& prior_arm.is_none_or(|(_, ty, _)| self.can_coerce(ty, ret_ty))
238238
// The match arms need to unify for the case of `impl Trait`.
239239
&& !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..))
240240
}

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
913913
if self
914914
.tcx
915915
.upvars_mentioned(closure_def_id_a.expect_local())
916-
.map_or(true, |u| u.is_empty()) =>
916+
.is_none_or(|u| u.is_empty()) =>
917917
{
918918
// We coerce the closure, which has fn type
919919
// `extern "rust-call" fn((arg0,arg1,...)) -> _`

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15571557

15581558
// If the length is 0, we don't create any elements, so we don't copy any. If the length is 1, we
15591559
// don't copy that one element, we move it. Only check for Copy if the length is larger.
1560-
if count.try_eval_target_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
1560+
if count.try_eval_target_usize(tcx, self.param_env).is_none_or(|len| len > 1) {
15611561
let lang_item = self.tcx.require_lang_item(LangItem::Copy, None);
15621562
let code = traits::ObligationCauseCode::RepeatElementCopy {
15631563
is_constable,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22402240
for (idx, (generic_param, param)) in
22412241
params_with_generics.iter().enumerate().filter(|(idx, _)| {
22422242
check_for_matched_generics
2243-
|| expected_idx.map_or(true, |expected_idx| expected_idx == *idx)
2243+
|| expected_idx.is_none_or(|expected_idx| expected_idx == *idx)
22442244
})
22452245
{
22462246
let Some(generic_param) = generic_param else {

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
440440
};
441441
// Given `Result<_, E>`, check our expected ty is `Result<_, &E>` for
442442
// `as_ref` and `as_deref` compatibility.
443-
let error_tys_equate_as_ref = error_tys.map_or(true, |(found, expected)| {
443+
let error_tys_equate_as_ref = error_tys.is_none_or(|(found, expected)| {
444444
self.can_eq(
445445
self.param_env,
446446
Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, found),
@@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492492
&& Some(adt.did()) == self.tcx.lang_items().string()
493493
&& peeled.is_str()
494494
// `Result::map`, conversely, does not take ref of the error type.
495-
&& error_tys.map_or(true, |(found, expected)| {
495+
&& error_tys.is_none_or(|(found, expected)| {
496496
self.can_eq(self.param_env, found, expected)
497497
})
498498
{

compiler/rustc_hir_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(box_patterns)]
55
#![feature(control_flow_enum)]
66
#![feature(if_let_guard)]
7+
#![feature(is_none_or)]
78
#![feature(let_chains)]
89
#![feature(never_type)]
910
#![feature(try_blocks)]

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<T> Trait<T> for X {
546546
for pred in hir_generics.bounds_for_param(def_id) {
547547
if self.constrain_generic_bound_associated_type_structured_suggestion(
548548
diag,
549-
&trait_ref,
549+
trait_ref,
550550
pred.bounds,
551551
assoc,
552552
assoc_args,
@@ -715,7 +715,7 @@ fn foo(&self) -> Self::T { String::new() }
715715

716716
self.constrain_generic_bound_associated_type_structured_suggestion(
717717
diag,
718-
&trait_ref,
718+
trait_ref,
719719
opaque_hir_ty.bounds,
720720
assoc,
721721
assoc_args,
@@ -869,7 +869,7 @@ fn foo(&self) -> Self::T { String::new() }
869869
fn constrain_generic_bound_associated_type_structured_suggestion(
870870
&self,
871871
diag: &mut Diag<'_>,
872-
trait_ref: &ty::TraitRef<'tcx>,
872+
trait_ref: ty::TraitRef<'tcx>,
873873
bounds: hir::GenericBounds<'_>,
874874
assoc: ty::AssocItem,
875875
assoc_args: &[ty::GenericArg<'tcx>],

compiler/rustc_infer/src/infer/relate/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
55
pub use rustc_middle::ty::relate::*;
66

7-
pub use self::_match::MatchAgainstFreshVars;
87
pub use self::combine::CombineFields;
98
pub use self::combine::PredicateEmittingRelation;
109

11-
pub mod _match;
1210
pub(super) mod combine;
1311
mod generalize;
1412
mod glb;

compiler/rustc_infer/src/traits/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
285285
let obligations =
286286
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
287287
elaboratable.child_with_derived_cause(
288-
clause
289-
.instantiate_supertrait(tcx, &bound_clause.rebind(data.trait_ref)),
288+
clause.instantiate_supertrait(tcx, bound_clause.rebind(data.trait_ref)),
290289
span,
291290
bound_clause.rebind(data),
292291
index,

compiler/rustc_lint_defs/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,11 @@ declare_lint! {
32573257
/// See the [Checking Conditional Configurations][check-cfg] section for more
32583258
/// details.
32593259
///
3260+
/// See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in
3261+
/// `Cargo.toml`.
3262+
///
32603263
/// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
3264+
/// [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table
32613265
pub UNEXPECTED_CFGS,
32623266
Warn,
32633267
"detects unexpected names and values in `#[cfg]` conditions",

compiler/rustc_middle/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> Elaborator<'tcx> {
3737
let super_predicates =
3838
self.tcx.super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map(
3939
|&(pred, _)| {
40-
let clause = pred.instantiate_supertrait(self.tcx, &trait_ref);
40+
let clause = pred.instantiate_supertrait(self.tcx, trait_ref);
4141
self.visited.insert(clause).then_some(clause)
4242
},
4343
);

compiler/rustc_middle/src/ty/predicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'tcx> Clause<'tcx> {
313313
pub fn instantiate_supertrait(
314314
self,
315315
tcx: TyCtxt<'tcx>,
316-
trait_ref: &ty::PolyTraitRef<'tcx>,
316+
trait_ref: ty::PolyTraitRef<'tcx>,
317317
) -> Clause<'tcx> {
318318
// The interaction between HRTB and supertraits is not entirely
319319
// obvious. Let me walk you (and myself) through an example.

compiler/rustc_trait_selection/src/solve/alias_relate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
4848
rhs
4949
};
5050

51+
// Add a `make_canonical_response` probe step so that we treat this as
52+
// a candidate, even if `try_evaluate_added_goals` bails due to an error.
53+
// It's `Certainty::AMBIGUOUS` because this candidate is not "finished",
54+
// since equating the normalized terms will lead to additional constraints.
55+
self.inspect.make_canonical_response(Certainty::AMBIGUOUS);
56+
5157
// Apply the constraints.
5258
self.try_evaluate_added_goals()?;
5359
let lhs = self.resolve_vars_if_possible(lhs);

compiler/rustc_trait_selection/src/solve/fulfill.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
460460
polarity: ty::PredicatePolarity::Positive,
461461
}))
462462
}
463-
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
464-
ChildMode::WellFormedObligation
465-
}
463+
ty::PredicateKind::Clause(
464+
ty::ClauseKind::WellFormed(_) | ty::ClauseKind::Projection(..),
465+
)
466+
| ty::PredicateKind::AliasRelate(..) => ChildMode::PassThrough,
466467
_ => {
467468
return ControlFlow::Break(self.obligation.clone());
468469
}
@@ -496,7 +497,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
496497
(_, GoalSource::InstantiateHigherRanked) => {
497498
obligation = self.obligation.clone();
498499
}
499-
(ChildMode::WellFormedObligation, _) => {
500+
(ChildMode::PassThrough, _) => {
500501
obligation = make_obligation(self.obligation.cause.clone());
501502
}
502503
}
@@ -527,7 +528,7 @@ enum ChildMode<'tcx> {
527528
// Skip trying to derive an `ObligationCause` from this obligation, and
528529
// report *all* sub-obligations as if they came directly from the parent
529530
// obligation.
530-
WellFormedObligation,
531+
PassThrough,
531532
}
532533

533534
fn derive_cause<'tcx>(

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
1515
use rustc_macros::extension;
1616
use rustc_middle::traits::query::NoSolution;
1717
use rustc_middle::traits::solve::{inspect, QueryResult};
18-
use rustc_middle::traits::solve::{Certainty, Goal};
18+
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
1919
use rustc_middle::traits::ObligationCause;
2020
use rustc_middle::ty::{TyCtxt, TypeFoldable};
2121
use rustc_middle::{bug, ty};
@@ -291,7 +291,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
291291
steps.push(step)
292292
}
293293
inspect::ProbeStep::MakeCanonicalResponse { shallow_certainty: c } => {
294-
assert_eq!(shallow_certainty.replace(c), None);
294+
assert!(matches!(
295+
shallow_certainty.replace(c),
296+
None | Some(Certainty::Maybe(MaybeCause::Ambiguity))
297+
));
295298
}
296299
inspect::ProbeStep::NestedProbe(ref probe) => {
297300
match probe.kind {

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

+8-10
Original file line numberDiff line numberDiff line change
@@ -3597,7 +3597,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
35973597
&self,
35983598
obligation: &PredicateObligation<'tcx>,
35993599
err: &mut Diag<'_>,
3600-
trait_ref: &ty::PolyTraitRef<'tcx>,
3600+
trait_ref: ty::PolyTraitRef<'tcx>,
36013601
) {
36023602
let rhs_span = match obligation.cause.code() {
36033603
ObligationCauseCode::BinOp { rhs_span: Some(span), rhs_is_lit, .. } if *rhs_is_lit => {
@@ -4592,7 +4592,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45924592
&self,
45934593
obligation: &PredicateObligation<'tcx>,
45944594
err: &mut Diag<'_>,
4595-
trait_ref: ty::PolyTraitRef<'tcx>,
4595+
trait_pred: ty::PolyTraitPredicate<'tcx>,
45964596
) {
45974597
if ObligationCauseCode::QuestionMark != *obligation.cause.code().peel_derives() {
45984598
return;
@@ -4602,10 +4602,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
46024602
if let hir::Node::Item(item) = node
46034603
&& let hir::ItemKind::Fn(sig, _, body_id) = item.kind
46044604
&& let hir::FnRetTy::DefaultReturn(ret_span) = sig.decl.output
4605-
&& self.tcx.is_diagnostic_item(sym::FromResidual, trait_ref.def_id())
4606-
&& let ty::Tuple(l) = trait_ref.skip_binder().args.type_at(0).kind()
4607-
&& l.len() == 0
4608-
&& let ty::Adt(def, _) = trait_ref.skip_binder().args.type_at(1).kind()
4605+
&& self.tcx.is_diagnostic_item(sym::FromResidual, trait_pred.def_id())
4606+
&& trait_pred.skip_binder().trait_ref.args.type_at(0).is_unit()
4607+
&& let ty::Adt(def, _) = trait_pred.skip_binder().trait_ref.args.type_at(1).kind()
46094608
&& self.tcx.is_diagnostic_item(sym::Result, def.did())
46104609
{
46114610
let body = self.tcx.hir().body(body_id);
@@ -4863,14 +4862,13 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
48634862
pub(super) fn get_explanation_based_on_obligation<'tcx>(
48644863
tcx: TyCtxt<'tcx>,
48654864
obligation: &PredicateObligation<'tcx>,
4866-
trait_ref: ty::PolyTraitRef<'tcx>,
4867-
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
4865+
trait_predicate: ty::PolyTraitPredicate<'tcx>,
48684866
pre_message: String,
48694867
) -> String {
48704868
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
48714869
"consider using `()`, or a `Result`".to_owned()
48724870
} else {
4873-
let ty_desc = match trait_ref.skip_binder().self_ty().kind() {
4871+
let ty_desc = match trait_predicate.self_ty().skip_binder().kind() {
48744872
ty::FnDef(_, _) => Some("fn item"),
48754873
ty::Closure(_, _) => Some("closure"),
48764874
_ => None,
@@ -4895,7 +4893,7 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
48954893
format!(
48964894
"{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
48974895
trait_predicate.print_modifiers_and_trait_path(),
4898-
tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
4896+
tcx.short_ty_string(trait_predicate.self_ty().skip_binder(), &mut None),
48994897
)
49004898
} else {
49014899
// "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is

0 commit comments

Comments
 (0)