Skip to content

Commit 4eeaaa7

Browse files
committed
Auto merge of #63124 - Centril:rollup-onohtqt, r=Centril
Rollup of 12 pull requests Successful merges: - #61965 (Remove mentions of removed `offset_to` method from `align_offset` docs) - #62928 (Syntax: Recover on `for ( $pat in $expr ) $block`) - #63000 (Impl Debug for Chars) - #63083 (Make generic parameters always use modern hygiene) - #63087 (Add very simple edition check to tidy.) - #63093 (Properly check the defining scope of existential types) - #63096 (Add tests for some `existential_type` ICEs) - #63099 (vxworks: Remove Linux-specific comments.) - #63106 (ci: Skip installing SWIG/xz on OSX ) - #63108 (Add links to None in Option doc) - #63109 (std: Fix a failing `fs` test on Windows) - #63111 (Add syntactic and semantic tests for rest patterns, i.e. `..`) Failed merges: r? @ghost
2 parents 04b88a9 + 91c10f8 commit 4eeaaa7

Some content is hidden

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

44 files changed

+1042
-247
lines changed

.azure-pipelines/steps/run.yml

-11
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ steps:
6262
- template: install-sccache.yml
6363
- template: install-clang.yml
6464

65-
# Install some dependencies needed to build LLDB/Clang, currently only needed
66-
# during the `dist` target
67-
- bash: |
68-
set -e
69-
brew update
70-
brew install xz
71-
brew install swig@3
72-
brew link --force swig@3
73-
displayName: Install build dependencies (OSX)
74-
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'), eq(variables['SCRIPT'],'./x.py dist'))
75-
7665
# Switch to XCode 9.3 on OSX since it seems to be the last version that supports
7766
# i686-apple-darwin. We'll eventually want to upgrade this and it will probably
7867
# force us to drop i686-apple-darwin, but let's keep the wheels turning for now.

src/liballoc/tests/str.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,16 @@ fn test_iterator_last() {
11081108
assert_eq!(it.last(), Some('m'));
11091109
}
11101110

1111+
#[test]
1112+
fn test_chars_debug() {
1113+
let s = "ศไทย中华Việt Nam";
1114+
let c = s.chars();
1115+
assert_eq!(
1116+
format!("{:?}", c),
1117+
r#"Chars(['ศ', 'ไ', 'ท', 'ย', '中', '华', 'V', 'i', 'ệ', 't', ' ', 'N', 'a', 'm'])"#
1118+
);
1119+
}
1120+
11111121
#[test]
11121122
fn test_bytesator() {
11131123
let s = "ศไทย中华Việt Nam";

src/libcore/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! * Initial values
99
//! * Return values for functions that are not defined
1010
//! over their entire input range (partial functions)
11-
//! * Return value for otherwise reporting simple errors, where `None` is
11+
//! * Return value for otherwise reporting simple errors, where [`None`] is
1212
//! returned on error
1313
//! * Optional struct fields
1414
//! * Struct fields that can be loaned or "taken"
@@ -752,7 +752,7 @@ impl<T> Option<T> {
752752
}
753753
}
754754

