Skip to content

Commit 69d25fc

Browse files
committed
Auto merge of #92915 - matthiaskrgr:rollup-pxxk8jp, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #92191 (Prefer projection candidates instead of param_env candidates for Sized predicates) - #92382 (Extend const_convert to rest of blanket core::convert impls) - #92625 (Add `#[track_caller]` to `mirbug`) - #92684 (Export `tcp::IntoIncoming`) - #92743 (Use pre-interned symbols in a couple of places) - #92838 (Clean up some links in RELEASES) - #92868 (librustdoc: Address some clippy lints) - #92875 (Make `opt_const_param_of` work in the presence of `GenericArg::Infer`) - #92891 (Add myself to .mailmap) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents de9b573 + ff6c175 commit 69d25fc

File tree

32 files changed

+378
-415
lines changed

32 files changed

+378
-415
lines changed

Diff for: .mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub.bukaj@yahoo.com>
129129
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub@jakub.cc>
130130
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakubw@jakubw.net>
131131
James Deng <cnjamesdeng@gmail.com> <cnJamesDeng@gmail.com>
132+
James Hinshelwood <jameshinshelwood1@gmail.com> <james.hinshelwood@bigpayme.com>
132133
James Miller <bladeon@gmail.com> <james@aatch.net>
133134
James Perry <james.austin.perry@gmail.com>
134135
Jason Fager <jfager@gmail.com>

Diff for: RELEASES.md

+16-126
Large diffs are not rendered by default.

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::Res;
1111
use rustc_hir::definitions::DefPathData;
1212
use rustc_span::hygiene::ExpnId;
1313
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
14-
use rustc_span::symbol::{sym, Ident, Symbol};
14+
use rustc_span::symbol::{sym, Ident};
1515
use rustc_span::DUMMY_SP;
1616

1717
impl<'hir> LoweringContext<'_, 'hir> {
@@ -1204,11 +1204,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
12041204
};
12051205

12061206
let fields = self.arena.alloc_from_iter(
1207-
e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| {
1208-
let expr = self.lower_expr(&e);
1209-
let ident = Ident::new(Symbol::intern(s), self.lower_span(e.span));
1210-
self.expr_field(ident, expr, e.span)
1211-
}),
1207+
e1.iter().map(|e| (sym::start, e)).chain(e2.iter().map(|e| (sym::end, e))).map(
1208+
|(s, e)| {
1209+
let expr = self.lower_expr(&e);
1210+
let ident = Ident::new(s, self.lower_span(e.span));
1211+
self.expr_field(ident, expr, e.span)
1212+
},
1213+
),
12121214
);
12131215

12141216
hir::ExprKind::Struct(

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
312312
}
313313
}
314314

315+
#[track_caller]
315316
fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: &str) {
316317
// We sometimes see MIR failures (notably predicate failures) due to
317318
// the fact that we check rvalue sized predicates here. So use `delay_span_bug`

Diff for: compiler/rustc_hir/src/hir.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ impl GenericArg<'_> {
293293
}
294294
}
295295

296-
pub fn is_const(&self) -> bool {
297-
matches!(self, GenericArg::Const(_))
298-
}
299-
300296
pub fn is_synthetic(&self) -> bool {
301297
matches!(self, GenericArg::Lifetime(lifetime) if lifetime.name.ident() == Ident::empty())
302298
}
@@ -318,6 +314,13 @@ impl GenericArg<'_> {
318314
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
319315
}
320316
}
317+
318+
pub fn is_ty_or_const(&self) -> bool {
319+
match self {
320+
GenericArg::Lifetime(_) => false,
321+
GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => true,
322+
}
323+
}
321324
}
322325

323326
#[derive(Debug, HashStable_Generic)]

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::print::Print;
1212
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
1313
use rustc_middle::ty::{self, Const, DefIdTree, InferConst, Ty, TyCtxt, TypeFoldable, TypeFolder};
1414
use rustc_span::symbol::kw;
15-
use rustc_span::Span;
15+
use rustc_span::{sym, Span};
1616
use std::borrow::Cow;
1717

