Skip to content

Commit a8437cf

Browse files
committed
Auto merge of #69507 - JohnTitor:rollup-jqf1gmw, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #69324 (Backport only: avoid ICE on bad placeholder type) - #69439 (resolve: `lifetimes.rs` -> `late/lifetimes.rs`) - #69473 (update llvm to silence gcc 9 warnings) - #69479 (clarify operator precedence) - #69480 (Clean up E0373 explanation) - #69500 (Simplify the signature of par_for_each_in) - #69505 (Enable setting diagnostic labels) Failed merges: r? @ghost
2 parents d28560e + c384ace commit a8437cf

File tree

19 files changed

+589
-329
lines changed

19 files changed

+589
-329
lines changed

src/libcore/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<S: Sip> super::Hasher for Hasher<S> {
304304

305305
if self.ntail != 0 {
306306
needed = 8 - self.ntail;
307-
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail;
307+
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail);
308308
if length < needed {
309309
self.ntail += length;
310310
return;

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ impl SpecializedEncoder<IntEncodedWithFixedSize> for opaque::Encoder {
997997
fn specialized_encode(&mut self, x: &IntEncodedWithFixedSize) -> Result<(), Self::Error> {
998998
let start_pos = self.position();
999999
for i in 0..IntEncodedWithFixedSize::ENCODED_SIZE {
1000-
((x.0 >> i * 8) as u8).encode(self)?;
1000+
((x.0 >> (i * 8)) as u8).encode(self)?;
10011001
}
10021002
let end_pos = self.position();
10031003
assert_eq!((end_pos - start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);

src/librustc_data_structures/sip128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl Hasher for SipHasher128 {
274274

275275
if self.ntail != 0 {
276276
needed = 8 - self.ntail;
277-
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail;
277+
self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail);
278278
if length < needed {
279279
self.ntail += length;
280280
return;

src/librustc_data_structures/sync.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ cfg_if! {
203203
t.into_iter()
204204
}
205205

206-
pub fn par_for_each_in<T: IntoIterator>(
207-
t: T,
208-
for_each:
209-
impl Fn(<<T as IntoIterator>::IntoIter as Iterator>::Item) + Sync + Send
210-
) {
206+
pub fn par_for_each_in<T: IntoIterator>(t: T, for_each: impl Fn(T::Item) + Sync + Send) {
211207
// We catch panics here ensuring that all the loop iterations execute.
212208
// This makes behavior consistent with the parallel compiler.
213209
let mut panic = None;
@@ -397,9 +393,7 @@ cfg_if! {
397393

398394
pub fn par_for_each_in<T: IntoParallelIterator>(
399395
t: T,
400-
for_each: impl Fn(
401-
<<T as IntoParallelIterator>::Iter as ParallelIterator>::Item
402-
) + Sync + Send
396+
for_each: impl Fn(T::Item) + Sync + Send,
403397
) {
404398
t.into_par_iter().for_each(for_each)
405399
}

src/librustc_error_codes/error_codes/E0373.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
This error occurs when an attempt is made to use data captured by a closure,
2-
when that data may no longer exist. It's most commonly seen when attempting to
3-
return a closure:
1+
A captured variable in a closure may not live long enough.
2+
3+
Erroneous code example:
44

55
```compile_fail,E0373
66
fn foo() -> Box<Fn(u32) -> u32> {
@@ -9,6 +9,10 @@ fn foo() -> Box<Fn(u32) -> u32> {
99
}
1010
```
1111

12+
This error occurs when an attempt is made to use data captured by a closure,
13+
when that data may no longer exist. It's most commonly seen when attempting to
14+
return a closure as shown in the previous code example.
15+
1216
Notice that `x` is stack-allocated by `foo()`. By default, Rust captures
1317
closed-over data by reference. This means that once `foo()` returns, `x` no
1418
longer exists. An attempt to access `x` within the closure would thus be

src/librustc_resolve/diagnostics.rs

+1-242
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use rustc::session::Session;
66
use rustc::ty::{self, DefIdTree};
77
use rustc_ast_pretty::pprust;
88
use rustc_data_structures::fx::FxHashSet;
9-
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
9+
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
1010
use rustc_feature::BUILTIN_ATTRIBUTES;
11-
use rustc_hir as hir;
1211
use rustc_hir::def::Namespace::{self, *};
1312
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind};
1413
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
@@ -20,7 +19,6 @@ use syntax::ast::{self, Ident, Path};
2019
use syntax::util::lev_distance::find_best_match_for_name;
2120

2221
use crate::imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
23-
use crate::lifetimes::{ElisionFailureInfo, LifetimeContext};
2422
use crate::path_names_to_string;
2523
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
2624
use crate::{BindingError, CrateLint, HasGenericParams, LegacyScope, Module, ModuleOrUniformRoot};
@@ -49,40 +47,6 @@ crate struct ImportSuggestion {
4947
pub path: Path,
5048
}
5149

52-
crate enum MissingLifetimeSpot<'tcx> {
53-
Generics(&'tcx hir::Generics<'tcx>),
54-
HigherRanked { span: Span, span_type: ForLifetimeSpanType },
55-
}
56-
57-
crate enum ForLifetimeSpanType {
58-
BoundEmpty,
59-
BoundTail,
60-
TypeEmpty,
61-
TypeTail,
62-
}
63-
64-
impl ForLifetimeSpanType {
65-
crate fn descr(&self) -> &'static str {
66-
match self {
67-
Self::BoundEmpty | Self::BoundTail => "bound",
68-
Self::TypeEmpty | Self::TypeTail => "type",
69-
}
70-
}
71-
72-
crate fn suggestion(&self, sugg: &str) -> String {
73-
match self {
74-
Self::BoundEmpty | Self::TypeEmpty => format!("for<{}> ", sugg),
75-
Self::BoundTail | Self::TypeTail => format!(", {}", sugg),
76-
}
77-
}
78-
}
79-
80-
impl<'tcx> Into<MissingLifetimeSpot<'tcx>> for &'tcx hir::Generics<'tcx> {
81-
fn into(self) -> MissingLifetimeSpot<'tcx> {
82-
MissingLifetimeSpot::Generics(self)
83-
}
84-
}
85-
8650
/// Adjust the impl span so that just the `impl` keyword is taken by removing
8751
/// everything after `<` (`"impl<T> Iterator for A<T> {}" -> "impl"`) and
8852
/// everything after the first whitespace (`"impl Iterator for A" -> "impl"`).
@@ -1491,208 +1455,3 @@ crate fn show_candidates(
14911455
err.note(&msg);
14921456
}
14931457
}
1494-
1495-
impl<'tcx> LifetimeContext<'_, 'tcx> {
1496-
crate fn report_missing_lifetime_specifiers(
1497-
&self,
1498-
span: Span,
1499-
count: usize,
1500-
) -> DiagnosticBuilder<'tcx> {
1501-
struct_span_err!(
1502-
self.tcx.sess,
1503-
span,
1504-
E0106,
1505-
"missing lifetime specifier{}",
1506-
pluralize!(count)
1507-
)
1508-
}
1509-
1510-
crate fn emit_undeclared_lifetime_error(&self, lifetime_ref: &hir::Lifetime) {
1511-
let mut err = struct_span_err!(
1512-
self.tcx.sess,
1513-
lifetime_ref.span,
1514-
E0261,
1515-
"use of undeclared lifetime name `{}`",
1516-
lifetime_ref
1517-
);
1518-
err.span_label(lifetime_ref.span, "undeclared lifetime");
1519-
for missing in &self.missing_named_lifetime_spots {
1520-
match missing {
1521-
MissingLifetimeSpot::Generics(generics) => {
1522-
let (span, sugg) = if let Some(param) = generics
1523-
.params
1524-
.iter()
1525-
.filter(|p| match p.kind {
1526-
hir::GenericParamKind::Type {
1527-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1528-
..
1529-
} => false,
1530-
_ => true,
1531-
})
1532-
.next()
1533-
{
1534-
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
1535-
} else {
1536-
(generics.span, format!("<{}>", lifetime_ref))
1537-
};
1538-
err.span_suggestion(
1539-
span,
1540-
&format!("consider introducing lifetime `{}` here", lifetime_ref),
1541-
sugg,
1542-
Applicability::MaybeIncorrect,
1543-
);
1544-
}
1545-
MissingLifetimeSpot::HigherRanked { span, span_type } => {
1546-
err.span_suggestion(
1547-
*span,
1548-
&format!(
1549-
"consider making the {} lifetime-generic with a new `{}` lifetime",
1550-
span_type.descr(),
1551-
lifetime_ref
1552-
),
1553-
span_type.suggestion(&lifetime_ref.to_string()),
1554-
Applicability::MaybeIncorrect,
1555-
);
1556-
err.note(
1557-
"for more information on higher-ranked polymorphism, visit \
1558-
https://doc.rust-lang.org/nomicon/hrtb.html",
1559-
);
1560-
}
1561-
}
1562-
}
1563-
err.emit();
1564-
}
1565-
1566-
crate fn is_trait_ref_fn_scope(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) -> bool {
1567-
if let def::Res::Def(_, did) = trait_ref.trait_ref.path.res {
1568-
if [
1569-
self.tcx.lang_items().fn_once_trait(),
1570-
self.tcx.lang_items().fn_trait(),
1571-
self.tcx.lang_items().fn_mut_trait(),
1572-
]
1573-
.contains(&Some(did))
1574-
{
1575-
let (span, span_type) = match &trait_ref.bound_generic_params {
1576-
[] => (trait_ref.span.shrink_to_lo(), ForLifetimeSpanType::BoundEmpty),
1577-
[.., bound] => (bound.span.shrink_to_hi(), ForLifetimeSpanType::BoundTail),
1578-
};
1579-
self.missing_named_lifetime_spots
1580-
.push(MissingLifetimeSpot::HigherRanked { span, span_type });
1581-
return true;
1582-
}
1583-
};
1584-
false
1585-
}
1586-
1587-
crate fn add_missing_lifetime_specifiers_label(
1588-
&self,
1589-
err: &mut DiagnosticBuilder<'_>,
1590-
span: Span,
1591-
count: usize,
1592-
lifetime_names: &FxHashSet<ast::Ident>,
1593-
params: &[ElisionFailureInfo],
1594-
) {
1595-
if count > 1 {
1596-
err.span_label(span, format!("expected {} lifetime parameters", count));
1597-
} else {
1598-
let snippet = self.tcx.sess.source_map().span_to_snippet(span).ok();
1599-
let suggest_existing = |err: &mut DiagnosticBuilder<'_>, sugg| {
1600-
err.span_suggestion(
1601-
span,
1602-
"consider using the named lifetime",
1603-
sugg,
1604-
Applicability::MaybeIncorrect,
1605-
);
1606-
};
1607-
let suggest_new =
1608-
|err: &mut DiagnosticBuilder<'_>, sugg: &str| {
1609-
err.span_label(span, "expected named lifetime parameter");
1610-
1611-
for missing in self.missing_named_lifetime_spots.iter().rev() {
1612-
let mut introduce_suggestion = vec![];
1613-
let msg;
1614-
let should_break;
1615-
introduce_suggestion.push(match missing {
1616-
MissingLifetimeSpot::Generics(generics) => {
1617-
msg = "consider introducing a named lifetime parameter".to_string();
1618-
should_break = true;
1619-
if let Some(param) = generics.params.iter().filter(|p| match p.kind {
1620-
hir::GenericParamKind::Type {
1621-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1622-
..
1623-
} => false,
1624-
_ => true,
1625-
}).next() {
1626-
(param.span.shrink_to_lo(), "'a, ".to_string())
1627-
} else {
1628-
(generics.span, "<'a>".to_string())
1629-
}
1630-
}
1631-
MissingLifetimeSpot::HigherRanked { span, span_type } => {
1632-
msg = format!(
1633-
"consider making the {} lifetime-generic with a new `'a` lifetime",
1634-
span_type.descr(),
1635-
);
1636-
should_break = false;
1637-
err.note(
1638-
"for more information on higher-ranked polymorphism, visit \
1639-
https://doc.rust-lang.org/nomicon/hrtb.html",
1640-
);
1641-
(*span, span_type.suggestion("'a"))
1642-
}
1643-
});
1644-
for param in params {
1645-
if let Ok(snippet) =
1646-
self.tcx.sess.source_map().span_to_snippet(param.span)
1647-
{
1648-
if snippet.starts_with("&") && !snippet.starts_with("&'") {
1649-
introduce_suggestion
1650-
.push((param.span, format!("&'a {}", &snippet[1..])));
1651-
} else if snippet.starts_with("&'_ ") {
1652-
introduce_suggestion
1653-
.push((param.span, format!("&'a {}", &snippet[4..])));
1654-
}
1655-
}
1656-
}
1657-
introduce_suggestion.push((span, sugg.to_string()));
1658-
err.multipart_suggestion(
1659-
&msg,
1660-
introduce_suggestion,
1661-
Applicability::MaybeIncorrect,
1662-
);
1663-
if should_break {
1664-
break;
1665-
}
1666-
}
1667-
};
1668-
1669-
match (
1670-
lifetime_names.len(),
1671-
lifetime_names.iter().next(),
1672-
snippet.as_ref().map(|s| s.as_str()),
1673-
) {
1674-
(1, Some(name), Some("&")) => {
1675-
suggest_existing(err, format!("&{} ", name));
1676-
}
1677-
(1, Some(name), Some("'_")) => {
1678-
suggest_existing(err, name.to_string());
1679-
}
1680-
(1, Some(name), Some(snippet)) if !snippet.ends_with(">") => {
1681-
suggest_existing(err, format!("{}<{}>", snippet, name));
1682-
}
1683-
(0, _, Some("&")) => {
1684-
suggest_new(err, "&'a ");
1685-
}
1686-
(0, _, Some("'_")) => {
1687-
suggest_new(err, "'a");
1688-
}
1689-
(0, _, Some(snippet)) if !snippet.ends_with(">") => {
1690-
suggest_new(err, &format!("{}<'a>", snippet));
1691-
}
1692-
_ => {
1693-
err.span_label(span, "expected lifetime parameter");
1694-
}
1695-
}
1696-
}
1697-
}
1698-
}

src/librustc_resolve/late.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use std::collections::BTreeSet;
3232
use std::mem::replace;
3333

3434
mod diagnostics;
35+
crate mod lifetimes;
3536

3637
type Res = def::Res<NodeId>;
3738

0 commit comments

Comments
 (0)