Skip to content

Commit db592f4

Browse files
committed
Auto merge of rust-lang#62485 - Centril:rollup-gg3it1u, r=Centril
Rollup of 5 pull requests Successful merges: - rust-lang#62356 (Implement Option::contains and Result::contains) - rust-lang#62462 (Document `while` keyword) - rust-lang#62472 (Normalize use of backticks in compiler messages p2) - rust-lang#62477 (Re-add bootstrap attribute to libunwind for llvm-libunwind feature) - rust-lang#62478 (normalize use of backticks for compiler messages in librustc_codegen) Failed merges: r? @ghost
2 parents a824723 + ada2684 commit db592f4

File tree

26 files changed

+186
-54
lines changed

26 files changed

+186
-54
lines changed

src/libcore/option.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,32 @@ impl<T> Option<T> {
208208
!self.is_some()
209209
}
210210

211+
/// Returns `true` if the option is a [`Some`] value containing the given value.
212+
///
213+
/// # Examples
214+
///
215+
/// ```
216+
/// #![feature(option_result_contains)]
217+
///
218+
/// let x: Option<u32> = Some(2);
219+
/// assert_eq!(x.contains(&2), true);
220+
///
221+
/// let x: Option<u32> = Some(3);
222+
/// assert_eq!(x.contains(&2), false);
223+
///
224+
/// let x: Option<u32> = None;
225+
/// assert_eq!(x.contains(&2), false);
226+
/// ```
227+
#[must_use]
228+
#[inline]
229+
#[unstable(feature = "option_result_contains", issue = "62358")]
230+
pub fn contains<U>(&self, x: &U) -> bool where U: PartialEq<T> {
231+
match self {
232+
Some(y) => x == y,
233+
None => false,
234+
}
235+
}
236+
211237
/////////////////////////////////////////////////////////////////////////
212238
// Adapter for working with references
213239
/////////////////////////////////////////////////////////////////////////

src/libcore/result.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,58 @@ impl<T, E> Result<T, E> {
309309
!self.is_ok()
310310
}
311311

