Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 18 pull requests #76414

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fcf1571
Add Atomic*::from_mut.
m-ou-se Jul 19, 2020
09fff5f
Disable Atomic*::from_mut when alignment is wrong.
m-ou-se Aug 13, 2020
8142457
Update tracking issue for const_caller_location
ArekPiekarz Aug 31, 2020
8783c62
Add missing link in README
camelid Sep 2, 2020
3e29fdb
Remove a number of vec UI tests, make them unit tests in the alloc li…
CraftSpider Sep 3, 2020
791f93c
Allow try blocks as the argument to return expressions
scottmcm Sep 3, 2020
2278c72
Remove vec-to_str.rs, merge the remaining test in with vec
CraftSpider Sep 3, 2020
a2e077e
Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`
CDirkx Sep 3, 2020
8c93125
Address review comments on `Peekable::next_if`
jyn514 Sep 3, 2020
7b823df
Link to `#capacity-and-reallocation` when using with_capacity
jyn514 Sep 3, 2020
538e198
Move various ui const tests to `library`
CDirkx Sep 4, 2020
a3ee65f
Remove a useless allowed attr
tesuji Sep 4, 2020
8f11127
time.rs: Make spelling of "Darwin" consistent
numbermaniac Sep 4, 2020
fac2726
Use ops::ControlFlow in graph::iterate
scottmcm Sep 4, 2020
d16bbd1
Move Vec slice UI tests in library
Sep 4, 2020
8f2d906
Implementation of incompatible features error
Amjad50 Sep 3, 2020
2ed1a21
add some intra-doc links to `Iterator`
euclio Sep 4, 2020
59e3733
Add `BREAK` too, and improve the comments
scottmcm Sep 4, 2020
dfd219d
Indent a note to make folding work nicer
tesuji Sep 5, 2020
7cc2569
Add tracking issue number for atomic_from_mut.
m-ou-se Sep 5, 2020
8af85fa
Improve the documentation of `filter()` and `filter_map()`.
vext01 Aug 26, 2020
7cbfbd3
compiletest: Introduce "min-cdb-version"
MaulingMonkey Sep 5, 2020
4046f92
debuginfo: Ignore HashMap tests before cdb 10.0.18362.1
MaulingMonkey Sep 5, 2020
099af05
Rollup merge of #74532 - fusion-engineering-forks:atomic-from-mut, r=…
Dylan-DPC Sep 6, 2020
8abb528
Rollup merge of #75949 - vext01:filter-docs, r=jyn514
Dylan-DPC Sep 6, 2020
bdd3b05
Rollup merge of #76157 - ArekPiekarz:const_caller_location_tracking_i…
Dylan-DPC Sep 6, 2020
de3e0a6
Rollup merge of #76229 - camelid:patch-3, r=jonas-schievink
Dylan-DPC Sep 6, 2020
26b67dd
Rollup merge of #76273 - CraftSpider:master, r=matklad
Dylan-DPC Sep 6, 2020
3e0a83c
Rollup merge of #76274 - scottmcm:fix-76271, r=petrochenkov
Dylan-DPC Sep 6, 2020
5d24dd0
Rollup merge of #76287 - lzutao:rm-allowed, r=jyn514
Dylan-DPC Sep 6, 2020
a979810
Rollup merge of #76293 - Amjad50:incompatible_features_error, r=lcnr
Dylan-DPC Sep 6, 2020
2d5f21d
Rollup merge of #76299 - CDirkx:ip-tests, r=matklad
Dylan-DPC Sep 6, 2020
f06c59e
Rollup merge of #76302 - jyn514:peekable-2, r=Dylan-DPC
Dylan-DPC Sep 6, 2020
7d9d348
Rollup merge of #76303 - jyn514:vec-assert-doc, r=Dylan-DPC
Dylan-DPC Sep 6, 2020
bdd9561
Rollup merge of #76305 - CDirkx:const-tests, r=matklad
Dylan-DPC Sep 6, 2020
4782725
Rollup merge of #76309 - lzutao:indent-note, r=jyn514
Dylan-DPC Sep 6, 2020
eb02832
Rollup merge of #76312 - numbermaniac:patch-1, r=shepmaster
Dylan-DPC Sep 6, 2020
97cd85d
Rollup merge of #76318 - scottmcm:one-control-flow, r=ecstatic-morse
Dylan-DPC Sep 6, 2020
378274b
Rollup merge of #76324 - ayushmishra2005:move_vec_tests_in_library, r…
Dylan-DPC Sep 6, 2020
d80185b
Rollup merge of #76338 - euclio:intra-link-iterator, r=jyn514
Dylan-DPC Sep 6, 2020
caaf743
Rollup merge of #76390 - MaulingMonkey:pr-min-cdb-version, r=petroche…
Dylan-DPC Sep 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -243,6 +243,8 @@ The Rust community congregates in a few places:
If you are interested in contributing to the Rust project, please take a look
at the [Getting Started][gettingstarted] guide in the [rustc-dev-guide].

