Skip to content

Commit ed8b708

Browse files
committed
Auto merge of #64658 - Centril:rollup-9s3raz6, r=Centril
Rollup of 9 pull requests Successful merges: - #64010 (Stabilize `param_attrs` in Rust 1.39.0) - #64136 (Document From trait for LhsExpr in parser) - #64342 (factor out pluralisation remains after #64280) - #64347 (Add long error explanation for E0312) - #64621 (Add Compatibility Notes to RELEASES.md for 1.38.0) - #64632 (remove the extra comma after the match arm) - #64640 (No home directory on vxWorks) - #64641 (Exempt extern "Rust" from improper_ctypes) - #64642 (Fix the span used to suggest avoiding for-loop moves) Failed merges: r? @ghost
2 parents 5349e69 + 97ca073 commit ed8b708

File tree

67 files changed

+261
-280
lines changed

Some content is hidden

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

67 files changed

+261
-280
lines changed

RELEASES.md

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ Misc
6868
- [`rustc` will now warn about some incorrect uses of
6969
`mem::{uninitialized, zeroed}` that are known to cause undefined behaviour.][63346]
7070

71+
Compatibility Notes
72+
-------------------
73+
- Unfortunately the [`x86_64-unknown-uefi` platform can not be built][62785]
74+
with rustc 1.39.0.
75+
- The [`armv7-unknown-linux-gnueabihf` platform is also known to have
76+
issues][62896] for certain crates such as libc.
77+
7178
[60260]: https://github.com/rust-lang/rust/pull/60260/
7279
[61457]: https://github.com/rust-lang/rust/pull/61457/
7380
[61491]: https://github.com/rust-lang/rust/pull/61491/
@@ -79,7 +86,9 @@ Misc
7986
[62735]: https://github.com/rust-lang/rust/pull/62735/
8087
[62766]: https://github.com/rust-lang/rust/pull/62766/
8188
[62784]: https://github.com/rust-lang/rust/pull/62784/
89+
[62785]: https://github.com/rust-lang/rust/issues/62785/
8290
[62814]: https://github.com/rust-lang/rust/pull/62814/
91+
[62896]: https://github.com/rust-lang/rust/issues/62896/
8392
[63000]: https://github.com/rust-lang/rust/pull/63000/
8493
[63056]: https://github.com/rust-lang/rust/pull/63056/
8594
[63107]: https://github.com/rust-lang/rust/pull/63107/

src/doc/unstable-book/src/language-features/param-attrs.md

-27
This file was deleted.

