Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #72379

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4088,7 +4088,6 @@ dependencies = [
"log",
"measureme",
"polonius-engine",
"rustc-rayon",
"rustc-rayon-core",
"rustc_apfloat",
"rustc_ast",
Expand Down Expand Up @@ -4151,7 +4150,6 @@ dependencies = [
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_macros",
"rustc_middle",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4295,7 +4293,6 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_fs_util",
"rustc_index",
"rustc_span",
"rustc_target",
"serialize",
Expand Down Expand Up @@ -4328,7 +4325,6 @@ dependencies = [
"rustc_ast",
"rustc_data_structures",
"rustc_hir",
"rustc_metadata",
"rustc_middle",
"rustc_session",
"rustc_span",
Expand Down
7 changes: 3 additions & 4 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,15 @@ impl<T, A: AllocRef> RawVec<T, A> {
needed_extra_capacity: usize,
placement: ReallocPlacement,
) -> Result<(), TryReserveError> {
// This is ensured by the calling contexts.
debug_assert!(needed_extra_capacity > 0);

if mem::size_of::<T>() == 0 {
// Since we return a capacity of `usize::MAX` when `elem_size` is
// 0, getting to here necessarily means the `RawVec` is overfull.
return Err(CapacityOverflow);
}

if needed_extra_capacity == 0 {
return Ok(());
}

// Nothing we can really do about these checks, sadly.
let required_cap =
used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
Expand Down
26 changes: 13 additions & 13 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ impl<T> [T] {
/// assert_eq!(iter.next().unwrap(), &[10, 40, 33]);
/// assert!(iter.next().is_none());
/// ```
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
#[inline]
pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, T, F>
where
Expand All @@ -1194,7 +1194,7 @@ impl<T> [T] {
/// }
/// assert_eq!(v, [10, 40, 1, 20, 1, 1]);
/// ```
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
#[inline]
pub fn split_inclusive_mut<F>(&mut self, pred: F) -> SplitInclusiveMut<'_, T, F>
where
Expand Down Expand Up @@ -3852,7 +3852,7 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
///
/// [`split_inclusive`]: ../../std/primitive.slice.html#method.split_inclusive
/// [slices]: ../../std/primitive.slice.html
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
pub struct SplitInclusive<'a, T: 'a, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -3862,7 +3862,7 @@ where
finished: bool,
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusive<'_, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -3876,7 +3876,7 @@ where
}

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<T, P> Clone for SplitInclusive<'_, T, P>
where
P: Clone + FnMut(&T) -> bool,
Expand All @@ -3886,7 +3886,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, T, P> Iterator for SplitInclusive<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -3915,7 +3915,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, T, P> DoubleEndedIterator for SplitInclusive<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -3940,7 +3940,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool {}

/// An iterator over the mutable subslices of the vector which are separated
Expand Down Expand Up @@ -4065,7 +4065,7 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
///
/// [`split_inclusive_mut`]: ../../std/primitive.slice.html#method.split_inclusive_mut
/// [slices]: ../../std/primitive.slice.html
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
pub struct SplitInclusiveMut<'a, T: 'a, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -4075,7 +4075,7 @@ where
finished: bool,
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<T: fmt::Debug, P> fmt::Debug for SplitInclusiveMut<'_, T, P>
where
P: FnMut(&T) -> bool,
Expand All @@ -4088,7 +4088,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, T, P> Iterator for SplitInclusiveMut<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -4128,7 +4128,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, T, P> DoubleEndedIterator for SplitInclusiveMut<'a, T, P>
where
P: FnMut(&T) -> bool,
Expand Down Expand Up @@ -4162,7 +4162,7 @@ where
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> bool {}

/// An iterator over subslices separated by elements that match a predicate
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3335,7 +3335,7 @@ impl str {
/// .split_inclusive('\n').collect();
/// assert_eq!(v, ["Mary had a little lamb\n", "little lamb\n", "little lamb.\n"]);
/// ```
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
#[inline]
pub fn split_inclusive<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitInclusive<'a, P> {
SplitInclusive(SplitInternal {
Expand Down Expand Up @@ -4575,7 +4575,7 @@ pub struct SplitAsciiWhitespace<'a> {
///
/// [`split_inclusive`]: ../../std/primitive.str.html#method.split_inclusive
/// [`str`]: ../../std/primitive.str.html
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
pub struct SplitInclusive<'a, P: Pattern<'a>>(SplitInternal<'a, P>);

impl_fn_for_zst! {
Expand Down Expand Up @@ -4668,7 +4668,7 @@ impl<'a> DoubleEndedIterator for SplitAsciiWhitespace<'a> {
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
impl FusedIterator for SplitAsciiWhitespace<'_> {}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
type Item = &'a str;

Expand All @@ -4678,22 +4678,22 @@ impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, P: Pattern<'a, Searcher: fmt::Debug>> fmt::Debug for SplitInclusive<'a, P> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SplitInclusive").field("0", &self.0).finish()
}
}

// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, P: Pattern<'a, Searcher: Clone>> Clone for SplitInclusive<'a, P> {
fn clone(&self) -> Self {
SplitInclusive(self.0.clone())
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
for SplitInclusive<'a, P>
{
Expand All @@ -4703,7 +4703,7 @@ impl<'a, P: Pattern<'a, Searcher: ReverseSearcher<'a>>> DoubleEndedIterator
}
}

#[unstable(feature = "split_inclusive", issue = "none")]
#[unstable(feature = "split_inclusive", issue = "72360")]
impl<'a, P: Pattern<'a>> FusedIterator for SplitInclusive<'a, P> {}

/// An iterator of [`u16`] over the string encoded as UTF-16.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
"`async` generators are not yet supported"
)
.emit();
return hir::ExprKind::Err;
}
None => self.generator_kind = Some(hir::GeneratorKind::Gen),
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ arena = { path = "../libarena" }
bitflags = "1.2.1"
scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0"
polonius-engine = "0.12.0"
rustc_apfloat = { path = "../librustc_apfloat" }
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,16 +1114,13 @@ impl<'tcx> TyCtxt<'tcx> {

let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map {
// FIXME(#71104) Should really be using just `node_id_to_hir_id` but
// some `NodeId` do not seem to have a corresponding HirId.
if let Some(hir_id) = definitions.opt_node_id_to_hir_id(k) {
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}
let hir_id = definitions.node_id_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}

GlobalCtxt {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ rustc_index = { path = "../librustc_index" }
rustc_errors = { path = "../librustc_errors" }
rustc_hir = { path = "../librustc_hir" }
rustc_infer = { path = "../librustc_infer" }
rustc_macros = { path = "../librustc_macros" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }
Expand Down
29 changes: 26 additions & 3 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
return;
}

// Replace `use foo::self;` with `use foo;`
// Replace `use foo::{ self };` with `use foo;`
source = module_path.pop().unwrap();
if rename.is_none() {
ident = source.ident;
Expand All @@ -435,10 +435,33 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
} else {
// Disallow `self`
if source.ident.name == kw::SelfLower {
let parent = module_path.last();

let span = match parent {
// only `::self` from `use foo::self as bar`
Some(seg) => seg.ident.span.shrink_to_hi().to(source.ident.span),
None => source.ident.span,
};
let span_with_rename = match rename {
// only `self as bar` from `use foo::self as bar`
Some(rename) => source.ident.span.to(rename.span),
None => source.ident.span,
};
self.r.report_error(
use_tree.span,
ResolutionError::SelfImportsOnlyAllowedWithin,
span,
ResolutionError::SelfImportsOnlyAllowedWithin {
root: parent.is_none(),
span_with_rename,
},
);

// Error recovery: replace `use foo::self;` with `use foo;`
if let Some(parent) = module_path.pop() {
source = parent;
if rename.is_none() {
ident = source.ident;
}
}
}

// Disallow `use $crate;`
Expand Down
41 changes: 34 additions & 7 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,40 @@ impl<'a> Resolver<'a> {
}
err
}
ResolutionError::SelfImportsOnlyAllowedWithin => struct_span_err!(
self.session,
span,
E0429,
"{}",
"`self` imports are only allowed within a { } list"
),
ResolutionError::SelfImportsOnlyAllowedWithin { root, span_with_rename } => {
let mut err = struct_span_err!(
self.session,
span,
E0429,
"{}",
"`self` imports are only allowed within a { } list"
);

// None of the suggestions below would help with a case like `use self`.
if !root {
// use foo::bar::self -> foo::bar
// use foo::bar::self as abc -> foo::bar as abc
err.span_suggestion(
span,
"consider importing the module directly",
"".to_string(),
Applicability::MachineApplicable,
);

// use foo::bar::self -> foo::bar::{self}
// use foo::bar::self as abc -> foo::bar::{self as abc}
let braces = vec![
(span_with_rename.shrink_to_lo(), "{".to_string()),
(span_with_rename.shrink_to_hi(), "}".to_string()),
];
err.multipart_suggestion(
"alternatively, use the multi-path `use` syntax to import `self`",
braces,
Applicability::MachineApplicable,
);
}
err
}
ResolutionError::SelfImportCanOnlyAppearOnceInTheList => {
let mut err = struct_span_err!(
self.session,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ enum ResolutionError<'a> {
/// Error E0426: use of undeclared label.
UndeclaredLabel(&'a str, Option<Symbol>),
/// Error E0429: `self` imports are only allowed within a `{ }` list.
SelfImportsOnlyAllowedWithin,
SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span },
/// Error E0430: `self` import can only appear once in the list.
SelfImportCanOnlyAppearOnceInTheList,
/// Error E0431: `self` import can only appear in an import list with a non-empty prefix.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ rustc_target = { path = "../librustc_target" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_span = { path = "../librustc_span" }
rustc_index = { path = "../librustc_index" }
rustc_fs_util = { path = "../librustc_fs_util" }
num_cpus = "1.0"
rustc_ast = { path = "../librustc_ast" }
1 change: 0 additions & 1 deletion src/librustc_symbol_mangling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ rustc_middle = { path = "../librustc_middle" }
rustc_hir = { path = "../librustc_hir" }
rustc_target = { path = "../librustc_target" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_session = { path = "../librustc_session" }
Loading