Skip to content

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

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

+2-2
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 =

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

+9-7
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
}

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

+2-2
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 { .. } => {}

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-1
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);

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+2-2
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 {

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+1-5
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
//

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

+12-14
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,

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+6-13
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,

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
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

Diff for: compiler/rustc_hir_typeck/src/method/confirm.rs

+1-1
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,

Diff for: compiler/rustc_hir_typeck/src/method/probe.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1739,8 +1739,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17391739
&self,
17401740
trait_ref: ty::TraitRef<'tcx>,
17411741
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1742-
let cause = traits::ObligationCause::misc(self.span, self.body_id);
1743-
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, trait_ref);
1742+
let obligation =
1743+
traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
17441744
traits::SelectionContext::new(self).select(&obligation)
17451745
}
17461746

@@ -1841,7 +1841,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18411841
self.scope_expr_id,
18421842
idx,
18431843
);
1844-
ObligationCause::new(self.span, self.body_id, code)
1844+
self.cause(self.span, code)
18451845
},
18461846
self.param_env,
18471847
impl_bounds,

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
105105
return false;
106106
};
107107
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
108-
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::Misc);
109-
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
108+
let obligation = Obligation::new(self.tcx, self.misc(span), self.param_env, trait_ref);
110109
if !self.predicate_must_hold_modulo_regions(&obligation) {
111110
return false;
112111
}
@@ -3489,7 +3488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34893488
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
34903489
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
34913490
self.tcx,
3492-
ObligationCause::misc(rcvr.span, self.body_id),
3491+
self.misc(rcvr.span),
34933492
self.param_env,
34943493
pred,
34953494
));

Diff for: library/core/src/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<T: Clone> Clone for Reverse<T> {
796796
/// }
797797
///
798798
/// impl Ord for Character {
799-
/// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
799+
/// fn cmp(&self, other: &Self) -> Ordering {
800800
/// self.experience
801801
/// .cmp(&other.experience)
802802
/// .then(self.health.cmp(&other.health))

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+17-30
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,10 @@ use crate::core::builder::{
1818
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, crate_description,
1919
};
2020
use crate::core::config::{Config, TargetSelection};
21-
use crate::utils::helpers::{symlink_dir, t, up_to_date};
22-
23-
macro_rules! submodule_helper {
24-
($path:expr, submodule) => {
25-
$path
26-
};
27-
($path:expr, submodule = $submodule:literal) => {
28-
$submodule
29-
};
30-
}
21+
use crate::helpers::{is_path_in_submodule, symlink_dir, t, up_to_date};
3122

3223
macro_rules! book {
33-
($($name:ident, $path:expr, $book_name:expr, $lang:expr $(, submodule $(= $submodule:literal)? )? ;)+) => {
24+
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
3425
$(
3526
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3627
pub struct $name {
@@ -53,10 +44,10 @@ macro_rules! book {
5344
}
5445

5546
fn run(self, builder: &Builder<'_>) {
56-
$(
57-
let path = submodule_helper!( $path, submodule $( = $submodule )? );
58-
builder.require_submodule(path, None);
59-
)?
47+
if is_path_in_submodule(&builder, $path) {
48+
builder.require_submodule($path, None);
49+
}
50+
6051
builder.ensure(RustbookSrc {
6152
target: self.target,
6253
name: $book_name.to_owned(),
@@ -77,12 +68,12 @@ macro_rules! book {
7768
// FIXME: Make checking for a submodule automatic somehow (maybe by having a list of all submodules
7869
// and checking against it?).
7970
book!(
80-
CargoBook, "src/tools/cargo/src/doc", "cargo", &[], submodule = "src/tools/cargo";
71+
CargoBook, "src/tools/cargo/src/doc", "cargo", &[];
8172
ClippyBook, "src/tools/clippy/book", "clippy", &[];
82-
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
83-
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
84-
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
85-
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"], submodule;
73+
EditionGuide, "src/doc/edition-guide", "edition-guide", &[];
74+
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[];
75+
Nomicon, "src/doc/nomicon", "nomicon", &[];
76+
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"];
8677
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
8778
StyleGuide, "src/doc/style-guide", "style-guide", &[];
8879
);
@@ -910,7 +901,6 @@ macro_rules! tool_doc {
910901
$(rustc_tool = $rustc_tool:literal, )?
911902
$(is_library = $is_library:expr,)?
912903
$(crates = $crates:expr)?
913-
$(, submodule $(= $submodule:literal)? )?
914904
) => {
915905
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
916906
pub struct $tool {
@@ -938,14 +928,12 @@ macro_rules! tool_doc {
938928
/// we do not merge it with the other documentation from std, test and
939929
/// proc_macros. This is largely just a wrapper around `cargo doc`.
940930
fn run(self, builder: &Builder<'_>) {
941-
let source_type = SourceType::InTree;
942-
$(
943-
let _ = source_type; // silence the "unused variable" warning
944-
let source_type = SourceType::Submodule;
931+
let mut source_type = SourceType::InTree;
945932

946-
let path = submodule_helper!( $path, submodule $( = $submodule )? );
947-
builder.require_submodule(path, None);
948-
)?
933+
if is_path_in_submodule(&builder, $path) {
934+
source_type = SourceType::Submodule;
935+
builder.require_submodule($path, None);
936+
}
949937

950938
let stage = builder.top_stage;
951939
let target = self.target;
@@ -1054,8 +1042,7 @@ tool_doc!(
10541042
"crates-io",
10551043
"mdman",
10561044
"rustfix",
1057-
],
1058-
submodule = "src/tools/cargo"
1045+
]
10591046
);
10601047
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
10611048
tool_doc!(

Diff for: src/bootstrap/src/utils/helpers.rs

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ pub fn is_dylib(path: &Path) -> bool {
6060
})
6161
}
6262

63+
/// Returns `true` if the given path is part of a submodule.
64+
pub fn is_path_in_submodule(builder: &Builder<'_>, path: &str) -> bool {
65+
let submodule_paths = build_helper::util::parse_gitmodules(&builder.src);
66+
submodule_paths.iter().any(|submodule_path| path.starts_with(submodule_path))
67+
}
68+
6369
fn is_aix_shared_archive(path: &Path) -> bool {
6470
let file = match fs::File::open(path) {
6571
Ok(file) => file,

0 commit comments

Comments
 (0)