src/liballoc/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
240240
#[stable(feature = "global_alloc", since = "1.28.0")]
241241
#[rustc_allocator_nounwind]
242242
pub fn handle_alloc_error(layout: Layout) -> ! {
243-
#[allow(improper_ctypes)]
243+
#[cfg_attr(bootstrap, allow(improper_ctypes))]
244244
extern "Rust" {
245245
#[lang = "oom"]
246246
fn oom_impl(layout: Layout) -> !;

src/libcore/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
7171
}
7272

7373
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
74-
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
74+
#[cfg_attr(boostrap_stdarch_ignore_this, allow(improper_ctypes))]
7575
extern "Rust" {
7676
#[lang = "panic_impl"]
7777
fn panic_impl(pi: &PanicInfo<'_>) -> !;

src/librustc/error_codes.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,39 @@ struct Foo<T: 'static> {
13471347
```
13481348
"##,
13491349

1350+
E0312: r##"
1351+
Reference's lifetime of borrowed content doesn't match the expected lifetime.
1352+
1353+
Erroneous code example:
1354+
1355+
```compile_fail,E0312
1356+
pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'static str {
1357+
if maybestr.is_none() {
1358+
"(none)"
1359+
} else {
1360+
let s: &'a str = maybestr.as_ref().unwrap();
1361+
s // Invalid lifetime!
1362+
}
1363+
}
1364+
```
1365+
1366+
To fix this error, either lessen the expected lifetime or find a way to not have
1367+
to use this reference outside of its current scope (by running the code directly
1368+
in the same block for example?):
1369+
1370+
```
1371+
// In this case, we can fix the issue by switching from "static" lifetime to 'a
1372+
pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {
1373+
if maybestr.is_none() {
1374+
"(none)"
1375+
} else {
1376+
let s: &'a str = maybestr.as_ref().unwrap();
1377+
s // Ok!
1378+
}
1379+
}
1380+
```
1381+
"##,
1382+
13501383
E0317: r##"
13511384
This error occurs when an `if` expression without an `else` block is used in a
13521385
context where a type other than `()` is expected, for example a `let`
@@ -2202,7 +2235,6 @@ static X: u32 = 42;
22022235
// E0304, // expected signed integer constant
22032236
// E0305, // expected constant
22042237
E0311, // thing may not live long enough
2205-
E0312, // lifetime of reference outlives lifetime of borrowed content
22062238
E0313, // lifetime of borrowed pointer outlives lifetime of captured
22072239
// variable
22082240
E0314, // closure outlives stack frame

src/librustc/lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use crate::lint::{LintPass, LateLintPass, LintArray};
88
use crate::middle::stability;
99
use crate::session::Session;
10-
use errors::{Applicability, DiagnosticBuilder};
10+
use errors::{Applicability, DiagnosticBuilder, pluralise};
1111
use syntax::ast;
1212
use syntax::source_map::Span;
1313
use syntax::symbol::Symbol;
@@ -524,7 +524,7 @@ pub(crate) fn add_elided_lifetime_in_path_suggestion(
524524
};
525525
db.span_suggestion(
526526
replace_span,
527-
&format!("indicate the anonymous lifetime{}", if n >= 2 { "s" } else { "" }),
527+
&format!("indicate the anonymous lifetime{}", pluralise!(n)),
528528
suggestion,
529529
Applicability::MachineApplicable
530530
);

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
1717
use crate::rustc::lint;
1818
use crate::session::Session;
1919
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
20-
use errors::{Applicability, DiagnosticBuilder};
20+
use errors::{Applicability, DiagnosticBuilder, pluralise};
2121
use rustc_macros::HashStable;
2222
use std::borrow::Cow;
2323
use std::cell::Cell;
@@ -3047,7 +3047,7 @@ pub fn report_missing_lifetime_specifiers(
30473047
span,
30483048
E0106,
30493049
"missing lifetime specifier{}",
3050-
if count > 1 { "s" } else { "" }
3050+
pluralise!(count)
30513051
)
30523052
}
30533053

src/librustc/traits/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::ty::subst::Subst;
3333
use crate::ty::SubtypePredicate;
3434
use crate::util::nodemap::{FxHashMap, FxHashSet};
3535

36-
use errors::{Applicability, DiagnosticBuilder};
36+
use errors::{Applicability, DiagnosticBuilder, pluralise};
3737
use std::fmt;
3838
use syntax::ast;
3939
use syntax::symbol::{sym, kw};
@@ -1214,7 +1214,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12141214
_ => format!("{} {}argument{}",
12151215
arg_length,
12161216
if distinct && arg_length > 1 { "distinct " } else { "" },
1217-
if arg_length == 1 { "" } else { "s" }),
1217+
pluralise!(arg_length))
12181218
}
12191219
};
12201220

src/librustc/ty/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'tcx> ty::TyS<'tcx> {
196196
let n = tcx.lift_to_global(&n).unwrap();
197197
match n.try_eval_usize(tcx, ty::ParamEnv::empty()) {
198198
Some(n) => {
199-
format!("array of {} element{}", n, if n != 1 { "s" } else { "" }).into()
199+
format!("array of {} element{}", n, pluralise!(n)).into()
200200
}
201201
None => "array".into(),
202202
}

src/librustc_lint/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
975975
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
976976
let mut vis = ImproperCTypesVisitor { cx };
977977
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
978-
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
978+
if let Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
979+
// Don't worry about types in internal ABIs.
980+
} else {
979981
match it.node {
980982
hir::ForeignItemKind::Fn(ref decl, _, _) => {
981983
vis.check_foreign_fn(it.hir_id, decl);

src/librustc_lint/unused.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use lint::{LintPass, EarlyLintPass, LateLintPass};
99

1010
use syntax::ast;
1111
use syntax::attr;
12-
use syntax::errors::Applicability;
12+
use syntax::errors::{Applicability, pluralise};
1313
use syntax::feature_gate::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
1414
use syntax::print::pprust;
1515
use syntax::symbol::{kw, sym};
@@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
4848
}
4949

5050
let ty = cx.tables.expr_ty(&expr);
51-
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", false);
51+
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1);
5252

5353
let mut fn_warned = false;
5454
let mut op_warned = false;
@@ -135,21 +135,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
135135
span: Span,
136136
descr_pre: &str,
137137
descr_post: &str,
138-
plural: bool,
138+
plural_len: usize,
139139
) -> bool {
140140
if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
141141
cx.tcx.hir().get_module_parent(expr.hir_id), ty)
142142
{
143143
return true;
144144
}
145145

146-
let plural_suffix = if plural { "s" } else { "" };
146+
let plural_suffix = pluralise!(plural_len);
147147

148148
match ty.sty {
149149
ty::Adt(..) if ty.is_box() => {
150150
let boxed_ty = ty.boxed_ty();
151151
let descr_pre = &format!("{}boxed ", descr_pre);
152-
check_must_use_ty(cx, boxed_ty, expr, span, descr_pre, descr_post, plural)
152+
check_must_use_ty(cx, boxed_ty, expr, span, descr_pre, descr_post, plural_len)
153153
}
154154
ty::Adt(def, _) => {
155155
check_must_use_def(cx, def.did, span, descr_pre, descr_post)
@@ -202,7 +202,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
202202
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
203203
let descr_post = &format!(" in tuple element {}", i);
204204
let span = *spans.get(i).unwrap_or(&span);
205-
if check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, plural) {
205+
if check_must_use_ty(
206+
cx,
207+
ty,
208+
expr,
209+
span,
210+
descr_pre,
211+
descr_post,
212+
plural_len
213+
) {
206214
has_emitted = true;
207215
}
208216
}
@@ -216,7 +224,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
216224
descr_pre,
217225
plural_suffix,
218226
);
219-
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, true)
227+
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, n as usize + 1)
220228
}
221229
// Otherwise, we don't lint, to avoid false positives.
222230
_ => false,

src/librustc_mir/borrow_check/conflict_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
180180
);
181181
}
182182
if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
183-
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
183+
let sess = self.infcx.tcx.sess;
184+
if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
184185
err.span_suggestion(
185186
move_span,
186187
"consider borrowing to avoid moving into the for loop",

src/librustc_resolve/check_unused.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use crate::Resolver;
2727
use crate::resolve_imports::ImportDirectiveSubclass;
2828

29+
use errors::pluralise;
30+
2931
use rustc::util::nodemap::NodeMap;
3032
use rustc::{lint, ty};
3133
use rustc_data_structures::fx::FxHashSet;
@@ -295,7 +297,7 @@ impl Resolver<'_> {
295297
}).collect::<Vec<String>>();
296298
span_snippets.sort();
297299
let msg = format!("unused import{}{}",
298-
if len > 1 { "s" } else { "" },
300+
pluralise!(len),
299301
if !span_snippets.is_empty() {
300302
format!(": {}", span_snippets.join(", "))
301303
} else {

src/librustc_resolve/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'a> LateResolutionVisitor<'a, '_> {
424424
} else {
425425
err.note("did you mean to use one of the enum's variants?");
426426
}
427-
},
427+
}
428428
(Res::Def(DefKind::Struct, def_id), _) if ns == ValueNS => {
429429
if let Some((ctor_def, ctor_vis))
430430
= self.r.struct_constructors.get(&def_id).cloned() {

src/librustc_resolve/resolve_imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{Resolver, ResolutionError, Segment, ModuleKind};
1111
use crate::{names_to_string, module_to_string};
1212
use crate::diagnostics::Suggestion;
1313

14-
use errors::Applicability;
14+
use errors::{Applicability, pluralise};
1515

1616
use rustc_data_structures::ptr_key::PtrKey;
1717
use rustc::ty;
@@ -728,7 +728,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
728728

729729
let msg = format!(
730730
"unresolved import{} {}",
731-
if paths.len() > 1 { "s" } else { "" },
731+
pluralise!(paths.len()),
732732
paths.join(", "),
733733
);
734734

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13461346
span,
13471347
E0191,
13481348
"the value of the associated type{} {} must be specified",
1349-
if associated_types.len() == 1 { "" } else { "s" },
1349+
pluralise!(associated_types.len()),
13501350
names,
13511351
);
13521352
let (suggest, potential_assoc_types_spans) =

src/librustc_typeck/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::util::common::ErrorReported;
1717
use crate::util::nodemap::FxHashMap;
1818
use crate::astconv::AstConv as _;
1919

20-
use errors::{Applicability, DiagnosticBuilder};
20+
use errors::{Applicability, DiagnosticBuilder, pluralise};
2121
use syntax::ast;
2222
use syntax::symbol::{Symbol, kw, sym};
2323
use syntax::source_map::Span;
@@ -1178,7 +1178,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11781178

11791179
struct_span_err!(tcx.sess, span, E0063,
11801180
"missing field{} {}{} in initializer of `{}`",
1181-
if remaining_fields.len() == 1 { "" } else { "s" },
1181+
pluralise!(remaining_fields.len()),
11821182
remaining_fields_names,
11831183
truncated_fields_error,
11841184
adt_ty)

src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::check::FnCtxt;
55
use crate::middle::lang_items::FnOnceTraitLangItem;
66
use crate::namespace::Namespace;
77
use crate::util::nodemap::FxHashSet;
8-
use errors::{Applicability, DiagnosticBuilder};
8+
use errors::{Applicability, DiagnosticBuilder, pluralise};
99
use rustc::hir::{self, ExprKind, Node, QPath};
1010
use rustc::hir::def::{Res, DefKind};
1111
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
@@ -560,7 +560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
560560
let help = format!("{an}other candidate{s} {were} found in the following \
561561
trait{s}, perhaps add a `use` for {one_of_them}:",
562562
an = if candidates.len() == 1 {"an" } else { "" },
563-
s = if candidates.len() == 1 { "" } else { "s" },
563+
s = pluralise!(candidates.len()),
564564
were = if candidates.len() == 1 { "was" } else { "were" },
565565
one_of_them = if candidates.len() == 1 {
566566
"it"

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub mod intrinsic;
8888
mod op;
8989

9090
use crate::astconv::{AstConv, PathSeg};
91-
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
91+
use errors::{Applicability, DiagnosticBuilder, DiagnosticId, pluralise};
9292
use rustc::hir::{self, ExprKind, GenericArg, ItemKind, Node, PatKind, QPath};
9393
use rustc::hir::def::{CtorOf, Res, DefKind};
9494
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -4935,5 +4935,5 @@ fn fatally_break_rust(sess: &Session) {
49354935
}
49364936

49374937
fn potentially_plural_count(count: usize, word: &str) -> String {
4938-
format!("{} {}{}", count, word, if count == 1 { "" } else { "s" })
4938+
format!("{} {}{}", count, word, pluralise!(count))
49394939
}

0 commit comments

Comments
 (0)