[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org

## License

Rust is primarily distributed under the terms of both the MIT license
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/token.rs
Expand Up @@ -173,6 +173,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
kw::Move,
kw::Return,
kw::True,
kw::Try,
kw::Unsafe,
kw::While,
kw::Yield,
Expand Down
34 changes: 34 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -608,6 +608,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

pub fn check_crate(krate: &ast::Crate, sess: &Session) {
maybe_stage_features(sess, krate);
check_incompatible_features(sess);
let mut visitor = PostExpansionVisitor { sess, features: &sess.features_untracked() };

let spans = sess.parse_sess.gated_spans.spans.borrow();
Expand Down Expand Up @@ -677,3 +678,36 @@ fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
}
}
}

fn check_incompatible_features(sess: &Session) {
let features = sess.features_untracked();

let declared_features = features
.declared_lang_features
.iter()
.copied()
.map(|(name, span, _)| (name, span))
.chain(features.declared_lib_features.iter().copied());

for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES
.iter()
.filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
{
if let Some((f1_name, f1_span)) = declared_features.clone().find(|(name, _)| name == f1) {
if let Some((f2_name, f2_span)) = declared_features.clone().find(|(name, _)| name == f2)
{
let spans = vec![f1_span, f2_span];
sess.struct_span_err(
spans.clone(),
&format!(
"features `{}` and `{}` are incompatible, using them at the same time \
is not allowed",
f1_name, f2_name
),
)
.help("remove one of these features")
.emit();
}
}
}
}
15 changes: 6 additions & 9 deletions compiler/rustc_data_structures/src/graph/iterate/mod.rs
Expand Up @@ -87,11 +87,8 @@ where
}

/// Allows searches to terminate early with a value.
#[derive(Clone, Copy, Debug)]
pub enum ControlFlow<T> {
Break(T),
Continue,
}
// FIXME (#75744): remove the alias once the generics are in a better order and `C=()`.
pub type ControlFlow<T> = std::ops::ControlFlow<(), T>;

/// The status of a node in the depth-first search.
///
Expand Down Expand Up @@ -260,12 +257,12 @@ where
_node: G::Node,
_prior_status: Option<NodeStatus>,
) -> ControlFlow<Self::BreakVal> {
ControlFlow::Continue
ControlFlow::CONTINUE
}

/// Called after all nodes reachable from this one have been examined.
fn node_settled(&mut self, _node: G::Node) -> ControlFlow<Self::BreakVal> {
ControlFlow::Continue
ControlFlow::CONTINUE
}

/// Behave as if no edges exist from `source` to `target`.
Expand All @@ -289,8 +286,8 @@ where
prior_status: Option<NodeStatus>,
) -> ControlFlow<Self::BreakVal> {
match prior_status {
Some(NodeStatus::Visited) => ControlFlow::Break(()),
_ => ControlFlow::Continue,
Some(NodeStatus::Visited) => ControlFlow::BREAK,
_ => ControlFlow::CONTINUE,
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Expand Up @@ -8,6 +8,7 @@

#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![allow(incomplete_features)]
#![feature(control_flow_enum)]
#![feature(in_band_lifetimes)]
#![feature(unboxed_closures)]
#![feature(generators)]
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -605,3 +605,8 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::lazy_normalization_consts,
sym::specialization,
];

/// Some features are not allowed to be used together at the same time, if
/// the two are present, produce an error
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] =
&[(sym::const_generics, sym::min_const_generics)];
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/lib.rs
Expand Up @@ -131,7 +131,7 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU3
}