755-
/// Returns [`Some`] if exactly one of `self`, `optb` is [`Some`], otherwise returns `None`.
755+
/// Returns [`Some`] if exactly one of `self`, `optb` is [`Some`], otherwise returns [`None`].
756756
///
757757
/// [`Some`]: #variant.Some
758758
/// [`None`]: #variant.None

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ impl<T: ?Sized> *const T {
16091609
/// `usize::max_value()`.
16101610
///
16111611
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be
1612-
/// used with the `offset` or `offset_to` methods.
1612+
/// used with the `add` method.
16131613
///
16141614
/// There are no guarantees whatsover that offsetting the pointer will not overflow or go
16151615
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that
@@ -2410,7 +2410,7 @@ impl<T: ?Sized> *mut T {
24102410
/// `usize::max_value()`.
24112411
///
24122412
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be
2413-
/// used with the `offset` or `offset_to` methods.
2413+
/// used with the `add` method.
24142414
///
24152415
/// There are no guarantees whatsover that offsetting the pointer will not overflow or go
24162416
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that

src/libcore/str/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ Section: Iterators
464464
///
465465
/// [`chars`]: ../../std/primitive.str.html#method.chars
466466
/// [`str`]: ../../std/primitive.str.html
467-
#[derive(Clone, Debug)]
467+
#[derive(Clone)]
468468
#[stable(feature = "rust1", since = "1.0.0")]
469469
pub struct Chars<'a> {
470470
iter: slice::Iter<'a, u8>
@@ -600,6 +600,16 @@ impl<'a> Iterator for Chars<'a> {
600600
}
601601
}
602602

603+
#[stable(feature = "chars_debug_impl", since = "1.38.0")]
604+
impl fmt::Debug for Chars<'_> {
605+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
606+
write!(f, "Chars(")?;
607+
f.debug_list().entries(self.clone()).finish()?;
608+
write!(f, ")")?;
609+
Ok(())
610+
}
611+
}
612+
603613
#[stable(feature = "rust1", since = "1.0.0")]
604614
impl<'a> DoubleEndedIterator for Chars<'a> {
605615
#[inline]

src/librustc/infer/opaque_types/mod.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1189,11 +1189,7 @@ pub fn may_define_existential_type(
11891189
opaque_hir_id: hir::HirId,
11901190
) -> bool {
11911191
let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
1192-
trace!(
1193-
"may_define_existential_type(def={:?}, opaque_node={:?})",
1194-
tcx.hir().get(hir_id),
1195-
tcx.hir().get(opaque_hir_id)
1196-
);
1192+
11971193

11981194
// Named existential types can be defined by any siblings or children of siblings.
11991195
let scope = tcx.hir().get_defining_scope(opaque_hir_id).expect("could not get defining scope");
@@ -1202,5 +1198,12 @@ pub fn may_define_existential_type(
12021198
hir_id = tcx.hir().get_parent_item(hir_id);
12031199
}
12041200
// Syntactically, we are allowed to define the concrete type if:
1205-
hir_id == scope
1201+
let res = hir_id == scope;
1202+
trace!(
1203+
"may_define_existential_type(def={:?}, opaque_node={:?}) = {}",
1204+
tcx.hir().get(hir_id),
1205+
tcx.hir().get(opaque_hir_id),
1206+
res
1207+
);
1208+
res
12061209
}

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25682568
let lifetimes: Vec<_> = params
25692569
.iter()
25702570
.filter_map(|param| match param.kind {
2571-
GenericParamKind::Lifetime { .. } => Some((param, param.name)),
2571+
GenericParamKind::Lifetime { .. } => Some((param, param.name.modern())),
25722572
_ => None,
25732573
})
25742574
.collect();

src/librustc_resolve/lib.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
869869
debug!("(resolving function) entering function");
870870
let rib_kind = match function_kind {
871871
FnKind::ItemFn(..) => FnItemRibKind,
872-
FnKind::Method(..) => AssocItemRibKind,
873-
FnKind::Closure(_) => NormalRibKind,
872+
FnKind::Method(..) | FnKind::Closure(_) => NormalRibKind,
874873
};
875874

876875
// Create a value rib for the function.
@@ -2307,21 +2306,32 @@ impl<'a> Resolver<'a> {
23072306
if ident.name == kw::Invalid {
23082307
return Some(LexicalScopeBinding::Res(Res::Err));
23092308
}
2310-
ident.span = if ident.name == kw::SelfUpper {
2309+
let (general_span, modern_span) = if ident.name == kw::SelfUpper {
23112310
// FIXME(jseyfried) improve `Self` hygiene
2312-
ident.span.with_ctxt(SyntaxContext::empty())
2311+
let empty_span = ident.span.with_ctxt(SyntaxContext::empty());
2312+
(empty_span, empty_span)
23132313
} else if ns == TypeNS {
2314-
ident.span.modern()
2314+
let modern_span = ident.span.modern();
2315+
(modern_span, modern_span)
23152316
} else {
2316-
ident.span.modern_and_legacy()
2317+
(ident.span.modern_and_legacy(), ident.span.modern())
23172318
};
2319+
ident.span = general_span;
2320+
let modern_ident = Ident { span: modern_span, ..ident };
23182321

23192322
// Walk backwards up the ribs in scope.
23202323
let record_used = record_used_id.is_some();
23212324
let mut module = self.graph_root;
23222325
for i in (0 .. self.ribs[ns].len()).rev() {
23232326
debug!("walk rib\n{:?}", self.ribs[ns][i].bindings);
2324-
if let Some(res) = self.ribs[ns][i].bindings.get(&ident).cloned() {
2327+
// Use the rib kind to determine whether we are resolving parameters
2328+
// (modern hygiene) or local variables (legacy hygiene).
2329+
let rib_ident = if let AssocItemRibKind | ItemRibKind = self.ribs[ns][i].kind {
2330+
modern_ident
2331+
} else {
2332+
ident
2333+
};
2334+
if let Some(res) = self.ribs[ns][i].bindings.get(&rib_ident).cloned() {
23252335
// The ident resolves to a type parameter or local variable.
23262336
return Some(LexicalScopeBinding::Res(
23272337
self.validate_res_from_ribs(ns, i, res, record_used, path_span),
@@ -2357,7 +2367,7 @@ impl<'a> Resolver<'a> {
23572367
}
23582368
}
23592369

2360-
ident.span = ident.span.modern();
2370+
ident = modern_ident;
23612371
let mut poisoned = None;
23622372
loop {
23632373
let opt_module = if let Some(node_id) = record_used_id {

src/librustc_typeck/collect.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
16641664
intravisit::NestedVisitorMap::All(&self.tcx.hir())
16651665
}
16661666
fn visit_item(&mut self, it: &'tcx Item) {
1667+
debug!("find_existential_constraints: visiting {:?}", it);
16671668
let def_id = self.tcx.hir().local_def_id(it.hir_id);
16681669
// The existential type itself or its children are not within its reveal scope.
16691670
if def_id != self.def_id {
@@ -1672,6 +1673,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
16721673
}
16731674
}
16741675
fn visit_impl_item(&mut self, it: &'tcx ImplItem) {
1676+
debug!("find_existential_constraints: visiting {:?}", it);
16751677
let def_id = self.tcx.hir().local_def_id(it.hir_id);
16761678
// The existential type itself or its children are not within its reveal scope.
16771679
if def_id != self.def_id {
@@ -1680,6 +1682,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
16801682
}
16811683
}
16821684
fn visit_trait_item(&mut self, it: &'tcx TraitItem) {
1685+
debug!("find_existential_constraints: visiting {:?}", it);
16831686
let def_id = self.tcx.hir().local_def_id(it.hir_id);
16841687
self.check(def_id);
16851688
intravisit::walk_trait_item(self, it);
@@ -1703,9 +1706,23 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
17031706
} else {
17041707
debug!("find_existential_constraints: scope={:?}", tcx.hir().get(scope));
17051708
match tcx.hir().get(scope) {
1706-
Node::Item(ref it) => intravisit::walk_item(&mut locator, it),
1707-
Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it),
1708-
Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it),
1709+
// We explicitly call `visit_*` methods, instead of using `intravisit::walk_*` methods
1710+
// This allows our visitor to process the defining item itself, causing
1711+
// it to pick up any 'sibling' defining uses.
1712+
//
1713+
// For example, this code:
1714+
// ```
1715+
// fn foo() {
1716+
// existential type Blah: Debug;
1717+
// let my_closure = || -> Blah { true };
1718+
// }
1719+
// ```
1720+
//
1721+
// requires us to explicitly process `foo()` in order
1722+
// to notice the defining usage of `Blah`.
1723+
Node::Item(ref it) => locator.visit_item(it),
1724+
Node::ImplItem(ref it) => locator.visit_impl_item(it),
1725+
Node::TraitItem(ref it) => locator.visit_trait_item(it),
17091726
other => bug!(
17101727
"{:?} is not a valid scope for an existential type item",
17111728
other

src/libstd/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3316,11 +3316,11 @@ mod tests {
33163316
fs::create_dir_all(&d).unwrap();
33173317
File::create(&f).unwrap();
33183318
if cfg!(not(windows)) {
3319-
symlink_dir("../d/e", &c).unwrap();
3319+
symlink_file("../d/e", &c).unwrap();
33203320
symlink_file("../f", &e).unwrap();
33213321
}
33223322
if cfg!(windows) {
3323-
symlink_dir(r"..\d\e", &c).unwrap();
3323+
symlink_file(r"..\d\e", &c).unwrap();
33243324
symlink_file(r"..\f", &e).unwrap();
33253325
}
33263326

src/libstd/sys/vxworks/fs.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,7 @@ impl File {
287287
let fd = cvt_r(|| unsafe {
288288
open(path.as_ptr(), flags, opts.mode as c_int)
289289
})?;
290-
let fd = FileDesc::new(fd);
291-
// Currently the standard library supports Linux 2.6.18 which did not
292-
// have the O_CLOEXEC flag (passed above). If we're running on an older
293-
// Linux kernel then the flag is just ignored by the OS. After we open
294-
// the first file, we check whether it has CLOEXEC set. If it doesn't,
295-
// we will explicitly ask for a CLOEXEC fd for every further file we
296-
// open, if it does, we will skip that step.
297-
//
298-
// The CLOEXEC flag, however, is supported on versions of macOS/BSD/etc
299-
// that we support, so we only do this on Linux currently.
300-
fn ensure_cloexec(_: &FileDesc) -> io::Result<()> {
301-
Ok(())
302-
}
303-
304-
ensure_cloexec(&fd)?;
305-
Ok(File(fd))
290+
Ok(File(FileDesc::new(fd)))
306291
}
307292

308293
pub fn file_attr(&self) -> io::Result<FileAttr> {

src/libstd/sys/vxworks/net.rs

-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ impl Socket {
141141

142142
pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t)
143143
-> io::Result<Socket> {
144-
// Unfortunately the only known way right now to accept a socket and
145-
// atomically set the CLOEXEC flag is to use the `accept4` syscall on
146-
// Linux. This was added in 2.6.28, however, and because we support
147-
// 2.6.18 we must detect this support dynamically.
148144
let fd = cvt_r(|| unsafe {
149145
libc::accept(self.0.raw(), storage, len)
150146
})?;

src/libstd/sys/vxworks/pipe.rs

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
1111
static INVALID: AtomicBool = AtomicBool::new(false);
1212

1313
let mut fds = [0; 2];
14-
15-
// Unfortunately the only known way right now to create atomically set the
16-
// CLOEXEC flag is to use the `pipe2` syscall on Linux. This was added in
17-
// 2.6.27, however, and because we support 2.6.18 we must detect this
18-
// support dynamically.
1914
cvt(unsafe { libc::pipe(fds.as_mut_ptr()) })?;
2015

2116
let fd0 = FileDesc::new(fds[0]);

0 commit comments

Comments
 (0)