Skip to content

Commit 0eb878d

Browse files
committed
Auto merge of #69555 - Centril:rollup-e53lxz4, r=Centril
Rollup of 10 pull requests Successful merges: - #68989 (Update RELEASES.md for 1.42.0) - #69340 (instantiate_value_path: on `SelfCtor`, avoid unconstrained tyvars) - #69384 (parser: `token` -> `normalized_token`, `nonnormalized_token` -> `token`) - #69452 (typeck: use `Pattern` obligation cause more for better diagnostics) - #69481 (use char instead of &str for single char patterns) - #69522 (error_derive_forbidden_on_non_adt: be more graceful) - #69538 (Stabilize `boxed_slice_try_from`) - #69539 (late resolve, visit_fn: bail early if there's no body.) - #69541 (Remove unneeded calls to format!()) - #69547 (remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.) Failed merges: r? @ghost
2 parents eaa02f5 + 13e4c6c commit 0eb878d

File tree

98 files changed

+853
-390
lines changed

Some content is hidden

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

98 files changed

+853
-390
lines changed

RELEASES.md

+98
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1+
Version 1.42.0 (2020-03-12)
2+
==========================
3+
4+
Language
5+
--------
6+
- [You can now use the slice pattern syntax with subslices.][67712] e.g.
7+
```rust
8+
fn foo(words: &[&str]) {
9+
match words {
10+
["Hello", "World", "!", ..] => println!("Hello World!"),
11+
["Foo", "Bar", ..] => println!("Baz"),
12+
rest => println!("{:?}", rest),
13+
}
14+
}
15+
```
16+
- [You can now use `#[repr(transparent)]` on univariant `enum`s.][68122] Meaning
17+
that you can create an enum that has the exact layout and ABI of the type
18+
it contains.
19+
- [There are some *syntax-only* changes:][67131]
20+
- `default` is syntactically allowed before items in `trait` definitions.
21+
- Items in `impl`s (i.e. `const`s, `type`s, and `fn`s) may syntactically
22+
leave out their bodies in favor of `;`.
23+
- Bounds on associated types in `impl`s are now syntactically allowed
24+
(e.g. `type Foo: Ord;`).
25+
- `...` (the C-variadic type) may occur syntactically directly as the type of
26+
any function parameter.
27+
28+
These are still rejected *semantically*, so you will likely receive an error
29+
but these changes can be seen and parsed by procedural macros and
30+
conditional compilation.
31+
32+
Compiler
33+
--------
34+
- [Added tier 2\* support for `armv7a-none-eabi`.][68253]
35+
- [Added tier 2 support for `riscv64gc-unknown-linux-gnu`.][68339]
36+
- [`Option::{expect,unwrap}` and
37+
`Result::{expect, expect_err, unwrap, unwrap_err}` now produce panic messages
38+
pointing to the location where they were called, rather than
39+
`core`'s internals. ][67887]
40+
41+
\* Refer to Rust's [platform support page][forge-platform-support] for more
42+
information on Rust's tiered platform support.
43+
44+
Libraries
45+
---------
46+
- [`iter::Empty<T>` now implements `Send` and `Sync` for any `T`.][68348]
47+
- [`Pin::{map_unchecked, map_unchecked_mut}` no longer require the return type
48+
to implement `Sized`.][67935]
49+
- [`io::Cursor` now derives `PartialEq` and `Eq`.][67233]
50+
- [`Layout::new` is now `const`.][66254]
51+
- [Added Standard Library support for `riscv64gc-unknown-linux-gnu`.][66899]
52+
53+
54+
Stabilized APIs
55+
---------------
56+
- [`CondVar::wait_while`]
57+
- [`CondVar::wait_timeout_while`]
58+
- [`DebugMap::key`]
59+
- [`DebugMap::value`]
60+
- [`ManuallyDrop::take`]
61+
- [`matches!`]
62+
- [`ptr::slice_from_raw_parts_mut`]
63+
- [`ptr::slice_from_raw_parts`]
64+
65+
Cargo
66+
-----
67+
- [You no longer need to include `extern crate proc_macro;` to be able to
68+
`use proc_macro;` in the `2018` edition.][cargo/7700]
69+
70+
Compatibility Notes
71+
-------------------
72+
- [`Error::description` has been deprecated, and its use will now produce a
73+
warning.][66919] It's recommended to use `Display`/`to_string` instead.
74+
75+
[68253]: https://github.com/rust-lang/rust/pull/68253/
76+
[68348]: https://github.com/rust-lang/rust/pull/68348/
77+
[67935]: https://github.com/rust-lang/rust/pull/67935/
78+
[68339]: https://github.com/rust-lang/rust/pull/68339/
79+
[68122]: https://github.com/rust-lang/rust/pull/68122/
80+
[67712]: https://github.com/rust-lang/rust/pull/67712/
81+
[67887]: https://github.com/rust-lang/rust/pull/67887/
82+
[67131]: https://github.com/rust-lang/rust/pull/67131/
83+
[67233]: https://github.com/rust-lang/rust/pull/67233/
84+
[66899]: https://github.com/rust-lang/rust/pull/66899/
85+
[66919]: https://github.com/rust-lang/rust/pull/66919/
86+
[66254]: https://github.com/rust-lang/rust/pull/66254/
87+
[cargo/7700]: https://github.com/rust-lang/cargo/pull/7700
88+
[`DebugMap::key`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.key
89+
[`DebugMap::value`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.value
90+
[`ManuallyDrop::take`]: https://doc.rust-lang.org/stable/std/mem/struct.ManuallyDrop.html#method.take
91+
[`matches!`]: https://doc.rust-lang.org/stable/std/macro.matches.html
92+
[`ptr::slice_from_raw_parts_mut`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts_mut.html
93+
[`ptr::slice_from_raw_parts`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts.html
94+
[`CondVar::wait_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_while
95+
[`CondVar::wait_timeout_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_timeout_while
96+
97+
198
Version 1.41.1 (2020-02-27)
299
===========================
3100

@@ -8,6 +105,7 @@ Version 1.41.1 (2020-02-27)
8105
[69225]: https://github.com/rust-lang/rust/issues/69225
9106
[69145]: https://github.com/rust-lang/rust/pull/69145
10107

108+
11109
Version 1.41.0 (2020-01-30)
12110
===========================
13111

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ impl From<Box<str>> for Box<[u8]> {
825825
}
826826
}
827827

828-
#[unstable(feature = "boxed_slice_try_from", issue = "none")]
828+
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
829829
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]>
830830
where
831831
[T; N]: LengthAtMost32,

src/liballoc/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ impl<T> From<Vec<T>> for Rc<[T]> {
14531453
}
14541454
}
14551455

1456-
#[unstable(feature = "boxed_slice_try_from", issue = "none")]
1456+
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
14571457
impl<T, const N: usize> TryFrom<Rc<[T]>> for Rc<[T; N]>
14581458
where
14591459
[T; N]: LengthAtMost32,

src/liballoc/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ impl<T> From<Vec<T>> for Arc<[T]> {
20022002
}
20032003
}
20042004

2005-
#[unstable(feature = "boxed_slice_try_from", issue = "none")]
2005+
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
20062006
impl<T, const N: usize> TryFrom<Arc<[T]>> for Arc<[T; N]>
20072007
where
20082008
[T; N]: LengthAtMost32,

src/librustc/hir/map/mod.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,13 @@ pub struct Map<'hir> {
153153
hir_to_node_id: FxHashMap<HirId, NodeId>,
154154
}
155155

156-
struct ParentHirIterator<'map, 'hir> {
156+
/// An iterator that walks up the ancestor tree of a given `HirId`.
157+
/// Constructed using `tcx.hir().parent_iter(hir_id)`.
158+
pub struct ParentHirIterator<'map, 'hir> {
157159
current_id: HirId,
158160
map: &'map Map<'hir>,
159161
}
160162

161-
impl<'map, 'hir> ParentHirIterator<'map, 'hir> {
162-
fn new(current_id: HirId, map: &'map Map<'hir>) -> Self {
163-
Self { current_id, map }
164-
}
165-
}
166-
167163
impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
168164
type Item = (HirId, Node<'hir>);
169165

@@ -618,6 +614,12 @@ impl<'hir> Map<'hir> {
618614
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
619615
}
620616

617+
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
618+
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
619+
pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> {
620+
ParentHirIterator { current_id, map: self }
621+
}
622+
621623
/// Checks if the node is an argument. An argument is a local variable whose
622624
/// immediate parent is an item or a closure.
623625
pub fn is_argument(&self, id: HirId) -> bool {
@@ -684,7 +686,7 @@ impl<'hir> Map<'hir> {
684686
/// }
685687
/// ```
686688
pub fn get_return_block(&self, id: HirId) -> Option<HirId> {
687-
let mut iter = ParentHirIterator::new(id, &self).peekable();
689+
let mut iter = self.parent_iter(id).peekable();
688690
let mut ignore_tail = false;
689691
if let Some(entry) = self.find_entry(id) {
690692
if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = entry.node {
@@ -731,7 +733,7 @@ impl<'hir> Map<'hir> {
731733
/// in the HIR which is recorded by the map and is an item, either an item
732734
/// in a module, trait, or impl.
733735
pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
734-
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) {
736+
for (hir_id, node) in self.parent_iter(hir_id) {
735737
match node {
736738
Node::Crate
737739
| Node::Item(_)
@@ -753,7 +755,7 @@ impl<'hir> Map<'hir> {
753755
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
754756
/// module parent is in this map.
755757
pub fn get_module_parent_node(&self, hir_id: HirId) -> HirId {
756-
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) {
758+
for (hir_id, node) in self.parent_iter(hir_id) {
757759
if let Node::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
758760
return hir_id;
759761
}
@@ -767,7 +769,7 @@ impl<'hir> Map<'hir> {
767769
/// Used by error reporting when there's a type error in a match arm caused by the `match`
768770
/// expression needing to be unit.
769771
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
770-
for (_, node) in ParentHirIterator::new(hir_id, &self) {
772+
for (_, node) in self.parent_iter(hir_id) {
771773
match node {
772774
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
773775
break;
@@ -788,7 +790,7 @@ impl<'hir> Map<'hir> {
788790

789791
/// Returns the nearest enclosing scope. A scope is roughly an item or block.
790792
pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> {
791-
for (hir_id, node) in ParentHirIterator::new(hir_id, &self) {
793+
for (hir_id, node) in self.parent_iter(hir_id) {
792794
if match node {
793795
Node::Item(i) => match i.kind {
794796
ItemKind::Fn(..)

src/librustc_builtin_macros/asm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn parse_inline_asm<'a>(
182182
};
183183

184184
let is_rw = output.is_some();
185-
let is_indirect = constraint_str.contains("*");
185+
let is_indirect = constraint_str.contains('*');
186186
outputs.push(ast::InlineAsmOutput {
187187
constraint: output.unwrap_or(constraint),
188188
expr,
@@ -199,15 +199,15 @@ fn parse_inline_asm<'a>(
199199

200200
let constraint = parse_asm_str(&mut p)?;
201201

202-
if constraint.as_str().starts_with("=") {
202+
if constraint.as_str().starts_with('=') {
203203
struct_span_err!(
204204
cx.parse_sess.span_diagnostic,
205205
p.prev_span,
206206
E0662,
207207
"input operand constraint contains '='"
208208
)
209209
.emit();
210-
} else if constraint.as_str().starts_with("+") {
210+
} else if constraint.as_str().starts_with('+') {
211211
struct_span_err!(
212212
cx.parse_sess.span_diagnostic,
213213
p.prev_span,
@@ -234,7 +234,7 @@ fn parse_inline_asm<'a>(
234234

235235
if OPTIONS.iter().any(|&opt| s == opt) {
236236
cx.span_warn(p.prev_span, "expected a clobber, found an option");
237-
} else if s.as_str().starts_with("{") || s.as_str().ends_with("}") {
237+
} else if s.as_str().starts_with('{') || s.as_str().ends_with('}') {
238238
struct_span_err!(
239239
cx.parse_sess.span_diagnostic,
240240
p.prev_span,

src/librustc_builtin_macros/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn parse_args<'a>(
158158
} // accept trailing commas
159159
if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
160160
named = true;
161-
let name = if let token::Ident(name, _) = p.token.kind {
161+
let name = if let token::Ident(name, _) = p.normalized_token.kind {
162162
p.bump();
163163
name
164164
} else {
@@ -894,7 +894,7 @@ pub fn expand_preparsed_format_args(
894894
};
895895

896896
let (is_literal, fmt_snippet) = match ecx.source_map().span_to_snippet(fmt_sp) {
897-
Ok(s) => (s.starts_with("\"") || s.starts_with("r#"), Some(s)),
897+
Ok(s) => (s.starts_with('"') || s.starts_with("r#"), Some(s)),
898898
_ => (false, None),
899899
};
900900

src/librustc_codegen_llvm/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ impl ThinLTOImports {
917917
if line.is_empty() {
918918
let importing_module = current_module.take().expect("Importing module not set");
919919
imports.insert(importing_module, mem::replace(&mut current_imports, vec![]));
920-
} else if line.starts_with(" ") {
920+
} else if line.starts_with(' ') {
921921
// Space marks an imported module
922922
assert_ne!(current_module, None);
923923
current_imports.push(line.trim().to_string());

src/librustc_codegen_utils/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
7878
}
7979
if let Input::File(ref path) = *input {
8080
if let Some(s) = path.file_stem().and_then(|s| s.to_str()) {
81-
if s.starts_with("-") {
81+
if s.starts_with('-') {
8282
let msg = format!(
8383
"crate names cannot start with a `-`, but \
8484
`{}` has a leading hyphen",

src/librustc_driver/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs;
44
use std::io;
55

66
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
7-
if arg.starts_with("@") {
7+
if arg.starts_with('@') {
88
let path = &arg[1..];
99
let file = match fs::read_to_string(path) {
1010
Ok(file) => file,

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fn stdout_isatty() -> bool {
521521

522522
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
523523
let normalised =
524-
if code.starts_with("E") { code.to_string() } else { format!("E{0:0>4}", code) };
524+
if code.starts_with('E') { code.to_string() } else { format!("E{0:0>4}", code) };
525525
match registry.find_description(&normalised) {
526526
Some(ref description) => {
527527
let mut is_in_code_block = false;
@@ -601,7 +601,7 @@ impl RustcDefaultCalls {
601601
});
602602
compiler.codegen_backend().link(&sess, Box::new(codegen_results), &outputs)
603603
} else {
604-
sess.fatal(&format!("rlink must be a file"))
604+
sess.fatal("rlink must be a file")
605605
}
606606
}
607607

src/librustc_expand/expand.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
503503
}
504504

505505
fn error_derive_forbidden_on_non_adt(&self, derives: &[Path], item: &Annotatable) {
506-
let attr =
507-
attr::find_by_name(item.attrs(), sym::derive).expect("`derive` attribute should exist");
508-
let span = attr.span;
506+
let attr = attr::find_by_name(item.attrs(), sym::derive);
507+
let span = attr.map_or(item.span(), |attr| attr.span);
509508
let mut err = self
510509
.cx
511510
.struct_span_err(span, "`derive` may only be applied to structs, enums and unions");
512-
if let ast::AttrStyle::Inner = attr.style {
511+
if let Some(ast::Attribute { style: ast::AttrStyle::Inner, .. }) = attr {
513512
let trait_list = derives.iter().map(|t| pprust::path_to_string(t)).collect::<Vec<_>>();
514513
let suggestion = format!("#[derive({})]", trait_list.join(", "));
515514
err.span_suggestion(
@@ -1669,10 +1668,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16691668
}
16701669
}
16711670
} else {
1672-
let mut err = self.cx.struct_span_err(
1673-
it.span(),
1674-
&format!("expected path to external documentation"),
1675-
);
1671+
let mut err = self
1672+
.cx
1673+
.struct_span_err(it.span(), "expected path to external documentation");
16761674

16771675
// Check if the user erroneously used `doc(include(...))` syntax.
16781676
let literal = it.meta_item_list().and_then(|list| {

src/librustc_expand/mbe/macro_parser.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,12 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
753753
fn get_macro_name(token: &Token) -> Option<(Name, bool)> {
754754
match token.kind {
755755
token::Ident(name, is_raw) if name != kw::Underscore => Some((name, is_raw)),
756+
token::Interpolated(ref nt) => match **nt {
757+
token::NtIdent(ident, is_raw) if ident.name != kw::Underscore => {
758+
Some((ident.name, is_raw))
759+
}
760+
_ => None,
761+
},
756762
_ => None,
757763
}
758764
}
@@ -883,9 +889,8 @@ fn parse_nt_inner<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> PResult<'a,
883889
// this could be handled like a token, since it is one
884890
sym::ident => {
885891
if let Some((name, is_raw)) = get_macro_name(&p.token) {
886-
let span = p.token.span;
887892
p.bump();
888-
token::NtIdent(Ident::new(name, span), is_raw)
893+
token::NtIdent(Ident::new(name, p.normalized_prev_token.span), is_raw)
889894
} else {
890895
let token_str = pprust::token_to_string(&p.token);
891896
let msg = &format!("expected ident, found {}", &token_str);

src/librustc_expand/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
205205
TokenTree::Literal(self::Literal {
206206
lit: token::Lit { kind: token::Integer, symbol, suffix },
207207
span,
208-
}) if symbol.as_str().starts_with("-") => {
208+
}) if symbol.as_str().starts_with('-') => {
209209
let minus = BinOp(BinOpToken::Minus);
210210
let symbol = Symbol::intern(&symbol.as_str()[1..]);
211211
let integer = TokenKind::lit(token::Integer, symbol, suffix);
@@ -216,7 +216,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
216216
TokenTree::Literal(self::Literal {
217217
lit: token::Lit { kind: token::Float, symbol, suffix },
218218
span,
219-
}) if symbol.as_str().starts_with("-") => {
219+
}) if symbol.as_str().starts_with('-') => {
220220
let minus = BinOp(BinOpToken::Minus);
221221
let symbol = Symbol::intern(&symbol.as_str()[1..]);
222222
let float = TokenKind::lit(token::Float, symbol, suffix);

src/librustc_hir/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
15041504
let end_point = sm.end_point(*span);
15051505

15061506
if let Ok(end_string) = sm.span_to_snippet(end_point) {
1507-
!(end_string.ends_with("}") || end_string.ends_with(")"))
1507+
!(end_string.ends_with('}') || end_string.ends_with(')'))
15081508
} else {
15091509
false
15101510
}

0 commit comments

Comments
 (0)