Skip to content

Commit 961a9d6

Browse files
committed
Auto merge of rust-lang#61741 - Centril:rollup-fgro5kz, r=Centril
Rollup of 11 pull requests Successful merges: - rust-lang#61518 (Add loops to doc list of things not stable in const fn) - rust-lang#61526 (move some tests into subfolders) - rust-lang#61550 (Windows 10 SDK is also required now.) - rust-lang#61606 (Remove some legacy proc macro flavors) - rust-lang#61652 (Mention slice patterns in array) - rust-lang#61686 (librustc_errors: Add some more documentation) - rust-lang#61698 (typeck: Fix const generic in repeat param ICE.) - rust-lang#61707 (Azure: retry failed awscli installs) - rust-lang#61715 (make sure make_ascii_lowercase actually leaves upper-case non-ASCII characters alone) - rust-lang#61724 (core: use memcmp optimization for 128 bit integer slices) - rust-lang#61726 (Use `for_each` in `Iterator::partition`) Failed merges: r? @ghost
2 parents 5f3656c + 681712b commit 961a9d6

Some content is hidden

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

48 files changed

+386
-749
lines changed

.azure-pipelines/steps/run.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ steps:
7474
# images, etc.
7575
- bash: |
7676
set -e
77+
source src/ci/shared.sh
7778
sudo apt-get install -y python3-setuptools
78-
pip3 install awscli --upgrade --user
79+
retry pip3 install awscli --upgrade --user
7980
echo "##vso[task.prependpath]$HOME/.local/bin"
8081
displayName: Install awscli (Linux)
8182
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ build.
130130

131131
MSVC builds of Rust additionally require an installation of Visual Studio 2017
132132
(or later) so `rustc` can use its linker. The simplest way is to get the
133-
[Visual Studio Build Tools] and check the “C++ build tools” workload.
133+
[Visual Studio], check the “C++ build tools” and “Windows 10 SDK” workload.
134134

135-
[Visual Studio Build Tools]: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
135+
[Visual Studio]: https://visualstudio.microsoft.com/downloads/
136136

137137
(If you're installing cmake yourself, be careful that “C++ CMake tools for
138138
Windows” doesn't get included under “Individual components”.)

src/libcore/iter/traits/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1495,13 +1495,13 @@ pub trait Iterator {
14951495
let mut left: B = Default::default();
14961496
let mut right: B = Default::default();
14971497

1498-
for x in self {
1498+
self.for_each(|x| {
14991499
if f(&x) {
15001500
left.extend(Some(x))
15011501
} else {
15021502
right.extend(Some(x))
15031503
}
1504-
}
1504+
});
15051505

15061506
(left, right)
15071507
}

src/libcore/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5420,7 +5420,7 @@ macro_rules! impl_marker_for {
54205420
}
54215421

54225422
impl_marker_for!(BytewiseEquality,
5423-
u8 i8 u16 i16 u32 i32 u64 i64 usize isize char bool);
5423+
u8 i8 u16 i16 u32 i32 u64 i64 u128 i128 usize isize char bool);
54245424