1818
struct FindHirNodeVisitor<'a, 'tcx> {
@@ -1003,9 +1003,9 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
10031003
| ty::Opaque(..)
10041004
| ty::Projection(_)
10051005
| ty::Never => t.super_fold_with(self),
1006-
ty::Array(ty, c) => self
1007-
.tcx()
1008-
.mk_ty(ty::Array(self.fold_ty(ty), self.replace_infers(c, 0, Symbol::intern("N")))),
1006+
ty::Array(ty, c) => {
1007+
self.tcx().mk_ty(ty::Array(self.fold_ty(ty), self.replace_infers(c, 0, sym::N)))
1008+
}
10091009
// We don't want to hide type params that haven't been resolved yet.
10101010
// This would be the type that will be written out with the type param
10111011
// name in the output.

Diff for: compiler/rustc_infer/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'tcx> Elaborator<'tcx> {
152152
obligation.cause.clone(),
153153
)
154154
});
155-
debug!("super_predicates: data={:?}", data);
155+
debug!(?data, ?obligations, "super_predicates");
156156

157157
// Only keep those bounds that we haven't already seen.
158158
// This is necessary to prevent infinite recursion in some

Diff for: compiler/rustc_middle/src/ty/generics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ impl GenericParamDefKind {
3131
GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
3232
}
3333
}
34+
35+
pub fn is_ty_or_const(&self) -> bool {
36+
match self {
37+
GenericParamDefKind::Lifetime => false,
38+
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => true,
39+
}
40+
}
3441
}
3542

3643
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]

Diff for: compiler/rustc_middle/src/ty/print/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ pub trait Printer<'tcx>: Sized {
188188
own_params.start = 1;
189189
}
190190

191+
// If we're in verbose mode, then print default-equal args too
192+
if self.tcx().sess.verbose() {
193+
return &substs[own_params];
194+
}
195+
191196
// Don't print args that are the defaults of their respective parameters.
192197
own_params.end -= generics
193198
.params

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1784,10 +1784,11 @@ impl<'tcx, F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
17841784
self = print_prefix(self)?;
17851785

17861786
// Don't print `'_` if there's no unerased regions.
1787-
let print_regions = args.iter().any(|arg| match arg.unpack() {
1788-
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
1789-
_ => false,
1790-
});
1787+
let print_regions = self.tcx.sess.verbose()
1788+
|| args.iter().any(|arg| match arg.unpack() {
1789+
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
1790+
_ => false,
1791+
});
17911792
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
17921793
GenericArgKind::Lifetime(_) => print_regions,
17931794
_ => true,

Diff for: compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ symbols! {
208208
LinkedList,
209209
LintPass,
210210
Mutex,
211+
N,
211212
None,
212213
Ok,
213214
Option,
@@ -327,6 +328,7 @@ symbols! {
327328
array,
328329
arrays,
329330
as_ptr,
331+
as_ref,
330332
as_str,
331333
asm,
332334
asm_const,
@@ -593,6 +595,7 @@ symbols! {
593595
enable,
594596
enclosing_scope,
595597
encode,
598+
end,
596599
env,
597600
eq,
598601
ermsb_target_feature,

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,10 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
12251225
);
12261226
}
12271227

1228+
#[tracing::instrument(
1229+
level = "debug",
1230+
skip(selcx, candidate_set, ctor, env_predicates, potentially_unnormalized_candidates)
1231+
)]
12281232
fn assemble_candidates_from_predicates<'cx, 'tcx>(
12291233
selcx: &mut SelectionContext<'cx, 'tcx>,
12301234
obligation: &ProjectionTyObligation<'tcx>,
@@ -1233,8 +1237,6 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
12331237
env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
12341238
potentially_unnormalized_candidates: bool,
12351239
) {
1236-
debug!(?obligation, "assemble_candidates_from_predicates");
1237-
12381240
let infcx = selcx.infcx();
12391241
for predicate in env_predicates {
12401242
debug!(?predicate);
@@ -1270,13 +1272,12 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
12701272
}
12711273
}
12721274

1275+
#[tracing::instrument(level = "debug", skip(selcx, obligation, candidate_set))]
12731276
fn assemble_candidates_from_impls<'cx, 'tcx>(
12741277
selcx: &mut SelectionContext<'cx, 'tcx>,
12751278
obligation: &ProjectionTyObligation<'tcx>,
12761279
candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
12771280
) {
1278-
debug!("assemble_candidates_from_impls");
1279-
12801281
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
12811282
// start out by selecting the predicate `T as TraitRef<...>`:
12821283
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));

Diff for: compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
173173

