Skip to content

Commit

Permalink
Auto merge of rust-lang#68685 - Dylan-DPC:rollup-rkbo05z, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#68588 (check_unsafety: more code reuse)
 - rust-lang#68638 (Add missing links for cmp traits)
 - rust-lang#68660 (Fix typo.)
 - rust-lang#68669 (suggest adding space in accidental doc comments)
 - rust-lang#68670 (clarify "incorrect issue" error)
 - rust-lang#68680 (Add `#![doc(html_playground_url = ...)]` to alloc crate)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jan 31, 2020
2 parents 138c50f + 6c67466 commit 266ecd6
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 93 deletions.
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Expand Up @@ -60,6 +60,7 @@
#![stable(feature = "alloc", since = "1.36.0")]
#![doc(
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/",
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
test(no_crate_inject, attr(allow(unused_variables), deny(warnings)))
)]
Expand Down
51 changes: 31 additions & 20 deletions src/libcore/cmp.rs
Expand Up @@ -35,7 +35,7 @@ use self::Ordering::*;
///
/// This trait allows for partial equality, for types that do not have a full
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
/// so floating point types implement `PartialEq` but not `Eq`.
/// so floating point types implement `PartialEq` but not [`Eq`].
///
/// Formally, the equality must be (for all `a`, `b` and `c`):
///
Expand All @@ -55,12 +55,12 @@ use self::Ordering::*;
///
/// ## How can I implement `PartialEq`?
///
/// PartialEq only requires the `eq` method to be implemented; `ne` is defined
/// in terms of it by default. Any manual implementation of `ne` *must* respect
/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
/// `PartialEq` only requires the [`eq`] method to be implemented; [`ne`] is defined
/// in terms of it by default. Any manual implementation of [`ne`] *must* respect
/// the rule that [`eq`] is a strict inverse of [`ne`]; that is, `!(a == b)` if and
/// only if `a != b`.
///
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with
/// Implementations of `PartialEq`, [`PartialOrd`], and [`Ord`] *must* agree with
/// each other. It's easy to accidentally make them disagree by deriving some
/// of the traits and manually implementing others.
///
Expand Down Expand Up @@ -190,6 +190,9 @@ use self::Ordering::*;
/// assert_eq!(x == y, false);
/// assert_eq!(x.eq(&y), false);
/// ```
///
/// [`eq`]: PartialEq::eq
/// [`ne`]: PartialEq::ne
#[lang = "eq"]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "==")]
Expand Down Expand Up @@ -233,7 +236,7 @@ pub macro PartialEq($item:item) {
/// - transitive: `a == b` and `b == c` implies `a == c`.
///
/// This property cannot be checked by the compiler, and therefore `Eq` implies
/// `PartialEq`, and has no extra methods.
/// [`PartialEq`], and has no extra methods.
///
/// ## Derivable
///
Expand Down Expand Up @@ -370,6 +373,7 @@ impl Ordering {
/// Chains two orderings.
///
/// Returns `self` when it's not `Equal`. Otherwise returns `other`.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -442,10 +446,12 @@ impl Ordering {

/// A helper struct for reverse ordering.
///
/// This struct is a helper to be used with functions like `Vec::sort_by_key` and
/// This struct is a helper to be used with functions like [`Vec::sort_by_key`] and
/// can be used to reverse order a part of a key.
///
/// Example usage:
/// [`Vec::sort_by_key`]: ../../std/vec/struct.Vec.html#method.sort_by_key
///
/// # Examples
///
/// ```
/// use std::cmp::Reverse;
Expand Down Expand Up @@ -506,12 +512,12 @@ impl<T: Ord> Ord for Reverse<T> {
///
/// ## How can I implement `Ord`?
///
/// `Ord` requires that the type also be `PartialOrd` and `Eq` (which requires `PartialEq`).
/// `Ord` requires that the type also be [`PartialOrd`] and [`Eq`] (which requires [`PartialEq`]).
///
/// Then you must define an implementation for `cmp()`. You may find it useful to use
/// `cmp()` on your type's fields.
/// Then you must define an implementation for [`cmp`]. You may find it useful to use
/// [`cmp`] on your type's fields.
///
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must*
/// Implementations of [`PartialEq`], [`PartialOrd`], and `Ord` *must*
/// agree with each other. That is, `a.cmp(b) == Ordering::Equal` if
/// and only if `a == b` and `Some(a.cmp(b)) == a.partial_cmp(b)` for
/// all `a` and `b`. It's easy to accidentally make them disagree by
Expand Down Expand Up @@ -548,13 +554,15 @@ impl<T: Ord> Ord for Reverse<T> {
/// }
/// }
/// ```
///
/// [`cmp`]: Ord::cmp
#[doc(alias = "<")]
#[doc(alias = ">")]
#[doc(alias = "<=")]
#[doc(alias = ">=")]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Ord: Eq + PartialOrd<Self> {
/// This method returns an `Ordering` between `self` and `other`.
/// This method returns an [`Ordering`] between `self` and `other`.
///
/// By convention, `self.cmp(&other)` returns the ordering matching the expression
/// `self <operator> other` if true.
Expand Down Expand Up @@ -689,20 +697,20 @@ impl PartialOrd for Ordering {
///
/// ## How can I implement `PartialOrd`?
///
/// `PartialOrd` only requires implementation of the `partial_cmp` method, with the others
/// `PartialOrd` only requires implementation of the [`partial_cmp`] method, with the others
/// generated from default implementations.
///
/// However it remains possible to implement the others separately for types which do not have a
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
/// false` (cf. IEEE 754-2008 section 5.11).
///
/// `PartialOrd` requires your type to be `PartialEq`.
/// `PartialOrd` requires your type to be [`PartialEq`].
///
/// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
/// Implementations of [`PartialEq`], `PartialOrd`, and [`Ord`] *must* agree with each other. It's
/// easy to accidentally make them disagree by deriving some of the traits and manually
/// implementing others.
///
/// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
/// If your type is [`Ord`], you can implement [`partial_cmp`] by using [`cmp`]:
///
/// ```
/// use std::cmp::Ordering;
Expand Down Expand Up @@ -733,7 +741,7 @@ impl PartialOrd for Ordering {
/// }
/// ```
///
/// You may also find it useful to use `partial_cmp()` on your type's fields. Here
/// You may also find it useful to use [`partial_cmp`] on your type's fields. Here
/// is an example of `Person` types who have a floating-point `height` field that
/// is the only field to be used for sorting:
///
Expand Down Expand Up @@ -768,6 +776,9 @@ impl PartialOrd for Ordering {
/// assert_eq!(x < y, true);
/// assert_eq!(x.lt(&y), true);
/// ```
///
/// [`partial_cmp`]: PartialOrd::partial_cmp
/// [`cmp`]: Ord::cmp
#[lang = "partial_ord"]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = ">")]
Expand Down Expand Up @@ -893,7 +904,7 @@ pub macro PartialOrd($item:item) {
///
/// Returns the first argument if the comparison determines them to be equal.
///
/// Internally uses an alias to `Ord::min`.
/// Internally uses an alias to [`Ord::min`].
///
/// # Examples
///
Expand Down Expand Up @@ -956,7 +967,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
///
/// Returns the second argument if the comparison determines them to be equal.
///
/// Internally uses an alias to `Ord::max`.
/// Internally uses an alias to [`Ord::max`].
///
/// # Examples
///
Expand Down
57 changes: 18 additions & 39 deletions src/librustc_mir/transform/check_unsafety.rs
Expand Up @@ -148,16 +148,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
match (cast_in, cast_out) {
(CastTy::Ptr(_), CastTy::Int(_)) | (CastTy::FnPtr, CastTy::Int(_)) => {
self.register_violations(
&[UnsafetyViolation {
source_info: self.source_info,
description: Symbol::intern("cast of pointer to int"),
details: Symbol::intern(
"casting pointers to integers in constants",
),
kind: UnsafetyViolationKind::General,
}],
&[],
self.require_unsafe(
"cast of pointer to int",
"casting pointers to integers in constants",
UnsafetyViolationKind::General,
);
}
_ => {}
Expand All @@ -171,14 +165,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
if self.const_context && self.tcx.features().const_compare_raw_pointers =>
{
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind {
self.register_violations(
&[UnsafetyViolation {
source_info: self.source_info,
description: Symbol::intern("pointer operation"),
details: Symbol::intern("operations on pointers in constants"),
kind: UnsafetyViolationKind::General,
}],
&[],
self.require_unsafe(
"pointer operation",
"operations on pointers in constants",
UnsafetyViolationKind::General,
);
}
}
Expand All @@ -199,18 +189,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
.as_ref()
.assert_crate_local()
.lint_root;
self.register_violations(
&[UnsafetyViolation {
source_info,
description: Symbol::intern("borrow of packed field"),
details: Symbol::intern(
"fields of packed structs might be misaligned: dereferencing a \
misaligned pointer or even just creating a misaligned reference \
is undefined behavior",
),
kind: UnsafetyViolationKind::BorrowPacked(lint_root),
}],
&[],
self.require_unsafe(
"borrow of packed field",
"fields of packed structs might be misaligned: dereferencing a \
misaligned pointer or even just creating a misaligned reference \
is undefined behavior",
UnsafetyViolationKind::BorrowPacked(lint_root),
);
}
}
Expand Down Expand Up @@ -434,15 +418,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
the field can be changed to invalid values",
)
};
let source_info = self.source_info;
self.register_violations(
&[UnsafetyViolation {
source_info,
description: Symbol::intern(description),
details: Symbol::intern(details),
kind: UnsafetyViolationKind::GeneralAndConstFn,
}],
&[],
self.require_unsafe(
description,
details,
UnsafetyViolationKind::GeneralAndConstFn,
);
}
},
Expand Down
21 changes: 19 additions & 2 deletions src/librustc_parse/parser/stmt.rs
Expand Up @@ -7,13 +7,13 @@ use crate::maybe_whole;
use crate::DirectoryOwnership;

use rustc_errors::{Applicability, PResult};
use rustc_span::source_map::{respan, Span};
use rustc_span::source_map::{respan, BytePos, Span};
use rustc_span::symbol::{kw, sym, Symbol};
use syntax::ast;
use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle, VisibilityKind};
use syntax::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
use syntax::ptr::P;
use syntax::token;
use syntax::token::{self, TokenKind};
use syntax::util::classify;

use std::mem;
Expand Down Expand Up @@ -431,6 +431,23 @@ impl<'a> Parser<'a> {
if let Err(mut e) =
self.expect_one_of(&[], &[token::Semi, token::CloseDelim(token::Brace)])
{
if let TokenKind::DocComment(..) = self.token.kind {
if let Ok(snippet) = self.span_to_snippet(self.token.span) {
let sp = self.token.span;
let marker = &snippet[..3];
let (comment_marker, doc_comment_marker) = marker.split_at(2);

e.span_suggestion(
sp.with_hi(sp.lo() + BytePos(marker.len() as u32)),
&format!(
"add a space before `{}` to use a regular comment",
doc_comment_marker,
),
format!("{} {}", comment_marker, doc_comment_marker),
Applicability::MaybeIncorrect,
);
}
}
e.emit();
self.recover_stmt();
// Don't complain about type errors in body tail after parse error (#57383).
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/thread.rs
Expand Up @@ -426,8 +426,8 @@ pub mod guard {
}

// glibc >= 2.15 has a __pthread_get_minstack() function that returns
// PTHREAD_STACK_MIN plus however many bytes are needed for thread-local
// storage. We need that information to avoid blowing up when a small stack
// PTHREAD_STACK_MIN plus bytes needed for thread-local storage.
// We need that information to avoid blowing up when a small stack
// is created in an application with big thread-local storage requirements.
// See #6233 for rationale and details.
#[cfg(target_os = "linux")]
Expand Down
55 changes: 34 additions & 21 deletions src/libsyntax/attr/builtin.rs
Expand Up @@ -371,6 +371,7 @@ where
let mut feature = None;
let mut reason = None;
let mut issue = None;
let mut issue_num = None;
let mut is_soft = false;
for meta in metas {
if let Some(mi) = meta.meta_item() {
Expand All @@ -389,6 +390,37 @@ where
if !get(mi, &mut issue) {
continue 'outer;
}

// These unwraps are safe because `get` ensures the meta item
// is a name/value pair string literal.
issue_num = match &*issue.unwrap().as_str() {
"none" => None,
issue => {
match issue.parse() {
Ok(num) => {
// FIXME(rossmacarthur): disallow 0
// Disallowing this requires updates to
// some submodules
NonZeroU32::new(num)
}
Err(err) => {
struct_span_err!(
diagnostic,
mi.span,
E0545,
"`issue` must be a numeric string \
or \"none\"",
)
.span_label(
mi.name_value_literal().unwrap().span,
&err.to_string(),
)
.emit();
continue 'outer;
}
}
}
};
}
sym::soft => {
if !mi.is_word() {
Expand Down Expand Up @@ -420,27 +452,8 @@ where
}

match (feature, reason, issue) {
(Some(feature), reason, Some(issue)) => {
let issue = match &*issue.as_str() {
"none" => None,
issue => {
if let Ok(num) = issue.parse() {
// FIXME(rossmacarthur): disallow 0
// Disallowing this requires updates to some submodules
NonZeroU32::new(num)
} else {
struct_span_err!(
diagnostic,
attr.span,
E0545,
"incorrect 'issue'"
)
.emit();
continue;
}
}
};
let level = Unstable { reason, issue, is_soft };
(Some(feature), reason, Some(_)) => {
let level = Unstable { reason, issue: issue_num, is_soft };
if sym::unstable == meta_name {
stab = Some(Stability { level, feature, rustc_depr: None });
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/feature-gate/unstable-attribute-allow-issue-0.rs
Expand Up @@ -9,5 +9,5 @@ fn unstable_issue_0() {}
#[unstable(feature = "unstable_test_feature", issue = "none")]
fn unstable_issue_none() {}

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

0 comments on commit 266ecd6

Please sign in to comment.