Skip to content

Commit ab61e34

Browse files
committed
Auto merge of #51214 - kennytm:rollup, r=kennytm
Rollup of 12 pull requests Successful merges: - #51050 (std::fs::DirEntry.metadata(): use fstatat instead of lstat when possible) - #51123 (Update build instructions) - #51127 (Add doc link from discriminant struct to function.) - #51146 (typeck: Do not pass the field check on field error) - #51147 (Stabilize SliceIndex trait.) - #51151 (Move slice::exact_chunks directly above exact_chunks_mut for more con…) - #51152 (Replace `if` with `if and only if` in the definition dox of `Sync`) - #51153 (Link panic and compile_error docs) - #51158 (Mention spec and indented blocks in doctest docs) - #51186 (Remove two redundant .nll.stderr files) - #51203 (Two minor `obligation_forest` tweaks.) - #51213 (fs: copy: Use File::set_permissions instead of fs::set_permissions) Failed merges:
2 parents fddb46e + b7b7b25 commit ab61e34

File tree

16 files changed

+226
-112
lines changed

16 files changed

+226
-112
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Read ["Installation"] from [The Book].
3838
3. Build and install:
3939

4040
```sh
41+
$ git submodule update --init --recursive --progress
4142
$ ./x.py build && sudo ./x.py install
4243
```
4344

src/doc/rustdoc/src/documentation-tests.md

