Skip to content

Commit

Permalink
Auto merge of #62485 - Centril:rollup-gg3it1u, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #62356 (Implement Option::contains and Result::contains)
 - #62462 (Document `while` keyword)
 - #62472 (Normalize use of backticks in compiler messages p2)
 - #62477 (Re-add bootstrap attribute to libunwind for llvm-libunwind feature)
 - #62478 (normalize use of backticks for compiler messages in librustc_codegen)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jul 8, 2019
2 parents a824723 + ada2684 commit db592f4
Show file tree
Hide file tree
Showing 26 changed files with 186 additions and 54 deletions.
26 changes: 26 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,32 @@ impl<T> Option<T> {
!self.is_some()
}

/// Returns `true` if the option is a [`Some`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(option_result_contains)]
///
/// let x: Option<u32> = Some(2);
/// assert_eq!(x.contains(&2), true);
///
/// let x: Option<u32> = Some(3);
/// assert_eq!(x.contains(&2), false);
///
/// let x: Option<u32> = None;
/// assert_eq!(x.contains(&2), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "option_result_contains", issue = "62358")]
pub fn contains<U>(&self, x: &U) -> bool where U: PartialEq<T> {
match self {
Some(y) => x == y,
None => false,
}
}

/////////////////////////////////////////////////////////////////////////
// Adapter for working with references
/////////////////////////////////////////////////////////////////////////
Expand Down
52 changes: 52 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,58 @@ impl<T, E> Result<T, E> {
!self.is_ok()
}

/// Returns `true` if the result is an [`Ok`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(option_result_contains)]
///
/// let x: Result<u32, &str> = Ok(2);
/// assert_eq!(x.contains(&2), true);
///
/// let x: Result<u32, &str> = Ok(3);
/// assert_eq!(x.contains(&2), false);
///
/// let x: Result<u32, &str> = Err("Some error message");
/// assert_eq!(x.contains(&2), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "option_result_contains", issue = "62358")]
pub fn contains<U>(&self, x: &U) -> bool where U: PartialEq<T> {
match self {
Ok(y) => x == y,
Err(_) => false
}
}

/// Returns `true` if the result is an [`Err`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(result_contains_err)]
///
/// let x: Result<u32, &str> = Ok(2);
/// assert_eq!(x.contains_err(&"Some error message"), false);
///
/// let x: Result<u32, &str> = Err("Some error message");
/// assert_eq!(x.contains_err(&"Some error message"), true);
///
/// let x: Result<u32, &str> = Err("Some other error message");
/// assert_eq!(x.contains_err(&"Some error message"), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "result_contains_err", issue = "62358")]
pub fn contains_err<F>(&self, f: &F) -> bool where F: PartialEq<E> {
match self {
Ok(_) => false,
Err(e) => f == e
}
}

