Skip to content

Commit 3afb2bb

Browse files
committed
Auto merge of rust-lang#130253 - workingjubilee:rollup-npqpnaf, r=workingjubilee
Rollup of 10 pull requests Successful merges: - rust-lang#129103 (Don't warn empty branches unreachable for now) - rust-lang#129696 (update stdarch) - rust-lang#129835 (enable const-float-classify test, and test_next_up/down on 32bit x86) - rust-lang#130077 (Fix linking error when compiling for 32-bit watchOS) - rust-lang#130114 (Remove needless returns detected by clippy in the compiler) - rust-lang#130168 (maint: update docs for change_time ext and doc links) - rust-lang#130228 (notify Miri when intrinsics are changed) - rust-lang#130239 (miri: fix overflow detection for unsigned pointer offset) - rust-lang#130244 (Use the same span for attributes and Try expansion of ?) - rust-lang#130248 (Limit `libc::link` usage to `nto70` target only, not NTO OS) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8d6b88b + b4201d3 commit 3afb2bb

File tree

83 files changed

+504
-861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+504
-861
lines changed

compiler/rustc_ast/src/ast_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl HasTokens for StmtKind {
153153
StmtKind::Let(local) => local.tokens.as_ref(),
154154
StmtKind::Item(item) => item.tokens(),
155155
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
156-
StmtKind::Empty => return None,
156+
StmtKind::Empty => None,
157157
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
158158
}
159159
}
@@ -162,7 +162,7 @@ impl HasTokens for StmtKind {
162162
StmtKind::Let(local) => Some(&mut local.tokens),
163163
StmtKind::Item(item) => item.tokens_mut(),
164164
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
165-
StmtKind::Empty => return None,
165+
StmtKind::Empty => None,
166166
StmtKind::MacCall(mac) => Some(&mut mac.tokens),
167167
}
168168
}

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18371837
Safety::Default,
18381838
sym::allow,
18391839
sym::unreachable_code,
1840-
self.lower_span(span),
1840+
try_span,
18411841
);
18421842
let attrs: AttrVec = thin_vec![attr];
18431843

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
12401240
candidates.push(meta_lit.symbol);
12411241
}
12421242

1243-
return Some(candidates);
1243+
Some(candidates)
12441244
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
36693669
reinits.push(location);
36703670
return true;
36713671
}
3672-
return false;
3672+
false
36733673
};
36743674

36753675
while let Some(location) = stack.pop() {

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
214214
let delegate = FnMutDelegate {
215215
regions: &mut |br: ty::BoundRegion| {
216216
if let Some(ex_reg_var) = reg_map.get(&br) {
217-
return *ex_reg_var;
217+
*ex_reg_var
218218
} else {
219219
let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name());
220220
debug!(?ex_reg_var);

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub(crate) fn check_tied_features(
290290
}
291291
}
292292
}
293-
return None;
293+
None
294294
}
295295

296296
/// Used to generate cfg variables and apply features

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn link_rlib<'a>(
438438
ab.add_file(&lib)
439439
}
440440

441-
return Ok(ab);
441+
Ok(ab)
442442
}
443443

444444
/// Extract all symbols defined in raw-dylib libraries, collated by library name.
@@ -1319,15 +1319,15 @@ fn link_sanitizer_runtime(
13191319
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
13201320
let path = sess.target_tlib_path.dir.join(filename);
13211321
if path.exists() {
1322-
return sess.target_tlib_path.dir.clone();
1322+
sess.target_tlib_path.dir.clone()
13231323
} else {
13241324
let default_sysroot =
13251325
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
13261326
let default_tlib = filesearch::make_target_lib_path(
13271327
&default_sysroot,
13281328
sess.opts.target_triple.triple(),
13291329
);
1330-
return default_tlib;
1330+
default_tlib
13311331
}
13321332
}
13331333

compiler/rustc_codegen_ssa/src/back/linker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,6 @@ impl<'a> Linker for L4Bender<'a> {
14841484
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
14851485
// ToDo, not implemented, copy from GCC
14861486
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
1487-
return;
14881487
}
14891488

14901489
fn subsystem(&mut self, subsystem: &str) {

compiler/rustc_codegen_ssa/src/back/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
171171
"Metadata at offset {offset} with size {len} is beyond .info section"
172172
));
173173
}
174-
return Ok(&info_data[offset..(offset + len)]);
174+
Ok(&info_data[offset..(offset + len)])
175175
} else {
176-
return Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"));
177-
};
176+
Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"))
177+
}
178178
}
179179

180180
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
@@ -413,7 +413,7 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
413413

