Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 62b13a9

Browse files
committed
Auto merge of rust-lang#135005 - matthiaskrgr:rollup-5ubuitt, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#134967 (handle submodules automatically on `doc` steps) - rust-lang#134973 (Fix typos) - rust-lang#134984 (`ObligationCause` construction tweaks in typeck) - rust-lang#134985 (Remove qualification of `std::cmp::Ordering` in `Ord` doc) - rust-lang#135000 (Fix ICE when opaque captures a duplicated/invalid lifetime) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 45d11e5 + 92dbfcc commit 62b13a9

File tree

26 files changed

+129
-109
lines changed

26 files changed

+129
-109
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,11 +1845,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18451845
GenericParamKind::Lifetime => {
18461846
// AST resolution emitted an error on those parameters, so we lower them using
18471847
// `ParamName::Error`.
1848+
let ident = self.lower_ident(param.ident);
18481849
let param_name =
18491850
if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
1850-
ParamName::Error
1851+
ParamName::Error(ident)
18511852
} else {
1852-
let ident = self.lower_ident(param.ident);
18531853
ParamName::Plain(ident)
18541854
};
18551855
let kind =

compiler/rustc_hir/src/hir.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ pub enum ParamName {
5252
/// Some user-given name like `T` or `'x`.
5353
Plain(Ident),
5454

55+
/// Indicates an illegal name was given and an error has been
56+
/// reported (so we should squelch other derived errors).
57+
///
58+
/// Occurs when, e.g., `'_` is used in the wrong place, or a
59+
/// lifetime name is duplicated.
60+
Error(Ident),
61+
5562
/// Synthetic name generated when user elided a lifetime in an impl header.
5663
///
5764
/// E.g., the lifetimes in cases like these:
@@ -67,18 +74,13 @@ pub enum ParamName {
6774
/// where `'f` is something like `Fresh(0)`. The indices are
6875
/// unique per impl, but not necessarily continuous.
6976
Fresh,
70-
71-
/// Indicates an illegal name was given and an error has been
72-
/// reported (so we should squelch other derived errors). Occurs
73-
/// when, e.g., `'_` is used in the wrong place.
74-
Error,
7577
}
7678

7779
impl ParamName {
7880
pub fn ident(&self) -> Ident {
7981
match *self {
80-
ParamName::Plain(ident) => ident,
81-
ParamName::Fresh | ParamName::Error => Ident::with_dummy_span(kw::UnderscoreLifetime),
82+
ParamName::Plain(ident) | ParamName::Error(ident) => ident,
83+
ParamName::Fresh => Ident::with_dummy_span(kw::UnderscoreLifetime),
8284
}
8385
}
8486
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,8 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(
928928
) -> V::Result {
929929
try_visit!(visitor.visit_id(param.hir_id));
930930
match param.name {
931-
ParamName::Plain(ident) => try_visit!(visitor.visit_ident(ident)),
932-
ParamName::Error | ParamName::Fresh => {}
931+
ParamName::Plain(ident) | ParamName::Error(ident) => try_visit!(visitor.visit_ident(ident)),
932+
ParamName::Fresh => {}
933933
}
934934
match param.kind {
935935
GenericParamKind::Lifetime { .. } => {}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,10 @@ fn check_variances_for_type_defn<'tcx>(
20072007
}
20082008

20092009
match hir_param.name {
2010-
hir::ParamName::Error => {}
2010+
hir::ParamName::Error(_) => {
2011+
// Don't report a bivariance error for a lifetime that isn't
2012+
// even valid to name.
2013+
}
20112014
_ => {
20122015
let has_explicit_bounds = explicitly_bounded_params.contains(&parameter);
20132016
report_bivariance(tcx, hir_param, has_explicit_bounds, item);

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77
use rustc_hir::{self as hir, HirId, LangItem};
88
use rustc_hir_analysis::autoderef::Autoderef;
99
use rustc_infer::infer;
10-
use rustc_infer::traits::{self, Obligation, ObligationCause, ObligationCauseCode};
10+
use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
1111
use rustc_middle::ty::adjustment::{
1212
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
1313
};
@@ -512,7 +512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
512512
self.register_bound(
513513
ty,
514514
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
515-
traits::ObligationCause::new(sp, self.body_id, ObligationCauseCode::RustCall),
515+
self.cause(sp, ObligationCauseCode::RustCall),
516516
);
517517
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
518518
} else {

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
580580
let mut selcx = traits::SelectionContext::new(self);
581581

582582
// Create an obligation for `Source: CoerceUnsized<Target>`.
583-
let cause =
584-
ObligationCause::new(self.cause.span, self.body_id, ObligationCauseCode::Coercion {
585-
source,
586-
target,
587-
});
583+
let cause = self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target });
588584

589585
// Use a FIFO queue for this custom fulfillment procedure.
590586
//

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_hir::{ExprKind, HirId, QPath};
2222
use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
2323
use rustc_infer::infer;
2424
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
25-
use rustc_infer::traits::ObligationCause;
2625
use rustc_infer::traits::query::NoSolution;
2726
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
2827
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -1174,9 +1173,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11741173
for err in errors {
11751174
let cause = &mut err.obligation.cause;
11761175
if let ObligationCauseCode::OpaqueReturnType(None) = cause.code() {
1177-
let new_cause = ObligationCause::new(
1176+
let new_cause = self.cause(
11781177
cause.span,
1179-
cause.body_id,
11801178
ObligationCauseCode::OpaqueReturnType(Some((return_expr_ty, hir_id))),
11811179
);
11821180
*cause = new_cause;
@@ -3856,7 +3854,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38563854

38573855
// Enums are anyway always sized. But just to safeguard against future
38583856
// language extensions, let's double-check.
3859-
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
3857+
self.require_type_is_sized(
3858+
field_ty,
3859+
expr.span,
3860+
ObligationCauseCode::FieldSized {
3861+
adt_kind: AdtKind::Enum,
3862+
span: self.tcx.def_span(field.did),
3863+
last: false,
3864+
},
3865+
);
38603866

38613867
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
38623868
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3884,11 +3890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38843890
let field_ty = self.field_ty(expr.span, field, args);
38853891

38863892
if self.tcx.features().offset_of_slice() {
3887-
self.require_type_has_static_alignment(
3888-
field_ty,
3889-
expr.span,
3890-
ObligationCauseCode::Misc,
3891-
);
3893+
self.require_type_has_static_alignment(field_ty, expr.span);
38923894
} else {
38933895
self.require_type_is_sized(
38943896
field_ty,
@@ -3917,11 +3919,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
39173919
{
39183920
if let Some(&field_ty) = tys.get(index) {
39193921
if self.tcx.features().offset_of_slice() {
3920-
self.require_type_has_static_alignment(
3921-
field_ty,
3922-
expr.span,
3923-
ObligationCauseCode::Misc,
3924-
);
3922+
self.require_type_has_static_alignment(field_ty, expr.span);
39253923
} else {
39263924
self.require_type_is_sized(
39273925
field_ty,

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
384384
code: traits::ObligationCauseCode<'tcx>,
385385
def_id: DefId,
386386
) {
387-
self.register_bound(ty, def_id, traits::ObligationCause::new(span, self.body_id, code));
387+
self.register_bound(ty, def_id, self.cause(span, code));
388388
}
389389

390390
pub(crate) fn require_type_is_sized(
@@ -410,12 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
410410
}
411411
}
412412

413-
pub(crate) fn require_type_has_static_alignment(
414-
&self,
415-
ty: Ty<'tcx>,
416-
span: Span,
417-
code: traits::ObligationCauseCode<'tcx>,
418-
) {
413+
pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
419414
if !ty.references_error() {
420415
let tail = self.tcx.struct_tail_raw(
421416
ty,
@@ -434,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
434429
} else {
435430
// We can't be sure, let's required full `Sized`.
436431
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
437-
self.require_type_meets(ty, span, code, lang_item);
432+
self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
438433
}
439434
}
440435
}
@@ -572,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
572567
code: traits::ObligationCauseCode<'tcx>,
573568
) {
574569
// WF obligations never themselves fail, so no real need to give a detailed cause:
575-
let cause = traits::ObligationCause::new(span, self.body_id, code);
570+
let cause = self.cause(span, code);
576571
self.register_predicate(traits::Obligation::new(
577572
self.tcx,
578573
cause,
@@ -1426,9 +1421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14261421
let bounds = self.instantiate_bounds(span, def_id, args);
14271422

14281423
for obligation in traits::predicates_for_generics(
1429-
|idx, predicate_span| {
1430-
traits::ObligationCause::new(span, self.body_id, code(idx, predicate_span))
1431-
},
1424+
|idx, predicate_span| self.cause(span, code(idx, predicate_span)),
14321425
param_env,
14331426
bounds,
14341427
) {
@@ -1561,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15611554
query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
15621555
) -> InferResult<'tcx, Ty<'tcx>> {
15631556
self.instantiate_query_response_and_region_obligations(
1564-
&traits::ObligationCause::misc(span, self.body_id),
1557+
&self.misc(span),
15651558
self.param_env,
15661559
original_values,
15671560
query_result,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
207207
self.register_wf_obligation(
208208
fn_input_ty.into(),
209209
arg_expr.span,
210-
ObligationCauseCode::Misc,
210+
ObligationCauseCode::WellFormed(None),
211211
);
212212
}
213213

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
601601
self.call_expr.hir_id,
602602
idx,
603603
);
604-
traits::ObligationCause::new(self.span, self.body_id, code)
604+
self.cause(self.span, code)
605605
},
606606
self.param_env,
607607
method_predicates,

0 commit comments

Comments
 (0)