Skip to content

Commit 266ecd6

Browse files
committed
Auto merge of #68685 - Dylan-DPC:rollup-rkbo05z, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #68588 (check_unsafety: more code reuse) - #68638 (Add missing links for cmp traits) - #68660 (Fix typo.) - #68669 (suggest adding space in accidental doc comments) - #68670 (clarify "incorrect issue" error) - #68680 (Add `#![doc(html_playground_url = ...)]` to alloc crate) Failed merges: r? @ghost
2 parents 138c50f + 6c67466 commit 266ecd6

File tree

12 files changed

+188
-93
lines changed

12 files changed

+188
-93
lines changed

Diff for: src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#![stable(feature = "alloc", since = "1.36.0")]
6161
#![doc(
6262
html_root_url = "https://doc.rust-lang.org/nightly/",
63+
html_playground_url = "https://play.rust-lang.org/",
6364
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
6465
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
6566
)]

Diff for: src/libcore/cmp.rs

+31-20
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use self::Ordering::*;
3535
///
3636
/// This trait allows for partial equality, for types that do not have a full
3737
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
38-
/// so floating point types implement `PartialEq` but not `Eq`.
38+
/// so floating point types implement `PartialEq` but not [`Eq`].
3939
///
4040
/// Formally, the equality must be (for all `a`, `b` and `c`):
4141
///
@@ -55,12 +55,12 @@ use self::Ordering::*;
5555
///
5656
/// ## How can I implement `PartialEq`?
5757
///
58-
/// PartialEq only requires the `eq` method to be implemented; `ne` is defined
59-
/// in terms of it by default. Any manual implementation of `ne` *must* respect
60-
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
58+
/// `PartialEq` only requires the [`eq`] method to be implemented; [`ne`] is defined
59+
/// in terms of it by default. Any manual implementation of [`ne`] *must* respect
60+
/// the rule that [`eq`] is a strict inverse of [`ne`]; that is, `!(a == b)` if and
6161
/// only if `a != b`.
6262
///
63-
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with
63+
/// Implementations of `PartialEq`, [`PartialOrd`], and [`Ord`] *must* agree with
6464
/// each other. It's easy to accidentally make them disagree by deriving some
6565
/// of the traits and manually implementing others.
6666
///
@@ -190,6 +190,9 @@ use self::Ordering::*;
190190
/// assert_eq!(x == y, false);
191191
/// assert_eq!(x.eq(&y), false);
192192
/// ```
193+
///
194+
/// [`eq`]: PartialEq::eq
195+
/// [`ne`]: PartialEq::ne
193196
#[lang = "eq"]
194197
#[stable(feature = "rust1", since = "1.0.0")]
195198
#[doc(alias = "==")]
@@ -233,7 +236,7 @@ pub macro PartialEq($item:item) {
233236
/// - transitive: `a == b` and `b == c` implies `a == c`.
234237
///
235238
/// This property cannot be checked by the compiler, and therefore `Eq` implies
236-
/// `PartialEq`, and has no extra methods.
239+
/// [`PartialEq`], and has no extra methods.
237240
///
238241
/// ## Derivable
239242
///
@@ -370,6 +373,7 @@ impl Ordering {
370373
/// Chains two orderings.
371374
///
372375
/// Returns `self` when it's not `Equal`. Otherwise returns `other`.
376+
///
373377
/// # Examples
374378
///
375379
/// ```
@@ -442,10 +446,12 @@ impl Ordering {
442446

443447
/// A helper struct for reverse ordering.
444448
///
445-
/// This struct is a helper to be used with functions like `Vec::sort_by_key` and
449+
/// This struct is a helper to be used with functions like [`Vec::sort_by_key`] and
446450
/// can be used to reverse order a part of a key.
447451
///
448-
/// Example usage:
452+
/// [`Vec::sort_by_key`]: ../../std/vec/struct.Vec.html#method.sort_by_key
453+
///
454+
/// # Examples
449455
///
450456
/// ```
451457
/// use std::cmp::Reverse;
@@ -506,12 +512,12 @@ impl<T: Ord> Ord for Reverse<T> {
506512
///
507513
/// ## How can I implement `Ord`?
508514
///
509-
/// `Ord` requires that the type also be `PartialOrd` and `Eq` (which requires `PartialEq`).
515+
/// `Ord` requires that the type also be [`PartialOrd`] and [`Eq`] (which requires [`PartialEq`]).
510516
///
511-
/// Then you must define an implementation for `cmp()`. You may find it useful to use
512-
/// `cmp()` on your type's fields.
517+
/// Then you must define an implementation for [`cmp`]. You may find it useful to use
518+
/// [`cmp`] on your type's fields.
513519
///
514-
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must*
520+
/// Implementations of [`PartialEq`], [`PartialOrd`], and `Ord` *must*
515521
/// agree with each other. That is, `a.cmp(b) == Ordering::Equal` if
516522
/// and only if `a == b` and `Some(a.cmp(b)) == a.partial_cmp(b)` for
517523
/// all `a` and `b`. It's easy to accidentally make them disagree by
@@ -548,13 +554,15 @@ impl<T: Ord> Ord for Reverse<T> {
548554
/// }
549555
/// }
550556
/// ```
557+
///
558+
/// [`cmp`]: Ord::cmp
551559
#[doc(alias = "<")]
552560
#[doc(alias = ">")]
553561
#[doc(alias = "<=")]
554562
#[doc(alias = ">=")]
555563
#[stable(feature = "rust1", since = "1.0.0")]
556564
pub trait Ord: Eq + PartialOrd<Self> {
557-
/// This method returns an `Ordering` between `self` and `other`.
565+
/// This method returns an [`Ordering`] between `self` and `other`.
558566
///
559567
/// By convention, `self.cmp(&other)` returns the ordering matching the expression
560568
/// `self <operator> other` if true.
@@ -689,20 +697,20 @@ impl PartialOrd for Ordering {
689697
///
690698
/// ## How can I implement `PartialOrd`?
691699
///
692-
/// `PartialOrd` only requires implementation of the `partial_cmp` method, with the others
700+
/// `PartialOrd` only requires implementation of the [`partial_cmp`] method, with the others
693701
/// generated from default implementations.
694702
///
695703
/// However it remains possible to implement the others separately for types which do not have a
696704
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
697705
/// false` (cf. IEEE 754-2008 section 5.11).
698706
///
699-
/// `PartialOrd` requires your type to be `PartialEq`.
707+
/// `PartialOrd` requires your type to be [`PartialEq`].
700708
///
701-
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
709+
/// Implementations of [`PartialEq`], `PartialOrd`, and [`Ord`] *must* agree with each other. It's
702710
/// easy to accidentally make them disagree by deriving some of the traits and manually
703711
/// implementing others.
704712
///
705-
/// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
713+
/// If your type is [`Ord`], you can implement [`partial_cmp`] by using [`cmp`]:
706714
///
707715
/// ```
708716
/// use std::cmp::Ordering;
@@ -733,7 +741,7 @@ impl PartialOrd for Ordering {
733741
/// }
734742
/// ```
735743
///
736-
/// You may also find it useful to use `partial_cmp()` on your type's fields. Here
744+
/// You may also find it useful to use [`partial_cmp`] on your type's fields. Here
737745
/// is an example of `Person` types who have a floating-point `height` field that
738746
/// is the only field to be used for sorting:
739747
///
@@ -768,6 +776,9 @@ impl PartialOrd for Ordering {
768776
/// assert_eq!(x < y, true);
769777
/// assert_eq!(x.lt(&y), true);
770778
/// ```
779+
///
780+
/// [`partial_cmp`]: PartialOrd::partial_cmp
781+
/// [`cmp`]: Ord::cmp
771782
#[lang = "partial_ord"]
772783
#[stable(feature = "rust1", since = "1.0.0")]
773784
#[doc(alias = ">")]
@@ -893,7 +904,7 @@ pub macro PartialOrd($item:item) {
893904
///
894905
/// Returns the first argument if the comparison determines them to be equal.
895906
///
896-
/// Internally uses an alias to `Ord::min`.
907+
/// Internally uses an alias to [`Ord::min`].
897908
///
898909
/// # Examples
899910
///
@@ -956,7 +967,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
956967
///
957968
/// Returns the second argument if the comparison determines them to be equal.
958969
///
959-
/// Internally uses an alias to `Ord::max`.
970+
/// Internally uses an alias to [`Ord::max`].
960971
///
961972
/// # Examples
962973
///

Diff for: src/librustc_mir/transform/check_unsafety.rs

+18-39
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
148148
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
149149
match (cast_in, cast_out) {
150150
(CastTy::Ptr(_), CastTy::Int(_)) | (CastTy::FnPtr, CastTy::Int(_)) => {
151-
self.register_violations(
152-
&[UnsafetyViolation {
153-
source_info: self.source_info,
154-
description: Symbol::intern("cast of pointer to int"),
155-
details: Symbol::intern(
156-
"casting pointers to integers in constants",
157-
),
158-
kind: UnsafetyViolationKind::General,
159-
}],
160-
&[],
151+
self.require_unsafe(
152+
"cast of pointer to int",
153+
"casting pointers to integers in constants",
154+
UnsafetyViolationKind::General,
161155
);
162156
}
163157
_ => {}
@@ -171,14 +165,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
171165
if self.const_context && self.tcx.features().const_compare_raw_pointers =>
172166
{
173167
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind {
174-
self.register_violations(
175-
&[UnsafetyViolation {
176-
source_info: self.source_info,
177-
description: Symbol::intern("pointer operation"),
178-
details: Symbol::intern("operations on pointers in constants"),
179-
kind: UnsafetyViolationKind::General,
180-
}],
181-
&[],
168+
self.require_unsafe(
169+
"pointer operation",
170+
"operations on pointers in constants",
171+
UnsafetyViolationKind::General,
182172
);
183173
}
184174
}
@@ -199,18 +189,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
199189
.as_ref()
200190
.assert_crate_local()
201191
.lint_root;
202-
self.register_violations(
203-
&[UnsafetyViolation {
204-
source_info,
205-
description: Symbol::intern("borrow of packed field"),
206-
details: Symbol::intern(
207-
"fields of packed structs might be misaligned: dereferencing a \
208-
misaligned pointer or even just creating a misaligned reference \
209-
is undefined behavior",
210-
),
211-
kind: UnsafetyViolationKind::BorrowPacked(lint_root),
212-
}],
213-
&[],
192+
self.require_unsafe(
193+
"borrow of packed field",
194+
"fields of packed structs might be misaligned: dereferencing a \
195+
misaligned pointer or even just creating a misaligned reference \
196+
is undefined behavior",
197+
UnsafetyViolationKind::BorrowPacked(lint_root),
214198
);
215199
}
216200
}
@@ -434,15 +418,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
434418
the field can be changed to invalid values",
435419
)
436420
};
437-
let source_info = self.source_info;
438-
self.register_violations(
439-
&[UnsafetyViolation {
440-
source_info,
441-
description: Symbol::intern(description),
442-
details: Symbol::intern(details),
443-
kind: UnsafetyViolationKind::GeneralAndConstFn,
444-
}],
445-
&[],
421+
self.require_unsafe(
422+
description,
423+
details,
424+
UnsafetyViolationKind::GeneralAndConstFn,
446425
);
447426
}
448427
},

Diff for: src/librustc_parse/parser/stmt.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use crate::maybe_whole;
77
use crate::DirectoryOwnership;
88

99
use rustc_errors::{Applicability, PResult};
10-
use rustc_span::source_map::{respan, Span};
10+
use rustc_span::source_map::{respan, BytePos, Span};
1111
use rustc_span::symbol::{kw, sym, Symbol};
1212
use syntax::ast;
1313
use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle, VisibilityKind};
1414
use syntax::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
1515
use syntax::ptr::P;
16-
use syntax::token;
16+
use syntax::token::{self, TokenKind};
1717
use syntax::util::classify;
1818

1919
use std::mem;
@@ -431,6 +431,23 @@ impl<'a> Parser<'a> {
431431
if let Err(mut e) =
432432
self.expect_one_of(&[], &[token::Semi, token::CloseDelim(token::Brace)])
433433
{
434+
if let TokenKind::DocComment(..) = self.token.kind {
435+
if let Ok(snippet) = self.span_to_snippet(self.token.span) {
436+
let sp = self.token.span;
437+
let marker = &snippet[..3];
438+
let (comment_marker, doc_comment_marker) = marker.split_at(2);
439+
440+
e.span_suggestion(
441+
sp.with_hi(sp.lo() + BytePos(marker.len() as u32)),
442+
&format!(
443+
"add a space before `{}` to use a regular comment",
444+
doc_comment_marker,
445+
),
446+
format!("{} {}", comment_marker, doc_comment_marker),
447+
Applicability::MaybeIncorrect,
448+
);
449+
}
450+
}
434451
e.emit();
435452
self.recover_stmt();
436453
// Don't complain about type errors in body tail after parse error (#57383).

Diff for: src/libstd/sys/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ pub mod guard {
426426
}
427427

428428
// glibc >= 2.15 has a __pthread_get_minstack() function that returns
429-
// PTHREAD_STACK_MIN plus however many bytes are needed for thread-local
430-
// storage. We need that information to avoid blowing up when a small stack
429+
// PTHREAD_STACK_MIN plus bytes needed for thread-local storage.
430+
// We need that information to avoid blowing up when a small stack
431431
// is created in an application with big thread-local storage requirements.
432432
// See #6233 for rationale and details.
433433
#[cfg(target_os = "linux")]

Diff for: src/libsyntax/attr/builtin.rs

+34-21
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ where
371371
let mut feature = None;
372372
let mut reason = None;
373373
let mut issue = None;
374+
let mut issue_num = None;
374375
let mut is_soft = false;
375376
for meta in metas {
376377
if let Some(mi) = meta.meta_item() {
@@ -389,6 +390,37 @@ where
389390
if !get(mi, &mut issue) {
390391
continue 'outer;
391392
}
393+
394+
// These unwraps are safe because `get` ensures the meta item
395+
// is a name/value pair string literal.
396+
issue_num = match &*issue.unwrap().as_str() {
397+
"none" => None,
398+
issue => {
399+
match issue.parse() {
400+
Ok(num) => {
401+
// FIXME(rossmacarthur): disallow 0
402+
// Disallowing this requires updates to
403+
// some submodules
404+
NonZeroU32::new(num)
405+
}
406+
Err(err) => {
407+
struct_span_err!(
408+
diagnostic,
409+
mi.span,
410+
E0545,
411+
"`issue` must be a numeric string \
412+
or \"none\"",
413+
)
414+
.span_label(
415+
mi.name_value_literal().unwrap().span,
416+
&err.to_string(),
417+
)
418+
.emit();
419+
continue 'outer;
420+
}
421+
}
422+
}
423+
};
392424
}
393425
sym::soft => {
394426
if !mi.is_word() {
@@ -420,27 +452,8 @@ where
420452
}
421453

422454
match (feature, reason, issue) {
423-
(Some(feature), reason, Some(issue)) => {
424-
let issue = match &*issue.as_str() {
425-
"none" => None,
426-
issue => {
427-
if let Ok(num) = issue.parse() {
428-
// FIXME(rossmacarthur): disallow 0
429-
// Disallowing this requires updates to some submodules
430-
NonZeroU32::new(num)
431-
} else {
432-
struct_span_err!(
433-
diagnostic,
434-
attr.span,
435-
E0545,
436-
"incorrect 'issue'"
437-
)
438-
.emit();
439-
continue;
440-
}
441-
}
442-
};
443-
let level = Unstable { reason, issue, is_soft };
455+
(Some(feature), reason, Some(_)) => {
456+
let level = Unstable { reason, issue: issue_num, is_soft };
444457
if sym::unstable == meta_name {
445458
stab = Some(Stability { level, feature, rustc_depr: None });
446459
} else {

Diff for: src/test/ui/feature-gate/unstable-attribute-allow-issue-0.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fn unstable_issue_0() {}
99
#[unstable(feature = "unstable_test_feature", issue = "none")]
1010
fn unstable_issue_none() {}
1111

12-
#[unstable(feature = "unstable_test_feature", issue = "something")] //~ ERROR incorrect 'issue'
13-
fn unstable_issue_not_allowed() {}
12+
#[unstable(feature = "unstable_test_feature", issue = "something")]
13+
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"

0 commit comments

Comments
 (0)