Skip to content

Commit 4933094

Browse files
committed
Auto merge of #155851 - jhpratt:rollup-Jst4hhC, r=jhpratt
Rollup of 12 pull requests Successful merges: - #149624 (Fix requires_lto targets needing lto set in cargo) - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.) - #155579 (Make Rcs and Arcs use pointer comparison for unsized types) - #155588 (Implement more traits for FRTs) - #155708 (Fix heap overflow in slice::join caused by misbehaving Borrow) - #155778 (Avoid Vec allocation in TyCtxt::mk_place_elem) - #151014 (std: sys: process: uefi: Add program searching) - #155682 (Add boxing suggestions for `impl Trait` return type mismatches) - #155770 (Avoid misleading closure return type note) - #155818 (Convert attribute `FinalizeFn` to fn pointer) - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`) - #155835 (couple of `crate_name` cleanups)
2 parents ca9a134 + bd2d1a8 commit 4933094

31 files changed

Lines changed: 568 additions & 61 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,11 @@ fn parse_directive_items<'p, S: Stage>(
236236
}}
237237

238238
macro or_malformed($($code:tt)*) {{
239-
let Some(ret) = (||{
240-
Some($($code)*)
241-
})() else {
239+
let Some(ret) = (
240+
try {
241+
$($code)*
242+
}
243+
) else {
242244
malformed!()
243245
};
244246
ret

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ pub(super) struct GroupTypeInnerAccept<S: Stage> {
8484

8585
pub(crate) type AcceptFn<S> =
8686
Box<dyn for<'sess, 'a> Fn(&mut AcceptContext<'_, 'sess, S>, &ArgParser) + Send + Sync>;
87-
pub(crate) type FinalizeFn<S> =
88-
Box<dyn Send + Sync + Fn(&mut FinalizeContext<'_, '_, S>) -> Option<AttributeKind>>;
87+
pub(crate) type FinalizeFn<S> = fn(&mut FinalizeContext<'_, '_, S>) -> Option<AttributeKind>;
8988

9089
macro_rules! attribute_parsers {
9190
(
@@ -131,10 +130,10 @@ macro_rules! attribute_parsers {
131130
}),
132131
safety: <$names as crate::attributes::AttributeParser<$stage>>::SAFETY,
133132
allowed_targets: <$names as crate::attributes::AttributeParser<$stage>>::ALLOWED_TARGETS,
134-
finalizer: Box::new(|cx| {
133+
finalizer: |cx| {
135134
let state = STATE_OBJECT.take();
136135
state.finalize(cx)
137-
})
136+
}
138137
});
139138
}
140139
Entry::Occupied(_) => panic!("Attribute {path:?} has multiple accepters"),

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
297297
let mut attr_paths: Vec<RefPathParser<'_>> = Vec::new();
298298
let mut early_parsed_state = EarlyParsedState::default();
299299

300-
let mut finalizers: Vec<&FinalizeFn<S>> = Vec::with_capacity(attrs.len());
300+
let mut finalizers: Vec<FinalizeFn<S>> = Vec::with_capacity(attrs.len());
301301

302302
for attr in attrs {
303303
// If we're only looking for a single attribute, skip all the ones we don't care about.
@@ -413,7 +413,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
413413
};
414414

415415
(accept.accept_fn)(&mut cx, &args);
416-
finalizers.push(&accept.finalizer);
416+
finalizers.push(accept.finalizer);
417417

418418
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
419419
Self::check_target(&accept.allowed_targets, target, &mut cx);

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl ModuleConfig {
153153
// `#![no_builtins]` is assumed to not participate in LTO and
154154
// instead goes on to generate object code.
155155
EmitObj::Bitcode
156-
} else if need_bitcode_in_object(tcx) {
156+
} else if need_bitcode_in_object(tcx) || sess.target.requires_lto {
157157
EmitObj::ObjectCode(BitcodeSection::Full)
158158
} else {
159159
EmitObj::ObjectCode(BitcodeSection::None)

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,9 @@ impl<'tcx> CoerceMany<'tcx> {
20092009
// note in this case, since it would be incorrect.
20102010
&& let Some(fn_sig) = fcx.body_fn_sig()
20112011
&& fn_sig.output().is_ty_var()
2012+
&& fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| {
2013+
fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected
2014+
})
20122015
{
20132016
err.span_note(sp, format!("return type inferred to be `{expected}` here"));
20142017
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::util::parser::ExprPrecedence;
77
use rustc_data_structures::packed::Pu128;
88
use rustc_errors::{Applicability, Diag, MultiSpan, listify, msg};
99
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
10+
use rustc_hir::intravisit::Visitor;
1011
use rustc_hir::lang_items::LangItem;
1112
use rustc_hir::{
1213
self as hir, Arm, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind,
@@ -26,13 +27,14 @@ use rustc_session::errors::ExprParenthesesNeeded;
2627
use rustc_span::{ExpnKind, Ident, MacroKind, Span, Spanned, Symbol, sym};
2728
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2829
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
30+
use rustc_trait_selection::error_reporting::traits::suggestions::ReturnsVisitor;
2931
use rustc_trait_selection::infer::InferCtxtExt;
3032
use rustc_trait_selection::traits;
3133
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
3234
use tracing::{debug, instrument};
3335

3436
use super::FnCtxt;
35-
use crate::errors;
37+
use crate::errors::{self, SuggestBoxingForReturnImplTrait};
3638
use crate::fn_ctxt::rustc_span::BytePos;
3739
use crate::method::probe;
3840
use crate::method::probe::{IsSuggestion, Mode, ProbeScope};
@@ -963,6 +965,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
963965
);
964966
}
965967

968+
let trait_def_id = trait_ref.trait_ref.path.res.def_id();
969+
if self.tcx.is_dyn_compatible(trait_def_id) {
970+
err.subdiagnostic(SuggestBoxingForReturnImplTrait::ChangeReturnType {
971+
start_sp: hir_ty.span.with_hi(hir_ty.span.lo() + BytePos(4)),
972+
end_sp: hir_ty.span.shrink_to_hi(),
973+
});
974+
975+
let body = self.tcx.hir_body_owned_by(fn_id);
976+
let mut visitor = ReturnsVisitor::default();
977+
visitor.visit_body(&body);
978+
979+
if !visitor.returns.is_empty() {
980+
let starts: Vec<Span> = visitor
981+
.returns
982+
.iter()
983+
.filter(|expr| expr.span.can_be_used_for_suggestions())
984+
.map(|expr| expr.span.shrink_to_lo())
985+
.collect();
986+
let ends: Vec<Span> = visitor
987+
.returns
988+
.iter()
989+
.filter(|expr| expr.span.can_be_used_for_suggestions())
990+
.map(|expr| expr.span.shrink_to_hi())
991+
.collect();
992+
993+
if !starts.is_empty() {
994+
err.subdiagnostic(SuggestBoxingForReturnImplTrait::BoxReturnExpr {
995+
starts,
996+
ends,
997+
});
998+
}
999+
}
1000+
}
1001+
9661002
self.try_suggest_return_impl_trait(err, expected, found, fn_id);
9671003
self.try_note_caller_chooses_ty_for_ty_param(err, expected, found);
9681004
return true;

compiler/rustc_middle/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(crate) struct Reentrant;
143143
#[note(
144144
"an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again"
145145
)]
146-
#[note("as a workaround, you can run {$run_cmd} to allow your project to compile")]
146+
#[note("as a workaround, you can {$run_cmd} to allow your project to compile")]
147147
pub(crate) struct IncrementCompilation {
148148
pub run_cmd: String,
149149
pub dep_node: String,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,10 +2416,10 @@ impl<'tcx> TyCtxt<'tcx> {
24162416
/// to build a full `Place` it's just a convenient way to grab a projection and modify it in
24172417
/// flight.
24182418
pub fn mk_place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> {
2419-
let mut projection = place.projection.to_vec();
2420-
projection.push(elem);
2421-
2422-
Place { local: place.local, projection: self.mk_place_elems(&projection) }
2419+
Place {
2420+
local: place.local,
2421+
projection: self.mk_place_elems_from_iter(place.projection.iter().chain([elem])),
2422+
}
24232423
}
24242424

24252425
pub fn mk_poly_existential_predicates(

compiler/rustc_middle/src/verify_ich.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::cell::Cell;
22

33
use rustc_data_structures::fingerprint::Fingerprint;
4+
use rustc_hir::def_id::LOCAL_CRATE;
5+
use rustc_session::utils::was_invoked_from_cargo;
46
use tracing::instrument;
57

68
use crate::dep_graph::{DepGraphData, SerializedDepNodeIndex};
@@ -66,10 +68,10 @@ fn incremental_verify_ich_failed<'tcx>(
6668
if old_in_panic {
6769
tcx.dcx().emit_err(crate::error::Reentrant);
6870
} else {
69-
let run_cmd = if let Some(crate_name) = &tcx.sess.opts.crate_name {
70-
format!("`cargo clean -p {crate_name}` or `cargo clean`")
71+
let run_cmd = if was_invoked_from_cargo() {
72+
format!("run `cargo clean -p {}` or `cargo clean`", tcx.crate_name(LOCAL_CRATE))
7173
} else {
72-
"`cargo clean`".to_string()
74+
"clean your build cache".to_owned()
7375
};
7476

7577
let dep_node = tcx.dep_graph.data().unwrap().prev_node_of(prev_index);

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ impl OutputFilenames {
12051205
}
12061206

12071207
pub fn interface_path(&self) -> PathBuf {
1208+
debug!("using crate_name={} for interface_path", self.crate_stem);
12081209
self.out_directory.join(format!("lib{}.rs", self.crate_stem))
12091210
}
12101211

@@ -1214,6 +1215,7 @@ impl OutputFilenames {
12141215
let extension = flavor.extension();
12151216
match flavor {
12161217
OutputType::Metadata => {
1218+
debug!("using crate_name={} for {extension}", self.crate_stem);
12171219
self.out_directory.join(format!("lib{}.{}", self.crate_stem, extension))
12181220
}
12191221
_ => self.with_directory_and_extension(&self.out_directory, extension),
@@ -1288,6 +1290,7 @@ impl OutputFilenames {
12881290
}
12891291

12901292
pub fn with_directory_and_extension(&self, directory: &Path, extension: &str) -> PathBuf {
1293+
debug!("using filestem={} for {extension}", self.filestem);
12911294
let mut path = directory.join(&self.filestem);
12921295
path.set_extension(extension);
12931296
path

0 commit comments

Comments
 (0)