pub use accepted::ACCEPTED_FEATURES;
pub use active::{Features, ACTIVE_FEATURES, INCOMPLETE_FEATURES};
pub use active::{Features, ACTIVE_FEATURES, INCOMPATIBLE_FEATURES, INCOMPLETE_FEATURES};
pub use builtin_attrs::{
deprecated_attributes, find_gated_cfg, is_builtin_attr_name, AttributeGate, AttributeTemplate,
AttributeType, BuiltinAttribute, GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/src/lib.rs
Expand Up @@ -6,6 +6,7 @@
#![feature(box_syntax)]
#![feature(const_fn)]
#![feature(const_panic)]
#![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)]
#![feature(bool_to_option)]
#![feature(or_patterns)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/lints.rs
Expand Up @@ -117,7 +117,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
// A diverging InlineAsm is treated as non-recursing
TerminatorKind::InlineAsm { destination, .. } => {
if destination.is_some() {
ControlFlow::Continue
ControlFlow::CONTINUE
} else {
ControlFlow::Break(NonRecursive)
}
Expand All @@ -131,7 +131,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
| TerminatorKind::FalseEdge { .. }
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::Goto { .. }
| TerminatorKind::SwitchInt { .. } => ControlFlow::Continue,
| TerminatorKind::SwitchInt { .. } => ControlFlow::CONTINUE,
}
}

Expand All @@ -144,7 +144,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
}
}

ControlFlow::Continue
ControlFlow::CONTINUE
}

