Skip to content

Commit

Permalink
Auto merge of rust-lang#80253 - Dylan-DPC:rollup-bkmn74z, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - rust-lang#80159 (Add array search aliases)
 - rust-lang#80166 (Edit rustc_middle docs)
 - rust-lang#80170 (Fix ICE when lookup method in trait for type that have bound vars)
 - rust-lang#80171 (Edit rustc_middle::ty::TyKind docs)
 - rust-lang#80199 (also const-check FakeRead)
 - rust-lang#80211 (Handle desugaring in impl trait bound suggestion)
 - rust-lang#80236 (Use pointer type in AtomicPtr::swap implementation)
 - rust-lang#80239 (Update Clippy)
 - rust-lang#80240 (make sure installer only creates directories in DESTDIR)
 - rust-lang#80244 (Cleanup markdown span handling)
 - rust-lang#80250 (Minor cleanups in LateResolver)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 21, 2020
2 parents c813545 + 0947e05 commit 15d1f81
Show file tree
Hide file tree
Showing 140 changed files with 3,573 additions and 1,234 deletions.
15 changes: 13 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};

let ty = substs.type_at(0);
if int_type_width_signed(ty, bx.tcx()).is_some() {
bx.atomic_rmw(atom_op, args[0].immediate(), args[1].immediate(), order)
if int_type_width_signed(ty, bx.tcx()).is_some()
|| (ty.is_unsafe_ptr() && op == "xchg")
{
let mut ptr = args[0].immediate();
let mut val = args[1].immediate();
if ty.is_unsafe_ptr() {
// Some platforms do not support atomic operations on pointers,
// so we cast to integer first.
let ptr_llty = bx.type_ptr_to(bx.type_isize());
ptr = bx.pointercast(ptr, ptr_llty);
val = bx.ptrtoint(val, bx.type_isize());
}
bx.atomic_rmw(atom_op, ptr, val, order)
} else {
return invalid_monomorphization(ty);
}
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_middle/src/hir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use rustc_target::abi::VariantIdx;
HashStable
)]
pub enum PlaceBase {
/// A temporary variable
/// A temporary variable.
Rvalue,
/// A named `static` item
/// A named `static` item.
StaticItem,
/// A named local variable
/// A named local variable.
Local(HirId),
/// An upvar referenced by closure env
/// An upvar referenced by closure env.
Upvar(ty::UpvarId),
}

Expand All @@ -40,7 +40,7 @@ pub enum PlaceBase {
HashStable
)]
pub enum ProjectionKind {
/// A dereference of a pointer, reference or `Box<T>` of the given type
/// A dereference of a pointer, reference or `Box<T>` of the given type.
Deref,

/// `B.F` where `B` is the base expression and `F` is
Expand Down Expand Up @@ -71,16 +71,16 @@ pub enum ProjectionKind {
HashStable
)]
pub struct Projection<'tcx> {
/// Type after the projection is being applied.
/// Type after the projection is applied.
pub ty: Ty<'tcx>,

/// Defines the type of access
/// Defines the kind of access made by the projection.
pub kind: ProjectionKind,
}

/// A `Place` represents how a value is located in memory.
///
/// This is an HIR version of `mir::Place`
/// This is an HIR version of [`rustc_middle::mir::Place`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
pub struct Place<'tcx> {
/// The type of the `PlaceBase`
Expand All @@ -93,13 +93,13 @@ pub struct Place<'tcx> {

/// A `PlaceWithHirId` represents how a value is located in memory.
///
/// This is an HIR version of `mir::Place`
/// This is an HIR version of [`rustc_middle::mir::Place`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
pub struct PlaceWithHirId<'tcx> {
/// `HirId` of the expression or pattern producing this value.
pub hir_id: HirId,

/// Information about the `Place`
/// Information about the `Place`.
pub place: Place<'tcx>,
}

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ impl BoundRegionKind {
}
}

/// Defines the kinds of types.
///
/// N.B., if you change this, you'll probably want to change the corresponding
/// AST structure in `librustc_ast/ast.rs` as well.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)]
Expand All @@ -110,7 +112,7 @@ pub enum TyKind<'tcx> {
/// A primitive floating-point type. For example, `f64`.
Float(ast::FloatTy),

