Skip to content

Commit 65445a5

Browse files
committed
Auto merge of #102471 - Dylan-DPC:rollup-ij3okjt, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #102336 (Fix associated type bindings with anon const in GAT position) - #102342 (Add negation methods for signed non-zero integers.) - #102385 (Don't export `__heap_base` and `__data_end` on wasm32-wasi.) - #102435 (Improve example of Iterator::reduce) - #102436 (rustdoc: clean up "normalize.css 8" input override CSS) - #102452 (fix minor ungrammatical sentence) - #102455 (Use let-chaining in `WhileTrue::check_expr`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c5bbf36 + f4e7094 commit 65445a5

File tree

9 files changed

+301
-86
lines changed

9 files changed

+301
-86
lines changed

Diff for: compiler/rustc_codegen_ssa/src/back/linker.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,12 @@ impl<'a> Linker for WasmLd<'a> {
13201320

13211321
// LLD will hide these otherwise-internal symbols since it only exports
13221322
// symbols explicitly passed via the `--export` flags above and hides all
1323-
// others. Various bits and pieces of tooling use this, so be sure these
1324-
// symbols make their way out of the linker as well.
1325-
self.cmd.arg("--export=__heap_base");
1326-
self.cmd.arg("--export=__data_end");
1323+
// others. Various bits and pieces of wasm32-unknown-unknown tooling use
1324+
// this, so be sure these symbols make their way out of the linker as well.
1325+
if self.sess.target.os == "unknown" {
1326+
self.cmd.arg("--export=__heap_base");
1327+
self.cmd.arg("--export=__data_end");
1328+
}
13271329
}
13281330

13291331
fn subsystem(&mut self, _subsystem: &str) {}

Diff for: compiler/rustc_hir_analysis/src/collect/type_of.rs

+87-30
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
333333
find_opaque_ty_constraints_for_tait(tcx, def_id)
334334
}
335335
// Opaque types desugared from `impl Trait`.
336-
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner), in_trait, .. }) => {
336+
ItemKind::OpaqueTy(OpaqueTy {
337+
origin:
338+
hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner),
339+
in_trait,
340+
..
341+
}) => {
337342
if in_trait {
338343
span_bug!(item.span, "impl-trait in trait has no default")
339344
} else {
@@ -378,7 +383,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
378383

379384
Node::Field(field) => icx.to_ty(field.ty),
380385

381-
Node::Expr(&Expr { kind: ExprKind::Closure{..}, .. }) => tcx.typeck(def_id).node_type(hir_id),
386+
Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => {
387+
tcx.typeck(def_id).node_type(hir_id)
388+
}
382389

383390
Node::AnonConst(_) if let Some(param) = tcx.opt_const_param_of(def_id) => {
384391
// We defer to `type_of` of the corresponding parameter
@@ -410,40 +417,91 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
410417
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
411418
if asm.operands.iter().any(|(op, _op_sp)| match op {
412419
hir::InlineAsmOperand::Const { anon_const }
413-
| hir::InlineAsmOperand::SymFn { anon_const } => anon_const.hir_id == hir_id,
420+
| hir::InlineAsmOperand::SymFn { anon_const } => {
421+
anon_const.hir_id == hir_id
422+
}
414423
_ => false,
415424
}) =>
416425
{
417426
tcx.typeck(def_id).node_type(hir_id)
418427
}
419428

420-
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
421-
.adt_def(tcx.hir().get_parent_item(hir_id))
422-
.repr()
423-
.discr_type()
424-
.to_ty(tcx),
429+
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
430+
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
431+
}
425432

426-
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
427-
if let Node::TraitRef(trait_ref) = tcx.hir().get(
428-
tcx.hir().get_parent_node(binding_id)
429-
) =>
433+
Node::TypeBinding(
434+
binding @ &TypeBinding {
435+
hir_id: binding_id,
436+
kind: TypeBindingKind::Equality { term: Term::Const(ref e) },
437+
..
438+
},
439+
) if let Node::TraitRef(trait_ref) =
440+
tcx.hir().get(tcx.hir().get_parent_node(binding_id))
441+
&& e.hir_id == hir_id =>
430442
{
431-
let Some(trait_def_id) = trait_ref.trait_def_id() else {
432-
return tcx.ty_error_with_message(DUMMY_SP, "Could not find trait");
433-
};
434-
let assoc_items = tcx.associated_items(trait_def_id);
435-
let assoc_item = assoc_items.find_by_name_and_kind(
436-
tcx, binding.ident, ty::AssocKind::Const, def_id.to_def_id(),
437-
);
438-
if let Some(assoc_item) = assoc_item {
439-
tcx.type_of(assoc_item.def_id)
440-
} else {
441-
// FIXME(associated_const_equality): add a useful error message here.
442-
tcx.ty_error_with_message(
443-
DUMMY_SP,
444-
"Could not find associated const on trait",
445-
)
446-
}
443+
let Some(trait_def_id) = trait_ref.trait_def_id() else {
444+
return tcx.ty_error_with_message(DUMMY_SP, "Could not find trait");
445+
};
446+
let assoc_items = tcx.associated_items(trait_def_id);
447+
let assoc_item = assoc_items.find_by_name_and_kind(
448+
tcx,
449+
binding.ident,
450+
ty::AssocKind::Const,
451+
def_id.to_def_id(),
452+
);
453+
if let Some(assoc_item) = assoc_item {
454+
tcx.type_of(assoc_item.def_id)
455+
} else {
456+
// FIXME(associated_const_equality): add a useful error message here.
457+
tcx.ty_error_with_message(
458+
DUMMY_SP,
459+
"Could not find associated const on trait",
460+
)
461+
}
462+
}
463+
464+
Node::TypeBinding(
465+
binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. },
466+
) if let Node::TraitRef(trait_ref) =
467+
tcx.hir().get(tcx.hir().get_parent_node(binding_id))
468+
&& let Some((idx, _)) =
469+
gen_args.args.iter().enumerate().find(|(_, arg)| {
470+
if let GenericArg::Const(ct) = arg {
471+
ct.value.hir_id == hir_id
472+
} else {
473+
false
474+
}
475+
}) =>
476+
{
477+
let Some(trait_def_id) = trait_ref.trait_def_id() else {
478+
return tcx.ty_error_with_message(DUMMY_SP, "Could not find trait");
479+
};
480+
let assoc_items = tcx.associated_items(trait_def_id);
481+
let assoc_item = assoc_items.find_by_name_and_kind(
482+
tcx,
483+
binding.ident,
484+
match kind {
485+
// I think `<A: T>` type bindings requires that `A` is a type
486+
TypeBindingKind::Constraint { .. }
487+
| TypeBindingKind::Equality { term: Term::Ty(..) } => {
488+
ty::AssocKind::Type
489+
}
490+
TypeBindingKind::Equality { term: Term::Const(..) } => {
491+
ty::AssocKind::Const
492+
}
493+
},
494+
def_id.to_def_id(),
495+
);
496+
if let Some(assoc_item) = assoc_item {
497+
tcx.type_of(tcx.generics_of(assoc_item.def_id).params[idx].def_id)
498+
} else {
499+
// FIXME(associated_const_equality): add a useful error message here.
500+
tcx.ty_error_with_message(
501+
DUMMY_SP,
502+
"Could not find associated const on trait",
503+
)
504+
}
447505
}
448506

449507
Node::GenericParam(&GenericParam {
@@ -452,8 +510,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
452510
..
453511
}) if ct.hir_id == hir_id => tcx.type_of(tcx.hir().local_def_id(param_hir_id)),
454512

455-
x =>
456-
tcx.ty_error_with_message(
513+
x => tcx.ty_error_with_message(
457514
DUMMY_SP,
458515
&format!("unexpected const parent in type_of(): {x:?}"),
459516
),

Diff for: compiler/rustc_lint/src/builtin.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,28 @@ fn pierce_parens(mut expr: &ast::Expr) -> &ast::Expr {
9797

9898
impl EarlyLintPass for WhileTrue {
9999
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
100-
if let ast::ExprKind::While(cond, _, label) = &e.kind {
101-
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
102-
if let ast::LitKind::Bool(true) = lit.kind {
103-
if !lit.span.from_expansion() {
104-
let condition_span = e.span.with_hi(cond.span.hi());
105-
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
106-
lint.build(fluent::lint::builtin_while_true)
107-
.span_suggestion_short(
108-
condition_span,
109-
fluent::lint::suggestion,
110-
format!(
111-
"{}loop",
112-
label.map_or_else(String::new, |label| format!(
113-
"{}: ",
114-
label.ident,
115-
))
116-
),
117-
Applicability::MachineApplicable,
118-
)
119-
.emit();
120-
})
121-
}
122-
}
123-
}
100+
if let ast::ExprKind::While(cond, _, label) = &e.kind
101+
&& let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind
102+
&& let ast::LitKind::Bool(true) = lit.kind
103+
&& !lit.span.from_expansion()
104+
{
105+
let condition_span = e.span.with_hi(cond.span.hi());
106+
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
107+
lint.build(fluent::lint::builtin_while_true)
108+
.span_suggestion_short(
109+
condition_span,
110+
fluent::lint::suggestion,
111+
format!(
112+
"{}loop",
113+
label.map_or_else(String::new, |label| format!(
114+
"{}: ",
115+
label.ident,
116+
))
117+
),
118+
Applicability::MachineApplicable,
119+
)
120+
.emit();
121+
})
124122
}
125123
}
126124
}