+24
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,27 @@ environment that has no network access.
284284
compiles, then the test will fail. However please note that code failing
285285
with the current Rust release may work in a future release, as new features
286286
are added.
287+
288+
## Syntax reference
289+
290+
The *exact* syntax for code blocks, including the edge cases, can be found
291+
in the [Fenced Code Blocks](https://spec.commonmark.org/0.28/#fenced-code-blocks)
292+
section of the CommonMark specification.
293+
294+
Rustdoc also accepts *indented* code blocks as an alternative to fenced
295+
code blocks: instead of surrounding your code with three backticks, you
296+
can indent each line by four or more spaces.
297+
298+
``````markdown
299+
let foo = "foo";
300+
assert_eq!(foo, "foo");
301+
``````
302+
303+
These, too, are documented in the CommonMark specification, in the
304+
[Indented Code Blocks](https://spec.commonmark.org/0.28/#indented-code-blocks)
305+
section.
306+
307+
However, it's preferable to use fenced code blocks over indented code blocks.
308+
Not only are fenced code blocks considered more idiomatic for Rust code,
309+
but there is no way to use directives such as `ignore` or `should_panic` with
310+
indented code blocks.

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
#![feature(ptr_internals)]
105105
#![feature(ptr_offset_from)]
106106
#![feature(rustc_attrs)]
107-
#![feature(slice_get_slice)]
108107
#![feature(specialization)]
109108
#![feature(staged_api)]
110109
#![feature(str_internals)]

src/liballoc/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub use core::slice::{RSplit, RSplitMut};
121121
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
122122
#[stable(feature = "from_ref", since = "1.28.0")]
123123
pub use core::slice::{from_ref, from_mut};
124-
#[unstable(feature = "slice_get_slice", issue = "35729")]
124+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
125125
pub use core::slice::SliceIndex;
126126
#[unstable(feature = "exact_chunks", issue = "47115")]
127127
pub use core::slice::{ExactChunks, ExactChunksMut};

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub trait Copy : Clone {
294294
/// This trait is automatically implemented when the compiler determines
295295
/// it's appropriate.
296296
///
297-
/// The precise definition is: a type `T` is `Sync` if `&T` is
297+
/// The precise definition is: a type `T` is `Sync` if and only if `&T` is
298298
/// [`Send`][send]. In other words, if there is no possibility of
299299
/// [undefined behavior][ub] (including data races) when passing
300300
/// `&T` references between threads.

src/libcore/mem.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,9 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
835835

836836
/// Opaque type representing the discriminant of an enum.
837837
///
838-
/// See the `discriminant` function in this module for more information.
838+
/// See the [`discriminant`] function in this module for more information.
839+
///
840+
/// [`discriminant`]: fn.discriminant.html
839841
#[stable(feature = "discriminant_value", since = "1.21.0")]
840842
pub struct Discriminant<T>(u64, PhantomData<fn() -> T>);
841843

src/libcore/slice/mod.rs

+65-37
Original file line numberDiff line numberDiff line change
@@ -691,41 +691,6 @@ impl<T> [T] {
691691
Chunks { v: self, chunk_size: chunk_size }
692692
}
693693

694-
/// Returns an iterator over `chunk_size` elements of the slice at a
695-
/// time. The chunks are slices and do not overlap. If `chunk_size` does
696-
/// not divide the length of the slice, then the last up to `chunk_size-1`
697-
/// elements will be omitted.
698-
///
699-
/// Due to each chunk having exactly `chunk_size` elements, the compiler
700-
/// can often optimize the resulting code better than in the case of
701-
/// [`chunks`].
702-
///
703-
/// # Panics
704-
///
705-
/// Panics if `chunk_size` is 0.
706-
///
707-
/// # Examples
708-
///
709-
/// ```
710-
/// #![feature(exact_chunks)]
711-
///
712-
/// let slice = ['l', 'o', 'r', 'e', 'm'];
713-
/// let mut iter = slice.exact_chunks(2);
714-
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
715-
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
716-
/// assert!(iter.next().is_none());
717-
/// ```
718-
///
719-
/// [`chunks`]: #method.chunks
720-
#[unstable(feature = "exact_chunks", issue = "47115")]
721-
#[inline]
722-
pub fn exact_chunks(&self, chunk_size: usize) -> ExactChunks<T> {
723-
assert!(chunk_size != 0);
724-
let rem = self.len() % chunk_size;
725-
let len = self.len() - rem;
726-
ExactChunks { v: &self[..len], chunk_size: chunk_size}
727-
}
728-
729694
/// Returns an iterator over `chunk_size` elements of the slice at a time.
730695
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
731696
/// not divide the length of the slice, then the last chunk will not
@@ -761,6 +726,41 @@ impl<T> [T] {
761726
ChunksMut { v: self, chunk_size: chunk_size }
762727
}
763728

729+
/// Returns an iterator over `chunk_size` elements of the slice at a
730+
/// time. The chunks are slices and do not overlap. If `chunk_size` does
731+
/// not divide the length of the slice, then the last up to `chunk_size-1`
732+
/// elements will be omitted.
733+
///
734+
/// Due to each chunk having exactly `chunk_size` elements, the compiler
735+
/// can often optimize the resulting code better than in the case of
736+
/// [`chunks`].
737+
///
738+
/// # Panics
739+
///
740+
/// Panics if `chunk_size` is 0.
741+
///
742+
/// # Examples
743+
///
744+
/// ```
745+
/// #![feature(exact_chunks)]
746+
///
747+
/// let slice = ['l', 'o', 'r', 'e', 'm'];
748+
/// let mut iter = slice.exact_chunks(2);
749+
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
750+
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
751+
/// assert!(iter.next().is_none());
752+
/// ```
753+
///
754+
/// [`chunks`]: #method.chunks
755+
#[unstable(feature = "exact_chunks", issue = "47115")]
756+
#[inline]
757+
pub fn exact_chunks(&self, chunk_size: usize) -> ExactChunks<T> {
758+
assert!(chunk_size != 0);
759+
let rem = self.len() % chunk_size;
760+
let len = self.len() - rem;
761+
ExactChunks { v: &self[..len], chunk_size: chunk_size}
762+
}
763+
764764
/// Returns an iterator over `chunk_size` elements of the slice at a time.
765765
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
766766
/// not divide the length of the slice, then the last up to `chunk_size-1`
@@ -1977,35 +1977,63 @@ fn slice_index_overflow_fail() -> ! {
19771977
panic!("attempted to index slice up to maximum usize");
19781978
}
19791979

1980+
mod private_slice_index {
1981+
use super::ops;
1982+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1983+
pub trait Sealed {}
1984+
1985+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1986+
impl Sealed for usize {}
1987+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1988+
impl Sealed for ops::Range<usize> {}
1989+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1990+
impl Sealed for ops::RangeTo<usize> {}
1991+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1992+
impl Sealed for ops::RangeFrom<usize> {}
1993+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1994+
impl Sealed for ops::RangeFull {}
1995+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1996+
impl Sealed for ops::RangeInclusive<usize> {}
1997+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
1998+
impl Sealed for ops::RangeToInclusive<usize> {}
1999+
}
2000+
19802001
/// A helper trait used for indexing operations.
1981-
#[unstable(feature = "slice_get_slice", issue = "35729")]
2002+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
19822003
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
1983-
pub trait SliceIndex<T: ?Sized> {
2004+
pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
19842005
/// The output type returned by methods.
2006+
#[stable(feature = "slice_get_slice", since = "1.28.0")]
19852007
type Output: ?Sized;
19862008

19872009
/// Returns a shared reference to the output at this location, if in
19882010
/// bounds.
2011+
#[unstable(feature = "slice_index_methods", issue = "0")]
19892012
fn get(self, slice: &T) -> Option<&Self::Output>;
19902013

19912014
/// Returns a mutable reference to the output at this location, if in
19922015
/// bounds.
2016+
#[unstable(feature = "slice_index_methods", issue = "0")]
19932017
fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>;
19942018

19952019
/// Returns a shared reference to the output at this location, without
19962020
/// performing any bounds checking.
2021+
#[unstable(feature = "slice_index_methods", issue = "0")]
19972022
unsafe fn get_unchecked(self, slice: &T) -> &Self::Output;
19982023

19992024
/// Returns a mutable reference to the output at this location, without
20002025
/// performing any bounds checking.
2026+
#[unstable(feature = "slice_index_methods", issue = "0")]
20012027
unsafe fn get_unchecked_mut(self, slice: &mut T) -> &mut Self::Output;
20022028

20032029
/// Returns a shared reference to the output at this location, panicking
20042030
/// if out of bounds.
2031+
#[unstable(feature = "slice_index_methods", issue = "0")]
20052032
fn index(self, slice: &T) -> &Self::Output;
20062033

20072034
/// Returns a mutable reference to the output at this location, panicking
20082035
/// if out of bounds.
2036+
#[unstable(feature = "slice_index_methods", issue = "0")]
20092037
fn index_mut(self, slice: &mut T) -> &mut Self::Output;
20102038
}
20112039

src/librustc_data_structures/obligation_forest/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ pub struct ObligationForest<O: ForestObligation> {
7575
done_cache: FxHashSet<O::Predicate>,
7676
/// An cache of the nodes in `nodes`, indexed by predicate.
7777
waiting_cache: FxHashMap<O::Predicate, NodeIndex>,
78-
/// A list of the obligations added in snapshots, to allow
79-
/// for their removal.
80-
cache_list: Vec<O::Predicate>,
8178
scratch: Option<Vec<usize>>,
8279
}
8380

@@ -158,7 +155,6 @@ impl<O: ForestObligation> ObligationForest<O> {
158155
nodes: vec![],
159156
done_cache: FxHashSet(),
160157
waiting_cache: FxHashMap(),
161-
cache_list: vec![],
162158
scratch: Some(vec![]),
163159
}
164160
}
@@ -207,7 +203,6 @@ impl<O: ForestObligation> ObligationForest<O> {
207203
debug!("register_obligation_at({:?}, {:?}) - ok, new index is {}",
208204
obligation, parent, self.nodes.len());
209205
v.insert(NodeIndex::new(self.nodes.len()));
210-
self.cache_list.push(obligation.as_predicate().clone());
211206
self.nodes.push(Node::new(parent, obligation));
212207
Ok(())
213208
}

src/librustc_data_structures/obligation_forest/node_index.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ pub struct NodeIndex {
1717
}
1818

1919
impl NodeIndex {
20+
#[inline]
2021
pub fn new(value: usize) -> NodeIndex {
2122
assert!(value < (u32::MAX as usize));
2223
NodeIndex { index: NonZeroU32::new((value as u32) + 1).unwrap() }
2324
}
2425

26+
#[inline]
2527
pub fn get(self) -> usize {
2628
(self.index.get() - 1) as usize
2729
}

src/librustc_typeck/check/_match.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,11 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
720720
self.demand_eqtype(pat.span, expected, pat_ty);
721721

722722
// Type check subpatterns.
723-
self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm);
724-
pat_ty
723+
if self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm) {
724+
pat_ty
725+
} else {
726+
self.tcx.types.err
727+
}
725728
}
726729