/// Structures, enumerations and unions.
/// Algebraic data types (ADT). For example: structures, enumerations and unions.
///
/// InternalSubsts here, possibly against intuition, *may* contain `Param`s.
/// That is, even after substitution it is possible that there are type
Expand Down Expand Up @@ -170,11 +172,11 @@ pub enum TyKind<'tcx> {
/// `|a| yield a`.
Generator(DefId, SubstsRef<'tcx>, hir::Movability),

/// A type representin the types stored inside a generator.
/// A type representing the types stored inside a generator.
/// This should only appear in GeneratorInteriors.
GeneratorWitness(Binder<&'tcx List<Ty<'tcx>>>),

/// The never type `!`
/// The never type `!`.
Never,

/// A tuple type. For example, `(i32, bool)`.
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,17 +722,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
trace!("visit_statement: statement={:?} location={:?}", statement, location);

match statement.kind {
StatementKind::Assign(..) | StatementKind::SetDiscriminant { .. } => {
self.super_statement(statement, location);
}
self.super_statement(statement, location);

match statement.kind {
StatementKind::LlvmInlineAsm { .. } => {
self.super_statement(statement, location);
self.check_op(ops::InlineAsm);
}

StatementKind::FakeRead(..)
StatementKind::Assign(..)
| StatementKind::SetDiscriminant { .. }
| StatementKind::FakeRead(..)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Retag { .. }
Expand Down
65 changes: 29 additions & 36 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rustc_span::Span;
use smallvec::{smallvec, SmallVec};

use rustc_span::source_map::{respan, Spanned};
use std::collections::BTreeSet;
use std::collections::{hash_map::Entry, BTreeSet};
use std::mem::{replace, take};
use tracing::debug;

Expand Down Expand Up @@ -953,8 +953,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
});
};

for item in trait_items {
this.with_trait_items(trait_items, |this| {
this.with_trait_items(trait_items, |this| {
for item in trait_items {
match &item.kind {
AssocItemKind::Const(_, ty, default) => {
this.visit_ty(ty);
Expand Down Expand Up @@ -983,8 +983,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
panic!("unexpanded macro in resolve!")
}
};
});
}
}
});
});
});
}
Expand Down Expand Up @@ -1060,36 +1060,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
continue;
}

let def_kind = match param.kind {
GenericParamKind::Type { .. } => DefKind::TyParam,
GenericParamKind::Const { .. } => DefKind::ConstParam,
_ => unreachable!(),
};

let ident = param.ident.normalize_to_macros_2_0();
debug!("with_generic_param_rib: {}", param.id);

if seen_bindings.contains_key(&ident) {
let span = seen_bindings.get(&ident).unwrap();
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, *span);
self.report_error(param.ident.span, err);
match seen_bindings.entry(ident) {
Entry::Occupied(entry) => {
let span = *entry.get();
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
self.report_error(param.ident.span, err);
}
Entry::Vacant(entry) => {
entry.insert(param.ident.span);
}
}
seen_bindings.entry(ident).or_insert(param.ident.span);

// Plain insert (no renaming).
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());

match param.kind {
GenericParamKind::Type { .. } => {
function_type_rib.bindings.insert(ident, res);
self.r.record_partial_res(param.id, PartialRes::new(res));
}
GenericParamKind::Const { .. } => {
function_value_rib.bindings.insert(ident, res);
self.r.record_partial_res(param.id, PartialRes::new(res));
}
let (rib, def_kind) = match param.kind {
GenericParamKind::Type { .. } => (&mut function_type_rib, DefKind::TyParam),
GenericParamKind::Const { .. } => (&mut function_value_rib, DefKind::ConstParam),
_ => unreachable!(),
}
};
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());
self.r.record_partial_res(param.id, PartialRes::new(res));
rib.bindings.insert(ident, res);
}

self.ribs[ValueNS].push(function_value_rib);
Expand Down Expand Up @@ -1778,7 +1771,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
path
);
let ns = source.namespace();
let is_expected = &|res| source.is_expected(res);

let report_errors = |this: &mut Self, res: Option<Res>| {
if this.should_report_errs() {
Expand Down Expand Up @@ -1881,7 +1873,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
crate_lint,
) {
Ok(Some(partial_res)) if partial_res.unresolved_segments() == 0 => {
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
if source.is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err
{
partial_res
} else {
report_errors(self, Some(partial_res.base_res()))
Expand All @@ -1898,11 +1891,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.r.trait_map.insert(id, traits);
}

let mut std_path = vec![Segment::from_ident(Ident::with_dummy_span(sym::std))];

std_path.extend(path);

if self.r.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
let mut std_path = Vec::with_capacity(1 + path.len());

std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
std_path.extend(path);
if let PathResult::Module(_) | PathResult::NonModule(_) =
self.resolve_path(&std_path, Some(ns), false, span, CrateLint::No)
{
Expand Down Expand Up @@ -1983,7 +1976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
let mut fin_res = None;

for (i, ns) in [primary_ns, TypeNS, ValueNS].iter().cloned().enumerate() {
for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
if i == 0 || ns != primary_ns {
match self.resolve_qpath(id, qself, path, ns, span, crate_lint)? {
Some(partial_res)
Expand All @@ -1993,7 +1986,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
partial_res => {
if fin_res.is_none() {
fin_res = partial_res
fin_res = partial_res;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,21 @@ fn suggest_restriction(
let pred = trait_ref.without_const().to_predicate(tcx).to_string();
let pred = pred.replace(&impl_trait_str, &type_param_name);
let mut sugg = vec![
// Find the last of the generic parameters contained within the span of
// the generics
match generics
.params
.iter()
.filter(|p| match p.kind {
hir::GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} => false,
_ => true,
})
.last()
.map(|p| p.bounds_span().unwrap_or(p.span))
.filter(|&span| generics.span.contains(span) && span.desugaring_kind().is_none())
.max_by_key(|span| span.hi())
{
// `fn foo(t: impl Trait)`
// ^ suggest `<T: Trait>` here
None => (generics.span, format!("<{}>", type_param)),
// `fn foo<A>(t: impl Trait)`
// ^^^ suggest `<A, T: Trait>` here
Some(param) => (
param.bounds_span().unwrap_or(param.span).shrink_to_hi(),
format!(", {}", type_param),
),
Some(span) => (span.shrink_to_hi(), format!(", {}", type_param)),
},
// `fn foo(t: impl Trait)`
// ^ suggest `where <T as Trait>::A: Bound`
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => (false, false, false),
};

// Type check the descriminant and get its type.
// Type check the discriminant and get its type.
let scrutinee_ty = if force_scrutinee_bool {
// Here we want to ensure:
//
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !self.tcx.has_typeck_results(def_id) {
return false;
}
// We're emitting a suggestion, so we can just ignore regions
let fn_sig = self.tcx.fn_sig(def_id).skip_binder();
// FIXME: Instead of exiting early when encountering bound vars in
// the function signature, consider keeping the binder here and
// propagating it downwards.
let fn_sig = if let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() {
fn_sig
} else {
return false;
};

let other_ty = if let FnDef(def_id, _) = *other_ty.kind() {
if !self.tcx.has_typeck_results(def_id) {
Expand Down
10 changes: 9 additions & 1 deletion library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,16 @@ impl<T> AtomicPtr<T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_has_atomic = "ptr")]
pub fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T {
#[cfg(bootstrap)]
// SAFETY: data races are prevented by atomic intrinsics.
unsafe { atomic_swap(self.p.get() as *mut usize, ptr as usize, order) as *mut T }
unsafe {
atomic_swap(self.p.get() as *mut usize, ptr as usize, order) as *mut T
}
#[cfg(not(bootstrap))]
// SAFETY: data races are prevented by atomic intrinsics.
unsafe {
atomic_swap(self.p.get(), ptr, order)
}
}

/// Stores a value into the pointer if the current value is the same as the `current` value.
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,10 @@ mod prim_unit {}
#[stable(feature = "rust1", since = "1.0.0")]
mod prim_pointer {}

#[doc(alias = "[]")]
#[doc(alias = "[T;N]")] // unfortunately, rustdoc doesn't have fuzzy search for aliases
#[doc(alias = "[T; N]")]
#[doc(primitive = "array")]
//
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
/// non-negative compile-time constant size, `N`.
///
Expand Down
14 changes: 8 additions & 6 deletions src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ fn install_sh(
let docdir_default = datadir_default.join("doc/rust");
let libdir_default = PathBuf::from("lib");
let mandir_default = datadir_default.join("man");
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
fs::create_dir_all(p)
.unwrap_or_else(|err| panic!("could not create {}: {}", p.display(), err));
fs::canonicalize(p)
.unwrap_or_else(|err| panic!("could not canonicalize {}: {}", p.display(), err))
});
let prefix = builder.config.prefix.as_ref().unwrap_or(&prefix_default);
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);
let docdir = builder.config.docdir.as_ref().unwrap_or(&docdir_default);
Expand All @@ -103,6 +98,13 @@ fn install_sh(
let libdir = add_destdir(&libdir, &destdir);
let mandir = add_destdir(&mandir, &destdir);

let prefix = {
fs::create_dir_all(&prefix)
.unwrap_or_else(|err| panic!("could not create {}: {}", prefix.display(), err));
fs::canonicalize(&prefix)
.unwrap_or_else(|err| panic!("could not canonicalize {}: {}", prefix.display(), err))
};

let empty_dir = builder.out.join("tmp/empty_dir");

t!(fs::create_dir_all(&empty_dir));
Expand Down
Loading

0 comments on commit 15d1f81

Please sign in to comment.