fn ignore_edge(&mut self, bb: BasicBlock, target: BasicBlock) -> bool {
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/vec.rs
Expand Up @@ -120,6 +120,9 @@ use crate::raw_vec::RawVec;
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
/// ```
///
/// For more information, see
/// [Capacity and Reallocation](#capacity-and-reallocation).
///
/// Use a `Vec<T>` as an efficient stack:
///
/// ```
Expand Down
13 changes: 13 additions & 0 deletions library/alloc/tests/borrow.rs
Expand Up @@ -45,3 +45,16 @@ fn test_from_cow_path() {
let path = Path::new("hello");
test_from_cow!(path: &Path);
}

#[test]
fn cow_const() {
// test that the methods of `Cow` are usable in a const context

const COW: Cow<'_, str> = Cow::Borrowed("moo");

const IS_BORROWED: bool = COW.is_borrowed();
assert!(IS_BORROWED);

const IS_OWNED: bool = COW.is_owned();
assert!(!IS_OWNED);
}
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
@@ -1,5 +1,6 @@
#![feature(allocator_api)]
#![feature(box_syntax)]
#![feature(cow_is_borrowed)]
#![feature(drain_filter)]
#![feature(exact_size_is_empty)]
#![feature(new_uninit)]
Expand Down
79 changes: 79 additions & 0 deletions library/alloc/tests/vec.rs
Expand Up @@ -74,6 +74,42 @@ fn test_zst_capacity() {
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
}

#[test]
fn test_indexing() {
let v: Vec<isize> = vec![10, 20];
assert_eq!(v[0], 10);
assert_eq!(v[1], 20);
let mut x: usize = 0;
assert_eq!(v[x], 10);
assert_eq!(v[x + 1], 20);
x = x + 1;
assert_eq!(v[x], 20);
assert_eq!(v[x - 1], 10);
}

#[test]
fn test_debug_fmt() {
let vec1: Vec<isize> = vec![];
assert_eq!("[]", format!("{:?}", vec1));

let vec2 = vec![0, 1];
assert_eq!("[0, 1]", format!("{:?}", vec2));

let slice: &[isize] = &[4, 5];
assert_eq!("[4, 5]", format!("{:?}", slice));
}

#[test]
fn test_push() {
let mut v = vec![];
v.push(1);
assert_eq!(v, [1]);
v.push(2);
assert_eq!(v, [1, 2]);
v.push(3);
assert_eq!(v, [1, 2, 3]);
}

#[test]
fn test_extend() {
let mut v = Vec::new();
Expand Down Expand Up @@ -119,6 +155,18 @@ fn test_extend() {
assert_eq!(count_x, 1);
}

#[test]
fn test_extend_from_slice() {
let a: Vec<isize> = vec![1, 2, 3, 4, 5];
let b: Vec<isize> = vec![6, 7, 8, 9, 0];

let mut v: Vec<isize> = a;

v.extend_from_slice(&b);

assert_eq!(v, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
}

#[test]
fn test_extend_ref() {
let mut v = vec![1, 2];
Expand All @@ -134,6 +182,14 @@ fn test_extend_ref() {
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7]);
}

#[test]
fn test_slice_from_ref() {
let values = vec![1, 2, 3, 4, 5];
let slice = &values[1..3];

assert_eq!(slice, [2, 3]);
}

#[test]
fn test_slice_from_mut() {
let mut values = vec![1, 2, 3, 4, 5];
Expand Down Expand Up @@ -345,6 +401,29 @@ fn test_zip_unzip() {
assert_eq!((3, 6), (left[2], right[2]));
}

#[test]
fn test_cmp() {
let x: &[isize] = &[1, 2, 3, 4, 5];
let cmp: &[isize] = &[1, 2, 3, 4, 5];
assert_eq!(&x[..], cmp);
let cmp: &[isize] = &[3, 4, 5];
assert_eq!(&x[2..], cmp);
let cmp: &[isize] = &[1, 2, 3];
assert_eq!(&x[..3], cmp);
let cmp: &[isize] = &[2, 3, 4];
assert_eq!(&x[1..4], cmp);

let x: Vec<isize> = vec![1, 2, 3, 4, 5];
let cmp: &[isize] = &[1, 2, 3, 4, 5];
assert_eq!(&x[..], cmp);
let cmp: &[isize] = &[3, 4, 5];
assert_eq!(&x[2..], cmp);
let cmp: &[isize] = &[1, 2, 3];
assert_eq!(&x[..3], cmp);
let cmp: &[isize] = &[2, 3, 4];
assert_eq!(&x[1..4], cmp);
}

#[test]
fn test_vec_truncate_drop() {
static mut DROPS: u32 = 0;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Expand Up @@ -831,7 +831,7 @@ extern "rust-intrinsic" {
/// Gets a reference to a static `Location` indicating where it was called.
///
/// Consider using [`crate::panic::Location::caller`] instead.
#[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
pub fn caller_location() -> &'static crate::panic::Location<'static>;

/// Moves a value out of scope without running drop glue.
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/iter/adapters/mod.rs
Expand Up @@ -1273,7 +1273,7 @@ where
) -> impl FnMut((), T) -> ControlFlow<(), B> + '_ {
move |(), x| match f(x) {
Some(x) => ControlFlow::Break(x),
None => ControlFlow::Continue(()),
None => ControlFlow::CONTINUE,
}
}

Expand Down Expand Up @@ -1772,7 +1772,7 @@ impl<I: Iterator> Peekable<I> {
self.peeked.get_or_insert_with(|| iter.next()).as_ref()
}

/// Consume the next value of this iterator if a condition is true.
/// Consume and return the next value of this iterator if a condition is true.
///
/// If `func` returns `true` for the next value of this iterator, consume and return it.
/// Otherwise, return `None`.
Expand Down Expand Up @@ -1812,7 +1812,7 @@ impl<I: Iterator> Peekable<I> {
}
}

/// Consume the next item if it is equal to `expected`.
/// Consume and return the next item if it is equal to `expected`.
///
/// # Example
/// Consume a number if it's equal to 0.
Expand All @@ -1827,10 +1827,10 @@ impl<I: Iterator> Peekable<I> {
/// assert_eq!(iter.next(), Some(1));
/// ```
#[unstable(feature = "peekable_next_if", issue = "72480")]
pub fn next_if_eq<R>(&mut self, expected: &R) -> Option<I::Item>
pub fn next_if_eq<T>(&mut self, expected: &T) -> Option<I::Item>
where
R: ?Sized,
I::Item: PartialEq<R>,
T: ?Sized,
I::Item: PartialEq<T>,
{
self.next_if(|next| next == expected)
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/traits/double_ended.rs
Expand Up @@ -310,7 +310,7 @@ pub trait DoubleEndedIterator: Iterator {
mut predicate: impl FnMut(&T) -> bool,
) -> impl FnMut((), T) -> ControlFlow<(), T> {
move |(), x| {
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) }
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
}
}

Expand Down