Skip to content

Rollup of 18 pull requests #76422

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

Merged
merged 38 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
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
bcfd15b
Remove unused duplicated `trivial_dropck_outlives`
jonas-schievink Sep 4, 2020
85b11d5
Improve docs for `std::env::args()`
camelid Sep 4, 2020
5456414
Fix nlink example typo
gillespiecd 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
4806e0a
Minor grammar fix in doc comment for soft-deprecated methods
Wilfred Sep 5, 2020
61ac138
Disable atomics on avr target.
m-ou-se Sep 5, 2020
e488c4f
Rollup merge of #76273 - CraftSpider:master, r=matklad
Dylan-DPC Sep 6, 2020
6545985
Rollup merge of #76274 - scottmcm:fix-76271, r=petrochenkov
Dylan-DPC Sep 6, 2020
7ad2b3a
Rollup merge of #76287 - lzutao:rm-allowed, r=jyn514
Dylan-DPC Sep 6, 2020
3d834bc
Rollup merge of #76293 - Amjad50:incompatible_features_error, r=lcnr
Dylan-DPC Sep 6, 2020
2c62189
Rollup merge of #76299 - CDirkx:ip-tests, r=matklad
Dylan-DPC Sep 6, 2020
ee840db
Rollup merge of #76302 - jyn514:peekable-2, r=Dylan-DPC
Dylan-DPC Sep 6, 2020
5b8f76d
Rollup merge of #76303 - jyn514:vec-assert-doc, r=Dylan-DPC
Dylan-DPC Sep 6, 2020
52d9162
Rollup merge of #76305 - CDirkx:const-tests, r=matklad
Dylan-DPC Sep 6, 2020
8ff13f4
Rollup merge of #76309 - lzutao:indent-note, r=jyn514
Dylan-DPC Sep 6, 2020
e735247
Rollup merge of #76312 - numbermaniac:patch-1, r=shepmaster
Dylan-DPC Sep 6, 2020
acd33e1
Rollup merge of #76318 - scottmcm:one-control-flow, r=ecstatic-morse
Dylan-DPC Sep 6, 2020
1b24f14
Rollup merge of #76324 - ayushmishra2005:move_vec_tests_in_library, r…
Dylan-DPC Sep 6, 2020
9f69a23
Rollup merge of #76338 - euclio:intra-link-iterator, r=jyn514
Dylan-DPC Sep 6, 2020
1db9290
Rollup merge of #76340 - jonas-schievink:rm-dupe, r=Mark-Simulacrum
Dylan-DPC Sep 6, 2020
346d54d
Rollup merge of #76344 - camelid:patch-6, r=KodrAus
Dylan-DPC Sep 6, 2020
d444913
Rollup merge of #76346 - gillespiecd:nlinks-docs, r=Dylan-DPC
Dylan-DPC Sep 6, 2020
5d89259
Rollup merge of #76358 - Wilfred:patch-3, r=lcnr
Dylan-DPC Sep 6, 2020
23f8dd1
Rollup merge of #76364 - fusion-engineering-forks:avr-no-atomic, r=jo…
Dylan-DPC Sep 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
68 changes: 0 additions & 68 deletions compiler/rustc_middle/src/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,74 +190,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
}
}

/// This returns true if the type `ty` is "trivial" for
/// dropck-outlives -- that is, if it doesn't require any types to
/// outlive. This is similar but not *quite* the same as the
/// `needs_drop` test in the compiler already -- that is, for every
/// type T for which this function return true, needs-drop would
/// return `false`. But the reverse does not hold: in particular,
/// `needs_drop` returns false for `PhantomData`, but it is not
/// trivial for dropck-outlives.
///
/// Note also that `needs_drop` requires a "global" type (i.e., one
/// with erased regions), but this function does not.
pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
match ty.kind() {
// None of these types have a destructor and hence they do not
// require anything in particular to outlive the dtor's
// execution.
ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Bool
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Never
| ty::FnDef(..)
| ty::FnPtr(_)
| ty::Char
| ty::GeneratorWitness(..)
| ty::RawPtr(_)
| ty::Ref(..)
| ty::Str
| ty::Foreign(..)
| ty::Error(_) => true,

// [T; N] and [T] have same properties as T.
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),

// (T1..Tn) and closures have same properties as T1..Tn --
// check if *any* of those are trivial.
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
ty::Closure(_, ref substs) => {
substs.as_closure().upvar_tys().all(|t| trivial_dropck_outlives(tcx, t))
}

ty::Adt(def, _) => {
if Some(def.did) == tcx.lang_items().manually_drop() {
// `ManuallyDrop` never has a dtor.
true
} else {
// Other types might. Moreover, PhantomData doesn't
// have a dtor, but it is considered to own its
// content, so it is non-trivial. Unions can have `impl Drop`,
// and hence are non-trivial as well.
false
}
}

// The following *might* require a destructor: needs deeper inspection.
ty::Dynamic(..)
| ty::Projection(..)
| ty::Param(_)
| ty::Opaque(..)
| ty::Placeholder(..)
| ty::Infer(_)
| ty::Bound(..)
| ty::Generator(..) => false,
}
}

#[derive(Debug, HashStable)]
pub struct CandidateStep<'tcx> {
pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/avr_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub fn target(target_cpu: String) -> TargetResult {
late_link_args: vec![(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])]
.into_iter()
.collect(),
max_atomic_width: Some(0),
atomic_cas: false,
..TargetOptions::default()
},
})
Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/vec.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading