Skip to content

Commit

Permalink
Auto merge of #66009 - tmandry:rollup-jt3wtfr, r=tmandry
Browse files Browse the repository at this point in the history
Rollup of 14 pull requests

Successful merges:

 - #65112 (Add lint and tests for unnecessary parens around types)
 - #65459 (Fix `-Zunpretty=mir-cfg` to render multiple items)
 - #65471 (Add long error explanation for E0578)
 - #65857 (rustdoc: Resolve module-level doc references more locally)
 - #65914 (Use structured suggestion for unnecessary bounds in type aliases)
 - #68635 (Optimize long-linker-command-line test)
 - #68636 (Make `promote_consts` emit the errors when required promotion fails)
 - #65960 (doc: reword iter module example and mention other methods)
 - #65963 (update submodules to rust-lang)
 - #65972 (Fix libunwind build: Define __LITTLE_ENDIAN__ for LE targets)
 - #65977 (Fix incorrect diagnostics for expected type in E0271 with an associated type)
 - #65995 (Add error code E0743 for "C-variadic has been used on a non-foreign function")
 - #65997 (Fix outdated rustdoc of Once::init_locking function)
 - #66005 (vxWorks: remove code related unix socket)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Oct 31, 2019
2 parents aa4e57c 1c5156a commit a143325
Show file tree
Hide file tree
Showing 54 changed files with 608 additions and 2,041 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 3,13 @@
url = https://github.com/rust-lang/rust-installer.git
[submodule "src/doc/nomicon"]
path = src/doc/nomicon
url = https://github.com/rust-lang-nursery/nomicon.git
url = https://github.com/rust-lang/nomicon.git
[submodule "src/tools/cargo"]
path = src/tools/cargo
url = https://github.com/rust-lang/cargo.git
[submodule "src/doc/reference"]
path = src/doc/reference
url = https://github.com/rust-lang-nursery/reference.git
url = https://github.com/rust-lang/reference.git
[submodule "src/doc/book"]
path = src/doc/book
url = https://github.com/rust-lang/book.git
Expand All @@ -36,7 36,7 @@
url = https://github.com/rust-lang/rustc-guide.git
[submodule "src/doc/edition-guide"]
path = src/doc/edition-guide
url = https://github.com/rust-lang-nursery/edition-guide.git
url = https://github.com/rust-lang/edition-guide.git
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
Expand Down
35 changes: 14 additions & 21 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 118,16 @@
//!
//! let mut counter = Counter::new();
//!
//! let x = counter.next().unwrap();
//! println!("{}", x);
//!
//! let x = counter.next().unwrap();
//! println!("{}", x);
//!
//! let x = counter.next().unwrap();
//! println!("{}", x);
//!
//! let x = counter.next().unwrap();
//! println!("{}", x);
//!
//! let x = counter.next().unwrap();
//! println!("{}", x);
//! assert_eq!(counter.next(), Some(1));
//! assert_eq!(counter.next(), Some(2));
//! assert_eq!(counter.next(), Some(3));
//! assert_eq!(counter.next(), Some(4));
//! assert_eq!(counter.next(), Some(5));
//! assert_eq!(counter.next(), None);
//! ```
//!
//! This will print `1` through `5`, each on their own line.
//!
//! Calling `next()` this way gets repetitive. Rust has a construct which can
//! call `next()` on your iterator, until it reaches `None`. Let's go over that
//! Calling [`next`] this way gets repetitive. Rust has a construct which can
//! call [`next`] on your iterator, until it reaches `None`. Let's go over that
//! next.
//!
//! Also note that `Iterator` provides a default implementation of methods such as `nth` and `fold`
Expand Down Expand Up @@ -253,20 243,23 @@
//! ```
//!
//! The idiomatic way to write a [`map`] for its side effects is to use a
//! `for` loop instead:
//! `for` loop or call the [`for_each`] method:
//!
//! ```
//! let v = vec![1, 2, 3, 4, 5];
//!
//! v.iter().for_each(|x| println!("{}", x));
//! // or
//! for x in &v {
//! println!("{}", x);
//! }
//! ```
//!
//! [`map`]: trait.Iterator.html#method.map
//! [`for_each`]: trait.Iterator.html#method.for_each
//!
//! The two most common ways to evaluate an iterator are to use a `for` loop
//! like this, or using the [`collect`] method to produce a new collection.
//! Another common way to evaluate an iterator is to use the [`collect`]
//! method to produce a new collection.
//!
//! [`collect`]: trait.Iterator.html#method.collect
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 62,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&self,
arg: &'tcx hir::Ty,
br: &ty::BoundRegion,
) -> Option<(&'tcx hir::Ty)> {
) -> Option<&'tcx hir::Ty> {
let mut nested_visitor = FindNestedTypeVisitor {
tcx: self.tcx(),
bound_region: *br,
Expand Down
23 changes: 18 additions & 5 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 226,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
0,
&mut obligations
);

debug!("report_projection_error obligation.cause={:?} obligation.param_env={:?}",
obligation.cause, obligation.param_env);

debug!("report_projection_error normalized_ty={:?} data.ty={:?}",
normalized_ty, data.ty);

let is_normalized_ty_expected = match &obligation.cause.code {
ObligationCauseCode::ItemObligation(_) |
ObligationCauseCode::BindingObligation(_, _) |
ObligationCauseCode::ObjectCastObligation(_) => false,
_ => true,
};

if let Err(error) = self.at(&obligation.cause, obligation.param_env)
.eq(normalized_ty, data.ty)
.eq_exp(is_normalized_ty_expected, normalized_ty, data.ty)
{
values = Some(infer::ValuePairs::Types(ExpectedFound {
expected: normalized_ty,
found: data.ty,
}));
values = Some(infer::ValuePairs::Types(
ExpectedFound::new(is_normalized_ty_expected, normalized_ty, data.ty)));

err_buf = error;
err = &err_buf;
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/owning_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,14 1046,14 @@ unsafe impl<O, T: ?Sized> CloneStableAddress for OwningRef<O, T>
where O: CloneStableAddress {}

unsafe impl<O, T: ?Sized> Send for OwningRef<O, T>
where O: Send, for<'a> (&'a T): Send {}
where O: Send, for<'a> &'a T: Send {}
unsafe impl<O, T: ?Sized> Sync for OwningRef<O, T>
where O: Sync, for<'a> (&'a T): Sync {}
where O: Sync, for<'a> &'a T: Sync {}

unsafe impl<O, T: ?Sized> Send for OwningRefMut<O, T>
where O: Send, for<'a> (&'a mut T): Send {}
where O: Send, for<'a> &'a mut T: Send {}
unsafe impl<O, T: ?Sized> Sync for OwningRefMut<O, T>
where O: Sync, for<'a> (&'a mut T): Sync {}
where O: Sync, for<'a> &'a mut T: Sync {}