/////////////////////////////////////////////////////////////////////////
// Adapter for each variant
/////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn inline_asm_call(
unsafe {
// Ask LLVM to verify that the constraints are well-formed.
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
debug!("Constraint verification result: {:?}", constraints_ok);
debug!("constraint verification result: {:?}", constraints_ok);
if constraints_ok {
let v = llvm::LLVMRustInlineAsm(
fty,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
funclet: Option<&Funclet<'ll>>,
) -> &'ll Value {

debug!("Invoke {:?} with args ({:?})",
debug!("invoke {:?} with args ({:?})",
llfn,
args);

Expand Down Expand Up @@ -1035,7 +1035,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
funclet: Option<&Funclet<'ll>>,
) -> &'ll Value {

debug!("Call {:?} with args ({:?})",
debug!("call {:?} with args ({:?})",
llfn,
args);

Expand Down Expand Up @@ -1238,7 +1238,7 @@ impl Builder<'a, 'll, 'tcx> {
if dest_ptr_ty == stored_ptr_ty {
ptr
} else {
debug!("Type mismatch in store. \
debug!("type mismatch in store. \
Expected {:?}, got {:?}; inserting bitcast",
dest_ptr_ty, stored_ptr_ty);
self.bitcast(ptr, stored_ptr_ty)
Expand Down Expand Up @@ -1274,7 +1274,7 @@ impl Builder<'a, 'll, 'tcx> {
.map(|(i, (expected_ty, &actual_val))| {
let actual_ty = self.val_ty(actual_val);
if expected_ty != actual_ty {
debug!("Type mismatch in function call of {:?}. \
debug!("type mismatch in function call of {:?}. \
Expected {:?} for param {}, got {:?}; injecting bitcast",
llfn, expected_ty, i, actual_ty);
self.bitcast(actual_val, expected_ty)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
if cx.get_defined_value("main").is_some() {
// FIXME: We should be smart and show a better diagnostic here.
cx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
.emit();
cx.sess().abort_if_errors();
bug!();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
// * packed struct - there is no alignment padding
match field.ty.sty {
_ if self.llextra.is_none() => {
debug!("Unsized field `{}`, of `{:?}` has no metadata for adjustment",
debug!("unsized field `{}`, of `{:?}` has no metadata for adjustment",
ix, self.llval);
return simple();
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn find_crate_name(sess: Option<&Session>,
if let Some(ref s) = sess.opts.crate_name {
if let Some((attr, name)) = attr_crate_name {
if name.as_str() != *s {
let msg = format!("--crate-name and #[crate_name] are \
let msg = format!("`--crate-name` and `#[crate_name]` are \
required to match, but `{}` != `{}`",
s, name);
sess.span_err(attr.span, &msg);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let (unsize_did, coerce_unsized_did) = if let (Some(u), Some(cu)) = traits {
(u, cu)
} else {
debug!("Missing Unsize or CoerceUnsized traits");
debug!("missing Unsize or CoerceUnsized traits");
return Err(TypeError::Mismatch);
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn resolve_interior<'a, 'tcx>(
// if a Sync generator contains an &'α T, we need to check whether &'α T: Sync),
// so knowledge of the exact relationships between them isn't particularly important.

debug!("Types in generator {:?}, span = {:?}", type_list, body.value.span);
debug!("types in generator {:?}, span = {:?}", type_list, body.value.span);

// Replace all regions inside the generator interior with late bound regions
// Note that each region slot in the types gets a new fresh late bound region,
Expand All @@ -144,7 +144,7 @@ pub fn resolve_interior<'a, 'tcx>(

let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));

debug!("Types in generator after region replacement {:?}, span = {:?}",
debug!("types in generator after region replacement {:?}, span = {:?}",
witness, body.value.span);

// Unify the type variable inside the generator with the new witness
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
if nightly_options::is_nightly_build() {
for (candidate, feature) in unstable_candidates {
diag.help(&format!(
"add #![feature({})] to the crate attributes to enable `{}`",
"add `#![feature({})]` to the crate attributes to enable `{}`",
feature,
self.tcx.def_path_str(candidate.item.def_id),
));
Expand Down Expand Up @@ -1432,7 +1432,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
/// candidate method where the method name may have been misspelt. Similarly to other
/// Levenshtein based suggestions, we provide at most one such suggestion.
fn probe_for_lev_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
debug!("Probing for method names similar to {:?}",
debug!("probing for method names similar to {:?}",
self.method_name);

let steps = self.steps.clone();
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
};
self.assign(local.span, local.hir_id, local_ty);

debug!("Local variable {:?} is assigned type {}",
debug!("local variable {:?} is assigned type {}",
local.pat,
self.fcx.ty_to_string(
self.fcx.locals.borrow().get(&local.hir_id).unwrap().clone().decl_ty));
Expand All @@ -1000,7 +1000,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
traits::VariableType(p.hir_id));
}

debug!("Pattern binding {} is assigned to {} with type {:?}",
debug!("pattern binding {} is assigned to {} with type {:?}",
ident,
self.fcx.ty_to_string(
self.fcx.locals.borrow().get(&p.hir_id).unwrap().clone().decl_ty),
Expand Down Expand Up @@ -4462,7 +4462,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t

for leaf_ty in ty.walk() {
if let ty::Param(ty::ParamTy { index, .. }) = leaf_ty.sty {
debug!("Found use of ty param num {}", index);
debug!("found use of ty param num {}", index);
types_used[index as usize - own_counts.lifetimes] = true;
} else if let ty::Error = leaf_ty.sty {
// If there is already another error, do not emit
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
debug!("callee_region={:?}", callee_region);

for arg_expr in arg_exprs {
debug!("Argument: {:?}", arg_expr);
debug!("argument: {:?}", arg_expr);

// ensure that any regions appearing in the argument type are
// valid for at least the lifetime of the function:
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let n_ty = self.fcx.node_ty(hir_id);
let n_ty = self.resolve(&n_ty, &span);
self.write_ty_to_tables(hir_id, n_ty);
debug!("Node {:?} has type {:?}", hir_id, n_ty);
debug!("node {:?} has type {:?}", hir_id, n_ty);

// Resolve any substitutions
if let Some(substs) = self.fcx.tables.borrow().node_substs_opt(hir_id) {
Expand All @@ -665,13 +665,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
.remove(hir_id);
match adjustment {
None => {
debug!("No adjustments for node {:?}", hir_id);
debug!("no adjustments for node {:?}", hir_id);
}

Some(adjustment) => {
let resolved_adjustment = self.resolve(&adjustment, &span);
debug!(
"Adjustments for node {:?}: {:?}",
"adjustments for node {:?}: {:?}",
hir_id, resolved_adjustment
);
self.tables
Expand All @@ -689,7 +689,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
.remove(hir_id);
match adjustment {
None => {
debug!("No pat_adjustments for node {:?}", hir_id);
debug!("no pat_adjustments for node {:?}", hir_id);
}

Some(adjustment) => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
tcx.hir().hir_to_pretty_string(ast_ty.hir_id)
),
)
.help("add #![feature(simd_ffi)] to the crate attributes to enable")
.help("add `#![feature(simd_ffi)]` to the crate attributes to enable")
.emit();
}
};
Expand Down Expand Up @@ -2479,7 +2479,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
}
} else if attr.check_name(sym::target_feature) {
if tcx.fn_sig(id).unsafety() == Unsafety::Normal {
let msg = "#[target_feature(..)] can only be applied to `unsafe` functions";
let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
tcx.sess.struct_span_err(attr.span, msg)
.span_label(attr.span, "can only be applied to `unsafe` functions")
.span_label(tcx.def_span(id), "not an `unsafe` function")
Expand Down Expand Up @@ -2593,8 +2593,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if let Some(span) = inline_span {
tcx.sess.span_err(
span,
"cannot use #[inline(always)] with \
#[target_feature]",
"cannot use `#[inline(always)]` with \
`#[target_feature]`",
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4848,6 +4848,6 @@ register_diagnostics! {
E0641, // cannot cast to/from a pointer with an unknown kind
E0645, // trait aliases not finished
E0719, // duplicate values for associated type binding
E0722, // Malformed #[optimize] attribute
E0722, // Malformed `#[optimize]` attribute
E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
}
2 changes: 1 addition & 1 deletion src/librustc_typeck/variance/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
let old_value = self.solutions[inferred];
let new_value = glb(variance, old_value);
if old_value != new_value {
debug!("Updating inferred {} \
debug!("updating inferred {} \
from {:?} to {:?} due to {:?}",
inferred,
old_value,
Expand Down
Loading

0 comments on commit db592f4

Please sign in to comment.