174174
let needs_infer = stack.obligation.predicate.has_infer_types_or_consts();
175175

176+
let sized_predicate = self.tcx().lang_items().sized_trait()
177+
== Some(stack.obligation.predicate.skip_binder().def_id());
178+
176179
// If there are STILL multiple candidates, we can further
177180
// reduce the list by dropping duplicates -- including
178181
// resolving specializations.
@@ -181,6 +184,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
181184
while i < candidates.len() {
182185
let is_dup = (0..candidates.len()).filter(|&j| i != j).any(|j| {
183186
self.candidate_should_be_dropped_in_favor_of(
187+
sized_predicate,
184188
&candidates[i],
185189
&candidates[j],
186190
needs_infer,
@@ -338,13 +342,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
338342
Ok(candidates)
339343
}
340344

345+
#[tracing::instrument(level = "debug", skip(self, candidates))]
341346
fn assemble_candidates_from_projected_tys(
342347
&mut self,
343348
obligation: &TraitObligation<'tcx>,
344349
candidates: &mut SelectionCandidateSet<'tcx>,
345350
) {
346-
debug!(?obligation, "assemble_candidates_from_projected_tys");
347-
348351
// Before we go into the whole placeholder thing, just
349352
// quickly check if the self-type is a projection at all.
350353
match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
@@ -369,12 +372,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
369372
/// supplied to find out whether it is listed among them.
370373
///
371374
/// Never affects the inference environment.
375+
#[tracing::instrument(level = "debug", skip(self, stack, candidates))]
372376
fn assemble_candidates_from_caller_bounds<'o>(
373377
&mut self,
374378
stack: &TraitObligationStack<'o, 'tcx>,
375379
candidates: &mut SelectionCandidateSet<'tcx>,
376380
) -> Result<(), SelectionError<'tcx>> {
377-
debug!(?stack.obligation, "assemble_candidates_from_caller_bounds");
381+
debug!(?stack.obligation);
378382

379383
let all_bounds = stack
380384
.obligation
@@ -876,14 +880,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
876880
};
877881
}
878882

883+
#[tracing::instrument(level = "debug", skip(self, obligation, candidates))]
879884
fn assemble_candidates_for_trait_alias(
880885
&mut self,
881886
obligation: &TraitObligation<'tcx>,
882887
candidates: &mut SelectionCandidateSet<'tcx>,
883888
) {
884889
// Okay to skip binder here because the tests we do below do not involve bound regions.
885890
let self_ty = obligation.self_ty().skip_binder();
886-
debug!(?self_ty, "assemble_candidates_for_trait_alias");
891+
debug!(?self_ty);
887892

888893
let def_id = obligation.predicate.def_id();
889894

@@ -894,21 +899,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
894899

895900
/// Assembles the trait which are built-in to the language itself:
896901
/// `Copy`, `Clone` and `Sized`.
902+
#[tracing::instrument(level = "debug", skip(self, candidates))]
897903
fn assemble_builtin_bound_candidates(
898904
&mut self,
899905
conditions: BuiltinImplConditions<'tcx>,
900906
candidates: &mut SelectionCandidateSet<'tcx>,
901907
) {
902908
match conditions {
903909
BuiltinImplConditions::Where(nested) => {
904-
debug!(?nested, "builtin_bound");
905910
candidates
906911
.vec
907912
.push(BuiltinCandidate { has_nested: !nested.skip_binder().is_empty() });
908913
}
909914
BuiltinImplConditions::None => {}
910915
BuiltinImplConditions::Ambiguous => {
911-
debug!("assemble_builtin_bound_candidates: ambiguous builtin");
912916
candidates.ambiguous = true;
913917
}
914918
}

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ struct EvaluatedCandidate<'tcx> {
201201
}
202202

203203
/// When does the builtin impl for `T: Trait` apply?
204+
#[derive(Debug)]
204205
enum BuiltinImplConditions<'tcx> {
205206
/// The impl is conditional on `T1, T2, ...: Trait`.
206207
Where(ty::Binder<'tcx, Vec<Ty<'tcx>>>),
@@ -344,7 +345,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
344345
}
345346
Err(e) => Err(e),
346347
Ok(candidate) => {
347-
debug!(?candidate);
348+
debug!(?candidate, "confirmed");
348349
Ok(Some(candidate))
349350
}
350351
}
@@ -1523,6 +1524,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15231524
/// See the comment for "SelectionCandidate" for more details.
15241525
fn candidate_should_be_dropped_in_favor_of(
15251526
&mut self,
1527+
sized_predicate: bool,
15261528
victim: &EvaluatedCandidate<'tcx>,
15271529
other: &EvaluatedCandidate<'tcx>,
15281530
needs_infer: bool,
@@ -1594,6 +1596,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15941596
// Drop otherwise equivalent non-const fn pointer candidates
15951597
(FnPointerCandidate { .. }, FnPointerCandidate { is_const: false }) => true,
15961598

1599+
// If obligation is a sized predicate or the where-clause bound is
1600+
// global, prefer the projection or object candidate. See issue
1601+
// #50825 and #89352.
1602+
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
1603+
sized_predicate || is_global(cand)
1604+
}
1605+
(ParamCandidate(ref cand), ObjectCandidate(_) | ProjectionCandidate(_)) => {
1606+
!(sized_predicate || is_global(cand))
1607+
}
1608+
15971609
// Global bounds from the where clause should be ignored
15981610
// here (see issue #50825). Otherwise, we have a where
15991611
// clause so don't go around looking for impls.
@@ -1609,15 +1621,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16091621
| BuiltinUnsizeCandidate
16101622
| TraitUpcastingUnsizeCandidate(_)
16111623
| BuiltinCandidate { .. }
1612-
| TraitAliasCandidate(..)
1613-
| ObjectCandidate(_)
1614-
| ProjectionCandidate(_),
1624+
| TraitAliasCandidate(..),
16151625
) => !is_global(cand),
1616-
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
1617-
// Prefer these to a global where-clause bound
1618-
// (see issue #50825).
1619-
is_global(cand)
1620-
}
16211626
(
16221627
ImplCandidate(_)
16231628
| ClosureCandidate

Diff for: compiler/rustc_typeck/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
288288
/// Given the type/lifetime/const arguments provided to some path (along with
289289
/// an implicit `Self`, if this is a trait reference), returns the complete
290290
/// set of substitutions. This may involve applying defaulted type parameters.
291-
/// Also returns back constraints on associated types.
291+
/// Constraints on associated typess are created from `create_assoc_bindings_for_generic_args`.
292292
///
293293
/// Example:
294294
///
@@ -302,7 +302,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
302302
/// which will have been resolved to a `def_id`
303303
/// 3. The `generic_args` contains info on the `<...>` contents. The `usize` type
304304
/// parameters are returned in the `SubstsRef`, the associated type bindings like
305-
/// `Output = u32` are returned in the `Vec<ConvertedBinding...>` result.
305+
/// `Output = u32` are returned from `create_assoc_bindings_for_generic_args`.
306306
///
307307
/// Note that the type listing given here is *exactly* what the user provided.
308308
///

Diff for: compiler/rustc_typeck/src/check/method/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
359359
let (obligation, substs) =
360360
self.obligation_for_method(span, trait_def_id, self_ty, opt_input_types);
361361

362+
debug!(?obligation);
363+
362364
// Now we want to know if this can be matched
363365
if !self.predicate_may_hold(&obligation) {
364366
debug!("--> Cannot match obligation");

Diff for: compiler/rustc_typeck/src/check/method/suggest.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::print::with_crate_prefix;
1515
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable};
1616
use rustc_span::lev_distance;
1717
use rustc_span::symbol::{kw, sym, Ident};
18-
use rustc_span::{source_map, FileName, MultiSpan, Span, Symbol};
18+
use rustc_span::{source_map, FileName, MultiSpan, Span};
1919
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
2020
use rustc_trait_selection::traits::{
2121
FulfillmentError, Obligation, ObligationCause, ObligationCauseCode,
@@ -1524,8 +1524,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15241524
// Explicitly ignore the `Pin::as_ref()` method as `Pin` does not
15251525
// implement the `AsRef` trait.
15261526
let skip = skippable.contains(&did)
1527-
|| (("Pin::new" == *pre)
1528-
&& (Symbol::intern("as_ref") == item_name.name));
1527+
|| (("Pin::new" == *pre) && (sym::as_ref == item_name.name));
15291528
// Make sure the method is defined for the *actual* receiver: we don't
15301529
// want to treat `Box<Self>` as a receiver if it only works because of
15311530
// an autoderef to `&self`

0 commit comments

Comments
 (0)