312+
/// Returns `true` if the result is an [`Ok`] value containing the given value.
313+
///
314+
/// # Examples
315+
///
316+
/// ```
317+
/// #![feature(option_result_contains)]
318+
///
319+
/// let x: Result<u32, &str> = Ok(2);
320+
/// assert_eq!(x.contains(&2), true);
321+
///
322+
/// let x: Result<u32, &str> = Ok(3);
323+
/// assert_eq!(x.contains(&2), false);
324+
///
325+
/// let x: Result<u32, &str> = Err("Some error message");
326+
/// assert_eq!(x.contains(&2), false);
327+
/// ```
328+
#[must_use]
329+
#[inline]
330+
#[unstable(feature = "option_result_contains", issue = "62358")]
331+
pub fn contains<U>(&self, x: &U) -> bool where U: PartialEq<T> {
332+
match self {
333+
Ok(y) => x == y,
334+
Err(_) => false
335+
}
336+
}
337+
338+
/// Returns `true` if the result is an [`Err`] value containing the given value.
339+
///
340+
/// # Examples
341+
///
342+
/// ```
343+
/// #![feature(result_contains_err)]
344+
///
345+
/// let x: Result<u32, &str> = Ok(2);
346+
/// assert_eq!(x.contains_err(&"Some error message"), false);
347+
///
348+
/// let x: Result<u32, &str> = Err("Some error message");
349+
/// assert_eq!(x.contains_err(&"Some error message"), true);
350+
///
351+
/// let x: Result<u32, &str> = Err("Some other error message");
352+
/// assert_eq!(x.contains_err(&"Some error message"), false);
353+
/// ```
354+
#[must_use]
355+
#[inline]
356+
#[unstable(feature = "result_contains_err", issue = "62358")]
357+
pub fn contains_err<F>(&self, f: &F) -> bool where F: PartialEq<E> {
358+
match self {
359+
Ok(_) => false,
360+
Err(e) => f == e
361+
}
362+
}
363+
312364
/////////////////////////////////////////////////////////////////////////
313365
// Adapter for each variant
314366
/////////////////////////////////////////////////////////////////////////

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn inline_asm_call(
146146
unsafe {
147147
// Ask LLVM to verify that the constraints are well-formed.
148148
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
149-
debug!("Constraint verification result: {:?}", constraints_ok);
149+
debug!("constraint verification result: {:?}", constraints_ok);
150150
if constraints_ok {
151151
let v = llvm::LLVMRustInlineAsm(
152152
fty,

src/librustc_codegen_llvm/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
215215
funclet: Option<&Funclet<'ll>>,
216216
) -> &'ll Value {
217217

218-
debug!("Invoke {:?} with args ({:?})",
218+
debug!("invoke {:?} with args ({:?})",
219219
llfn,
220220
args);
221221

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

1038-
debug!("Call {:?} with args ({:?})",
1038+
debug!("call {:?} with args ({:?})",
10391039
llfn,
10401040
args);
10411041

@@ -1238,7 +1238,7 @@ impl Builder<'a, 'll, 'tcx> {
12381238
if dest_ptr_ty == stored_ptr_ty {
12391239
ptr
12401240
} else {
1241-
debug!("Type mismatch in store. \
1241+
debug!("type mismatch in store. \
12421242
Expected {:?}, got {:?}; inserting bitcast",
12431243
dest_ptr_ty, stored_ptr_ty);
12441244
self.bitcast(ptr, stored_ptr_ty)
@@ -1274,7 +1274,7 @@ impl Builder<'a, 'll, 'tcx> {
12741274
.map(|(i, (expected_ty, &actual_val))| {
12751275
let actual_ty = self.val_ty(actual_val);
12761276
if expected_ty != actual_ty {
1277-
debug!("Type mismatch in function call of {:?}. \
1277+
debug!("type mismatch in function call of {:?}. \
12781278
Expected {:?} for param {}, got {:?}; injecting bitcast",
12791279
llfn, expected_ty, i, actual_ty);
12801280
self.bitcast(actual_val, expected_ty)

src/librustc_codegen_ssa/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
433433
if cx.get_defined_value("main").is_some() {
434434
// FIXME: We should be smart and show a better diagnostic here.
435435
cx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
436-
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
436+
.help("did you use `#[no_mangle]` on `fn main`? Use `#[start]` instead")
437437
.emit();
438438
cx.sess().abort_if_errors();
439439
bug!();

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
138138
// * packed struct - there is no alignment padding
139139
match field.ty.sty {
140140
_ if self.llextra.is_none() => {
141-
debug!("Unsized field `{}`, of `{:?}` has no metadata for adjustment",
141+
debug!("unsized field `{}`, of `{:?}` has no metadata for adjustment",
142142
ix, self.llval);
143143
return simple();
144144
}

src/librustc_codegen_utils/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn find_crate_name(sess: Option<&Session>,
5757
if let Some(ref s) = sess.opts.crate_name {
5858
if let Some((attr, name)) = attr_crate_name {
5959
if name.as_str() != *s {
60-
let msg = format!("--crate-name and #[crate_name] are \
60+
let msg = format!("`--crate-name` and `#[crate_name]` are \
6161
required to match, but `{}` != `{}`",
6262
s, name);
6363
sess.span_err(attr.span, &msg);

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
459459
let (unsize_did, coerce_unsized_did) = if let (Some(u), Some(cu)) = traits {
460460
(u, cu)
461461
} else {
462-
debug!("Missing Unsize or CoerceUnsized traits");
462+
debug!("missing Unsize or CoerceUnsized traits");
463463
return Err(TypeError::Mismatch);
464464
};
465465

src/librustc_typeck/check/generator_interior.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn resolve_interior<'a, 'tcx>(
130130
// if a Sync generator contains an &'α T, we need to check whether &'α T: Sync),
131131
// so knowledge of the exact relationships between them isn't particularly important.
132132

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

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

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

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

150150
// Unify the type variable inside the generator with the new witness

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12301230
if nightly_options::is_nightly_build() {
12311231
for (candidate, feature) in unstable_candidates {
12321232
diag.help(&format!(
1233-
"add #![feature({})] to the crate attributes to enable `{}`",
1233+
"add `#![feature({})]` to the crate attributes to enable `{}`",
12341234
feature,
12351235
self.tcx.def_path_str(candidate.item.def_id),
12361236
));
@@ -1432,7 +1432,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14321432
/// candidate method where the method name may have been misspelt. Similarly to other
14331433
/// Levenshtein based suggestions, we provide at most one such suggestion.
14341434
fn probe_for_lev_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
1435-
debug!("Probing for method names similar to {:?}",
1435+
debug!("probing for method names similar to {:?}",
14361436
self.method_name);
14371437

14381438
let steps = self.steps.clone();

0 commit comments

Comments
 (0)