414414
/// Is Apple's CPU subtype `arm64e`s
415415
fn macho_is_arm64e(target: &Target) -> bool {
416-
return target.llvm_target.starts_with("arm64e");
416+
target.llvm_target.starts_with("arm64e")
417417
}
418418

419419
pub enum MetadataPosition {

compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
235235
if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
236236
// Ensure that our checks imply actual ABI compatibility for this concrete call.
237237
assert!(caller_abi.eq_abi(callee_abi));
238-
return Ok(true);
238+
Ok(true)
239239
} else {
240240
trace!(
241241
"check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
242242
caller_abi, callee_abi
243243
);
244-
return Ok(false);
244+
Ok(false)
245245
}
246246
}
247247

compiler/rustc_const_eval/src/interpret/operator.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
303303
let pointee_layout = self.layout_of(pointee_ty)?;
304304
assert!(pointee_layout.abi.is_sized());
305305

306-
// We cannot overflow i64 as a type's size must be <= isize::MAX.
306+
// The size always fits in `i64` as it can be at most `isize::MAX`.
307307
let pointee_size = i64::try_from(pointee_layout.size.bytes()).unwrap();
308+
// This uses the same type as `right`, which can be `isize` or `usize`.
309+
// `pointee_size` is guaranteed to fit into both types.
308310
let pointee_size = ImmTy::from_int(pointee_size, right.layout);
309311
// Multiply element size and element count.
310312
let (val, overflowed) = self
@@ -316,6 +318,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
316318
}
317319

318320
let offset_bytes = val.to_target_isize(self)?;
321+
if !right.layout.abi.is_signed() && offset_bytes < 0 {
322+
// We were supposed to do an unsigned offset but the result is negative -- this
323+
// can only mean that the cast wrapped around.
324+
throw_ub!(PointerArithOverflow)
325+
}
319326
let offset_ptr = self.ptr_offset_inbounds(ptr, offset_bytes)?;
320327
Ok(ImmTy::from_scalar(Scalar::from_maybe_pointer(offset_ptr, self), left.layout))
321328
}

compiler/rustc_expand/src/mbe/transcribe.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -773,34 +773,34 @@ fn extract_symbol_from_pnr<'a>(
773773
match pnr {
774774
ParseNtResult::Ident(nt_ident, is_raw) => {
775775
if let IdentIsRaw::Yes = is_raw {
776-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
776+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
777+
} else {
778+
Ok(nt_ident.name)
777779
}
778-
return Ok(nt_ident.name);
779780
}
780781
ParseNtResult::Tt(TokenTree::Token(
781782
Token { kind: TokenKind::Ident(symbol, is_raw), .. },
782783
_,
783784
)) => {
784785
if let IdentIsRaw::Yes = is_raw {
785-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
786+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
787+
} else {
788+
Ok(*symbol)
786789
}
787-
return Ok(*symbol);
788790
}
789791
ParseNtResult::Tt(TokenTree::Token(
790792
Token {
791793
kind: TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }),
792794
..
793795
},
794796
_,
795-
)) => {
796-
return Ok(*symbol);
797-
}
797+
)) => Ok(*symbol),
798798
ParseNtResult::Nt(nt)
799799
if let Nonterminal::NtLiteral(expr) = &**nt
800800
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) =
801801
&expr.kind =>
802802
{
803-
return Ok(*symbol);
803+
Ok(*symbol)
804804
}
805805
_ => Err(dcx
806806
.struct_err(

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>(
10381038
false,
10391039
);
10401040

1041-
return diag.emit();
1041+
diag.emit()
10421042
}
10431043

10441044
fn check_region_bounds_on_impl_item<'tcx>(

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
274274
return false;
275275
}
276276

277-
return true;
277+
true
278278
})
279279
.collect::<Vec<_>>();
280280

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
605605
Abi::Rust,
606606
));
607607

608-
return Some(ExpectedSig { cause_span, sig });
608+
Some(ExpectedSig { cause_span, sig })
609609
}
610610

611611
fn sig_of_closure(

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10421042
return true;
10431043
}
10441044
}
1045-
return false;
1045+
false
10461046
}
10471047

10481048
fn explain_self_literal(

compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'tcx> ArgMatrix<'tcx> {
307307
permutation.into_iter().map(|x| x.unwrap()).collect();
308308
return Some(Issue::Permutation(final_permutation));
309309
}
310-
return None;
310+
None
311311
}
312312

313313
// Obviously, detecting exact user intention is impossible, so the goal here is to
@@ -410,6 +410,6 @@ impl<'tcx> ArgMatrix<'tcx> {
410410
// sort errors with same type by the order they appear in the source
411411
// so that suggestion will be handled properly, see #112507
412412
errors.sort();
413-
return (errors, matched_inputs);
413+
(errors, matched_inputs)
414414
}
415415
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20512051

