Skip to content

Rollup of 10 pull requests #70275

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

Merged
merged 29 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
becebf3
Ammend Rc/Arc::from_raw() docs regarding unsafety
lukaslueg Jan 10, 2020
b4c96a9
Refine [Arc/Rc]::from_raw() docs
lukaslueg Jan 28, 2020
586c7e3
Make rc::RcBox and sync::ArcInner repr(C)
lukaslueg Feb 3, 2020
6f6fe38
parse/lexer: support `StringReader::retokenize` called on external fi…
eddyb Mar 20, 2020
4d30b92
recover on `for<'a> |...| body` closures.
Centril Mar 21, 2020
a9c2378
fix type of const params in associated types.
lcnr Mar 21, 2020
54e103b
don't convert results to options just for matching (clippy::if_let_so…
matthiaskrgr Mar 21, 2020
1dcbdbd
use let instead of match for matches with single bindings (clippy::ma…
matthiaskrgr Mar 21, 2020
5566a1c
remove redundant returns (clippy::needless_return)
matthiaskrgr Mar 21, 2020
3b4c2f6
don't redundantly repeat field names (clippy::redundant_field_names)
matthiaskrgr Mar 21, 2020
c8140a8
Return NonZeroU64 from ThreadId::as_u64.
Mar 21, 2020
a6692b7
clarify when we pass () to functions (clippy::unit_arg)
matthiaskrgr Mar 21, 2020
47e9775
make some let-if-bindings more idiomatic (clippy::useless_let_if_seq)
matthiaskrgr Mar 21, 2020
e45fdcf
remove unused unit values (clippy::unused_unit)
matthiaskrgr Mar 21, 2020
c746d93
Remove wrong entry from RELEASES.md
jplatte Mar 21, 2020
3f42104
Remove another wrong entry from RELEASES.md
jplatte Mar 21, 2020
3599fd3
summarize if-else-code with identical blocks (clippy::if_same_then_else)
matthiaskrgr Mar 21, 2020
74d68ea
don't create variable bindings just to return the bound value immedia…
matthiaskrgr Mar 21, 2020
bdd07f9
proc_macro_harness: Use item header spans for errors
petrochenkov Mar 22, 2020
0bc5fc9
Rollup merge of #68099 - lukaslueg:into_raw_unsafe, r=LukasKalbertodt
Dylan-DPC Mar 22, 2020
9890d9a
Rollup merge of #70172 - eddyb:retokenize-external-src, r=petrochenkov
Dylan-DPC Mar 22, 2020
ea44d71
Rollup merge of #70209 - Centril:recover-quant-closure, r=petrochenkov
Dylan-DPC Mar 22, 2020
3c8f8b6
Rollup merge of #70223 - lcnr:issue70167, r=eddyb
Dylan-DPC Mar 22, 2020
e58fec0
Rollup merge of #70229 - matthiaskrgr:cl3ppy, r=Mark-Simulacrum
Dylan-DPC Mar 22, 2020
c882b10
Rollup merge of #70240 - brain0:thread_id, r=Mark-Simulacrum
Dylan-DPC Mar 22, 2020
bc3dad1
Rollup merge of #70250 - jplatte:patch-1, r=Centril
Dylan-DPC Mar 22, 2020
e5d3476
Rollup merge of #70253 - jplatte:patch-2, r=Mark-Simulacrum
Dylan-DPC Mar 22, 2020
8fe8bad
Rollup merge of #70254 - matthiaskrgr:cl4ppy, r=Centril
Dylan-DPC Mar 22, 2020
69c0bcd
Rollup merge of #70266 - petrochenkov:prochead, r=varkor
Dylan-DPC Mar 22, 2020
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
3 changes: 0 additions & 3 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4838,7 +4838,6 @@ Version 1.11.0 (2016-08-18)
Language
--------

* [`cfg_attr` works on `path` attributes](https://github.com/rust-lang/rust/pull/34546)
* [Support nested `cfg_attr` attributes](https://github.com/rust-lang/rust/pull/34216)
* [Allow statement-generating braced macro invocations at the end of blocks](https://github.com/rust-lang/rust/pull/34436)
* [Macros can be expanded inside of trait definitions](https://github.com/rust-lang/rust/pull/34213)
Expand Down Expand Up @@ -4957,8 +4956,6 @@ Version 1.10.0 (2016-07-07)
Language
--------

* [Allow `concat_idents!` in type positions as well as in expression
positions](https://github.com/rust-lang/rust/pull/33735).
* [`Copy` types are required to have a trivial implementation of `Clone`](https://github.com/rust-lang/rust/pull/33420).
[RFC 1521](https://github.com/rust-lang/rfcs/blob/master/text/1521-copy-clone-semantics.md).
* [Single-variant enums support the `#[repr(..)]` attribute](https://github.com/rust-lang/rust/pull/33355).
Expand Down
23 changes: 18 additions & 5 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ use crate::vec::Vec;
#[cfg(test)]
mod tests;

// This is repr(C) to future-proof against possible field-reordering, which
// would interfere with otherwise safe [into|from]_raw() of transmutable
// inner types.
#[repr(C)]
struct RcBox<T: ?Sized> {
strong: Cell<usize>,
weak: Cell<usize>,
Expand Down Expand Up @@ -580,15 +584,24 @@ impl<T: ?Sized> Rc<T> {
}
}

/// Constructs an `Rc` from a raw pointer.
/// Constructs an `Rc<T>` from a raw pointer.
///
/// The raw pointer must have been previously returned by a call to a
/// [`Rc::into_raw`][into_raw].
/// The raw pointer must have been previously returned by a call to
/// [`Rc<U>::into_raw`][into_raw] where `U` must have the same size
/// and alignment as `T`. This is trivially true if `U` is `T`.
/// Note that if `U` is not `T` but has the same size and alignment, this is
/// basically like transmuting references of different types. See
/// [`mem::transmute`][transmute] for more information on what
/// restrictions apply in this case.
///
/// This function is unsafe because improper use may lead to memory problems. For example, a
/// double-free may occur if the function is called twice on the same raw pointer.
/// The user of `from_raw` has to make sure a specific value of `T` is only
/// dropped once.
///
/// This function is unsafe because improper use may lead to memory unsafety,
/// even if the returned `Rc<T>` is never accessed.
///
/// [into_raw]: struct.Rc.html#method.into_raw
/// [transmute]: ../../std/mem/fn.transmute.html
///
/// # Examples
///
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ mod hack {
unsafe {
let len = b.len();
let b = Box::into_raw(b);
let xs = Vec::from_raw_parts(b as *mut T, len, len);
xs
Vec::from_raw_parts(b as *mut T, len, len)
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
}
}

// This is repr(C) to future-proof against possible field-reordering, which
// would interfere with otherwise safe [into|from]_raw() of transmutable
// inner types.
#[repr(C)]
struct ArcInner<T: ?Sized> {
strong: atomic::AtomicUsize,

Expand Down Expand Up @@ -577,15 +581,24 @@ impl<T: ?Sized> Arc<T> {
}
}

/// Constructs an `Arc` from a raw pointer.
/// Constructs an `Arc<T>` from a raw pointer.
///
/// The raw pointer must have been previously returned by a call to a
/// [`Arc::into_raw`][into_raw].
/// The raw pointer must have been previously returned by a call to
/// [`Arc<U>::into_raw`][into_raw] where `U` must have the same size and
/// alignment as `T`. This is trivially true if `U` is `T`.
/// Note that if `U` is not `T` but has the same size and alignment, this is
/// basically like transmuting references of different types. See
/// [`mem::transmute`][transmute] for more information on what
/// restrictions apply in this case.
///
/// This function is unsafe because improper use may lead to memory problems. For example, a
/// double-free may occur if the function is called twice on the same raw pointer.
/// The user of `from_raw` has to make sure a specific value of `T` is only
/// dropped once.
///
/// This function is unsafe because improper use may lead to memory unsafety,
/// even if the returned `Arc<T>` is never accessed.
///
/// [into_raw]: struct.Arc.html#method.into_raw
/// [transmute]: ../../std/mem/fn.transmute.html
///
/// # Examples
///
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,7 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
};

let map = tcx.arena.alloc(IndexedHir { crate_hash, map });

map
tcx.arena.alloc(IndexedHir { crate_hash, map })
}

/// Identical to the `PpAnn` implementation for `hir::Crate`,
Expand Down
54 changes: 25 additions & 29 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// Field 5 would be the first element, so memory_index is i:
// Note: if we didn't optimize, it's already right.

let memory_index;
if optimize {
memory_index = invert_mapping(&inverse_memory_index);
} else {
memory_index = inverse_memory_index;
}
let memory_index =
if optimize { invert_mapping(&inverse_memory_index) } else { inverse_memory_index };

let size = min_size.align_to(align.abi);
let mut abi = Abi::Aggregate { sized };
Expand Down Expand Up @@ -944,33 +940,33 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let offset = st[i].fields.offset(field_index) + niche.offset;
let size = st[i].size;

let mut abi = match st[i].abi {
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
Abi::ScalarPair(ref first, ref second) => {
// We need to use scalar_unit to reset the
// valid range to the maximal one for that
// primitive, because only the niche is
// guaranteed to be initialised, not the
// other primitive.
if offset.bytes() == 0 {
Abi::ScalarPair(
niche_scalar.clone(),
scalar_unit(second.value),
)
} else {
Abi::ScalarPair(
scalar_unit(first.value),
niche_scalar.clone(),
)
let abi = if st.iter().all(|v| v.abi.is_uninhabited()) {
Abi::Uninhabited
} else {
match st[i].abi {
Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
Abi::ScalarPair(ref first, ref second) => {
// We need to use scalar_unit to reset the
// valid range to the maximal one for that
// primitive, because only the niche is
// guaranteed to be initialised, not the
// other primitive.
if offset.bytes() == 0 {
Abi::ScalarPair(
niche_scalar.clone(),
scalar_unit(second.value),
)
} else {
Abi::ScalarPair(
scalar_unit(first.value),
niche_scalar.clone(),
)
}
}
_ => Abi::Aggregate { sized: true },
}
_ => Abi::Aggregate { sized: true },
};

if st.iter().all(|v| v.abi.is_uninhabited()) {
abi = Abi::Uninhabited;
}

let largest_niche =
Niche::from_scalar(dl, offset, niche_scalar.clone());

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) -> () {
pub(super) fn ensure_query<Q: QueryDescription<'tcx> + 'tcx>(self, key: Q::Key) {
if Q::EVAL_ALWAYS {
let _ = self.get_query::<Q>(DUMMY_SP, key);
return;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,9 @@ impl<'a> MethodDef<'a> {
self_: field,
other: other_fields
.iter_mut()
.map(|l| match l.next().unwrap() {
(.., ex, _) => ex,
.map(|l| {
let (.., ex, _) = l.next().unwrap();
ex
})
.collect(),
attrs,
Expand Down
13 changes: 8 additions & 5 deletions src/librustc_builtin_macros/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_expand::base::{ExtCtxt, Resolver};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_session::parse::ParseSess;
use rustc_span::hygiene::AstPass;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym};
use rustc_span::{Span, DUMMY_SP};
use smallvec::smallvec;
Expand Down Expand Up @@ -44,6 +45,7 @@ struct CollectProcMacros<'a> {
macros: Vec<ProcMacro>,
in_root: bool,
handler: &'a rustc_errors::Handler,
source_map: &'a SourceMap,
is_proc_macro_crate: bool,
is_test_crate: bool,
}
Expand All @@ -65,6 +67,7 @@ pub fn inject(
macros: Vec::new(),
in_root: true,
handler,
source_map: sess.source_map(),
is_proc_macro_crate,
is_test_crate,
};
Expand Down Expand Up @@ -195,7 +198,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_derive]` must be `pub`"
};
self.handler.span_err(item.span, msg);
self.handler.span_err(self.source_map.def_span(item.span), msg);
}
}

Expand All @@ -214,7 +217,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_attribute]` must be `pub`"
};
self.handler.span_err(item.span, msg);
self.handler.span_err(self.source_map.def_span(item.span), msg);
}
}

Expand All @@ -233,7 +236,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro]` must be `pub`"
};
self.handler.span_err(item.span, msg);
self.handler.span_err(self.source_map.def_span(item.span), msg);
}
}
}
Expand All @@ -244,7 +247,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
let msg =
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
self.handler.span_err(item.span, msg);
self.handler.span_err(self.source_map.def_span(item.span), msg);
}
}

Expand Down Expand Up @@ -295,7 +298,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {

let attr = match found_attr {
None => {
self.check_not_pub_in_root(&item.vis, item.span);
self.check_not_pub_in_root(&item.vis, self.source_map.def_span(item.span));
let prev_in_root = mem::replace(&mut self.in_root, false);
visit::walk_item(self, item);
self.in_root = prev_in_root;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_ssa/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ fn get_rpaths(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
rpaths.extend_from_slice(&fallback_rpaths);

// Remove duplicates
let rpaths = minimize_rpaths(&rpaths);

rpaths
minimize_rpaths(&rpaths)
}

fn get_rpaths_relative_to_output(config: &mut RPathConfig<'_>, libs: &[PathBuf]) -> Vec<String> {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules).unwrap_or_else(|e| e.raise())
};

let result = lto_modules
lto_modules
.into_iter()
.map(|module| {
let cost = module.cost();
Expand All @@ -303,9 +303,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
0,
)
}))
.collect();

result
.collect()
}

pub struct CompiledModules {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_data_structures/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl SelfProfilerRef {
) {
drop(self.exec(event_filter, |profiler| {
let event_id = StringId::new_virtual(query_invocation_id.0);
let thread_id = std::thread::current().id().as_u64() as u32;
let thread_id = std::thread::current().id().as_u64().get() as u32;

profiler.profiler.record_instant_event(
event_kind(profiler),
Expand Down Expand Up @@ -522,7 +522,7 @@ impl<'a> TimingGuard<'a> {
event_kind: StringId,
event_id: EventId,
) -> TimingGuard<'a> {
let thread_id = std::thread::current().id().as_u64() as u32;
let thread_id = std::thread::current().id().as_u64().get() as u32;
let raw_profiler = &profiler.profiler;
let timing_guard =
raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
// avoid allocations in those cases. We also don't use `indices` to
// determine if a kind has been seen before until the limit of 8 has
// been exceeded, to also avoid allocations for `indices`.
let var = if !var_values.spilled() {
if !var_values.spilled() {
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
// direct linear search of `var_values`.
if let Some(idx) = var_values.iter().position(|&k| k == kind) {
Expand Down Expand Up @@ -589,9 +589,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
assert_eq!(variables.len(), var_values.len());
BoundVar::new(variables.len() - 1)
})
};

var
}
}

/// Shorthand helper that creates a canonical region variable for
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub type NormalizedTy<'tcx> = Normalized<'tcx, Ty<'tcx>>;

impl<'tcx, T> Normalized<'tcx, T> {
pub fn with<U>(self, value: U) -> Normalized<'tcx, U> {
Normalized { value: value, obligations: self.obligations }
Normalized { value, obligations: self.obligations }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct PredicateSet<'tcx> {

impl PredicateSet<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> Self {
Self { tcx: tcx, set: Default::default() }
Self { tcx, set: Default::default() }
}

fn insert(&mut self, pred: &ty::Predicate<'tcx>) -> bool {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_metadata/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ mod dl {
let result = f();

let last_error = libc::dlerror() as *const _;
let ret = if ptr::null() == last_error {
if ptr::null() == last_error {
Ok(result)
} else {
let s = CStr::from_ptr(last_error).to_bytes();
Err(str::from_utf8(s).unwrap().to_owned())
};

ret
}
}
}

Expand Down
Loading