Skip to content

Commit

Permalink
Auto merge of #70275 - Dylan-DPC:rollup-1fbosob, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - #68099 (Amend Rc/Arc::from_raw() docs regarding unsafety)
 - #70172 (parse/lexer: support `StringReader::retokenize` called on external files.)
 - #70209 (parser: recover on `for<'a> |...| body` closures)
 - #70223 (fix type of const params in associated types.)
 - #70229 (more clippy fixes)
 - #70240 (Return NonZeroU64 from ThreadId::as_u64.)
 - #70250 (Remove wrong entry from RELEASES.md)
 - #70253 (Remove another wrong entry from RELEASES.md)
 - #70254 (couple more clippy fixes (let_and_return, if_same_then_else))
 - #70266 (proc_macro_harness: Use item header spans for errors)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 22, 2020
2 parents 5ae85f4 + 69c0bcd commit 1902d1e
Show file tree
Hide file tree
Showing 58 changed files with 321 additions and 255 deletions.
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

0 comments on commit 1902d1e

Please sign in to comment.