727730
fn check_pat_path(&self,
@@ -846,7 +849,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
846849
variant: &'tcx ty::VariantDef,
847850
fields: &'gcx [Spanned<hir::FieldPat>],
848851
etc: bool,
849-
def_bm: ty::BindingMode) {
852+
def_bm: ty::BindingMode) -> bool {
850853
let tcx = self.tcx;
851854

852855
let (substs, adt) = match adt_ty.sty {
@@ -864,6 +867,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
864867

865868
// Keep track of which fields have already appeared in the pattern.
866869
let mut used_fields = FxHashMap();
870+
let mut no_field_errors = true;
867871

868872
let mut inexistent_fields = vec![];
869873
// Typecheck each field.
@@ -879,6 +883,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
879883
format!("multiple uses of `{}` in pattern", field.ident))
880884
.span_label(*occupied.get(), format!("first use of `{}`", field.ident))
881885
.emit();
886+
no_field_errors = false;
882887
tcx.types.err
883888
}
884889
Vacant(vacant) => {
@@ -891,6 +896,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
891896
})
892897
.unwrap_or_else(|| {
893898
inexistent_fields.push((span, field.ident));
899+
no_field_errors = false;
894900
tcx.types.err
895901
})
896902
}
@@ -989,5 +995,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
989995
diag.emit();
990996
}
991997
}
998+
no_field_errors
992999
}
9931000
}