20522052
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
20532053
err.span_suggestion_verbose(span.shrink_to_hi(), msg, sugg, Applicability::HasPlaceholders);
2054-
return true;
2054+
true
20552055
}
20562056

20572057
pub(crate) fn suggest_coercing_result_via_try_operator(

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ impl<'tcx> InferCtxt<'tcx> {
14811481
// This hoists the borrow/release out of the loop body.
14821482
let inner = self.inner.try_borrow();
14831483

1484-
return move |infer_var: TyOrConstInferVar| match (infer_var, &inner) {
1484+
move |infer_var: TyOrConstInferVar| match (infer_var, &inner) {
14851485
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
14861486
use self::type_variable::TypeVariableValue;
14871487

@@ -1491,7 +1491,7 @@ impl<'tcx> InferCtxt<'tcx> {
14911491
)
14921492
}
14931493
_ => false,
1494-
};
1494+
}
14951495
}
14961496

14971497
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn extract_iterator_next_call<'tcx>(
133133
{
134134
Some(recv)
135135
} else {
136-
return None;
136+
None
137137
}
138138
}
139139

compiler/rustc_middle/src/hir/map/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
7171
debug_assert_ne!(parent_id, self.current_id);
7272

7373
self.current_id = parent_id;
74-
return Some(parent_id);
74+
Some(parent_id)
7575
}
7676
}
7777

@@ -103,7 +103,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
103103
self.current_id = HirId::make_owner(parent_id.def_id);
104104

105105
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
106-
return Some((self.current_id.owner, node));
106+
Some((self.current_id.owner, node))
107107
}
108108
}
109109

@@ -1233,14 +1233,14 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12331233
body_owners,
12341234
..
12351235
} = collector;
1236-
return ModuleItems {
1236+
ModuleItems {
12371237
submodules: submodules.into_boxed_slice(),
12381238
free_items: items.into_boxed_slice(),
12391239
trait_items: trait_items.into_boxed_slice(),
12401240
impl_items: impl_items.into_boxed_slice(),
12411241
foreign_items: foreign_items.into_boxed_slice(),
12421242
body_owners: body_owners.into_boxed_slice(),
1243-
};
1243+
}
12441244
}
12451245

12461246
pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
@@ -1262,14 +1262,14 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
12621262
..
12631263
} = collector;
12641264

1265-
return ModuleItems {
1265+
ModuleItems {
12661266
submodules: submodules.into_boxed_slice(),
12671267
free_items: items.into_boxed_slice(),
12681268
trait_items: trait_items.into_boxed_slice(),
12691269
impl_items: impl_items.into_boxed_slice(),
12701270
foreign_items: foreign_items.into_boxed_slice(),
12711271
body_owners: body_owners.into_boxed_slice(),
1272-
};
1272+
}
12731273
}
12741274

12751275
struct ItemCollector<'tcx> {

compiler/rustc_middle/src/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
641641
pub fn write_uninit(&mut self, cx: &impl HasDataLayout, range: AllocRange) -> AllocResult {
642642
self.mark_init(range, false);
643643
self.provenance.clear(range, cx)?;
644-
return Ok(());
644+
Ok(())
645645
}
646646

647647
/// Remove all provenance in the given memory range.

compiler/rustc_middle/src/mir/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1166,10 +1166,9 @@ impl<'tcx> LocalDecl<'tcx> {
11661166
/// Returns `true` if this is a DerefTemp
11671167
pub fn is_deref_temp(&self) -> bool {
11681168
match self.local_info() {
1169-
LocalInfo::DerefTemp => return true,
1170-
_ => (),
1169+
LocalInfo::DerefTemp => true,
1170+
_ => false,
11711171
}
1172-
return false;
11731172
}
11741173

11751174
/// Returns `true` is the local is from a compiler desugaring, e.g.,

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ impl<'tcx> TyCtxt<'tcx> {
20072007
));
20082008
}
20092009
}
2010-
return None;
2010+
None
20112011
}
20122012

20132013
/// Checks if the bound region is in Impl Item.

compiler/rustc_middle/src/ty/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl BoundRegionKind {
431431

432432
pub fn get_id(&self) -> Option<DefId> {
433433
match *self {
434-
BoundRegionKind::BrNamed(id, _) => return Some(id),
434+
BoundRegionKind::BrNamed(id, _) => Some(id),
435435
_ => None,
436436
}
437437
}

0 commit comments

Comments
 (0)