Skip to content

Commit db592f4

Browse files
committed
Auto merge of #62485 - Centril:rollup-gg3it1u, r=Centril
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
2 parents a824723 + ada2684 commit db592f4

26 files changed

+186
-54
lines changed

src/libcore/option.rs

+26
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

+52
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

+1-1
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

+4-4
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+2-2
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();

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
983983
};
984984
self.assign(local.span, local.hir_id, local_ty);
985985

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

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

44634463
for leaf_ty in ty.walk() {
44644464
if let ty::Param(ty::ParamTy { index, .. }) = leaf_ty.sty {
4465-
debug!("Found use of ty param num {}", index);
4465+
debug!("found use of ty param num {}", index);
44664466
types_used[index as usize - own_counts.lifetimes] = true;
44674467
} else if let ty::Error = leaf_ty.sty {
44684468
// If there is already another error, do not emit

src/librustc_typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
799799
debug!("callee_region={:?}", callee_region);
800800

801801
for arg_expr in arg_exprs {
802-
debug!("Argument: {:?}", arg_expr);
802+
debug!("argument: {:?}", arg_expr);
803803

804804
// ensure that any regions appearing in the argument type are
805805
// valid for at least the lifetime of the function:

src/librustc_typeck/check/writeback.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
646646
let n_ty = self.fcx.node_ty(hir_id);
647647
let n_ty = self.resolve(&n_ty, &span);
648648
self.write_ty_to_tables(hir_id, n_ty);
649-
debug!("Node {:?} has type {:?}", hir_id, n_ty);
649+
debug!("node {:?} has type {:?}", hir_id, n_ty);
650650

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

671671
Some(adjustment) => {
672672
let resolved_adjustment = self.resolve(&adjustment, &span);
673673
debug!(
674-
"Adjustments for node {:?}: {:?}",
674+
"adjustments for node {:?}: {:?}",
675675
hir_id, resolved_adjustment
676676
);
677677
self.tables
@@ -689,7 +689,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
689689
.remove(hir_id);
690690
match adjustment {
691691
None => {
692-
debug!("No pat_adjustments for node {:?}", hir_id);
692+
debug!("no pat_adjustments for node {:?}", hir_id);
693693
}
694694

695695
Some(adjustment) => {

src/librustc_typeck/collect.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
22562256
tcx.hir().hir_to_pretty_string(ast_ty.hir_id)
22572257
),
22582258
)
2259-
.help("add #![feature(simd_ffi)] to the crate attributes to enable")
2259+
.help("add `#![feature(simd_ffi)]` to the crate attributes to enable")
22602260
.emit();
22612261
}
22622262
};
@@ -2479,7 +2479,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
24792479
}
24802480
} else if attr.check_name(sym::target_feature) {
24812481
if tcx.fn_sig(id).unsafety() == Unsafety::Normal {
2482-
let msg = "#[target_feature(..)] can only be applied to `unsafe` functions";
2482+
let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
24832483
tcx.sess.struct_span_err(attr.span, msg)
24842484
.span_label(attr.span, "can only be applied to `unsafe` functions")
24852485
.span_label(tcx.def_span(id), "not an `unsafe` function")
@@ -2593,8 +2593,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
25932593
if let Some(span) = inline_span {
25942594
tcx.sess.span_err(
25952595
span,
2596-
"cannot use #[inline(always)] with \
2597-
#[target_feature]",
2596+
"cannot use `#[inline(always)]` with \
2597+
`#[target_feature]`",
25982598
);
25992599
}
26002600
}

src/librustc_typeck/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4848,6 +4848,6 @@ register_diagnostics! {
48484848
E0641, // cannot cast to/from a pointer with an unknown kind
48494849
E0645, // trait aliases not finished
48504850
E0719, // duplicate values for associated type binding
4851-
E0722, // Malformed #[optimize] attribute
4851+
E0722, // Malformed `#[optimize]` attribute
48524852
E0724, // `#[ffi_returns_twice]` is only allowed in foreign functions
48534853
}

src/librustc_typeck/variance/solve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
6464
let old_value = self.solutions[inferred];
6565
let new_value = glb(variance, old_value);
6666
if old_value != new_value {
67-
debug!("Updating inferred {} \
67+
debug!("updating inferred {} \
6868
from {:?} to {:?} due to {:?}",
6969
inferred,
7070
old_value,

0 commit comments

Comments
 (0)