impl Debug for dyn Erased {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 492,10 @@ impl<T> Once<T> {
assert!(self.try_set(value).is_none());
}

/// Tries to initialize the inner value by calling the closure while ensuring that no-one else
/// can access the value in the mean time by holding a lock for the duration of the closure.
/// If the value was already initialized the closure is not called and `false` is returned,
/// otherwise if the value from the closure initializes the inner value, `true` is returned
/// Initializes the inner value if it wasn't already done by calling the provided closure. It
/// ensures that no-one else can access the value in the mean time by holding a lock for the
/// duration of the closure.
/// A reference to the inner value is returned.
#[inline]
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
{
Expand Down
17 changes: 13 additions & 4 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 1125,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
.map(|pred| pred.span()).collect();
let mut err = cx.struct_span_lint(TYPE_ALIAS_BOUNDS, spans,
"where clauses are not enforced in type aliases");
err.help("the clause will not be checked when the type alias is used, \
and should be removed");
err.span_suggestion(
type_alias_generics.where_clause.span_for_predicates_or_empty_place(),
"the clause will not be checked when the type alias is used, and should be removed",
String::new(),
Applicability::MachineApplicable,
);
if !suggested_changing_assoc_types {
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
suggested_changing_assoc_types = true;
Expand All @@ -1136,14 1140,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
// The parameters must not have bounds
for param in type_alias_generics.params.iter() {
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
let suggestion = spans.iter().map(|sp| {
let start = param.span.between(*sp); // Include the `:` in `T: Bound`.
(start.to(*sp), String::new())
}).collect();
if !spans.is_empty() {
let mut err = cx.struct_span_lint(
TYPE_ALIAS_BOUNDS,
spans,
"bounds on generic parameters are not enforced in type aliases",
);
err.help("the bound will not be checked when the type alias is used, \
and should be removed");
let msg = "the bound will not be checked when the type alias is used, \
and should be removed";
err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable);
if !suggested_changing_assoc_types {
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
suggested_changing_assoc_types = true;
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 598,25 @@ impl EarlyLintPass for UnusedParens {
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
self.check_unused_parens_pat(cx, &arm.pat, false, false);
}

fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
if let &ast::TyKind::Paren(ref r) = &ty.kind {
match &r.kind {
&ast::TyKind::TraitObject(..) => {}
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {}
_ => {
let pattern_text = if let Ok(snippet) = cx.sess().source_map()
.span_to_snippet(ty.span) {
snippet
} else {
pprust::ty_to_string(ty)
};

Self::remove_outer_parens(cx, ty.span, &pattern_text, "type", (false, false));
}
}
}
}
}

declare_lint! {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/prefixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,7 @@ pub(super) struct Prefixes<'cx, 'tcx> {
body: &'cx Body<'tcx>,
tcx: TyCtxt<'tcx>,
kind: PrefixSet,
next: Option<(PlaceRef<'cx, 'tcx>)>,
next: Option<PlaceRef<'cx, 'tcx>>,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 2545,7 @@ There are some known bugs that trigger this message.
// E0471, // constant evaluation error (in pattern)
// E0385, // {} in an aliasable location
E0521, // borrowed data escapes outside of closure
E0526, // shuffle indices are not constant
// E0526, // shuffle indices are not constant
E0863, // cannot assign to {}
// E0598, // lifetime of {} is too short to guarantee its contents can be...
E0625, // thread-local statics cannot be accessed at compile-time
Expand Down
29 changes: 23 additions & 6 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 80,17 @@ pub enum Candidate {
Argument { bb: BasicBlock, index: usize },
}

impl Candidate {
/// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`.
fn forces_explicit_promotion(&self) -> bool {
match self {
Candidate::Ref(_) |
Candidate::Repeat(_) => false,
Candidate::Argument { .. } => true,
}
}
}

fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
let attrs = tcx.get_attrs(def_id);
let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
Expand Down Expand Up @@ -727,16 738,22 @@ pub fn validate_candidates(
};

candidates.iter().copied().filter(|&candidate| {
validator.explicit = match candidate {
Candidate::Ref(_) |
Candidate::Repeat(_) => false,
Candidate::Argument { .. } => true,
};
validator.explicit = candidate.forces_explicit_promotion();

// FIXME(eddyb) also emit the errors for shuffle indices
// and `#[rustc_args_required_const]` arguments here.

validator.validate_candidate(candidate).is_ok()
let is_promotable = validator.validate_candidate(candidate).is_ok();
match candidate {
Candidate::Argument { bb, index } if !is_promotable => {
let span = body[bb].terminator().source_info.span;
let msg = format!("argument {} is required to be a constant", index 1);
tcx.sess.span_err(span, &msg);
}
_ => ()
}

is_promotable
}).collect()
}

Expand Down
14 changes: 3 additions & 11 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,20 1606,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
// This is not a problem, because the argument explicitly
// requests constness, in contrast to regular promotion
// which happens even without the user requesting it.
// We can error out with a hard error if the argument is not
// constant here.
//
// `promote_consts` is responsible for emitting the error if
// the argument is not promotable.
if !IsNotPromotable::in_operand(self, arg) {
debug!("visit_terminator_kind: candidate={:?}", candidate);
self.promotion_candidates.push(candidate);
} else {
if is_shuffle {
span_err!(self.tcx.sess, self.span, E0526,
"shuffle indices are not constant");
} else {
self.tcx.sess.span_err(self.span,
&format!("argument {} is required to be a constant",
i 1));
}
}
}
}
Expand Down
Loading

0 comments on commit a143325

Please sign in to comment.