Diff for: library/core/src/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub trait TryInto<T>: Sized {
440440
///
441441
/// fn try_from(value: i32) -> Result<Self, Self::Error> {
442442
/// if value <= 0 {
443-
/// Err("GreaterThanZero only accepts value superior than zero!")
443+
/// Err("GreaterThanZero only accepts values greater than zero!")
444444
/// } else {
445445
/// Ok(GreaterThanZero(value))
446446
/// }

Diff for: library/core/src/iter/traits/iterator.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -2431,22 +2431,13 @@ pub trait Iterator {
24312431
///
24322432
/// # Example
24332433
///
2434-
/// Find the maximum value:
2435-
///
24362434
/// ```
2437-
/// fn find_max<I>(iter: I) -> Option<I::Item>
2438-
/// where I: Iterator,
2439-
/// I::Item: Ord,
2440-
/// {
2441-
/// iter.reduce(|accum, item| {
2442-
/// if accum >= item { accum } else { item }
2443-
/// })
2444-
/// }
2445-
/// let a = [10, 20, 5, -23, 0];
2446-
/// let b: [u32; 0] = [];
2435+
/// let reduced: i32 = (1..10).reduce(|acc, e| acc + e).unwrap();
2436+
/// assert_eq!(reduced, 45);
24472437
///
2448-
/// assert_eq!(find_max(a.iter()), Some(&20));
2449-
/// assert_eq!(find_max(b.iter()), None);
2438+
/// // Which is equivalent to doing it with `fold`:
2439+
/// let folded: i32 = (1..10).fold(0, |acc, e| acc + e);
2440+
/// assert_eq!(reduced, folded);
24502441
/// ```
24512442
#[inline]
24522443
#[stable(feature = "iterator_fold_self", since = "1.51.0")]

0 commit comments

Comments
 (0)