Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 65445a5

Browse files
committedSep 29, 2022
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
 

‎compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 6 additions & 4 deletions
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) {}

‎compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 87 additions & 30 deletions
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
),

‎compiler/rustc_lint/src/builtin.rs

Lines changed: 22 additions & 24 deletions
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
}

‎library/core/src/convert/mod.rs

Lines changed: 1 addition & 1 deletion
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
/// }

‎library/core/src/iter/traits/iterator.rs

Lines changed: 5 additions & 14 deletions
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")]

‎library/core/src/num/nonzero.rs

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,160 @@ macro_rules! nonzero_signed_operations {
721721
// SAFETY: absolute value of nonzero cannot yield zero values.
722722
unsafe { $Uty::new_unchecked(self.get().unsigned_abs()) }
723723
}
724+
725+
/// Returns `true` if `self` is negative and `false` if the
726+
/// number is positive.
727+
///
728+
/// # Example
729+
///
730+
/// ```
731+
/// #![feature(nonzero_negation_ops)]
732+
///
733+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
734+
/// # fn main() { test().unwrap(); }
735+
/// # fn test() -> Option<()> {
736+
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
737+
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
738+
///
739+
/// assert!(neg_five.is_negative());
740+
/// assert!(!pos_five.is_negative());
741+
/// # Some(())
742+
/// # }
743+
/// ```
744+
#[must_use]
745+
#[inline]
746+
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
747+
pub const fn is_negative(self) -> bool {
748+
self.get().is_negative()
749+
}
750+
751+
/// Checked negation. Computes `-self`, returning `None` if `self == i32::MIN`.
752+
///
753+
/// # Example
754+
///
755+
/// ```
756+
/// #![feature(nonzero_negation_ops)]
757+
///
758+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
759+
/// # fn main() { test().unwrap(); }
760+
/// # fn test() -> Option<()> {
761+
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
762+
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
763+
#[doc = concat!("let min = ", stringify!($Ty), "::new(",
764+
stringify!($Int), "::MIN)?;")]
765+
///
766+
/// assert_eq!(pos_five.checked_neg(), Some(neg_five));
767+
/// assert_eq!(min.checked_neg(), None);
768+
/// # Some(())
769+
/// # }
770+
/// ```
771+
#[inline]
772+
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
773+
pub const fn checked_neg(self) -> Option<$Ty> {
774+
if let Some(result) = self.get().checked_neg() {
775+
// SAFETY: negation of nonzero cannot yield zero values.
776+
return Some(unsafe { $Ty::new_unchecked(result) });
777+
}
778+
None
779+
}
780+
781+
/// Negates self, overflowing if this is equal to the minimum value.
782+
///
783+
#[doc = concat!("See [`", stringify!($Int), "::overflowing_neg`]")]
784+
/// for documentation on overflow behaviour.
785+
///
786+
/// # Example
787+
///
788+
/// ```
789+
/// #![feature(nonzero_negation_ops)]
790+
///
791+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
792+
/// # fn main() { test().unwrap(); }
793+
/// # fn test() -> Option<()> {
794+
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
795+
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
796+
#[doc = concat!("let min = ", stringify!($Ty), "::new(",
797+
stringify!($Int), "::MIN)?;")]
798+
///
799+
/// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
800+
/// assert_eq!(min.overflowing_neg(), (min, true));
801+
/// # Some(())
802+
/// # }
803+
/// ```
804+
#[inline]
805+
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
806+
pub const fn overflowing_neg(self) -> ($Ty, bool) {
807+
let (result, overflow) = self.get().overflowing_neg();
808+
// SAFETY: negation of nonzero cannot yield zero values.
809+
((unsafe { $Ty::new_unchecked(result) }), overflow)
810+
}
811+
812+
/// Saturating negation. Computes `-self`, returning `MAX` if
813+
/// `self == i32::MIN` instead of overflowing.
814+
///
815+
/// # Example
816+
///
817+
/// ```
818+
/// #![feature(nonzero_negation_ops)]
819+
///
820+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
821+
/// # fn main() { test().unwrap(); }
822+
/// # fn test() -> Option<()> {
823+
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
824+
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
825+
#[doc = concat!("let min = ", stringify!($Ty), "::new(",
826+
stringify!($Int), "::MIN)?;")]
827+
#[doc = concat!("let min_plus_one = ", stringify!($Ty), "::new(",
828+
stringify!($Int), "::MIN + 1)?;")]
829+
#[doc = concat!("let max = ", stringify!($Ty), "::new(",
830+
stringify!($Int), "::MAX)?;")]
831+
///
832+
/// assert_eq!(pos_five.saturating_neg(), neg_five);
833+
/// assert_eq!(min.saturating_neg(), max);
834+
/// assert_eq!(max.saturating_neg(), min_plus_one);
835+
/// # Some(())
836+
/// # }
837+
/// ```
838+
#[inline]
839+
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
840+
pub const fn saturating_neg(self) -> $Ty {
841+
if let Some(result) = self.checked_neg() {
842+
return result;
843+
}
844+
$Ty::MAX
845+
}
846+
847+
/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
848+
/// of the type.
849+
///
850+
#[doc = concat!("See [`", stringify!($Int), "::wrapping_neg`]")]
851+
/// for documentation on overflow behaviour.
852+
///
853+
/// # Example
854+
///
855+
/// ```
856+
/// #![feature(nonzero_negation_ops)]
857+
///
858+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
859+
/// # fn main() { test().unwrap(); }
860+
/// # fn test() -> Option<()> {
861+
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
862+
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
863+
#[doc = concat!("let min = ", stringify!($Ty), "::new(",
864+
stringify!($Int), "::MIN)?;")]
865+
///
866+
/// assert_eq!(pos_five.wrapping_neg(), neg_five);
867+
/// assert_eq!(min.wrapping_neg(), min);
868+
/// # Some(())
869+
/// # }
870+
/// ```
871+
#[inline]
872+
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
873+
pub const fn wrapping_neg(self) -> $Ty {
874+
let result = self.get().wrapping_neg();
875+
// SAFETY: negation of nonzero cannot yield zero values.
876+
unsafe { $Ty::new_unchecked(result) }
877+
}
724878
}
725879
)+
726880
}

