Skip to content

Commit

Permalink
Auto merge of rust-lang#135005 - matthiaskrgr:rollup-5ubuitt, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Jan 1, 2025
2 parents 45d11e5 + 92dbfcc commit 62b13a9
Show file tree
Hide file tree
Showing 26 changed files with 129 additions and 109 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,11 +1845,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericParamKind::Lifetime => {
// AST resolution emitted an error on those parameters, so we lower them using
// `ParamName::Error`.
let ident = self.lower_ident(param.ident);
let param_name =
if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
ParamName::Error
ParamName::Error(ident)
} else {
let ident = self.lower_ident(param.ident);
ParamName::Plain(ident)
};
let kind =
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ pub enum ParamName {
/// Some user-given name like `T` or `'x`.
Plain(Ident),

/// Indicates an illegal name was given and an error has been
/// reported (so we should squelch other derived errors).
///
/// Occurs when, e.g., `'_` is used in the wrong place, or a
/// lifetime name is duplicated.
Error(Ident),

/// Synthetic name generated when user elided a lifetime in an impl header.
///
/// E.g., the lifetimes in cases like these:
Expand All @@ -67,18 +74,13 @@ pub enum ParamName {
/// where `'f` is something like `Fresh(0)`. The indices are
/// unique per impl, but not necessarily continuous.
Fresh,

/// Indicates an illegal name was given and an error has been
/// reported (so we should squelch other derived errors). Occurs
/// when, e.g., `'_` is used in the wrong place.
Error,
}

impl ParamName {
pub fn ident(&self) -> Ident {
match *self {
ParamName::Plain(ident) => ident,
ParamName::Fresh | ParamName::Error => Ident::with_dummy_span(kw::UnderscoreLifetime),
ParamName::Plain(ident) | ParamName::Error(ident) => ident,
ParamName::Fresh => Ident::with_dummy_span(kw::UnderscoreLifetime),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,8 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(
) -> V::Result {
try_visit!(visitor.visit_id(param.hir_id));
match param.name {
ParamName::Plain(ident) => try_visit!(visitor.visit_ident(ident)),
ParamName::Error | ParamName::Fresh => {}
ParamName::Plain(ident) | ParamName::Error(ident) => try_visit!(visitor.visit_ident(ident)),
ParamName::Fresh => {}
}
match param.kind {
GenericParamKind::Lifetime { .. } => {}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,10 @@ fn check_variances_for_type_defn<'tcx>(
}

match hir_param.name {
hir::ParamName::Error => {}
hir::ParamName::Error(_) => {
// Don't report a bivariance error for a lifetime that isn't
// even valid to name.
}
_ => {
let has_explicit_bounds = explicitly_bounded_params.contains(&parameter);
report_bivariance(tcx, hir_param, has_explicit_bounds, item);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, HirId, LangItem};
use rustc_hir_analysis::autoderef::Autoderef;
use rustc_infer::infer;
use rustc_infer::traits::{self, Obligation, ObligationCause, ObligationCauseCode};
use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
};
Expand Down Expand Up @@ -512,7 +512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_bound(
ty,
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
traits::ObligationCause::new(sp, self.body_id, ObligationCauseCode::RustCall),
self.cause(sp, ObligationCauseCode::RustCall),
);
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
} else {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let mut selcx = traits::SelectionContext::new(self);

// Create an obligation for `Source: CoerceUnsized<Target>`.
let cause =
ObligationCause::new(self.cause.span, self.body_id, ObligationCauseCode::Coercion {
source,
target,
});
let cause = self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target });

// Use a FIFO queue for this custom fulfillment procedure.
//
Expand Down
26 changes: 12 additions & 14 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rustc_hir::{ExprKind, HirId, QPath};
use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
use rustc_infer::infer;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_infer::traits::ObligationCause;
use rustc_infer::traits::query::NoSolution;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
Expand Down Expand Up @@ -1174,9 +1173,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
for err in errors {
let cause = &mut err.obligation.cause;
if let ObligationCauseCode::OpaqueReturnType(None) = cause.code() {
let new_cause = ObligationCause::new(
let new_cause = self.cause(
cause.span,
cause.body_id,
ObligationCauseCode::OpaqueReturnType(Some((return_expr_ty, hir_id))),
);
*cause = new_cause;
Expand Down Expand Up @@ -3856,7 +3854,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Enums are anyway always sized. But just to safeguard against future
// language extensions, let's double-check.
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
self.require_type_is_sized(
field_ty,
expr.span,
ObligationCauseCode::FieldSized {
adt_kind: AdtKind::Enum,
span: self.tcx.def_span(field.did),
last: false,
},
);

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

if self.tcx.features().offset_of_slice() {
self.require_type_has_static_alignment(
field_ty,
expr.span,
ObligationCauseCode::Misc,
);
self.require_type_has_static_alignment(field_ty, expr.span);
} else {
self.require_type_is_sized(
field_ty,
Expand Down Expand Up @@ -3917,11 +3919,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
if let Some(&field_ty) = tys.get(index) {
if self.tcx.features().offset_of_slice() {
self.require_type_has_static_alignment(
field_ty,
expr.span,
ObligationCauseCode::Misc,
);
self.require_type_has_static_alignment(field_ty, expr.span);
} else {
self.require_type_is_sized(
field_ty,
Expand Down
19 changes: 6 additions & 13 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
code: traits::ObligationCauseCode<'tcx>,
def_id: DefId,
) {
self.register_bound(ty, def_id, traits::ObligationCause::new(span, self.body_id, code));
self.register_bound(ty, def_id, self.cause(span, code));
}

pub(crate) fn require_type_is_sized(
Expand All @@ -410,12 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(crate) fn require_type_has_static_alignment(
&self,
ty: Ty<'tcx>,
span: Span,
code: traits::ObligationCauseCode<'tcx>,
) {
pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
if !ty.references_error() {
let tail = self.tcx.struct_tail_raw(
ty,
Expand All @@ -434,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
// We can't be sure, let's required full `Sized`.
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
self.require_type_meets(ty, span, code, lang_item);
self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
}
}
}
Expand Down Expand Up @@ -572,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
code: traits::ObligationCauseCode<'tcx>,
) {
// WF obligations never themselves fail, so no real need to give a detailed cause:
let cause = traits::ObligationCause::new(span, self.body_id, code);
let cause = self.cause(span, code);
self.register_predicate(traits::Obligation::new(
self.tcx,
cause,
Expand Down Expand Up @@ -1426,9 +1421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let bounds = self.instantiate_bounds(span, def_id, args);

for obligation in traits::predicates_for_generics(
|idx, predicate_span| {
traits::ObligationCause::new(span, self.body_id, code(idx, predicate_span))
},
|idx, predicate_span| self.cause(span, code(idx, predicate_span)),
param_env,
bounds,
) {
Expand Down Expand Up @@ -1561,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
) -> InferResult<'tcx, Ty<'tcx>> {
self.instantiate_query_response_and_region_obligations(
&traits::ObligationCause::misc(span, self.body_id),
&self.misc(span),
self.param_env,
original_values,
query_result,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.register_wf_obligation(
fn_input_ty.into(),
arg_expr.span,
ObligationCauseCode::Misc,
ObligationCauseCode::WellFormed(None),
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
self.call_expr.hir_id,
idx,
);
traits::ObligationCause::new(self.span, self.body_id, code)
self.cause(self.span, code)
},
self.param_env,
method_predicates,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,8 +1739,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
&self,
trait_ref: ty::TraitRef<'tcx>,
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, trait_ref);
let obligation =
traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
traits::SelectionContext::new(self).select(&obligation)
}

Expand Down Expand Up @@ -1841,7 +1841,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.scope_expr_id,
idx,
);
ObligationCause::new(self.span, self.body_id, code)
self.cause(self.span, code)
},
self.param_env,
impl_bounds,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false;
};
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::Misc);
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
let obligation = Obligation::new(self.tcx, self.misc(span), self.param_env, trait_ref);
if !self.predicate_must_hold_modulo_regions(&obligation) {
return false;
}
Expand Down Expand Up @@ -3489,7 +3488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
self.tcx,
ObligationCause::misc(rcvr.span, self.body_id),
self.misc(rcvr.span),
self.param_env,
pred,
));
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl<T: Clone> Clone for Reverse<T> {
/// }
///
/// impl Ord for Character {
/// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
/// fn cmp(&self, other: &Self) -> Ordering {
/// self.experience
/// .cmp(&other.experience)
/// .then(self.health.cmp(&other.health))
Expand Down
47 changes: 17 additions & 30 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@ use crate::core::builder::{
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, crate_description,
};
use crate::core::config::{Config, TargetSelection};
use crate::utils::helpers::{symlink_dir, t, up_to_date};

macro_rules! submodule_helper {
($path:expr, submodule) => {
$path
};
($path:expr, submodule = $submodule:literal) => {
$submodule
};
}
use crate::helpers::{is_path_in_submodule, symlink_dir, t, up_to_date};

macro_rules! book {
($($name:ident, $path:expr, $book_name:expr, $lang:expr $(, submodule $(= $submodule:literal)? )? ;)+) => {
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
$(
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct $name {
Expand All @@ -53,10 +44,10 @@ macro_rules! book {
}

fn run(self, builder: &Builder<'_>) {
$(
let path = submodule_helper!( $path, submodule $( = $submodule )? );
builder.require_submodule(path, None);
)?
if is_path_in_submodule(&builder, $path) {
builder.require_submodule($path, None);
}

builder.ensure(RustbookSrc {
target: self.target,
name: $book_name.to_owned(),
Expand All @@ -77,12 +68,12 @@ macro_rules! book {
// FIXME: Make checking for a submodule automatic somehow (maybe by having a list of all submodules
// and checking against it?).
book!(
CargoBook, "src/tools/cargo/src/doc", "cargo", &[], submodule = "src/tools/cargo";
CargoBook, "src/tools/cargo/src/doc", "cargo", &[];
ClippyBook, "src/tools/clippy/book", "clippy", &[];
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"], submodule;
EditionGuide, "src/doc/edition-guide", "edition-guide", &[];
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[];
Nomicon, "src/doc/nomicon", "nomicon", &[];
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja", "zh"];
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
StyleGuide, "src/doc/style-guide", "style-guide", &[];
);
Expand Down Expand Up @@ -910,7 +901,6 @@ macro_rules! tool_doc {
$(rustc_tool = $rustc_tool:literal, )?
$(is_library = $is_library:expr,)?
$(crates = $crates:expr)?
$(, submodule $(= $submodule:literal)? )?
) => {
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct $tool {
Expand Down Expand Up @@ -938,14 +928,12 @@ macro_rules! tool_doc {
/// we do not merge it with the other documentation from std, test and
/// proc_macros. This is largely just a wrapper around `cargo doc`.
fn run(self, builder: &Builder<'_>) {
let source_type = SourceType::InTree;
$(
let _ = source_type; // silence the "unused variable" warning
let source_type = SourceType::Submodule;
let mut source_type = SourceType::InTree;

let path = submodule_helper!( $path, submodule $( = $submodule )? );
builder.require_submodule(path, None);
)?
if is_path_in_submodule(&builder, $path) {
source_type = SourceType::Submodule;
builder.require_submodule($path, None);
}

let stage = builder.top_stage;
let target = self.target;
Expand Down Expand Up @@ -1054,8 +1042,7 @@ tool_doc!(
"crates-io",
"mdman",
"rustfix",
],
submodule = "src/tools/cargo"
]
);
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
tool_doc!(
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ pub fn is_dylib(path: &Path) -> bool {
})
}

/// Returns `true` if the given path is part of a submodule.
pub fn is_path_in_submodule(builder: &Builder<'_>, path: &str) -> bool {
let submodule_paths = build_helper::util::parse_gitmodules(&builder.src);
submodule_paths.iter().any(|submodule_path| path.starts_with(submodule_path))
}

fn is_aix_shared_archive(path: &Path) -> bool {
let file = match fs::File::open(path) {
Ok(file) => file,
Expand Down
Loading

0 comments on commit 62b13a9

Please sign in to comment.