Skip to content

Commit 8383257

Browse files
committed
Auto merge of #76422 - Dylan-DPC:rollup-0579ucb, r=Dylan-DPC
Rollup of 18 pull requests Successful merges: - #76273 (Move some Vec UI tests into alloc unit tests) - #76274 (Allow try blocks as the argument to return expressions) - #76287 (Remove an unnecessary allowed lint) - #76293 (Implementation of incompatible features error) - #76299 (Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`) - #76302 (Address review comments on `Peekable::next_if`) - #76303 (Link to `#capacity-and-reallocation` when using with_capacity) - #76305 (Move various ui const tests to `library`) - #76309 (Indent a note to make folding work nicer) - #76312 (time.rs: Make spelling of "Darwin" consistent) - #76318 (Use ops::ControlFlow in rustc_data_structures::graph::iterate) - #76324 (Move Vec slice UI tests in library) - #76338 (add some intra-doc links to `Iterator`) - #76340 (Remove unused duplicated `trivial_dropck_outlives`) - #76344 (Improve docs for `std::env::args()`) - #76346 (Docs: nlink example typo) - #76358 (Minor grammar fix in doc comment for soft-deprecated methods) - #76364 (Disable atomics on avr target.) Failed merges: - #76304 (Make delegation methods of `std::net::IpAddr` unstably const) r? @ghost
2 parents bf4d6cc + 23f8dd1 commit 8383257

File tree

46 files changed

+408
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+408
-417
lines changed

compiler/rustc_ast/src/token.rs

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
173173
kw::Move,
174174
kw::Return,
175175
kw::True,
176+
kw::Try,
176177
kw::Unsafe,
177178
kw::While,
178179
kw::Yield,

compiler/rustc_ast_passes/src/feature_gate.rs

+34
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
608608

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

613614
let spans = sess.parse_sess.gated_spans.spans.borrow();
@@ -677,3 +678,36 @@ fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
677678
}
678679
}
679680
}
681+
682+
fn check_incompatible_features(sess: &Session) {
683+
let features = sess.features_untracked();
684+
685+
let declared_features = features
686+
.declared_lang_features
687+
.iter()
688+
.copied()
689+
.map(|(name, span, _)| (name, span))
690+
.chain(features.declared_lib_features.iter().copied());
691+
692+
for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES
693+
.iter()
694+
.filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
695+
{
696+
if let Some((f1_name, f1_span)) = declared_features.clone().find(|(name, _)| name == f1) {
697+
if let Some((f2_name, f2_span)) = declared_features.clone().find(|(name, _)| name == f2)
698+
{
699+
let spans = vec![f1_span, f2_span];
700+
sess.struct_span_err(
701+
spans.clone(),
702+
&format!(
703+
"features `{}` and `{}` are incompatible, using them at the same time \
704+
is not allowed",
705+
f1_name, f2_name
706+
),
707+
)
708+
.help("remove one of these features")
709+
.emit();
710+
}
711+
}
712+
}
713+
}

compiler/rustc_data_structures/src/graph/iterate/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ where
8787
}
8888

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

9693
/// The status of a node in the depth-first search.
9794
///
@@ -260,12 +257,12 @@ where
260257
_node: G::Node,
261258
_prior_status: Option<NodeStatus>,
262259
) -> ControlFlow<Self::BreakVal> {
263-
ControlFlow::Continue
260+
ControlFlow::CONTINUE
264261
}
265262

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

271268
/// Behave as if no edges exist from `source` to `target`.
@@ -289,8 +286,8 @@ where
289286
prior_status: Option<NodeStatus>,
290287
) -> ControlFlow<Self::BreakVal> {
291288
match prior_status {
292-
Some(NodeStatus::Visited) => ControlFlow::Break(()),
293-
_ => ControlFlow::Continue,
289+
Some(NodeStatus::Visited) => ControlFlow::BREAK,
290+
_ => ControlFlow::CONTINUE,
294291
}
295292
}
296293
}

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
1010
#![allow(incomplete_features)]
11+
#![feature(control_flow_enum)]
1112
#![feature(in_band_lifetimes)]
1213
#![feature(unboxed_closures)]
1314
#![feature(generators)]

compiler/rustc_feature/src/active.rs

+5
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,8 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
605605
sym::lazy_normalization_consts,
606606
sym::specialization,
607607
];
608+
609+
/// Some features are not allowed to be used together at the same time, if
610+
/// the two are present, produce an error
611+
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] =
612+
&[(sym::const_generics, sym::min_const_generics)];

compiler/rustc_feature/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU3
131131
}
132132

133133
pub use accepted::ACCEPTED_FEATURES;
134-
pub use active::{Features, ACTIVE_FEATURES, INCOMPLETE_FEATURES};
134+
pub use active::{Features, ACTIVE_FEATURES, INCOMPATIBLE_FEATURES, INCOMPLETE_FEATURES};
135135
pub use builtin_attrs::{
136136
deprecated_attributes, find_gated_cfg, is_builtin_attr_name, AttributeGate, AttributeTemplate,
137137
AttributeType, BuiltinAttribute, GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,

compiler/rustc_middle/src/traits/query.rs

-68
Original file line numberDiff line numberDiff line change
@@ -190,74 +190,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
190190
}
191191
}
192192