‎src/librustdoc/html/static/css/rustdoc.css

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ h4.code-header {
191191
position: relative;
192192
}
193193

194+
#crate-search,
194195
h1, h2, h3, h4, h5, h6,
195196
.sidebar,
196197
.mobile-topbar,
@@ -304,16 +305,6 @@ summary {
304305

305306
/* Fix some style changes due to normalize.css 8 */
306307

307-
button,
308-
input,
309-
optgroup,
310-
select,
311-
textarea {
312-
color: inherit;
313-
font: inherit;
314-
margin: 0;
315-
}
316-
317308
button {
318309
/* Buttons on Safari have different default padding than other platforms. Make them the same. */
319310
padding: 1px 6px;
@@ -887,6 +878,9 @@ table,
887878
/* Removes default arrow from firefox */
888879
text-indent: 0.01px;
889880
background-color: var(--main-background-color);
881+
color: inherit;
882+
line-height: 1.5;
883+
font-weight: 500;
890884
}
891885
/* cancel stylistic differences in padding in firefox
892886
for "appearance: none"-style (or equivalent) <select>s */
@@ -1363,6 +1357,8 @@ pre.rust {
13631357
border: 0;
13641358
border-top: 2px solid;
13651359
flex: 1;
1360+
line-height: 1.5;
1361+
color: inherit;
13661362
}
13671363

13681364
#titles > button > div.count {
@@ -1380,7 +1376,6 @@ pre.rust {
13801376
position: sticky;
13811377
top: 0;
13821378
left: 0;
1383-
font-weight: bold;
13841379
font-size: 1.25rem;
13851380
border-bottom: 1px solid;
13861381
display: flex;
@@ -1400,6 +1395,8 @@ pre.rust {
14001395
margin-bottom: 6px;
14011396
}
14021397
#sidebar-toggle > button {
1398+
font-size: inherit;
1399+
font-weight: bold;
14031400
background: none;
14041401
color: inherit;
14051402
cursor: pointer;
@@ -1428,6 +1425,7 @@ pre.rust {
14281425
border: 1px solid var(--border-color);
14291426
border-radius: 2px;
14301427
cursor: pointer;
1428+
line-height: 1.5;
14311429
}
14321430

14331431
#settings-menu > a, #help-button > button {
@@ -1887,7 +1885,6 @@ in storage.js plus the media query with (min-width: 701px)
18871885
border-top-right-radius: 3px;
18881886
border-bottom-right-radius: 3px;
18891887
cursor: pointer;
1890-
font-weight: bold;
18911888
border: 1px solid;
18921889
border-left: 0;
18931890
}

‎src/librustdoc/html/static/css/settings.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
margin-right: 0.3em;
1313
height: 1.2rem;
1414
width: 1.2rem;
15-
border: 1px solid;
15+
color: inherit;
16+
border: 1px solid currentColor;
1617
outline: none;
1718
-webkit-appearance: none;
1819
cursor: pointer;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
trait A {
4+
type T: B<U<1i32> = ()>;
5+
}
6+
7+
trait B {
8+
type U<const C: i32>;
9+
}
10+
11+
fn f<T: A>() {
12+
let _: <<T as A>::T as B>::U<1i32> = ();
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.