Skip to content

Commit f875143

Browse files
committed
Auto merge of #89683 - GuillaumeGomez:rollup-q2mjd9m, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #86506 (Don't normalize xform_ret_ty during method candidate assembly ) - #89538 (Make rustdoc not highlight `->` and `=>` as operators) - #89649 (clippy::complexity fixes) - #89668 (Cfg hide more conditions for core and alloc) - #89669 (Remove special-casing of never primitive in rustdoc-json-types) - #89672 (Remove unwrap_or! macro) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 54bb4fe + cda07c7 commit f875143

File tree

36 files changed

+166
-84
lines changed

36 files changed

+166
-84
lines changed

Diff for: compiler/rustc_ast/src/lib.rs

-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
#[macro_use]
2121
extern crate rustc_macros;
2222

23-
#[macro_export]
24-
macro_rules! unwrap_or {
25-
($opt:expr, $default:expr) => {
26-
match $opt {
27-
Some(x) => x,
28-
None => $default,
29-
}
30-
};
31-
}
32-
3323
pub mod util {
3424
pub mod classify;
3525
pub mod comments;

Diff for: compiler/rustc_ast_lowering/src/item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13451345
generics
13461346
.params
13471347
.iter()
1348-
.find(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
1349-
.is_some()
1348+
.any(|p| def_id == self.resolver.local_def_id(p.id).to_def_id())
13501349
}
13511350
// Either the `bounded_ty` is not a plain type parameter, or
13521351
// it's not found in the generic type parameters list.

Diff for: compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
201201
let bb_data = &self.body[bb];
202202
debug_assert!(hi == bb_data.statements.len());
203203
for &succ_bb in bb_data.terminator().successors() {
204-
if self.visited.insert(succ_bb) == false {
204+
if !self.visited.insert(succ_bb) {
205205
if succ_bb == location.block && first_lo > 0 {
206206
// `succ_bb` has been seen before. If it wasn't
207207
// fully processed, add its first part to `stack`

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,7 @@ fn suggest_ampmut<'tcx>(
972972
if let Some(assignment_rhs_span) = opt_assignment_rhs_span {
973973
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) {
974974
let is_mutbl = |ty: &str| -> bool {
975-
if ty.starts_with("mut") {
976-
let rest = &ty[3..];
975+
if let Some(rest) = ty.strip_prefix("mut") {
977976
match rest.chars().next() {
978977
// e.g. `&mut x`
979978
Some(c) if c.is_whitespace() => true,

Diff for: compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<'a> TraitDef<'a> {
594594
GenericParamKind::Const { ty, kw_span, .. } => {
595595
let const_nodefault_kind = GenericParamKind::Const {
596596
ty: ty.clone(),
597-
kw_span: kw_span.clone(),
597+
kw_span: *kw_span,
598598

599599
// We can't have default values inside impl block
600600
default: None,

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
130130
.tcx()
131131
.sess
132132
.struct_span_err(span, &format!("`impl` associated type signature for `{}` doesn't match `trait` associated type signature", item_name));
133-
err.span_label(impl_sp, &format!("found"));
134-
err.span_label(trait_sp, &format!("expected"));
133+
err.span_label(impl_sp, "found");
134+
err.span_label(trait_sp, "expected");
135135

136136
err.emit();
137137
}

Diff for: compiler/rustc_lint/src/levels.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::context::{CheckLintNameResult, LintStore};
22
use crate::late::unerased_lint_store;
33
use rustc_ast as ast;
4-
use rustc_ast::unwrap_or;
54
use rustc_ast_pretty::pprust;
65
use rustc_data_structures::fx::FxHashMap;
76
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
@@ -233,7 +232,10 @@ impl<'s> LintLevelsBuilder<'s> {
233232
Some(lvl) => lvl,
234233
};
235234

236-
let mut metas = unwrap_or!(attr.meta_item_list(), continue);
235+
let mut metas = match attr.meta_item_list() {
236+
Some(x) => x,
237+
None => continue,
238+
};
237239

238240
if metas.is_empty() {
239241
// FIXME (#55112): issue unused-attributes lint for `#[level()]`

Diff for: compiler/rustc_lint/src/non_fmt_panic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ fn check_panic_str<'tcx>(
230230
Err(_) => (None, None),
231231
};
232232

233-
let mut fmt_parser =
234-
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
233+
let mut fmt_parser = Parser::new(fmt, style, snippet.clone(), false, ParseMode::Format);
235234
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
236235

237236
if n_arguments > 0 && fmt_parser.errors.is_empty() {

Diff for: compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Collector<'tcx> {
363363
.collect::<Vec<_>>();
364364
if existing.is_empty() {
365365
// Add if not found
366-
let new_name = passed_lib.new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
366+
let new_name: Option<&str> = passed_lib.new_name.as_deref();
367367
let lib = NativeLib {
368368
name: Some(Symbol::intern(new_name.unwrap_or(&passed_lib.name))),
369369
kind: passed_lib.kind,

Diff for: compiler/rustc_middle/src/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
986986
let niche = if def.repr.hide_niche() {
987987
None
988988
} else {
989-
Niche::from_scalar(dl, Size::ZERO, scalar.clone())
989+
Niche::from_scalar(dl, Size::ZERO, *scalar)
990990
};
991991
if let Some(niche) = niche {
992992
match st.largest_niche {
@@ -2273,7 +2273,7 @@ where
22732273
) -> TyMaybeWithLayout<'tcx> {
22742274
let tcx = cx.tcx();
22752275
let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> {
2276-
let layout = Layout::scalar(cx, tag.clone());
2276+
let layout = Layout::scalar(cx, tag);
22772277
TyAndLayout { layout: tcx.intern_layout(layout), ty: tag.value.to_ty(tcx) }
22782278
};
22792279

Diff for: compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
130130
TerminatorKind::Call {
131131
func: exchange_malloc,
132132
args: vec![Operand::Move(size), Operand::Move(align)],
133-
destination: Some((Place::from(storage), success)),
133+
destination: Some((storage, success)),
134134
cleanup: None,
135135
from_hir_call: false,
136136
fn_span: expr_span,
@@ -153,7 +153,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
153153
}
154154

155155
// Transmute `*mut u8` to the box (thus far, uninitialized):
156-
let box_ = Rvalue::ShallowInitBox(Operand::Move(Place::from(storage)), value.ty);
156+
let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value.ty);
157157
this.cfg.push_assign(block, source_info, Place::from(result), box_);
158158

159159
// initialize the box contents:

Diff for: compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,7 @@ impl<'tcx> SplitWildcard<'tcx> {
10681068
Missing {
10691069
nonexhaustive_enum_missing_real_variants: self
10701070
.iter_missing(pcx)
1071-
.filter(|c| !c.is_non_exhaustive())
1072-
.next()
1073-
.is_some(),
1071+
.any(|c| !c.is_non_exhaustive()),
10741072
}
10751073
} else {
10761074
Missing { nonexhaustive_enum_missing_real_variants: false }

Diff for: compiler/rustc_mir_transform/src/early_otherwise_branch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
263263
}
264264

265265
// check that the value being matched on is the same. The
266-
if this_bb_discr_info.targets_with_values.iter().find(|x| x.0 == value).is_none() {
266+
if !this_bb_discr_info.targets_with_values.iter().any(|x| x.0 == value) {
267267
trace!("NO: values being matched on are not the same");
268268
return None;
269269
}

Diff for: compiler/rustc_mir_transform/src/normalize_array_len.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl<'a, 'tcx> Patcher<'a, 'tcx> {
111111
Operand::Copy(place) | Operand::Move(place) => {
112112
// create new local
113113
let ty = operand.ty(self.local_decls, self.tcx);
114-
let local_decl =
115-
LocalDecl::with_source_info(ty, statement.source_info.clone());
114+
let local_decl = LocalDecl::with_source_info(ty, statement.source_info);
116115
let local = self.local_decls.push(local_decl);
117116
// make it live
118117
let mut make_live_statement = statement.clone();

Diff for: compiler/rustc_passes/src/check_attr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,7 @@ impl CheckAttrVisitor<'tcx> {
17671767
fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
17681768
if target != Target::MacroDef {
17691769
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1770-
lint.build(&format!("`#[macro_export]` only has an effect on macro definitions"))
1771-
.emit();
1770+
lint.build("`#[macro_export]` only has an effect on macro definitions").emit();
17721771
});
17731772
}
17741773
}

Diff for: compiler/rustc_resolve/src/imports.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
99
use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak};
1010
use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding};
1111

12-
use rustc_ast::unwrap_or;
1312
use rustc_ast::NodeId;
1413
use rustc_data_structures::fx::FxHashSet;
1514
use rustc_data_structures::ptr_key::PtrKey;
@@ -349,10 +348,10 @@ impl<'a> Resolver<'a> {
349348
if !self.is_accessible_from(single_import.vis.get(), parent_scope.module) {
350349
continue;
351350
}
352-
let module = unwrap_or!(
353-
single_import.imported_module.get(),
354-
return Err((Undetermined, Weak::No))
355-
);
351+
let module = match single_import.imported_module.get() {
352+
Some(x) => x,
353+
None => return Err((Undetermined, Weak::No)),
354+
};
356355
let ident = match single_import.kind {
357356
ImportKind::Single { source, .. } => source,
358357
_ => unreachable!(),

Diff for: compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
278278

279279
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
280280
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
281-
if self.is_poly == false {
281+
if !self.is_poly {
282282
visit::walk_expr(self, expr)
283283
}
284284
}
285285

286286
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
287287
self.is_poly |= pat.ty.definitely_has_param_types_or_consts(self.tcx);
288-
if self.is_poly == false {
288+
if !self.is_poly {
289289
visit::walk_pat(self, pat);
290290
}
291291
}
@@ -298,7 +298,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
298298
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
299299
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
300300
debug!("AbstractConstBuilder: is_poly={}", is_poly_vis.is_poly);
301-
if is_poly_vis.is_poly == false {
301+
if !is_poly_vis.is_poly {
302302
return Ok(None);
303303
}
304304

Diff for: compiler/rustc_traits/src/chalk/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
892892
match r {
893893
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
894894
ty::BoundRegionKind::BrNamed(def_id, _name) => {
895-
if self.named_parameters.iter().find(|d| **d == def_id).is_none() {
895+
if !self.named_parameters.iter().any(|d| *d == def_id) {
896896
self.named_parameters.push(def_id);
897897
}
898898
}

Diff for: compiler/rustc_typeck/src/check/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
329329
let obligation = Obligation::new(
330330
ObligationCause::dummy_with_span(callee_expr.span),
331331
self.param_env,
332-
predicate.clone(),
332+
*predicate,
333333
);
334334
let result = self.infcx.evaluate_obligation(&obligation);
335335
self.tcx

Diff for: compiler/rustc_typeck/src/check/method/probe.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -753,17 +753,27 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
753753
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
754754
let impl_ty = impl_ty.subst(self.tcx, impl_substs);
755755

756+
debug!("impl_ty: {:?}", impl_ty);
757+
756758
// Determine the receiver type that the method itself expects.
757-
let xform_tys = self.xform_self_ty(&item, impl_ty, impl_substs);
759+
let (xform_self_ty, xform_ret_ty) = self.xform_self_ty(&item, impl_ty, impl_substs);
760+
debug!("xform_self_ty: {:?}, xform_ret_ty: {:?}", xform_self_ty, xform_ret_ty);
758761

759762
// We can't use normalize_associated_types_in as it will pollute the
760763
// fcx's fulfillment context after this probe is over.
764+
// Note: we only normalize `xform_self_ty` here since the normalization
765+
// of the return type can lead to inference results that prohibit
766+
// valid canidates from being found, see issue #85671
767+
// FIXME Postponing the normalization of the return type likely only hides a deeper bug,
768+
// which might be caused by the `param_env` itself. The clauses of the `param_env`
769+
// maybe shouldn't include `Param`s, but rather fresh variables or be canonicalized,
770+
// see isssue #89650
761771
let cause = traits::ObligationCause::misc(self.span, self.body_id);
762772
let selcx = &mut traits::SelectionContext::new(self.fcx);
763-
let traits::Normalized { value: (xform_self_ty, xform_ret_ty), obligations } =
764-
traits::normalize(selcx, self.param_env, cause, xform_tys);
773+
let traits::Normalized { value: xform_self_ty, obligations } =
774+
traits::normalize(selcx, self.param_env, cause, xform_self_ty);
765775
debug!(
766-
"assemble_inherent_impl_probe: xform_self_ty = {:?}/{:?}",
776+
"assemble_inherent_impl_probe after normalization: xform_self_ty = {:?}/{:?}",
767777
xform_self_ty, xform_ret_ty
768778
);
769779

@@ -1420,6 +1430,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14201430
};
14211431

14221432
let mut result = ProbeResult::Match;
1433+
let mut xform_ret_ty = probe.xform_ret_ty;
1434+
debug!(?xform_ret_ty);
1435+
14231436
let selcx = &mut traits::SelectionContext::new(self);
14241437
let cause = traits::ObligationCause::misc(self.span, self.body_id);
14251438

@@ -1428,7 +1441,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14281441
// match as well (or at least may match, sometimes we
14291442
// don't have enough information to fully evaluate).
14301443
match probe.kind {
1431-
InherentImplCandidate(substs, ref ref_obligations) => {
1444+
InherentImplCandidate(ref substs, ref ref_obligations) => {
1445+
// `xform_ret_ty` hasn't been normalized yet, only `xform_self_ty`,
1446+
// see the reasons mentioned in the comments in `assemble_inherent_impl_probe`
1447+
// for why this is necessary
1448+
let traits::Normalized {
1449+
value: normalized_xform_ret_ty,
1450+
obligations: normalization_obligations,
1451+
} = traits::normalize(selcx, self.param_env, cause.clone(), probe.xform_ret_ty);
1452+
xform_ret_ty = normalized_xform_ret_ty;
1453+
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
1454+
14321455
// Check whether the impl imposes obligations we have to worry about.
14331456
let impl_def_id = probe.item.container.id();
14341457
let impl_bounds = self.tcx.predicates_of(impl_def_id);
@@ -1442,7 +1465,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14421465

14431466
let candidate_obligations = impl_obligations
14441467
.chain(norm_obligations.into_iter())
1445-
.chain(ref_obligations.iter().cloned());
1468+
.chain(ref_obligations.iter().cloned())
1469+
.chain(normalization_obligations.into_iter());
1470+
14461471
// Evaluate those obligations to see if they might possibly hold.
14471472
for o in candidate_obligations {
14481473
let o = self.resolve_vars_if_possible(o);
@@ -1527,9 +1552,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15271552
}
15281553

15291554
if let ProbeResult::Match = result {
1530-
if let (Some(return_ty), Some(xform_ret_ty)) =
1531-
(self.return_type, probe.xform_ret_ty)
1532-
{
1555+
if let (Some(return_ty), Some(xform_ret_ty)) = (self.return_type, xform_ret_ty) {
15331556
let xform_ret_ty = self.resolve_vars_if_possible(xform_ret_ty);
15341557
debug!(
15351558
"comparing return_ty {:?} with xform ret ty {:?}",
@@ -1669,6 +1692,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16691692
self.static_candidates.push(source);
16701693
}
16711694

1695+
#[instrument(level = "debug", skip(self))]
16721696
fn xform_self_ty(
16731697
&self,
16741698
item: &ty::AssocItem,
@@ -1683,9 +1707,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16831707
}
16841708
}
16851709

1710+
#[instrument(level = "debug", skip(self))]
16861711
fn xform_method_sig(&self, method: DefId, substs: SubstsRef<'tcx>) -> ty::FnSig<'tcx> {
16871712
let fn_sig = self.tcx.fn_sig(method);
1688-
debug!("xform_self_ty(fn_sig={:?}, substs={:?})", fn_sig, substs);
1713+
debug!(?fn_sig);
16891714

16901715
assert!(!substs.has_escaping_bound_vars());
16911716

Diff for: compiler/rustc_typeck/src/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
413413
}
414414

415415
hir::ExprKind::Match(ref discr, arms, _) => {
416-
self.link_match(discr, &arms[..]);
416+
self.link_match(discr, arms);
417417

418418
intravisit::walk_expr(self, expr);
419419
}

Diff for: library/alloc/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@
6969
)]
7070
#![cfg_attr(
7171
not(bootstrap),
72-
doc(cfg_hide(not(test), not(any(test, bootstrap)), target_has_atomic = "ptr"))
72+
doc(cfg_hide(
73+
not(test),
74+
not(any(test, bootstrap)),
75+
any(not(feature = "miri-test-libstd"), test, doctest),
76+
target_has_atomic = "ptr"
77+
))
7378
)]
7479
#![no_std]
7580
#![needs_allocator]

Diff for: library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
not(bootstrap),
6565
doc(cfg_hide(
6666
not(test),
67+
any(not(feature = "miri-test-libstd"), test, doctest),
6768
target_pointer_width = "16",
6869
target_pointer_width = "32",
6970
target_pointer_width = "64",

0 commit comments

Comments
 (0)