193-
/// This returns true if the type `ty` is "trivial" for
194-
/// dropck-outlives -- that is, if it doesn't require any types to
195-
/// outlive. This is similar but not *quite* the same as the
196-
/// `needs_drop` test in the compiler already -- that is, for every
197-
/// type T for which this function return true, needs-drop would
198-
/// return `false`. But the reverse does not hold: in particular,
199-
/// `needs_drop` returns false for `PhantomData`, but it is not
200-
/// trivial for dropck-outlives.
201-
///
202-
/// Note also that `needs_drop` requires a "global" type (i.e., one
203-
/// with erased regions), but this function does not.
204-
pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
205-
match ty.kind() {
206-
// None of these types have a destructor and hence they do not
207-
// require anything in particular to outlive the dtor's
208-
// execution.
209-
ty::Infer(ty::FreshIntTy(_))
210-
| ty::Infer(ty::FreshFloatTy(_))
211-
| ty::Bool
212-
| ty::Int(_)
213-
| ty::Uint(_)
214-
| ty::Float(_)
215-
| ty::Never
216-
| ty::FnDef(..)
217-
| ty::FnPtr(_)
218-
| ty::Char
219-
| ty::GeneratorWitness(..)
220-
| ty::RawPtr(_)
221-
| ty::Ref(..)
222-
| ty::Str
223-
| ty::Foreign(..)
224-
| ty::Error(_) => true,
225-
226-
// [T; N] and [T] have same properties as T.
227-
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),
228-
229-
// (T1..Tn) and closures have same properties as T1..Tn --
230-
// check if *any* of those are trivial.
231-
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
232-
ty::Closure(_, ref substs) => {
233-
substs.as_closure().upvar_tys().all(|t| trivial_dropck_outlives(tcx, t))
234-
}
235-
236-
ty::Adt(def, _) => {
237-
if Some(def.did) == tcx.lang_items().manually_drop() {
238-
// `ManuallyDrop` never has a dtor.
239-
true
240-
} else {
241-
// Other types might. Moreover, PhantomData doesn't
242-
// have a dtor, but it is considered to own its
243-
// content, so it is non-trivial. Unions can have `impl Drop`,
244-
// and hence are non-trivial as well.
245-
false
246-
}
247-
}
248-
249-
// The following *might* require a destructor: needs deeper inspection.
250-
ty::Dynamic(..)
251-
| ty::Projection(..)
252-
| ty::Param(_)
253-
| ty::Opaque(..)
254-
| ty::Placeholder(..)
255-
| ty::Infer(_)
256-
| ty::Bound(..)
257-
| ty::Generator(..) => false,
258-
}
259-
}
260-
261193
#[derive(Debug, HashStable)]
262194
pub struct CandidateStep<'tcx> {
263195
pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,

compiler/rustc_mir_build/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(box_syntax)]
77
#![feature(const_fn)]
88
#![feature(const_panic)]
9+
#![feature(control_flow_enum)]
910
#![feature(crate_visibility_modifier)]
1011
#![feature(bool_to_option)]
1112
#![feature(or_patterns)]

compiler/rustc_mir_build/src/lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
117117
// A diverging InlineAsm is treated as non-recursing
118118
TerminatorKind::InlineAsm { destination, .. } => {
119119
if destination.is_some() {
120-
ControlFlow::Continue
120+
ControlFlow::CONTINUE
121121
} else {
122122
ControlFlow::Break(NonRecursive)
123123
}
@@ -131,7 +131,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
131131
| TerminatorKind::FalseEdge { .. }
132132
| TerminatorKind::FalseUnwind { .. }
133133
| TerminatorKind::Goto { .. }
134-
| TerminatorKind::SwitchInt { .. } => ControlFlow::Continue,
134+
| TerminatorKind::SwitchInt { .. } => ControlFlow::CONTINUE,
135135
}
136136
}
137137

@@ -144,7 +144,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
144144
}
145145
}
146146

147-
ControlFlow::Continue
147+
ControlFlow::CONTINUE
148148
}
149149

150150
fn ignore_edge(&mut self, bb: BasicBlock, target: BasicBlock) -> bool {

compiler/rustc_target/src/spec/avr_gnu_base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub fn target(target_cpu: String) -> TargetResult {
4545
late_link_args: vec![(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])]
4646
.into_iter()
4747
.collect(),
48+
max_atomic_width: Some(0),
49+
atomic_cas: false,
4850
..TargetOptions::default()
4951
},
5052
})

library/alloc/src/vec.rs

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ use crate::raw_vec::RawVec;
120120
/// assert_eq!(vec, [0, 0, 0, 0, 0]);
121121
/// ```
122122
///
123+
/// For more information, see
124+
/// [Capacity and Reallocation](#capacity-and-reallocation).
125+
///
123126
/// Use a `Vec<T>` as an efficient stack:
124127
///
125128
/// ```