src/libstd/macros.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
/// The multi-argument form of this macro panics with a string and has the
3939
/// [`format!`] syntax for building a string.
4040
///
41+
/// See also the macro [`compile_error!`], for raising errors during compilation.
42+
///
4143
/// [runwrap]: ../std/result/enum.Result.html#method.unwrap
4244
/// [`Option`]: ../std/option/enum.Option.html#method.unwrap
4345
/// [`Result`]: ../std/result/enum.Result.html
4446
/// [`format!`]: ../std/macro.format.html
47+
/// [`compile_error!`]: ../std/macro.compile_error.html
4548
/// [book]: ../book/second-edition/ch09-01-unrecoverable-errors-with-panic.html
4649
///
4750
/// # Current implementation
@@ -286,13 +289,16 @@ pub mod builtin {
286289
/// Unconditionally causes compilation to fail with the given error message when encountered.
287290
///
288291
/// This macro should be used when a crate uses a conditional compilation strategy to provide
289-
/// better error messages for erroneous conditions.
292+
/// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
293+
/// which emits an error at *runtime*, rather than during compilation.
290294
///
291295
/// # Examples
292296
///
293297
/// Two such examples are macros and `#[cfg]` environments.
294298
///
295-
/// Emit better compiler error if a macro is passed invalid values.
299+
/// Emit better compiler error if a macro is passed invalid values. Without the final branch,
300+
/// the compiler would still emit an error, but the error's message would not mention the two
301+
/// valid values.
296302
///
297303
/// ```compile_fail
298304
/// macro_rules! give_me_foo_or_bar {
@@ -313,6 +319,8 @@ pub mod builtin {
313319
/// #[cfg(not(any(feature = "foo", feature = "bar")))]
314320
/// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
315321
/// ```
322+
///
323+
/// [`panic!`]: ../std/macro.panic.html
316324
#[stable(feature = "compile_error_macro", since = "1.20.0")]
317325
#[macro_export]
318326
macro_rules! compile_error {

0 commit comments

Comments
 (0)