54255425
#[doc(hidden)]
54265426
unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> {

src/libcore/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4000,11 +4000,11 @@ impl str {
40004000
/// # Examples
40014001
///
40024002
/// ```
4003-
/// let mut s = String::from("Grüße, Jürgen ❤");
4003+
/// let mut s = String::from("GRÜßE, JÜRGEN ❤");
40044004
///
40054005
/// s.make_ascii_lowercase();
40064006
///
4007-
/// assert_eq!("grüße, jürgen ❤", s);
4007+
/// assert_eq!("grÜße, jÜrgen ❤", s);
40084008
/// ```
40094009
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
40104010
pub fn make_ascii_lowercase(&mut self) {

src/librustc/session/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,17 @@ impl OutputType {
227227
}
228228
}
229229

230+
/// The type of diagnostics output to generate.
230231
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
231232
pub enum ErrorOutputType {
233+
/// Output meant for the consumption of humans.
232234
HumanReadable(HumanReadableErrorType),
235+
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
233236
Json {
234-
/// Render the json in a human readable way (with indents and newlines)
237+
/// Render the JSON in a human readable way (with indents and newlines).
235238
pretty: bool,
236-
/// The way the `rendered` field is created
239+
/// The JSON output includes a `rendered` field that includes the rendered
240+
/// human output.
237241
json_rendered: HumanReadableErrorType,
238242
},
239243
}

src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'a> DiagnosticBuilder<'a> {
348348

349349
/// Convenience function for internal use, clients should use one of the
350350
/// struct_* methods on Handler.
351-
pub fn new_with_code(handler: &'a Handler,
351+
crate fn new_with_code(handler: &'a Handler,
352352
level: Level,
353353
code: Option<DiagnosticId>,
354354
message: &str)

src/librustc_errors/emitter.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! The current rustc diagnostics emitter.
2+
//!
3+
//! An `Emitter` takes care of generating the output from a `DiagnosticBuilder` struct.
4+
//!
5+
//! There are various `Emitter` implementations that generate different output formats such as
6+
//! JSON and human readable output.
7+
//!
8+
//! The output types are defined in `librustc::session::config::ErrorOutputType`.
9+
110
use Destination::*;
211

312
use syntax_pos::{SourceFile, Span, MultiSpan};

src/librustc_errors/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
//! Diagnostics creation and emission for `rustc`.
2+
//!
3+
//! This module contains the code for creating and emitting diagnostics.
4+
15
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
26

7+
#![feature(crate_visibility_modifier)]
38
#![allow(unused_attributes)]
49
#![cfg_attr(unix, feature(libc))]
510
#![feature(nll)]

src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl<'a> CrateLoader<'a> {
614614
match decl {
615615
ProcMacro::CustomDerive { trait_name, attributes, client } => {
616616
let attrs = attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
617-
(trait_name, SyntaxExtension::ProcMacroDerive(
617+
(trait_name, SyntaxExtension::Derive(
618618
Box::new(ProcMacroDerive {
619619
client,
620620
attrs: attrs.clone(),
@@ -624,13 +624,13 @@ impl<'a> CrateLoader<'a> {
624624
))
625625
}
626626
ProcMacro::Attr { name, client } => {
627-
(name, SyntaxExtension::AttrProcMacro(
627+
(name, SyntaxExtension::Attr(
628628
Box::new(AttrProcMacro { client }),
629629
root.edition,
630630
))
631631
}
632632
ProcMacro::Bang { name, client } => {
633-
(name, SyntaxExtension::ProcMacro {
633+
(name, SyntaxExtension::Bang {
634634
expander: Box::new(BangProcMacro { client }),
635635
allow_internal_unstable: None,
636636
edition: root.edition,

src/librustc_metadata/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl cstore::CStore {
430430
use syntax_ext::proc_macro_impl::BangProcMacro;
431431

432432
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
433-
let ext = SyntaxExtension::ProcMacro {
433+
let ext = SyntaxExtension::Bang {
434434
expander: Box::new(BangProcMacro { client }),
435435
allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()),
436436
edition: data.root.edition,

src/librustc_mir/transform/qualify_min_const_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn check_terminator(
299299

300300
TerminatorKind::FalseEdges { .. } | TerminatorKind::SwitchInt { .. } => Err((
301301
span,
302-
"`if`, `match`, `&&` and `||` are not stable in const fn".into(),
302+
"loops and conditional expressions are not stable in const fn".into(),
303303
)),
304304
| TerminatorKind::Abort | TerminatorKind::Unreachable => {
305305
Err((span, "const fn with unreachable code is not stable".into()))

src/librustc_plugin/registry.rs

+10-30
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use rustc::lint::{EarlyLintPassObject, LateLintPassObject, LintId, Lint};
44
use rustc::session::Session;
55
use rustc::util::nodemap::FxHashMap;
66

7-
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT, IdentTT};
7+
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension};
88
use syntax::ext::base::MacroExpanderFn;
9+
use syntax::ext::hygiene::Transparency;
910
use syntax::symbol::{Symbol, sym};
1011
use syntax::ast;
1112
use syntax::feature_gate::AttributeType;
@@ -84,47 +85,26 @@ impl<'a> Registry<'a> {
8485
/// Register a syntax extension of any kind.
8586
///
8687
/// This is the most general hook into `libsyntax`'s expansion behavior.
87-
pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
88+
pub fn register_syntax_extension(&mut self, name: ast::Name, mut extension: SyntaxExtension) {
8889
if name == sym::macro_rules {
8990
panic!("user-defined macros may not be named `macro_rules`");
9091
}
91-
self.syntax_exts.push((name, match extension {
92-
NormalTT {
93-
expander,
94-
def_info: _,
95-
allow_internal_unstable,
96-
allow_internal_unsafe,
97-
local_inner_macros,
98-
unstable_feature,
99-
edition,
100-
} => {
101-
let nid = ast::CRATE_NODE_ID;
102-
NormalTT {
103-
expander,
104-
def_info: Some((nid, self.krate_span)),
105-
allow_internal_unstable,
106-
allow_internal_unsafe,
107-
local_inner_macros,
108-
unstable_feature,
109-
edition,
110-
}
111-
}
112-
IdentTT { expander, span: _, allow_internal_unstable } => {
113-
IdentTT { expander, span: Some(self.krate_span), allow_internal_unstable }
114-
}
115-
_ => extension,
116-
}));
92+
if let SyntaxExtension::LegacyBang { def_info: ref mut def_info @ None, .. } = extension {
93+
*def_info = Some((ast::CRATE_NODE_ID, self.krate_span));
94+
}
95+
self.syntax_exts.push((name, extension));
11796
}
11897

11998
/// Register a macro of the usual kind.
12099
///
121100
/// This is a convenience wrapper for `register_syntax_extension`.
122-
/// It builds for you a `NormalTT` that calls `expander`,
101+
/// It builds for you a `SyntaxExtension::LegacyBang` that calls `expander`,
123102
/// and also takes care of interning the macro's name.
124103
pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
125-
self.register_syntax_extension(Symbol::intern(name), NormalTT {
104+
self.register_syntax_extension(Symbol::intern(name), SyntaxExtension::LegacyBang {
126105
expander: Box::new(expander),
127106
def_info: None,
107+
transparency: Transparency::SemiTransparent,
128108
allow_internal_unstable: None,
129109
allow_internal_unsafe: false,
130110
local_inner_macros: false,

src/librustc_resolve/macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ impl<'a> base::Resolver for Resolver<'a> {
242242
fn check_unused_macros(&self) {
243243
for did in self.unused_macros.iter() {
244244
let id_span = match *self.macro_map[did] {
245-
SyntaxExtension::NormalTT { def_info, .. } |
246-
SyntaxExtension::DeclMacro { def_info, .. } => def_info,
245+
SyntaxExtension::LegacyBang { def_info, .. } => def_info,
247246
_ => None,
248247
};
249248
if let Some((id, span)) = id_span {
@@ -587,7 +586,7 @@ impl<'a> Resolver<'a> {
587586
match self.resolve_macro_to_res(derive, MacroKind::Derive,
588587
&parent_scope, true, force) {
589588
Ok((_, ext)) => {
590-
if let SyntaxExtension::ProcMacroDerive(_, helpers, _) = &*ext {
589+
if let SyntaxExtension::Derive(_, helpers, _) = &*ext {
591590
if helpers.contains(&ident.name) {
592591
let binding =
593592
(Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper),

src/librustc_typeck/astconv.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,17 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
21552155
result_ty
21562156
}
21572157

2158+
/// Returns the `DefId` of the constant parameter that the provided expression is a path to.
2159+
pub fn const_param_def_id(&self, expr: &hir::Expr) -> Option<DefId> {
2160+
match &expr.node {
2161+
ExprKind::Path(hir::QPath::Resolved(_, path)) => match path.res {
2162+
Res::Def(DefKind::ConstParam, did) => Some(did),
2163+
_ => None,
2164+
},
2165+
_ => None,
2166+
}
2167+
}
2168+
21582169
pub fn ast_const_to_const(
21592170
&self,
21602171
ast_const: &hir::AnonConst,
@@ -2185,19 +2196,17 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
21852196
}
21862197
}
21872198

2188-
if let ExprKind::Path(ref qpath) = expr.node {
2189-
if let hir::QPath::Resolved(_, ref path) = qpath {
2190-
if let Res::Def(DefKind::ConstParam, def_id) = path.res {
2191-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
2192-
let item_id = tcx.hir().get_parent_node(node_id);
2193-
let item_def_id = tcx.hir().local_def_id(item_id);
2194-
let generics = tcx.generics_of(item_def_id);
2195-
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)];
2196-
let name = tcx.hir().name(node_id).as_interned_str();
2197-
const_.val = ConstValue::Param(ty::ParamConst::new(index, name));
2198-
}
2199-
}
2200-
};
2199+
if let Some(def_id) = self.const_param_def_id(expr) {
2200+
// Find the name and index of the const parameter by indexing the generics of the
2201+
// parent item and construct a `ParamConst`.
2202+
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
2203+
let item_id = tcx.hir().get_parent_node(node_id);
2204+
let item_def_id = tcx.hir().local_def_id(item_id);
2205+
let generics = tcx.generics_of(item_def_id);
2206+
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)];
2207+
let name = tcx.hir().name(node_id).as_interned_str();
2208+
const_.val = ConstValue::Param(ty::ParamConst::new(index, name));
2209+
}
22012210

22022211
tcx.mk_const(const_)
22032212
}

src/librustc_typeck/check/mod.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
25042504
ty
25052505
}
25062506

2507+
/// Returns the `DefId` of the constant parameter that the provided expression is a path to.
2508+
pub fn const_param_def_id(&self, hir_c: &hir::AnonConst) -> Option<DefId> {
2509+
AstConv::const_param_def_id(self, &self.tcx.hir().body(hir_c.body).value)
2510+
}
2511+
25072512
pub fn to_const(&self, ast_c: &hir::AnonConst, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
25082513
AstConv::ast_const_to_const(self, ast_c, ty)
25092514
}
@@ -4479,19 +4484,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44794484
}
44804485
ExprKind::Repeat(ref element, ref count) => {
44814486
let count_def_id = tcx.hir().local_def_id_from_hir_id(count.hir_id);
4482-
let param_env = ty::ParamEnv::empty();
4483-
let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), count_def_id);
4484-
let instance = ty::Instance::resolve(
4485-
tcx.global_tcx(),
4486-
param_env,
4487-
count_def_id,
4488-
substs,
4489-
).unwrap();
4490-
let global_id = GlobalId {
4491-
instance,
4492-
promoted: None
4487+
let count = if self.const_param_def_id(count).is_some() {
4488+
Ok(self.to_const(count, self.tcx.type_of(count_def_id)))
4489+
} else {
4490+
let param_env = ty::ParamEnv::empty();
4491+
let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), count_def_id);
4492+
let instance = ty::Instance::resolve(
4493+
tcx.global_tcx(),
4494+
param_env,
4495+
count_def_id,
4496+
substs,
4497+
).unwrap();
4498+
let global_id = GlobalId {
4499+
instance,
4500+
promoted: None
4501+
};
4502+
4503+
tcx.const_eval(param_env.and(global_id))
44934504
};
4494-
let count = tcx.const_eval(param_env.and(global_id));
44954505

44964506
let uty = match expected {
44974507
ExpectHasType(uty) => {

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: ast::Name) -> clean::ItemE
471471
}
472472
LoadedMacro::ProcMacro(ext) => {
473473
let helpers = match &*ext {
474-
&SyntaxExtension::ProcMacroDerive(_, ref syms, ..) => { syms.clean(cx) }
474+
&SyntaxExtension::Derive(_, ref syms, ..) => { syms.clean(cx) }
475475
_ => Vec::new(),
476476
};
477477

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
433433
if let Res::Def(DefKind::Macro(MacroKind::ProcMacroStub), _) = res {
434434
// skip proc-macro stubs, they'll cause `get_macro` to crash
435435
} else {
436-
if let SyntaxExtension::DeclMacro { .. } = *resolver.get_macro(res) {
436+
if let SyntaxExtension::LegacyBang { .. } = *resolver.get_macro(res) {
437437
return Some(res.map_id(|_| panic!("unexpected id")));
438438
}
439439
}

src/libstd/primitive_docs.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ mod prim_pointer { }
482482
/// an array. Indeed, this provides most of the API for working with arrays.
483483
/// Slices have a dynamic size and do not coerce to arrays.
484484
///
485-
/// There is no way to move elements out of an array. See [`mem::replace`][replace]
486-
/// for an alternative.
485+
/// You can move elements out of an array with a slice pattern. If you want
486+
/// one element, see [`mem::replace`][replace].
487487
///
488488
/// # Examples
489489
///
@@ -525,6 +525,16 @@ mod prim_pointer { }
525525
/// for x in &array { }
526526
/// ```
527527
///
528+
/// You can use a slice pattern to move elements out of an array:
529+
///
530+
/// ```
531+
/// fn move_away(_: String) { /* Do interesting things. */ }
532+
///
533+
/// let [john, roa] = ["John".to_string(), "Roa".to_string()];
534+
/// move_away(john);
535+
/// move_away(roa);
536+
/// ```
537+
///
528538
/// [slice]: primitive.slice.html
529539
/// [copy]: marker/trait.Copy.html
530540
/// [clone]: clone/trait.Clone.html

0 commit comments

Comments
 (0)