library/alloc/tests/borrow.rs

+13
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ fn test_from_cow_path() {
4545
let path = Path::new("hello");
4646
test_from_cow!(path: &Path);
4747
}
48+
49+
#[test]
50+
fn cow_const() {
51+
// test that the methods of `Cow` are usable in a const context
52+
53+
const COW: Cow<'_, str> = Cow::Borrowed("moo");
54+
55+
const IS_BORROWED: bool = COW.is_borrowed();
56+
assert!(IS_BORROWED);
57+
58+
const IS_OWNED: bool = COW.is_owned();
59+
assert!(!IS_OWNED);
60+
}

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(allocator_api)]
22
#![feature(box_syntax)]
3+
#![feature(cow_is_borrowed)]
34
#![feature(drain_filter)]
45
#![feature(exact_size_is_empty)]
56
#![feature(new_uninit)]

library/alloc/tests/vec.rs

+79
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,42 @@ fn test_zst_capacity() {
7474
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
7575
}
7676

77+
#[test]
78+
fn test_indexing() {
79+
let v: Vec<isize> = vec![10, 20];
80+
assert_eq!(v[0], 10);
81+
assert_eq!(v[1], 20);
82+
let mut x: usize = 0;
83+
assert_eq!(v[x], 10);
84+
assert_eq!(v[x + 1], 20);
85+
x = x + 1;
86+
assert_eq!(v[x], 20);
87+
assert_eq!(v[x - 1], 10);
88+
}
89+
90+
#[test]
91+
fn test_debug_fmt() {
92+
let vec1: Vec<isize> = vec![];
93+
assert_eq!("[]", format!("{:?}", vec1));
94+
95+
let vec2 = vec![0, 1];
96+
assert_eq!("[0, 1]", format!("{:?}", vec2));
97+
98+
let slice: &[isize] = &[4, 5];
99+
assert_eq!("[4, 5]", format!("{:?}", slice));
100+
}
101+
102+
#[test]
103+
fn test_push() {
104+
let mut v = vec![];
105+
v.push(1);
106+
assert_eq!(v, [1]);
107+
v.push(2);
108+
assert_eq!(v, [1, 2]);
109+
v.push(3);
110+
assert_eq!(v, [1, 2, 3]);
111+
}
112+
77113
#[test]
78114
fn test_extend() {
79115
let mut v = Vec::new();
@@ -119,6 +155,18 @@ fn test_extend() {
119155
assert_eq!(count_x, 1);
120156
}
121157

158+
#[test]
159+
fn test_extend_from_slice() {
160+
let a: Vec<isize> = vec![1, 2, 3, 4, 5];
161+
let b: Vec<isize> = vec![6, 7, 8, 9, 0];
162+
163+
let mut v: Vec<isize> = a;
164+
165+
v.extend_from_slice(&b);
166+
167+
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
168+
}
169+
122170
#[test]
123171
fn test_extend_ref() {
124172
let mut v = vec![1, 2];
@@ -134,6 +182,14 @@ fn test_extend_ref() {
134182
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7]);
135183
}
136184

185+
#[test]
186+
fn test_slice_from_ref() {
187+
let values = vec![1, 2, 3, 4, 5];
188+
let slice = &values[1..3];
189+
190+
assert_eq!(slice, [2, 3]);
191+
}
192+
137193
#[test]
138194
fn test_slice_from_mut() {
139195
let mut values = vec![1, 2, 3, 4, 5];
@@ -345,6 +401,29 @@ fn test_zip_unzip() {
345401
assert_eq!((3, 6), (left[2], right[2]));
346402
}
347403

404+
#[test]
405+
fn test_cmp() {
406+
let x: &[isize] = &[1, 2, 3, 4, 5];
407+
let cmp: &[isize] = &[1, 2, 3, 4, 5];
408+
assert_eq!(&x[..], cmp);
409+
let cmp: &[isize] = &[3, 4, 5];
410+
assert_eq!(&x[2..], cmp);
411+
let cmp: &[isize] = &[1, 2, 3];
412+
assert_eq!(&x[..3], cmp);
413+
let cmp: &[isize] = &[2, 3, 4];
414+
assert_eq!(&x[1..4], cmp);
415+
416+
let x: Vec<isize> = vec![1, 2, 3, 4, 5];
417+
let cmp: &[isize] = &[1, 2, 3, 4, 5];
418+
assert_eq!(&x[..], cmp);
419+
let cmp: &[isize] = &[3, 4, 5];
420+
assert_eq!(&x[2..], cmp);
421+
let cmp: &[isize] = &[1, 2, 3];
422+
assert_eq!(&x[..3], cmp);
423+
let cmp: &[isize] = &[2, 3, 4];
424+
assert_eq!(&x[1..4], cmp);
425+
}
426+
348427
#[test]
349428
fn test_vec_truncate_drop() {
350429
static mut DROPS: u32 = 0;

0 commit comments

Comments
 (0)