authorbors <bors@rust-lang.org> 2026-07-07 13:17:11 UTC
committerGitHub <noreply@github.com> 2026-07-07 13:17:11 UTC
logba533458e2924a6333b2d89d7b9d8d0126df6906
tree7f1b89cb00cd3ee20b32de90c9211e87401ccbf4
parentf10db292a3733b5c67c8da8c7661195ff4b05774
parent75c6569541fc73fc9c1e9298fb024e08b0677049

merge commit


150 files changed, 1472 insertions(+), 554 deletions(-)

compiler/rustc_ast/src/expand/typetree.rs+11
......@@ -28,6 +28,9 @@ pub enum Kind {
2828 Anything,
2929 Integer,
3030 Pointer,
31 // We prefer to directly lower to things that our Enzyme backend supports.
32 // However, it's sometimes convenient to pass ptr+int as one type.
33 RustSlice,
3134 Half,
3235 Float,
3336 Double,
......@@ -57,6 +60,9 @@ impl TypeTree {
5760 }
5861 Self(ints)
5962 }
63 pub fn add_indirection(self) -> Self {
64 Self(vec![Type { offset: 0, size: 1, kind: Kind::Pointer, child: self }])
65 }
6066}
6167
6268#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, StableHash)]
......@@ -72,6 +78,11 @@ pub struct Type {
7278 pub kind: Kind,
7379 pub child: TypeTree,
7480}
81impl Type {
82 pub fn from_ty(offset: isize, other: &Type) -> Self {
83 Self { offset, size: other.size, kind: other.kind, child: other.child.clone() }
84 }
85}
7586
7687impl Type {
7788 pub fn add_offset(self, add: isize) -> Self {
compiler/rustc_ast_lowering/src/delegation/generics.rs+11-12
......@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
88use rustc_middle::{bug, ty};
99use rustc_span::symbol::kw;
10use rustc_span::{Ident, Span, sym};
10use rustc_span::{ErrorGuaranteed, Ident, Span, sym};
1111
1212use crate::LoweringContext;
1313use crate::delegation::resolution::resolver::DelegationResolver;
......@@ -281,7 +281,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
281281 &self,
282282 delegation: &'a Delegation,
283283 sig_id: DefId,
284 ) -> GenericsResolution<'a, 'hir> {
284 ) -> Result<GenericsResolution<'a, 'hir>, ErrorGuaranteed> {
285285 let tcx = self.tcx();
286286 let delegation_parent_kind = tcx.def_kind(tcx.local_parent(self.owner_id()));
287287
......@@ -300,9 +300,8 @@ impl<'hir> DelegationResolver<'_, 'hir> {
300300 let qself_is_none = delegation.qself.is_none();
301301
302302 let parent_args = if let [.., parent_segment, _] = &delegation.path.segments[..] {
303 if let Some(res) = self.get_resolution_id(parent_segment.id)
304 && matches!(tcx.def_kind(res), DefKind::Trait | DefKind::TraitAlias)
305 {
303 let res = self.get_resolution_id(parent_segment.id)?;
304 if matches!(tcx.def_kind(res), DefKind::Trait | DefKind::TraitAlias) {
306305 sig_parent_params = &tcx.generics_of(sig_parent).own_params;
307306 self.get_user_args(parent_segment)
308307 .map(|args| ParentSegmentArgs::Specified(args))
......@@ -314,7 +313,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
314313 ParentSegmentArgs::Invalid
315314 };
316315
317 GenericsResolution {
316 Ok(GenericsResolution {
318317 parent_args,
319318 sig_parent_params,
320319 qself_is_none,
......@@ -326,7 +325,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
326325 child_args: self.get_user_args(
327326 delegation.path.segments.last().expect("must be at least one segment"),
328327 ),
329 }
328 })
330329 }
331330
332331 fn get_user_args<'a>(&self, segment: &'a PathSegment) -> Option<&'a AngleBracketedArgs> {
......@@ -350,14 +349,14 @@ impl<'hir> DelegationResolver<'_, 'hir> {
350349 &self,
351350 delegation: &Delegation,
352351 sig_id: DefId,
353 ) -> GenericsGenerationResults<'hir> {
352 ) -> Result<GenericsGenerationResults<'hir>, ErrorGuaranteed> {
354353 let res @ GenericsResolution {
355354 trait_impl,
356355 generate_self,
357356 sig_child_params,
358357 sig_parent_params,
359358 ..
360 } = self.resolve_generics(delegation, sig_id);
359 } = self.resolve_generics(delegation, sig_id)?;
361360
362361 // If we are in trait impl always generate function whose generics matches
363362 // those that are defined in trait.
......@@ -374,7 +373,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
374373
375374 let child = GenericsGenerationResult::new(child);
376375
377 return GenericsGenerationResults { parent, child, self_ty_propagation_kind: None };
376 return Ok(GenericsGenerationResults { parent, child, self_ty_propagation_kind: None });
378377 }
379378
380379 let tcx = self.tcx();
......@@ -421,7 +420,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
421420 DelegationGenerics::generate_all(sig_child_params, GenericsPosition::Child, trait_impl)
422421 };
423422
424 GenericsGenerationResults {
423 Ok(GenericsGenerationResults {
425424 parent: GenericsGenerationResult::new(parent_generics),
426425 child: GenericsGenerationResult::new(child_generics),
427426 self_ty_propagation_kind: match res.free_to_trait_delegation {
......@@ -435,7 +434,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
435434 }),
436435 false => None,
437436 },
438 }
437 })
439438 }
440439
441440 /// Generates generic argument slots for user-specified `args` and
compiler/rustc_ast_lowering/src/delegation/mod.rs+89-41
......@@ -45,6 +45,7 @@ use hir::def::Res;
4545use rustc_abi::ExternAbi;
4646use rustc_ast as ast;
4747use rustc_ast::*;
48use rustc_hir::def::DefKind;
4849use rustc_hir::{self as hir, FnDeclFlags};
4950use rustc_middle::ty::Asyncness;
5051use rustc_span::def_id::DefId;
......@@ -249,20 +250,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
249250 let mut unused_target_expr = false;
250251
251252 let block_id = self.lower_body(|this| {
252 let &DelegationResolution {
253 param_info, span, should_generate_block, is_method, ..
254 } = res;
255
253 let &DelegationResolution { param_info, span, is_method, .. } = res;
256254 let ParamInfo { param_count, .. } = param_info;
255 let arguments_to_map = &res.sig_mapping.arguments_to_map;
257256
258257 let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
259258 let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
260 let mut stmts: &[hir::Stmt<'hir>] = &[];
259 let mut stmts = vec![];
261260
262261 // Consider non-specified target expression as generated,
263262 // as we do not want to emit error when target expression is
264263 // not specified.
265 unused_target_expr = block.is_some() && (param_count == 0 || !should_generate_block);
264 unused_target_expr =
265 block.is_some() && (param_count == 0 || arguments_to_map.is_empty());
266266
267267 for idx in 0..param_count {
268268 let (param, pat_node_id) = this.generate_param(is_method, idx, span);
......@@ -271,41 +271,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
271271 let generate_arg =
272272 |this: &mut Self| this.generate_arg(is_method, idx, param.pat.hir_id, span);
273273
274 let arg = if let Some(block) = block
275 && idx == 0
276 && should_generate_block
277 {
278 let mut self_resolver = SelfResolver {
279 ctxt: this,
280 path_id: delegation.id,
281 self_param_id: pat_node_id,
282 };
283 self_resolver.visit_block(block);
284 // Target expr needs to lower `self` path.
285 this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);
286
287 // Lower with `HirId::INVALID` as we will use only expr and stmts.
288 // FIXME(fn_delegation): Alternatives for target expression lowering:
289 // https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600.
290 let block = this.lower_block_noalloc(HirId::INVALID, block, false);
291
292 stmts = block.stmts;
293
294 // The behavior of the delegation's target expression differs from the
295 // behavior of the usual block, where if there is no final expression
296 // the `()` is returned. In case of the similar situation in delegation
297 // (no final expression) we propagate first argument instead of replacing
298 // it with `()`.
299 if let Some(&expr) = block.expr { expr } else { generate_arg(this) }
300 } else {
301 generate_arg(this)
302 };
274 let arg = block
275 .filter(|_| arguments_to_map.contains(&idx))
276 .and_then(|block| {
277 let block = this.lower_block_maybe_more_than_once(
278 block,
279 pat_node_id,
280 param.pat.hir_id.local_id,
281 delegation.id,
282 );
283
284 stmts.push(block.stmts);
285
286 // The behavior of the delegation's target expression differs from the
287 // behavior of the usual block, where if there is no final expression
288 // the `()` is returned. In case of the similar situation in delegation
289 // (no final expression) we propagate first argument instead of replacing
290 // it with `()`.
291 block.expr.copied()
292 })
293 .unwrap_or_else(|| generate_arg(this));
303294
304295 args.push(arg);
305296 }
306297
307 let (final_expr, hir_id) =
308 this.finalize_body_lowering(delegation, stmts, args, res, generics, span);
298 let (final_expr, hir_id) = this.finalize_body_lowering(
299 delegation,
300 this.arena.alloc_from_iter(stmts.into_iter().flatten().copied()),
301 args,
302 res,
303 generics,
304 span,
305 );
309306
310307 call_expr_id = hir_id;
311308
......@@ -317,6 +314,48 @@ impl<'hir> LoweringContext<'_, 'hir> {
317314 (block_id, call_expr_id, unused_target_expr)
318315 }
319316
317 fn lower_block_maybe_more_than_once(
318 &mut self,
319 block: &Block,
320 pat_node_id: NodeId,
321 param_local_id: hir::ItemLocalId,
322 delegation_id: NodeId,
323 ) -> hir::Block<'hir> {
324 let mut self_resolver = SelfResolver {
325 ctxt: self,
326 path_id: delegation_id,
327 self_param_id: pat_node_id,
328 overwrites: vec![],
329 };
330
331 self_resolver.visit_block(block);
332
333 let overwrites = self_resolver.overwrites;
334
335 // Target expr needs to lower `self` path.
336 self.ident_and_label_to_local_id.insert(pat_node_id, param_local_id);
337
338 let block = cfg_select! {
339 debug_assertions => {
340 crate::re_lowering::ReloweringChecker::allow_relowering(self, |this| {
341 this.lower_block_noalloc(HirId::INVALID, block, false)
342 })
343 },
344 _ => self.lower_block_noalloc(HirId::INVALID, block, false)
345 };
346
347 // Remove node ids for which we overwrote resolution to generated param
348 // before block lowering as block can be relowered. We need to do it because
349 // check in `SelfResolver` uses `get_partial_res` to decide whether to overwrite
350 // resolution, and if it is already overwritten from previous block lowering this
351 // check will not pass.
352 for id in overwrites {
353 self.partial_res_overrides.remove(&id);
354 }
355
356 block
357 }
358
320359 fn finalize_body_lowering(
321360 &mut self,
322361 delegation: &Delegation,
......@@ -392,8 +431,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
392431 let args = self.arena.alloc_from_iter(args);
393432 let call = self.mk_expr(hir::ExprKind::Call(callee_path, args), span);
394433
395 let expr = if let Some((parent, of_trait)) = res.output_self_mapping {
396 let res = Res::SelfTyAlias { alias_to: parent.to_def_id(), is_trait_impl: of_trait };
434 let expr = if res.sig_mapping.map_return {
435 let res = Res::SelfTyAlias {
436 alias_to: res.parent.to_def_id(),
437 is_trait_impl: self.tcx.def_kind(res.parent) == DefKind::Impl { of_trait: true },
438 };
439
397440 let ident = Ident::new(kw::SelfUpper, span);
398441 let path = self.create_resolved_path(res, ident, span);
399442
......@@ -453,11 +496,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
453496 })
454497 .unwrap_or_else(|| self.arena.alloc_from_iter(args_iter.consume_all(self)));
455498
499 // Do not omit constraints as there might be some and they must be present in HIR (#158812).
500 let has_constraints = segment.args.is_some_and(|a| !a.constraints.is_empty());
501
456502 // Needed for better error messages (`trait-impl-wrong-args-count.rs` test).
457 segment.args = (!new_args.is_empty()).then(|| {
503 segment.args = (has_constraints || !new_args.is_empty()).then(|| {
458504 &*self.arena.alloc(hir::GenericArgs {
459505 args: new_args,
460 constraints: &[],
506 constraints: segment.args.map(|a| a.constraints).unwrap_or(&[]),
461507 parenthesized: hir::GenericArgsParentheses::No,
462508 span_ext: segment.args.map_or(span, |args| args.span_ext),
463509 })
......@@ -538,6 +584,7 @@ struct SelfResolver<'a, 'b, 'hir> {
538584 ctxt: &'a mut LoweringContext<'b, 'hir>,
539585 path_id: NodeId,
540586 self_param_id: NodeId,
587 overwrites: Vec<NodeId>,
541588}
542589
543590impl SelfResolver<'_, '_, '_> {
......@@ -546,6 +593,7 @@ impl SelfResolver<'_, '_, '_> {
546593 && let Some(Res::Local(sig_id)) = res.full_res()
547594 && sig_id == self.path_id
548595 {
596 self.overwrites.push(id);
549597 self.ctxt.partial_res_overrides.insert(id, self.self_param_id);
550598 }
551599 }
compiler/rustc_ast_lowering/src/delegation/resolution.rs+87-39
......@@ -6,7 +6,7 @@ use rustc_ast as ast;
66use rustc_ast::*;
77use rustc_data_structures::fx::FxHashSet;
88use rustc_hir as hir;
9use rustc_middle::span_bug;
9use rustc_middle::{span_bug, ty};
1010use rustc_span::def_id::{DefId, LocalDefId};
1111use rustc_span::{ErrorGuaranteed, Span};
1212
......@@ -14,7 +14,8 @@ use crate::delegation::generics::GenericsGenerationResults;
1414use crate::delegation::resolution::resolver::DelegationResolver;
1515use crate::diagnostics::{
1616 CycleInDelegationSignatureResolution, DelegationAttemptedBlockWithDefsDeletion,
17 DelegationBlockSpecifiedWhenNoParams, UnresolvedDelegationCallee,
17 DelegationAttemptedBlockWithDefsRelowering, DelegationBlockSpecifiedWhenNoParams,
18 UnresolvedDelegationCallee,
1819};
1920
2021/// Summary info about function parameters.
......@@ -30,21 +31,28 @@ pub(super) struct ParamInfo {
3031 pub splatted: Option<u8>,
3132}
3233
34#[derive(Default)]
35pub(super) struct SigMapping {
36 pub map_return: bool,
37 pub arguments_to_map: FxHashSet<usize>,
38}
39
3340pub(super) struct DelegationResolution {
3441 pub sig_id: DefId,
3542 pub is_method: bool,
3643 pub param_info: ParamInfo,
3744 pub span: Span,
38 pub should_generate_block: bool,
39 pub call_path_res: Option<DefId>,
45 pub call_path_res: DefId,
4046 pub source: DelegationSource,
41 pub output_self_mapping: Option<(LocalDefId, bool)>,
47 pub parent: LocalDefId,
48 pub sig_mapping: SigMapping,
4249}
4350
4451pub(super) mod resolver {
4552 use rustc_ast::NodeId;
4653 use rustc_hir::def_id::{DefId, LocalDefId};
4754 use rustc_middle::ty::TyCtxt;
55 use rustc_span::ErrorGuaranteed;
4856
4957 use crate::LoweringContext;
5058
......@@ -87,8 +95,10 @@ pub(super) mod resolver {
8795 }
8896
8997 #[inline]
90 pub(crate) fn get_resolution_id(&self, id: NodeId) -> Option<DefId> {
91 self.0.get_partial_res(id).and_then(|r| r.expect_full_res().opt_def_id())
98 pub(crate) fn get_resolution_id(&self, id: NodeId) -> Result<DefId, ErrorGuaranteed> {
99 self.0.get_partial_res(id).and_then(|r| r.expect_full_res().opt_def_id()).ok_or_else(
100 || self.tcx().dcx().delayed_bug(format!("failed to resolve node {id:?}")),
101 )
92102 }
93103 }
94104}
......@@ -126,25 +136,31 @@ impl<'tcx> DelegationResolver<'_, 'tcx> {
126136
127137 let sig = tcx.fn_sig(sig_id).skip_binder().skip_binder();
128138 let param_count = sig.inputs().len() + usize::from(sig.c_variadic());
139 let parent = tcx.local_parent(def_id);
140
141 let (should_generate_block, contains_defs) =
142 self.check_block_soundness(delegation, sig_id, is_method, param_count)?;
129143
130144 let res = DelegationResolution {
131145 is_method,
132146 span,
133147 sig_id,
148 parent,
134149 // FIXME(splat): use `sig.splatted()` once FnSig has it
135150 param_info: ParamInfo { param_count, c_variadic: sig.c_variadic(), splatted: None },
136 should_generate_block: self.check_block_soundness(
151 source: delegation.source,
152 call_path_res: self.get_resolution_id(delegation.id)?,
153 sig_mapping: self.create_self_mapping(
137154 delegation,
138 sig_id,
139 is_method,
140 param_count,
155 span,
156 should_generate_block,
157 parent,
158 sig,
159 contains_defs,
141160 )?,
142 source: delegation.source,
143 call_path_res: self.get_resolution_id(delegation.id),
144 output_self_mapping: self.should_map_return_value(delegation),
145161 };
146162
147 Ok((res, self.resolve_and_generate_generics(delegation, sig_id)))
163 Ok((res, self.resolve_and_generate_generics(delegation, sig_id)?))
148164 }
149165
150166 fn check_for_cycles(&self, mut def_id: DefId, span: Span) -> Result<(), ErrorGuaranteed> {
......@@ -180,13 +196,13 @@ impl<'tcx> DelegationResolver<'_, 'tcx> {
180196 sig_id: DefId,
181197 is_method: bool,
182198 param_count: usize,
183 ) -> Result<bool, ErrorGuaranteed> {
199 ) -> Result<(/* should generate block */ bool, /* contains defs */ bool), ErrorGuaranteed> {
184200 let tcx = self.tcx();
185201 let should_generate_block = is_method
186202 || matches!(tcx.def_kind(sig_id), DefKind::Fn)
187203 || matches!(delegation.source, DelegationSource::Single);
188204
189 let Some(block) = &delegation.body else { return Ok(should_generate_block) };
205 let Some(block) = &delegation.body else { return Ok((should_generate_block, false)) };
190206
191207 // Report an error if user has explicitly specified delegation's target expression
192208 // in a single delegation when reused function has no params.
......@@ -194,44 +210,84 @@ impl<'tcx> DelegationResolver<'_, 'tcx> {
194210 let err = DelegationBlockSpecifiedWhenNoParams { span: block.span };
195211 return Err(tcx.dcx().emit_err(err));
196212 }
197
198213 struct DefinitionsFinder<'a, 'hir> {
199 ctx: &'a DelegationResolver<'a, 'hir>,
214 resolver: &'a DelegationResolver<'a, 'hir>,
200215 }
201216
202217 impl<'a> Visitor<'a> for DefinitionsFinder<'a, '_> {
203218 type Result = ControlFlow<()>;
204219
205220 fn visit_id(&mut self, id: NodeId) -> Self::Result {
206 match self.ctx.is_definition(id) {
221 match self.resolver.is_definition(id) {
207222 true => ControlFlow::Break(()),
208223 false => ControlFlow::Continue(()),
209224 }
210225 }
211226 }
212227
213 let mut collector = DefinitionsFinder { ctx: self };
228 let mut collector = DefinitionsFinder { resolver: self };
214229
215230 let contains_defs = collector.visit_block(block).is_break();
216231
217232 // If there are definitions inside and we can't delete target expression, then report an error.
218233 // FIXME(fn_delegation): support deletion of target expression with defs inside.
219234 if should_generate_block || !contains_defs {
220 Ok(should_generate_block)
235 Ok((should_generate_block, contains_defs))
221236 } else {
222237 Err(tcx.dcx().emit_err(DelegationAttemptedBlockWithDefsDeletion { span: block.span }))
223238 }
224239 }
225240
226 fn should_map_return_value(&self, delegation: &Delegation) -> Option<(LocalDefId, bool)> {
241 fn create_self_mapping(
242 &self,
243 delegation: &Delegation,
244 span: Span,
245 should_generate_block: bool,
246 parent: LocalDefId,
247 sig: ty::FnSig<'tcx>,
248 contains_defs: bool,
249 ) -> Result<SigMapping, ErrorGuaranteed> {
250 let mut mapping = SigMapping::default();
251 if should_generate_block {
252 mapping.arguments_to_map.insert(0);
253 }
254
255 if self.can_perform_self_mapping(delegation, parent)? {
256 mapping.map_return = sig.output().is_param(0);
257
258 let arguments_to_map = sig
259 .inputs()
260 .iter()
261 .enumerate()
262 .skip(1) // Already checked above.
263 .filter_map(|(idx, param)| param.is_param(0).then_some(idx));
264
265 mapping.arguments_to_map.extend(arguments_to_map);
266 }
267
268 // We can't yet map more than one argument if there are definitions inside.
269 // FIXME(fn_delegation): support relowering with defs inside
270 if contains_defs && mapping.arguments_to_map.len() > 1 {
271 return Err(self
272 .tcx()
273 .dcx()
274 .emit_err(DelegationAttemptedBlockWithDefsRelowering { span }));
275 }
276
277 Ok(mapping)
278 }
279
280 fn can_perform_self_mapping(
281 &self,
282 delegation: &Delegation,
283 parent: LocalDefId,
284 ) -> Result<bool, ErrorGuaranteed> {
227285 // Heuristic: don't do wrapping if there is no target expression.
228286 if delegation.body.is_none() {
229 return None;
287 return Ok(false);
230288 }
231289
232290 let tcx = self.tcx();
233 let parent = tcx.local_parent(self.owner_id());
234 let parent_kind = tcx.def_kind(parent);
235291
236292 // Apply wrapping for delegations inside
237293 // 1) Trait impls, as the return type of both signature function
......@@ -244,21 +300,13 @@ impl<'tcx> DelegationResolver<'_, 'tcx> {
244300 // 2) Inherent methods when delegating to trait, as we change the type of
245301 // `Self` to type of struct or enum we delegate from.
246302 if !matches!(tcx.def_kind(parent), DefKind::Impl { .. }) {
247 return None;
303 return Ok(false);
248304 }
249305
250 let is_trait_impl = parent_kind == DefKind::Impl { of_trait: true };
251
252306 // Check that delegation path resolves to a trait AssocFn, not to a free method.
253 Some((parent, is_trait_impl)).filter(|_| {
254 self.get_resolution_id(delegation.id).is_some_and(|id| {
255 tcx.def_kind(id) == DefKind::AssocFn
256 // Check that the return type of the callee is `Self` param.
257 // After previous check we are sure that `sig_id` and `delegation.id`
258 // point to the same function.
259 && tcx.def_kind(tcx.parent(id)) == DefKind::Trait
260 && tcx.fn_sig(id).skip_binder().output().skip_binder().is_param(0)
261 })
262 })
307 // After previous check we are sure that `sig_id` and `delegation.id`
308 // point to the same function.
309 let id = self.get_resolution_id(delegation.id)?;
310 Ok(tcx.def_kind(id) == DefKind::AssocFn && tcx.def_kind(tcx.parent(id)) == DefKind::Trait)
263311 }
264312}
compiler/rustc_ast_lowering/src/diagnostics.rs+9
......@@ -569,3 +569,12 @@ pub(crate) struct DelegationInfersMismatch {
569569 pub expected: Symbol,
570570 pub actual: Symbol,
571571}
572
573#[derive(Diagnostic)]
574#[diag(
575 "attempted to lower target expression with definitions more than once while mapping argument"
576)]
577pub(crate) struct DelegationAttemptedBlockWithDefsRelowering {
578 #[primary_span]
579 pub span: Span,
580}
compiler/rustc_ast_lowering/src/lib.rs+51-12
......@@ -100,6 +100,49 @@ pub fn provide(providers: &mut Providers) {
100100 providers.lower_to_hir = lower_to_hir;
101101}
102102
103#[cfg(debug_assertions)]
104pub(crate) mod re_lowering {
105 use rustc_ast::NodeId;
106 use rustc_ast::node_id::NodeMap;
107 use rustc_hir::{self as hir};
108
109 use crate::LoweringContext;
110
111 #[derive(Debug, Default)]
112 pub(crate) struct ReloweringChecker {
113 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
114 can_relower: bool,
115 }
116
117 impl ReloweringChecker {
118 pub(crate) fn assert_node_is_not_relowered(
119 &mut self,
120 ast_node_id: NodeId,
121 local_id: hir::ItemLocalId,
122 ) {
123 if !self.can_relower {
124 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
125 assert_eq!(old, None);
126 }
127 }
128
129 pub(crate) fn allow_relowering<'a, 'hir, TRes>(
130 ctx: &mut LoweringContext<'a, 'hir>,
131 op: impl FnOnce(&mut LoweringContext<'a, 'hir>) -> TRes,
132 ) -> TRes {
133 assert!(!ctx.relowering_checker.can_relower, "reentrant relowering is not supported");
134
135 ctx.relowering_checker.can_relower = true;
136
137 let res = op(ctx);
138
139 ctx.relowering_checker.can_relower = false;
140
141 res
142 }
143 }
144}
145
103146struct LoweringContext<'a, 'hir> {
104147 tcx: TyCtxt<'hir>,
105148 resolver: &'a ResolverAstLowering<'hir>,
......@@ -146,7 +189,7 @@ struct LoweringContext<'a, 'hir> {
146189 ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
147190 /// NodeIds that are lowered inside the current HIR owner. Only used for duplicate lowering check.
148191 #[cfg(debug_assertions)]
149 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
192 relowering_checker: re_lowering::ReloweringChecker,
150193 /// The `NodeId` space is split in two.
151194 /// `0..resolver.next_node_id` are created by the resolver on the AST.
152195 /// The higher part `resolver.next_node_id..next_node_id` are created during lowering.
......@@ -205,8 +248,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
205248 // and we never call `lower_node_id(owner)`.
206249 item_local_id_counter: hir::ItemLocalId::new(1),
207250 ident_and_label_to_local_id: Default::default(),
251
208252 #[cfg(debug_assertions)]
209 node_id_to_local_id: Default::default(),
253 relowering_checker: Default::default(),
254
210255 trait_map: Default::default(),
211256 next_node_id: resolver.next_node_id,
212257 node_id_to_def_id: NodeMap::default(),
......@@ -808,7 +853,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
808853 let current_ident_and_label_to_local_id = mem::take(&mut self.ident_and_label_to_local_id);
809854
810855 #[cfg(debug_assertions)]
811 let current_node_id_to_local_id = mem::take(&mut self.node_id_to_local_id);
856 let current_relowering_checker = mem::take(&mut self.relowering_checker);
812857 let current_trait_map = mem::take(&mut self.trait_map);
813858 let current_owner = mem::replace(&mut self.current_hir_id_owner, owner_id);
814859 let current_local_counter =
......@@ -824,10 +869,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
824869
825870 // Always allocate the first `HirId` for the owner itself.
826871 #[cfg(debug_assertions)]
827 {
828 let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
829 debug_assert_eq!(_old, None);
830 }
872 self.relowering_checker.assert_node_is_not_relowered(owner, hir::ItemLocalId::ZERO);
831873
832874 let item = f(self);
833875 assert_eq!(owner_id, item.def_id());
......@@ -845,7 +887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
845887
846888 #[cfg(debug_assertions)]
847889 {
848 self.node_id_to_local_id = current_node_id_to_local_id;
890 self.relowering_checker = current_relowering_checker;
849891 }
850892 self.trait_map = current_trait_map;
851893 self.current_hir_id_owner = current_owner;
......@@ -936,10 +978,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
936978
937979 // Check whether the same `NodeId` is lowered more than once.
938980 #[cfg(debug_assertions)]
939 {
940 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
941 assert_eq!(old, None);
942 }
981 self.relowering_checker.assert_node_is_not_relowered(ast_node_id, local_id);
943982
944983 hir_id
945984 }
compiler/rustc_codegen_llvm/src/builder.rs+1-1
......@@ -1180,7 +1180,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11801180 // vs. copying a struct with mixed types requires different derivative handling.
11811181 // The TypeTree tells Enzyme exactly what memory layout to expect.
11821182 if let Some(tt) = tt {
1183 crate::typetree::add_tt(self.cx().llmod, self.cx().llcx, memcpy, tt);
1183 crate::typetree::add_tt(self, memcpy, tt);
11841184 }
11851185 }
11861186
compiler/rustc_codegen_llvm/src/builder/autodiff.rs+10-17
......@@ -143,7 +143,6 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
143143// FIXME(ZuseZ4): This logic is a bit more complicated than it should be, can we simplify it
144144// using iterators and peek()?
145145fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
146 cx: &SimpleCx<'ll>,
147146 builder: &mut Builder<'_, 'll, 'tcx>,
148147 width: u32,
149148 args: &mut Vec<&'ll Value>,
......@@ -157,6 +156,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
157156 // need to match those.
158157 // FIXME(ZuseZ4): This logic is a bit more complicated than it should be, can we simplify it
159158 // using iterators and peek()?
159 let cx = &builder.scx;
160160 let mut outer_pos: usize = 0;
161161 let mut activity_pos = 0;
162162
......@@ -292,8 +292,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
292292// FIXME(ZuseZ4): `outer_fn` should include upstream safety checks to
293293// cover some assumptions of enzyme/autodiff, which could lead to UB otherwise.
294294pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
295 builder: &mut Builder<'_, 'll, 'tcx>,
296 cx: &SimpleCx<'ll>,
295 bx: &mut Builder<'_, 'll, 'tcx>,
297296 fn_to_diff: &'ll Value,
298297 outer_name: &str,
299298 ret_ty: &'ll Type,
......@@ -303,6 +302,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
303302 dest_place: Option<PlaceValue<&'ll Value>>,
304303 fnc_tree: FncTree,
305304) -> IntrinsicResult<'tcx, &'ll Value> {
305 let cx: &SimpleCx<'ll> = &bx.scx;
306306 // We have to pick the name depending on whether we want forward or reverse mode autodiff.
307307 let mut ad_name: String = match attrs.mode {
308308 DiffMode::Forward => "__enzyme_fwddiff",
......@@ -369,34 +369,27 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
369369 args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
370370 }
371371
372 match_args_from_caller_to_enzyme(
373 &cx,
374 builder,
375 attrs.width,
376 &mut args,
377 &attrs.input_activity,
378 fn_args,
379 );
372 match_args_from_caller_to_enzyme(bx, attrs.width, &mut args, &attrs.input_activity, fn_args);
380373
381374 if !fnc_tree.args.is_empty() || !fnc_tree.ret.0.is_empty() {
382 crate::typetree::add_tt(cx.llmod, cx.llcx, fn_to_diff, fnc_tree);
375 crate::typetree::add_tt(&bx, fn_to_diff, fnc_tree);
383376 }
384377
385 let call = builder.call(enzyme_ty, None, None, ad_fn, &args, None, None);
378 let call = bx.call(enzyme_ty, None, None, ad_fn, &args, None, None);
386379
387 let fn_ret_ty = builder.cx.val_ty(call);
388 if fn_ret_ty == builder.cx.type_void() || fn_ret_ty == builder.cx.type_struct(&[], false) {
380 let fn_ret_ty = bx.cx.val_ty(call);
381 if fn_ret_ty == bx.cx.type_void() || fn_ret_ty == bx.cx.type_struct(&[], false) {
389382 // If we return void or an empty struct, then our caller (due to how we generated it)
390383 // does not expect a return value. As such, we have no pointer (or place) into which
391384 // we could store our value, and would store into an undef, which would cause UB.
392385 // As such, we just ignore the return value in those cases.
393386 IntrinsicResult::Operand(OperandValue::ZeroSized)
394387 } else if let Some(dest_place) = dest_place {
395 builder.store_to_place(call, dest_place);
388 bx.store_to_place(call, dest_place);
396389 IntrinsicResult::WroteIntoPlace
397390 } else {
398391 IntrinsicResult::Operand(
399 OperandRef::from_immediate_or_packed_pair(builder, call, dest_layout).val,
392 OperandRef::from_immediate_or_packed_pair(bx, call, dest_layout).val,
400393 )
401394 }
402395}
compiler/rustc_codegen_llvm/src/intrinsic.rs+2-3
......@@ -225,7 +225,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
225225 )
226226 }
227227 sym::autodiff => {
228 return codegen_autodiff(self, tcx, instance, args, result_layout, result_place);
228 return codegen_autodiff(self, instance, args, result_layout, result_place);
229229 }
230230 sym::offload => {
231231 if tcx.sess.opts.unstable_opts.offload.is_empty() {
......@@ -1743,12 +1743,12 @@ fn codegen_retag_inner<'ll, 'tcx>(
17431743
17441744fn codegen_autodiff<'ll, 'tcx>(
17451745 bx: &mut Builder<'_, 'll, 'tcx>,
1746 tcx: TyCtxt<'tcx>,
17471746 instance: ty::Instance<'tcx>,
17481747 args: &[OperandRef<'tcx, &'ll Value>],
17491748 result_layout: ty::layout::TyAndLayout<'tcx>,
17501749 result_place: Option<PlaceValue<&'ll Value>>,
17511750) -> IntrinsicResult<'tcx, &'ll Value> {
1751 let tcx = bx.tcx;
17521752 if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
17531753 let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
17541754 }
......@@ -1815,7 +1815,6 @@ fn codegen_autodiff<'ll, 'tcx>(
18151815 // Build body
18161816 generate_enzyme_call(
18171817 bx,
1818 bx.cx,
18191818 fn_to_diff,
18201819 &diff_symbol,
18211820 llret_ty,
compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs+6
......@@ -66,6 +66,7 @@ unsafe extern "C" {
6666 NameLen: libc::size_t,
6767 ) -> Option<&Value>;
6868
69 pub(crate) safe fn LLVMRustIsCall(V: &Value) -> bool;
6970}
7071
7172unsafe extern "C" {
......@@ -292,6 +293,11 @@ pub(crate) mod Enzyme_AD {
292293 unsafe { (self.EnzymeTypeTreeToString)(tree) }
293294 }
294295
296 pub(crate) fn tree_to_cstr(&self, tree: *mut EnzymeTypeTree) -> &std::ffi::CStr {
297 let c_str = self.tree_to_string(tree);
298 unsafe { std::ffi::CStr::from_ptr(c_str) }
299 }
300
295301 pub(crate) fn tree_to_string_free(&self, ch: *const c_char) {
296302 unsafe { (self.EnzymeTypeTreeToStringFree)(ch) }
297303 }
compiler/rustc_codegen_llvm/src/llvm/mod.rs+15
......@@ -76,6 +76,21 @@ pub(crate) fn CreateAttrStringValue<'ll>(
7676 )
7777 }
7878}
79pub(crate) fn CreateAttrStringValueFromCStr<'ll>(
80 llcx: &'ll Context,
81 attr: &std::ffi::CStr,
82 value: &std::ffi::CStr,
83) -> &'ll Attribute {
84 unsafe {
85 LLVMCreateStringAttribute(
86 llcx,
87 (*attr).as_ptr(),
88 (*attr).to_bytes().len() as c_uint,
89 (*value).as_ptr(),
90 (*value).to_bytes().len() as c_uint,
91 )
92 }
93}
7994
8095pub(crate) fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute {
8196 unsafe {
compiler/rustc_codegen_llvm/src/typetree.rs+119-50
......@@ -1,35 +1,47 @@
1use std::ffi::{CString, c_char, c_uint};
1use std::ffi::{CString, c_char};
22
3use rustc_ast::expand::typetree::{FncTree, TypeTree as RustTypeTree};
3use rustc_ast::expand::typetree::{FncTree, Kind, TypeTree as RustTypeTree};
44
55use crate::attributes;
6use crate::context::FullCx;
67use crate::llvm::{self, EnzymeWrapper, Value};
78
89fn to_enzyme_typetree(
9 rust_typetree: RustTypeTree,
10 rust_typetree: &RustTypeTree,
1011 _data_layout: &str,
1112 llcx: &llvm::Context,
12) -> llvm::TypeTree {
13) -> (llvm::TypeTree, Vec<llvm::TypeTree>) {
1314 let mut enzyme_tt = llvm::TypeTree::new();
14 process_typetree_recursive(&mut enzyme_tt, &rust_typetree, &[], llcx);
15 enzyme_tt
15 let extra_ints = process_typetree_recursive(&mut enzyme_tt, &rust_typetree, &[], llcx);
16
17 let mut int_vec = vec![];
18 for _ in 0..extra_ints {
19 let mut int_tt = llvm::TypeTree::new();
20 int_tt.insert(&[0], llvm::CConcreteType::DT_Integer, llcx);
21 int_vec.push(int_tt);
22 }
23
24 (enzyme_tt, int_vec)
1625}
26
1727fn process_typetree_recursive(
1828 enzyme_tt: &mut llvm::TypeTree,
1929 rust_typetree: &RustTypeTree,
2030 parent_indices: &[i64],
2131 llcx: &llvm::Context,
22) {
32) -> u32 {
33 let mut extra_ints = 0;
2334 for rust_type in &rust_typetree.0 {
2435 let concrete_type = match rust_type.kind {
25 rustc_ast::expand::typetree::Kind::Anything => llvm::CConcreteType::DT_Anything,
26 rustc_ast::expand::typetree::Kind::Integer => llvm::CConcreteType::DT_Integer,
27 rustc_ast::expand::typetree::Kind::Pointer => llvm::CConcreteType::DT_Pointer,
28 rustc_ast::expand::typetree::Kind::Half => llvm::CConcreteType::DT_Half,
29 rustc_ast::expand::typetree::Kind::Float => llvm::CConcreteType::DT_Float,
30 rustc_ast::expand::typetree::Kind::Double => llvm::CConcreteType::DT_Double,
31 rustc_ast::expand::typetree::Kind::F128 => llvm::CConcreteType::DT_FP128,
32 rustc_ast::expand::typetree::Kind::Unknown => llvm::CConcreteType::DT_Unknown,
36 Kind::Anything => llvm::CConcreteType::DT_Anything,
37 Kind::Integer => llvm::CConcreteType::DT_Integer,
38 Kind::Pointer => llvm::CConcreteType::DT_Pointer,
39 Kind::RustSlice => llvm::CConcreteType::DT_Pointer,
40 Kind::Half => llvm::CConcreteType::DT_Half,
41 Kind::Float => llvm::CConcreteType::DT_Float,
42 Kind::Double => llvm::CConcreteType::DT_Double,
43 Kind::F128 => llvm::CConcreteType::DT_FP128,
44 Kind::Unknown => llvm::CConcreteType::DT_Unknown,
3345 };
3446
3547 let mut indices = parent_indices.to_vec();
......@@ -43,21 +55,28 @@ fn process_typetree_recursive(
4355
4456 enzyme_tt.insert(&indices, concrete_type, llcx);
4557
46 if rust_type.kind == rustc_ast::expand::typetree::Kind::Pointer
58 if matches!(rust_type.kind, Kind::RustSlice) {
59 // We lower slices to `ptr,int`, so add the int here.
60 extra_ints += 1;
61 }
62
63 if matches!(rust_type.kind, Kind::Pointer | Kind::RustSlice)
4764 && !rust_type.child.0.is_empty()
4865 {
4966 process_typetree_recursive(enzyme_tt, &rust_type.child, &indices, llcx);
5067 }
5168 }
69 extra_ints
70}
71
72// Describes all the locations in which we know how to apply an Enzyme TypeTree.
73enum TTLocation {
74 Definition,
75 Callsite,
5276}
5377
5478#[cfg_attr(not(feature = "llvm_enzyme"), allow(unused))]
55pub(crate) fn add_tt<'ll>(
56 llmod: &'ll llvm::Module,
57 llcx: &'ll llvm::Context,
58 fn_def: &'ll Value,
59 tt: FncTree,
60) {
79pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: &'ll Value, tt: FncTree) {
6180 // TypeTree processing uses functions from Enzyme, which we might not have available if we did
6281 // not build this compiler with `llvm_enzyme`. This feature is not strictly necessary, but
6382 // skipping this function increases the chance that Enzyme fails to compile some code.
......@@ -66,6 +85,16 @@ pub(crate) fn add_tt<'ll>(
6685 #[cfg(not(feature = "llvm_enzyme"))]
6786 return;
6887
88 let tcx = cx.tcx;
89 if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
90 return;
91 }
92 if tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::NoTT) {
93 return;
94 }
95
96 let llmod = cx.llmod;
97 let llcx = cx.llcx;
6998 let inputs = tt.args;
7099 let ret_tt: RustTypeTree = tt.ret;
71100
......@@ -77,41 +106,81 @@ pub(crate) fn add_tt<'ll>(
77106 let attr_name = "enzyme_type";
78107 let c_attr_name = CString::new(attr_name).unwrap();
79108
109 let tt_location: TTLocation =
110 if llvm::LLVMRustIsCall(fn_def) { TTLocation::Callsite } else { TTLocation::Definition };
111
112 let mut offset = 0;
80113 for (i, input) in inputs.iter().enumerate() {
81 unsafe {
82 let enzyme_tt = to_enzyme_typetree(input.clone(), llvm_data_layout, llcx);
114 let (enzyme_tt, extra_ints) = to_enzyme_typetree(&input, llvm_data_layout, llcx);
115
116 // This scope is just a visual reminder that we *must* drop the enzyme_wrapper before
117 // we drop any typetrees (mainly enzyme_tt and extra_ints). Drop calls can not accept
118 // arguments like an enzyme_wrapper, so the typetree drop impl has to call get_instance
119 // on the static enzyme instance, which is behind a Mutex. Therefore we'd deadlock if we
120 // hold the enzyme_wrapper while dropping the typetrees.
121 {
83122 let enzyme_wrapper = EnzymeWrapper::get_instance();
84 let c_str = enzyme_wrapper.tree_to_string(enzyme_tt.inner);
85 let c_str = std::ffi::CStr::from_ptr(c_str);
86
87 let attr = llvm::LLVMCreateStringAttribute(
88 llcx,
89 c_attr_name.as_ptr(),
90 c_attr_name.as_bytes().len() as c_uint,
91 c_str.as_ptr(),
92 c_str.to_bytes().len() as c_uint,
93 );
94
95 attributes::apply_to_llfn(fn_def, llvm::AttributePlace::Argument(i as u32), &[attr]);
123 let c_str = enzyme_wrapper.tree_to_cstr(enzyme_tt.inner);
124
125 let attr = llvm::CreateAttrStringValueFromCStr(llcx, &c_attr_name, &c_str);
126 let arg_pos = llvm::AttributePlace::Argument(i as u32 + offset);
127 // FIXME(autodiff): We currently know that this is correct for all the cases in which we
128 // call this function. But we should make it more robust for the future.
129 match tt_location {
130 TTLocation::Definition => {
131 attributes::apply_to_llfn(fn_def, arg_pos, &[attr]);
132 }
133 TTLocation::Callsite => {
134 attributes::apply_to_callsite(fn_def, arg_pos, &[attr]);
135 }
136 }
96137 enzyme_wrapper.tree_to_string_free(c_str.as_ptr());
138 for v in &extra_ints {
139 offset += 1;
140 let c_str = enzyme_wrapper.tree_to_cstr(v.inner);
141 let int_attr = llvm::CreateAttrStringValueFromCStr(llcx, &c_attr_name, &c_str);
142 let arg_pos = llvm::AttributePlace::Argument(i as u32 + offset);
143 match tt_location {
144 TTLocation::Definition => {
145 attributes::apply_to_llfn(fn_def, arg_pos, &[int_attr]);
146 }
147 TTLocation::Callsite => {
148 attributes::apply_to_callsite(fn_def, arg_pos, &[int_attr]);
149 }
150 }
151 enzyme_wrapper.tree_to_string_free(c_str.as_ptr());
152 }
153 }
154 }
155 // We will only fail this if Rust types got lowered to LLVM in a way that we didn't predict.
156 // Error, so we can learn from our mistakes.
157 if matches!(tt_location, TTLocation::Definition) {
158 let expected = offset as usize + inputs.len();
159 let actual = llvm::count_params(fn_def) as usize;
160 if expected != actual {
161 tcx.dcx().warn(format!(
162 "autodiff type-tree failure. We expected {expected} LLVM argument(s), \
163 but the generated LLVM function has {actual} parameter(s)"
164 ));
97165 }
98166 }
99167
100 unsafe {
101 let enzyme_tt = to_enzyme_typetree(ret_tt, llvm_data_layout, llcx);
168 // FIXME(autodiff): We should think more about what it means if a function returns a slice or
169 // other fat ptrs.
170 let (enzyme_tt, _extra_ints) = to_enzyme_typetree(&ret_tt, llvm_data_layout, llcx);
171 if ret_tt != RustTypeTree::new() {
102172 let enzyme_wrapper = EnzymeWrapper::get_instance();
103 let c_str = enzyme_wrapper.tree_to_string(enzyme_tt.inner);
104 let c_str = std::ffi::CStr::from_ptr(c_str);
105
106 let ret_attr = llvm::LLVMCreateStringAttribute(
107 llcx,
108 c_attr_name.as_ptr(),
109 c_attr_name.as_bytes().len() as c_uint,
110 c_str.as_ptr(),
111 c_str.to_bytes().len() as c_uint,
112 );
113
114 attributes::apply_to_llfn(fn_def, llvm::AttributePlace::ReturnValue, &[ret_attr]);
173 let c_str = enzyme_wrapper.tree_to_cstr(enzyme_tt.inner);
174 let ret_attr = llvm::CreateAttrStringValueFromCStr(llcx, &c_attr_name, &c_str);
175 let arg_pos = llvm::AttributePlace::ReturnValue;
176 match tt_location {
177 TTLocation::Definition => {
178 attributes::apply_to_llfn(fn_def, arg_pos, &[ret_attr]);
179 }
180 TTLocation::Callsite => {
181 attributes::apply_to_callsite(fn_def, arg_pos, &[ret_attr]);
182 }
183 }
115184 enzyme_wrapper.tree_to_string_free(c_str.as_ptr());
116185 }
117186}
compiler/rustc_codegen_ssa/src/traits/builder.rs+8-2
......@@ -2,10 +2,12 @@ use std::assert_matches;
22use std::ops::Deref;
33
44use rustc_abi::{Align, Scalar, Size, WrappingRange};
5use rustc_ast::expand::typetree::{FncTree, TypeTree};
56use rustc_hir::attrs::AttributeKind;
67use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
78use rustc_middle::mir;
89use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
10use rustc_middle::ty::typetree::typetree_from_ty;
911use rustc_middle::ty::{AtomicOrdering, Instance, Ty};
1012use rustc_session::config::OptLevel;
1113use rustc_span::Span;
......@@ -456,7 +458,7 @@ pub trait BuilderMethods<'a, 'tcx>:
456458 src_align: Align,
457459 size: Self::Value,
458460 flags: MemFlags,
459 tt: Option<rustc_ast::expand::typetree::FncTree>,
461 tt: Option<FncTree>,
460462 );
461463 fn memmove(
462464 &mut self,
......@@ -517,6 +519,10 @@ pub trait BuilderMethods<'a, 'tcx>:
517519 let temp = self.load_operand(src.with_type(layout));
518520 temp.val.store_with_flags(self, dst.with_type(layout), flags);
519521 } else if !layout.is_zst() {
522 let tt = typetree_from_ty(self.tcx(), layout.ty);
523 // We seem to pass all values to memcpy with one more indirection.
524 let tt = tt.add_indirection();
525 let fnc_tree = FncTree { args: vec![tt.clone(), tt], ret: TypeTree::new() };
520526 let bytes = self.const_usize(layout.size.bytes());
521527 let bytes = if layout.peel_transparent_wrappers(self).ty.is_scalable_vector() {
522528 let vscale = self.vscale(self.type_i64());
......@@ -524,7 +530,7 @@ pub trait BuilderMethods<'a, 'tcx>:
524530 } else {
525531 bytes
526532 };
527 self.memcpy(dst.llval, dst.align, src.llval, src.align, bytes, flags, None);
533 self.memcpy(dst.llval, dst.align, src.llval, src.align, bytes, flags, Some(fnc_tree));
528534 }
529535 }
530536
compiler/rustc_hir/src/hir.rs+1-1
......@@ -3877,7 +3877,7 @@ pub enum DelegationSelfTyPropagationKind {
38773877#[derive(Debug, Clone, Copy, PartialEq, Eq, StableHash)]
38783878pub struct DelegationInfo {
38793879 pub call_expr_id: HirId,
3880 pub call_path_res: Option<DefId>,
3880 pub call_path_res: DefId,
38813881
38823882 /// Id of the child segment in delegation: `reuse Trait::foo`,
38833883 /// `child_seg_id` points to `foo`.
compiler/rustc_hir_analysis/src/autoderef.rs+4-4
......@@ -34,7 +34,7 @@ pub struct Autoderef<'a, 'tcx> {
3434 // Meta infos:
3535 infcx: &'a InferCtxt<'tcx>,
3636 span: Span,
37 body_id: LocalDefId,
37 body_def_id: LocalDefId,
3838 param_env: ty::ParamEnv<'tcx>,
3939
4040 // Current state:
......@@ -119,7 +119,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
119119 Autoderef {
120120 infcx,
121121 span,
122 body_id: body_def_id,
122 body_def_id,
123123 param_env,
124124 state: AutoderefSnapshot {
125125 steps: vec![],
......@@ -149,7 +149,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
149149 (tcx.lang_items().deref_trait()?, tcx.lang_items().deref_target()?)
150150 };
151151 let trait_ref = ty::TraitRef::new(tcx, trait_def_id, [ty]);
152 let cause = traits::ObligationCause::misc(self.span, self.body_id);
152 let cause = traits::ObligationCause::misc(self.span, self.body_def_id);
153153 let obligation = traits::Obligation::new(
154154 tcx,
155155 cause.clone(),
......@@ -181,7 +181,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
181181 ) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> {
182182 let ocx = ObligationCtxt::new(self.infcx);
183183 let normalized_ty = ocx.normalize(
184 &traits::ObligationCause::misc(self.span, self.body_id),
184 &traits::ObligationCause::misc(self.span, self.body_def_id),
185185 self.param_env,
186186 ty,
187187 );
compiler/rustc_hir_analysis/src/check/compare_impl_item.rs+8-8
......@@ -177,10 +177,10 @@ fn compare_method_predicate_entailment<'tcx>(
177177 trait_m: ty::AssocItem,
178178 impl_trait_ref: ty::TraitRef<'tcx>,
179179) -> Result<(), ErrorGuaranteed> {
180 // This node-id should be used for the `body_id` field on each
180 // This node-id should be used for the `body_def_id` field on each
181181 // `ObligationCause` (and the `FnCtxt`).
182182 //
183 // FIXME(@lcnr): remove that after removing `cause.body_id` from
183 // FIXME(@lcnr): remove that after removing `cause.body_def_id` from
184184 // obligations.
185185 let impl_m_def_id = impl_m.def_id.expect_local();
186186 let impl_m_span = tcx.def_span(impl_m_def_id);
......@@ -798,7 +798,7 @@ struct ImplTraitInTraitCollector<'a, 'tcx, E> {
798798 types: FxIndexMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>,
799799 span: Span,
800800 param_env: ty::ParamEnv<'tcx>,
801 body_id: LocalDefId,
801 impl_m_id: LocalDefId,
802802}
803803
804804impl<'a, 'tcx, E> ImplTraitInTraitCollector<'a, 'tcx, E>
......@@ -809,9 +809,9 @@ where
809809 ocx: &'a ObligationCtxt<'a, 'tcx, E>,
810810 span: Span,
811811 param_env: ty::ParamEnv<'tcx>,
812 body_id: LocalDefId,
812 impl_m_id: LocalDefId,
813813 ) -> Self {
814 ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id }
814 ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, impl_m_id }
815815 }
816816}
817817
......@@ -847,7 +847,7 @@ where
847847 {
848848 let pred = pred.fold_with(self);
849849 let pred = self.ocx.normalize(
850 &ObligationCause::misc(self.span, self.body_id),
850 &ObligationCause::misc(self.span, self.impl_m_id),
851851 self.param_env,
852852 Unnormalized::new_wip(pred),
853853 );
......@@ -856,7 +856,7 @@ where
856856 self.cx(),
857857 ObligationCause::new(
858858 self.span,
859 self.body_id,
859 self.impl_m_id,
860860 ObligationCauseCode::WhereClause(def_id, pred_span),
861861 ),
862862 self.param_env,
......@@ -2346,7 +2346,7 @@ fn compare_type_predicate_entailment<'tcx>(
23462346 return Ok(());
23472347 }
23482348
2349 // This `DefId` should be used for the `body_id` field on each
2349 // This `DefId` should be used for the `body_def_id` field on each
23502350 // `ObligationCause` (and the `FnCtxt`). This is what
23512351 // `regionck_item` expects.
23522352 let impl_ty_def_id = impl_ty.def_id.expect_local();
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+9-6
......@@ -431,13 +431,16 @@ impl<'tcx> ForbidParamUsesFolder<'tcx> {
431431 diag.span_note(impl_.self_ty.span, "not a concrete type");
432432 }
433433 }
434 if matches!(self.context, ForbidParamContext::ConstArgument)
435 && self.tcx.features().min_generic_const_args()
436 {
437 if !self.tcx.features().generic_const_args() {
438 diag.help("add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items");
439 } else {
434 if matches!(self.context, ForbidParamContext::ConstArgument) {
435 if self.tcx.features().generic_const_args() {
440436 diag.help("consider factoring the expression into a `type const` item and use it as the const argument instead");
437 } else if self.tcx.features().min_generic_const_args() {
438 diag.help("add `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
439 } else if self.tcx.sess.is_nightly_build() {
440 diag.help(
441 "add `#![feature(generic_const_exprs)]` to allow generic const expressions",
442 );
443 diag.help("alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
441444 }
442445 }
443446 diag.emit()
compiler/rustc_hir_typeck/src/_match.rs+2-2
......@@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216216 prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
217217 ) {
218218 // First, check that we're actually in the tail of a function.
219 let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_id) else {
219 let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_def_id) else {
220220 return;
221221 };
222222 let hir::ExprKind::Block(block, _) = body.value.kind else {
......@@ -233,7 +233,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
233233
234234 // Next, make sure that we have no type expectation.
235235 let Some(ret) =
236 self.tcx.hir_node_by_def_id(self.body_id).fn_decl().map(|decl| decl.output.span())
236 self.tcx.hir_node_by_def_id(self.body_def_id).fn_decl().map(|decl| decl.output.span())
237237 else {
238238 return;
239239 };
compiler/rustc_hir_typeck/src/autoderef.rs+1-1
......@@ -15,7 +15,7 @@ use super::{FnCtxt, PlaceOp};
1515
1616impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1717 pub(crate) fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
18 Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
18 Autoderef::new(self, self.param_env, self.body_def_id, span, base_ty)
1919 }
2020
2121 pub(crate) fn try_overloaded_deref(
compiler/rustc_hir_typeck/src/callee.rs+6-8
......@@ -39,11 +39,11 @@ pub(crate) fn check_legal_trait_for_method_call(
3939 receiver: Option<Span>,
4040 expr_span: Span,
4141 trait_id: DefId,
42 body_id: DefId,
42 body_def_id: DefId,
4343) -> Result<(), ErrorGuaranteed> {
4444 if tcx.is_lang_item(trait_id, LangItem::Drop)
4545 // Allow calling `Drop::pin_drop` in `Drop::drop`
46 && !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop)
46 && !tcx.is_lang_item(tcx.parent(body_def_id), LangItem::Drop)
4747 {
4848 let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
4949 diagnostics::ExplicitDestructorCallSugg::Snippet {
......@@ -724,17 +724,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
724724 return None;
725725 };
726726
727 let Some(path_res_id) = info.call_path_res else { return None };
728
729727 // Check that delegation has first provided arg and that the call path
730728 // resolves to a trait method (inherent methods are not yet supported).
731729 if arg_exprs.is_empty()
732 || !self.tcx.opt_associated_item(path_res_id).is_some_and(|i| i.is_method())
730 || !self.tcx.opt_associated_item(info.call_path_res).is_some_and(|i| i.is_method())
733731 {
734732 return None;
735733 }
736734
737 Some(ProbeScope::Single(path_res_id))
735 Some(ProbeScope::Single(info.call_path_res))
738736 }
739737
740738 /// Attempts to reinterpret `method(rcvr, args...)` as `rcvr.method(args...)`
......@@ -1042,7 +1040,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10421040 callee_did: DefId,
10431041 callee_args: GenericArgsRef<'tcx>,
10441042 ) {
1045 let const_context = self.tcx.hir_body_const_context(self.body_id);
1043 let const_context = self.tcx.hir_body_const_context(self.body_def_id);
10461044
10471045 if let hir::Constness::Const { always: true } = self.tcx.constness(callee_did) {
10481046 match const_context {
......@@ -1062,7 +1060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10621060 }
10631061
10641062 // If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
1065 if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) {
1063 if self.has_rustc_attrs && find_attr!(self.tcx, self.body_def_id, RustcDoNotConstCheck) {
10661064 return;
10671065 }
10681066
compiler/rustc_hir_typeck/src/cast.rs+10-3
......@@ -64,7 +64,7 @@ pub(crate) struct CastCheck<'tcx> {
6464 cast_ty: Ty<'tcx>,
6565 cast_span: Span,
6666 span: Span,
67 pub body_id: LocalDefId,
67 pub body_def_id: LocalDefId,
6868}
6969
7070/// The kind of pointer and associated metadata (thin, length or vtable) - we
......@@ -247,8 +247,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
247247 span: Span,
248248 ) -> Result<CastCheck<'tcx>, ErrorGuaranteed> {
249249 let expr_span = expr.span.find_ancestor_inside(span).unwrap_or(expr.span);
250 let check =
251 CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span, body_id: fcx.body_id };
250 let check = CastCheck {
251 expr,
252 expr_ty,
253 expr_span,
254 cast_ty,
255 cast_span,
256 span,
257 body_def_id: fcx.body_def_id,
258 };
252259
253260 // For better error messages, check for some obviously unsized
254261 // cases now. We do a more thorough check at the end, once
compiler/rustc_hir_typeck/src/coercion.rs+9-9
......@@ -1258,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12581258 let sig = if fn_attrs.safe_target_features {
12591259 // Allow the coercion if the current function has all the features that would be
12601260 // needed to call the coercee safely.
1261 match tcx.adjust_target_feature_sig(def_id, sig, self.body_id.into()) {
1261 match tcx.adjust_target_feature_sig(def_id, sig, self.body_def_id.into()) {
12621262 Some(adjusted_sig) => adjusted_sig,
12631263 None if matches!(expected_safety, Some(hir::Safety::Safe)) => {
12641264 return Err(TypeError::TargetFeatureCast(def_id));
......@@ -1477,12 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14771477pub fn can_coerce<'tcx>(
14781478 tcx: TyCtxt<'tcx>,
14791479 param_env: ty::ParamEnv<'tcx>,
1480 body_id: LocalDefId,
1480 body_def_id: LocalDefId,
14811481 ty: Ty<'tcx>,
14821482 output_ty: Ty<'tcx>,
14831483) -> bool {
1484 let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_id);
1485 let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_id);
1484 let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_def_id);
1485 let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_def_id);
14861486 fn_ctxt.may_coerce(ty, output_ty)
14871487}
14881488
......@@ -2057,7 +2057,7 @@ impl<'tcx> CoerceMany<'tcx> {
20572057 if due_to_block
20582058 && let Some(expr) = expression
20592059 && let Some(parent_fn_decl) =
2060 fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
2060 fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id))
20612061 {
20622062 fcx.suggest_missing_break_or_return_expr(
20632063 &mut err,
......@@ -2066,14 +2066,14 @@ impl<'tcx> CoerceMany<'tcx> {
20662066 expected,
20672067 found,
20682068 block_or_return_id,
2069 fcx.body_id,
2069 fcx.body_def_id,
20702070 );
20712071 }
20722072
20732073 let is_return_position = fcx
20742074 .tcx
20752075 .hir_get_fn_id_for_return_block(block_or_return_id)
2076 .is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id));
2076 .is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id));
20772077
20782078 if is_return_position
20792079 && let Some(sp) = fcx.ret_coercion_span.get()
......@@ -2083,7 +2083,7 @@ impl<'tcx> CoerceMany<'tcx> {
20832083 // may occur at the first return expression we see in the closure
20842084 // (if it conflicts with the declared return type). Skip adding a
20852085 // note in this case, since it would be incorrect.
2086 && let Some(fn_sig) = fcx.body_fn_sig()
2086 && let Some(fn_sig) = fcx.fn_sig()
20872087 && fn_sig.output().is_ty_var()
20882088 {
20892089 err.span_note(sp, format!("return type inferred to be `{expected}` here"));
......@@ -2096,7 +2096,7 @@ impl<'tcx> CoerceMany<'tcx> {
20962096 /// sure we consider `dyn Trait: Sized` where clauses, which are trivially
20972097 /// false but technically valid for typeck.
20982098 fn is_return_ty_definitely_unsized(&self, fcx: &FnCtxt<'_, 'tcx>) -> bool {
2099 if let Some(sig) = fcx.body_fn_sig() {
2099 if let Some(sig) = fcx.fn_sig() {
21002100 !fcx.predicate_may_hold(&Obligation::new(
21012101 fcx.tcx,
21022102 ObligationCause::dummy(),
compiler/rustc_hir_typeck/src/demand.rs+1-1
......@@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332332 }
333333
334334 let mut expr_finder = FindExprs { hir_id: local_hir_id, uses: init.into_iter().collect() };
335 let body = self.tcx.hir_body_owned_by(self.body_id);
335 let body = self.tcx.hir_body_owned_by(self.body_def_id);
336336 expr_finder.visit_expr(body.value);
337337
338338 // Replaces all of the variables in the given type with a fresh inference variable.
compiler/rustc_hir_typeck/src/expectation.rs+2-2
......@@ -76,9 +76,9 @@ impl<'a, 'tcx> Expectation<'tcx> {
7676 pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
7777 let span = match ty.kind() {
7878 ty::Adt(adt_def, _) => fcx.tcx.def_span(adt_def.did()),
79 _ => fcx.tcx.def_span(fcx.body_id),
79 _ => fcx.tcx.def_span(fcx.body_def_id),
8080 };
81 let cause = ObligationCause::misc(span, fcx.body_id);
81 let cause = ObligationCause::misc(span, fcx.body_def_id);
8282
8383 // FIXME(#155345): Missing normalization call
8484 match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty.skip_normalization(), || {}).kind() {
compiler/rustc_hir_typeck/src/expr.rs+16-10
......@@ -965,7 +965,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
965965 return_expr_ty,
966966 );
967967
968 if let Some(fn_sig) = self.body_fn_sig()
968 if let Some(fn_sig) = self.fn_sig()
969969 && fn_sig.output().has_opaque_types()
970970 {
971971 // Point any obligations that were registered due to opaque type
......@@ -2764,8 +2764,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27642764 return Ty::new_error(self.tcx(), guar);
27652765 }
27662766
2767 let (ident, def_scope) =
2768 self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id);
2767 let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
2768 field,
2769 base_def.did(),
2770 self.body_def_id,
2771 );
27692772
27702773 if let Some((idx, field)) = self.find_adt_field(*base_def, ident) {
27712774 self.write_field_index(expr.hir_id, idx);
......@@ -2938,7 +2941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29382941 field_ident.span,
29392942 "field not available in `impl Future`, but it is available in its `Output`",
29402943 );
2941 match self.tcx.coroutine_kind(self.body_id) {
2944 match self.tcx.coroutine_kind(self.body_def_id) {
29422945 Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
29432946 err.span_suggestion_verbose(
29442947 base.span.shrink_to_hi(),
......@@ -2949,7 +2952,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29492952 }
29502953 _ => {
29512954 let mut span: MultiSpan = base.span.into();
2952 span.push_span_label(self.tcx.def_span(self.body_id), "this is not `async`");
2955 span.push_span_label(self.tcx.def_span(self.body_def_id), "this is not `async`");
29532956 err.span_note(
29542957 span,
29552958 "this implements `Future` and its output type has the field, \
......@@ -3119,7 +3122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31193122 }
31203123
31213124 fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
3122 let generics = self.tcx.generics_of(self.body_id);
3125 let generics = self.tcx.generics_of(self.body_def_id);
31233126 let generic_param = generics.type_param(param, self.tcx);
31243127 if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
31253128 return;
......@@ -3703,7 +3706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37033706
37043707 fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) -> Ty<'tcx> {
37053708 if let rustc_ast::AsmMacro::NakedAsm = asm.asm_macro {
3706 if !find_attr!(self.tcx, self.body_id, Naked(..)) {
3709 if !find_attr!(self.tcx, self.body_def_id, Naked(..)) {
37073710 self.tcx.dcx().emit_err(NakedAsmOutsideNakedFn { span });
37083711 }
37093712 }
......@@ -3802,8 +3805,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38023805 .emit();
38033806 break;
38043807 };
3805 let (subident, sub_def_scope) =
3806 self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, self.body_id);
3808 let (subident, sub_def_scope) = self.tcx.adjust_ident_and_get_scope(
3809 subfield,
3810 variant.def_id,
3811 self.body_def_id,
3812 );
38073813
38083814 let Some((subindex, field)) = variant
38093815 .fields
......@@ -3854,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38543860 let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
38553861 field,
38563862 container_def.did(),
3857 self.body_id,
3863 self.body_def_id,
38583864 );
38593865
38603866 let fields = &container_def.non_enum_variant().fields;
compiler/rustc_hir_typeck/src/expr_use_visitor.rs+1-1
......@@ -217,7 +217,7 @@ impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
217217 }
218218
219219 fn body_owner_def_id(&self) -> LocalDefId {
220 self.body_id
220 self.body_def_id
221221 }
222222
223223 fn tcx(&self) -> TyCtxt<'tcx> {
compiler/rustc_hir_typeck/src/fallback.rs+7-8
......@@ -293,7 +293,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
293293 root_vid: ty::TyVid,
294294 ) {
295295 let unsafe_infer_vars = unsafe_infer_vars.get_or_init(|| {
296 let unsafe_infer_vars = compute_unsafe_infer_vars(self, self.body_id);
296 let unsafe_infer_vars = compute_unsafe_infer_vars(self, self.body_def_id);
297297 debug!(?unsafe_infer_vars);
298298 unsafe_infer_vars
299299 });
......@@ -378,8 +378,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
378378 let sugg = self.try_to_suggest_annotations(diverging_vids, coercions);
379379 self.tcx.emit_node_span_lint(
380380 lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
381 self.tcx.local_def_id_to_hir_id(self.body_id),
382 self.tcx.def_span(self.body_id),
381 self.tcx.local_def_id_to_hir_id(self.body_def_id),
382 self.tcx.def_span(self.body_def_id),
383383 diagnostics::DependencyOnUnitNeverTypeFallback {
384384 obligation_span: never_error.obligation.cause.span,
385385 obligation: never_error.obligation.predicate,
......@@ -446,8 +446,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
446446 diverging_vids: &[ty::TyVid],
447447 coercions: &VecGraph<ty::TyVid, true>,
448448 ) -> diagnostics::SuggestAnnotations {
449 let body =
450 self.tcx.hir_maybe_body_owned_by(self.body_id).expect("body id must have an owner");
449 let body = self.tcx.hir_body_owned_by(self.body_def_id);
451450 // For each diverging var, look through the HIR for a place to give it
452451 // a type annotation. We do this per var because we only really need one
453452 // suggestion to influence a var to be `()`.
......@@ -633,9 +632,9 @@ pub(crate) enum UnsafeUseReason {
633632/// `compute_unsafe_infer_vars` will return `{ id(?X) -> (hir_id, span, Call) }`
634633fn compute_unsafe_infer_vars<'a, 'tcx>(
635634 fcx: &'a FnCtxt<'a, 'tcx>,
636 body_id: LocalDefId,
635 body_def_id: LocalDefId,
637636) -> UnordMap<ty::TyVid, (HirId, Span, UnsafeUseReason)> {
638 let body = fcx.tcx.hir_maybe_body_owned_by(body_id).expect("body id must have an owner");
637 let body = fcx.tcx.hir_body_owned_by(body_def_id);
639638 let mut res = UnordMap::default();
640639
641640 struct UnsafeInferVarsVisitor<'a, 'tcx> {
......@@ -763,7 +762,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>(
763762
764763 UnsafeInferVarsVisitor { fcx, res: &mut res }.visit_expr(&body.value);
765764
766 debug!(?res, "collected the following unsafe vars for {body_id:?}");
765 debug!(?res, "collected the following unsafe vars for {body_def_id:?}");
767766
768767 res
769768}
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+5-5
......@@ -213,7 +213,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
213213 // let it keep doing that and just ensure that compilation won't succeed.
214214 self.dcx().span_delayed_bug(
215215 self.tcx.hir_span(id),
216 format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id),
216 format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_def_id),
217217 );
218218 }
219219 }
......@@ -1070,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10701070 arg_span,
10711071 span,
10721072 container_id,
1073 self.body_id.to_def_id(),
1073 self.body_def_id.to_def_id(),
10741074 ) {
10751075 self.set_tainted_by_errors(e);
10761076 }
......@@ -1192,7 +1192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921192 // error in `validate_res_from_ribs` -- it's just difficult to tell whether the
11931193 // self type has any generic types during rustc_resolve, which is what we use
11941194 // to determine if this is a hard error or warning.
1195 if std::iter::successors(Some(self.body_id.to_def_id()), |&def_id| {
1195 if std::iter::successors(Some(self.body_def_id.to_def_id()), |&def_id| {
11961196 self.tcx.generics_of(def_id).parent
11971197 })
11981198 .all(|def_id| def_id != impl_def_id)
......@@ -1534,7 +1534,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15341534 let guar = self.tainted_by_errors().unwrap_or_else(|| {
15351535 self.err_ctxt()
15361536 .emit_inference_failure_err(
1537 self.body_id,
1537 self.body_def_id,
15381538 sp,
15391539 ty.into(),
15401540 TypeAnnotationNeeded::E0282,
......@@ -1560,7 +1560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15601560 let e = self.tainted_by_errors().unwrap_or_else(|| {
15611561 self.err_ctxt()
15621562 .emit_inference_failure_err(
1563 self.body_id,
1563 self.body_def_id,
15641564 sp,
15651565 ct.into(),
15661566 TypeAnnotationNeeded::E0282,
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+5-5
......@@ -68,9 +68,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6868 let mut deferred_cast_checks = self.root_ctxt.deferred_cast_checks.borrow_mut();
6969 debug!("FnCtxt::check_casts: {} deferred checks", deferred_cast_checks.len());
7070 for cast in deferred_cast_checks.drain(..) {
71 let body_id = std::mem::replace(&mut self.body_id, cast.body_id);
71 let body_def_id = std::mem::replace(&mut self.body_def_id, cast.body_def_id);
7272 cast.check(self);
73 self.body_id = body_id;
73 self.body_def_id = body_def_id;
7474 }
7575 }
7676
......@@ -346,7 +346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
346346 // in `execute_delegation_aware_arguments_check`.
347347 let checked_ty = self
348348 .tcx
349 .hir_opt_delegation_info(self.body_id)
349 .hir_opt_delegation_info(self.body_def_id)
350350 .and_then(|_| self.typeck_results.borrow().node_type_opt(provided_arg.hir_id))
351351 .unwrap_or_else(|| self.check_expr_with_expectation(provided_arg, expectation));
352352
......@@ -1627,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16271627 let callee_ty = callee_ty.peel_refs();
16281628 match *callee_ty.kind() {
16291629 ty::Param(param) => {
1630 let param = self.tcx.generics_of(self.body_id).type_param(param, self.tcx);
1630 let param = self.tcx.generics_of(self.body_def_id).type_param(param, self.tcx);
16311631 if param.kind.is_synthetic() {
16321632 // if it's `impl Fn() -> ..` then just fall down to the def-id based logic
16331633 def_id = param.def_id;
......@@ -1636,7 +1636,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16361636 // and point at that.
16371637 let instantiated = self
16381638 .tcx
1639 .explicit_predicates_of(self.body_id)
1639 .explicit_predicates_of(self.body_def_id)
16401640 .instantiate_identity(self.tcx);
16411641 // FIXME(compiler-errors): This could be problematic if something has two
16421642 // fn-like predicates with different args, but callable types really never
compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs+5-5
......@@ -43,7 +43,7 @@ use crate::{CoroutineTypes, Diverges, EnclosingBreakables, TypeckRootCtxt};
4343///
4444/// [`InferCtxt`]: infer::InferCtxt
4545pub(crate) struct FnCtxt<'a, 'tcx> {
46 pub(super) body_id: LocalDefId,
46 pub(super) body_def_id: LocalDefId,
4747
4848 /// The parameter environment used for proving trait obligations
4949 /// in this function. This can change when we descend into
......@@ -138,12 +138,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
138138 pub(crate) fn new(
139139 root_ctxt: &'a TypeckRootCtxt<'tcx>,
140140 param_env: ty::ParamEnv<'tcx>,
141 body_id: LocalDefId,
141 body_def_id: LocalDefId,
142142 ) -> FnCtxt<'a, 'tcx> {
143143 let (diverging_fallback_behavior, diverging_block_behavior) =
144144 never_type_behavior(root_ctxt.tcx);
145145 FnCtxt {
146 body_id,
146 body_def_id,
147147 param_env,
148148 ret_coercion: None,
149149 ret_coercion_span: Cell::new(None),
......@@ -179,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179179 span: Span,
180180 code: ObligationCauseCode<'tcx>,
181181 ) -> ObligationCause<'tcx> {
182 ObligationCause::new(span, self.body_id, code)
182 ObligationCause::new(span, self.body_def_id, code)
183183 }
184184
185185 pub(crate) fn misc(&self, span: Span) -> ObligationCause<'tcx> {
......@@ -230,7 +230,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
230230 }
231231
232232 fn item_def_id(&self) -> LocalDefId {
233 self.body_id
233 self.body_def_id
234234 }
235235
236236 fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx> {
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs+4-4
......@@ -40,11 +40,11 @@ use crate::method::probe;
4040use crate::method::probe::{IsSuggestion, Mode, ProbeScope};
4141
4242impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
43 pub(crate) fn body_fn_sig(&self) -> Option<ty::FnSig<'tcx>> {
43 pub(crate) fn fn_sig(&self) -> Option<ty::FnSig<'tcx>> {
4444 self.typeck_results
4545 .borrow()
4646 .liberated_fn_sigs()
47 .get(self.tcx.local_def_id_to_hir_id(self.body_id))
47 .get(self.tcx.local_def_id_to_hir_id(self.body_def_id))
4848 .copied()
4949 }
5050
......@@ -170,7 +170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
170170 &self,
171171 ty: Ty<'tcx>,
172172 ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
173 self.err_ctxt().extract_callable_info(self.body_id, self.param_env, ty)
173 self.err_ctxt().extract_callable_info(self.body_def_id, self.param_env, ty)
174174 }
175175
176176 pub(crate) fn suggest_two_fn_call(
......@@ -2292,7 +2292,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22922292 return false;
22932293 };
22942294 let ret_ty_matches = |diagnostic_item| {
2295 let Some(sig) = self.body_fn_sig() else {
2295 let Some(sig) = self.fn_sig() else {
22962296 return false;
22972297 };
22982298 let ty::Adt(kind, _) = sig.output().kind() else {
compiler/rustc_hir_typeck/src/gather_locals.rs+1-1
......@@ -193,7 +193,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
193193 // ascription, or if it's an implicit `self` parameter
194194 ObligationCauseCode::SizedArgumentType(
195195 if ty_span == ident.span
196 && self.fcx.tcx.is_closure_like(self.fcx.body_id.into())
196 && self.fcx.tcx.is_closure_like(self.fcx.body_def_id.into())
197197 {
198198 None
199199 } else {
compiler/rustc_hir_typeck/src/lib.rs+1-1
......@@ -378,7 +378,7 @@ fn extend_err_with_const_context(
378378
379379fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Option<Ty<'tcx>> {
380380 let tcx = fcx.tcx;
381 let def_id = fcx.body_id;
381 let def_id = fcx.body_def_id;
382382 let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer(()), span, .. }) = node.ty()
383383 {
384384 if let Some(item) = tcx.opt_associated_item(def_id.into())
compiler/rustc_hir_typeck/src/method/confirm.rs+1-1
......@@ -702,7 +702,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
702702 Some(self.self_expr.span),
703703 self.call_expr.span,
704704 trait_def_id,
705 self.body_id.to_def_id(),
705 self.body_def_id.to_def_id(),
706706 )
707707 {
708708 self.set_tainted_by_errors(e);
compiler/rustc_hir_typeck/src/method/probe.rs+3-2
......@@ -511,7 +511,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
511511 && !self.tcx.features().arbitrary_self_types();
512512
513513 let mut err = self.err_ctxt().emit_inference_failure_err(
514 self.body_id,
514 self.body_def_id,
515515 err_span,
516516 ty.into(),
517517 TypeAnnotationNeeded::E0282,
......@@ -811,7 +811,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
811811 let is_accessible = if let Some(name) = self.method_name {
812812 let item = candidate.item;
813813 let container_id = item.container_id(self.tcx);
814 let def_scope = self.tcx.adjust_ident_and_get_scope(name, container_id, self.body_id).1;
814 let def_scope =
815 self.tcx.adjust_ident_and_get_scope(name, container_id, self.body_def_id).1;
815816 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
816817 } else {
817818 true
compiler/rustc_hir_typeck/src/method/suggest.rs+9-9
......@@ -160,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
160160
161161 match *ty.peel_refs().kind() {
162162 ty::Param(param) => {
163 let generics = self.tcx.generics_of(self.body_id);
163 let generics = self.tcx.generics_of(self.body_def_id);
164164 let generic_param = generics.type_param(param, self.tcx);
165165 for unsatisfied in unsatisfied_predicates.iter() {
166166 // The parameter implements `IntoIterator`
......@@ -634,7 +634,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
634634 impl<'a, 'tcx> LetVisitor<'a, 'tcx> {
635635 // Check scope of binding.
636636 fn is_sub_scope(&self, sub_id: hir::ItemLocalId, super_id: hir::ItemLocalId) -> bool {
637 let scope_tree = self.fcx.tcx.region_scope_tree(self.fcx.body_id);
637 let scope_tree = self.fcx.tcx.region_scope_tree(self.fcx.body_def_id);
638638 if let Some(sub_var_scope) = scope_tree.var_scope(sub_id)
639639 && let Some(super_var_scope) = scope_tree.var_scope(super_id)
640640 && scope_tree.is_subscope_of(sub_var_scope, super_var_scope)
......@@ -742,7 +742,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
742742 && let hir::def::Res::Local(recv_id) = path.res
743743 && let Some(segment) = path.segments.first()
744744 {
745 let body = self.tcx.hir_body_owned_by(self.body_id);
745 let body = self.tcx.hir_body_owned_by(self.body_def_id);
746746
747747 if let Node::Expr(call_expr) = self.tcx.parent_hir_node(rcvr.hir_id) {
748748 let mut let_visitor = LetVisitor {
......@@ -1148,7 +1148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11481148 ) {
11491149 let mut ty_span = match rcvr_ty.kind() {
11501150 ty::Param(param_type) => {
1151 Some(param_type.span_from_generics(self.tcx, self.body_id.to_def_id()))
1151 Some(param_type.span_from_generics(self.tcx, self.body_def_id.to_def_id()))
11521152 }
11531153 ty::Adt(def, _) if def.did().is_local() => Some(self.tcx.def_span(def.did())),
11541154 _ => None,
......@@ -1779,7 +1779,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17791779 ty::Param(_) => {
17801780 // Account for `fn` items like in `issue-35677.rs` to
17811781 // suggest restricting its type params.
1782 Some(self.tcx.hir_node_by_def_id(self.body_id))
1782 Some(self.tcx.hir_node_by_def_id(self.body_def_id))
17831783 }
17841784 ty::Adt(def, _) => {
17851785 def.did().as_local().map(|def_id| self.tcx.hir_node_by_def_id(def_id))
......@@ -2842,7 +2842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28422842 _ => None,
28432843 });
28442844 if let Some((field, field_ty)) = field_receiver {
2845 let scope = tcx.parent_module_from_def_id(self.body_id);
2845 let scope = tcx.parent_module_from_def_id(self.body_def_id);
28462846 let is_accessible = field.vis.is_accessible_from(scope, tcx);
28472847
28482848 if is_accessible {
......@@ -3147,7 +3147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31473147 seg1.ident.span,
31483148 StashKey::CallAssocMethod,
31493149 |err| {
3150 let body = self.tcx.hir_body_owned_by(self.body_id);
3150 let body = self.tcx.hir_body_owned_by(self.body_def_id);
31513151 struct LetVisitor {
31523152 ident_name: Symbol,
31533153 }
......@@ -3997,7 +3997,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
39973997 {
39983998 let parent_map = self.tcx.visible_parent_map(());
39993999
4000 let scope = self.tcx.parent_module_from_def_id(self.body_id);
4000 let scope = self.tcx.parent_module_from_def_id(self.body_def_id);
40014001 let (accessible_candidates, inaccessible_candidates): (Vec<_>, Vec<_>) =
40024002 candidates.into_iter().partition(|id| {
40034003 let vis = self.tcx.visibility(*id);
......@@ -4555,7 +4555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
45554555 };
45564556 // Obtain the span for `param` and use it for a structured suggestion.
45574557 if let Some(param) = param_type {
4558 let generics = self.tcx.generics_of(self.body_id.to_def_id());
4558 let generics = self.tcx.generics_of(self.body_def_id.to_def_id());
45594559 let type_param = generics.type_param(param, self.tcx);
45604560 let tcx = self.tcx;
45614561 if let Some(def_id) = type_param.def_id.as_local() {
compiler/rustc_hir_typeck/src/op.rs+2-2
......@@ -517,7 +517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517517 &mut err,
518518 trait_pred,
519519 output_associated_item,
520 self.body_id,
520 self.body_def_id,
521521 );
522522 }
523523 }
......@@ -1004,7 +1004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10041004 &mut err,
10051005 pred,
10061006 None,
1007 self.body_id,
1007 self.body_def_id,
10081008 );
10091009 }
10101010 }
compiler/rustc_hir_typeck/src/opaque_types.rs+9-4
......@@ -163,13 +163,18 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
163163 if let Some(guar) = self.tainted_by_errors() {
164164 guar
165165 } else {
166 report_item_does_not_constrain_error(self.tcx, self.body_id, def_id, None)
166 report_item_does_not_constrain_error(
167 self.tcx,
168 self.body_def_id,
169 def_id,
170 None,
171 )
167172 }
168173 }
169174 UsageKind::NonDefiningUse(opaque_type_key, hidden_type) => {
170175 report_item_does_not_constrain_error(
171176 self.tcx,
172 self.body_id,
177 self.body_def_id,
173178 def_id,
174179 Some((opaque_type_key, hidden_type.span)),
175180 )
......@@ -186,7 +191,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
186191 .unwrap_or_else(|| hidden_type.ty.into());
187192 self.err_ctxt()
188193 .emit_inference_failure_err(
189 self.body_id,
194 self.body_def_id,
190195 hidden_type.span,
191196 infer_var,
192197 TypeAnnotationNeeded::E0282,
......@@ -235,7 +240,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
235240 return UsageKind::UnconstrainedHiddenType(hidden_type);
236241 }
237242
238 let cause = ObligationCause::misc(hidden_type.span, self.body_id);
243 let cause = ObligationCause::misc(hidden_type.span, self.body_def_id);
239244 let at = self.at(&cause, self.param_env);
240245 let hidden_type = match solve::deeply_normalize(at, Unnormalized::new_wip(hidden_type)) {
241246 Ok(hidden_type) => hidden_type,
compiler/rustc_hir_typeck/src/writeback.rs+2-2
......@@ -948,8 +948,8 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
948948 // We must deeply normalize in the new solver, since later lints expect
949949 // that types that show up in the typeck are fully normalized.
950950 let mut value = if self.should_normalize && self.fcx.next_trait_solver() {
951 let body_id = tcx.hir_body_owner_def_id(self.body.id());
952 let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
951 let body_def_id = tcx.hir_body_owner_def_id(self.body.id());
952 let cause = ObligationCause::misc(self.span.to_span(tcx), body_def_id);
953953 let at = self.fcx.at(&cause, self.fcx.param_env);
954954 let universes = vec![None; outer_exclusive_binder(&value).as_usize()];
955955 match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
compiler/rustc_infer/src/infer/opaque_types/mod.rs+2-2
......@@ -26,7 +26,7 @@ impl<'tcx> InferCtxt<'tcx> {
2626 pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<TyCtxt<'tcx>>>(
2727 &self,
2828 value: T,
29 body_id: LocalDefId,
29 body_def_id: LocalDefId,
3030 span: Span,
3131 param_env: ty::ParamEnv<'tcx>,
3232 ) -> InferOk<'tcx, T> {
......@@ -60,7 +60,7 @@ impl<'tcx> InferCtxt<'tcx> {
6060 self.tcx,
6161 ObligationCause::new(
6262 span,
63 body_id,
63 body_def_id,
6464 traits::ObligationCauseCode::OpaqueReturnType(None),
6565 ),
6666 goal.param_env,
compiler/rustc_infer/src/traits/mod.rs+2-2
......@@ -158,11 +158,11 @@ impl<'tcx, O> Obligation<'tcx, O> {
158158 pub fn misc(
159159 tcx: TyCtxt<'tcx>,
160160 span: Span,
161 body_id: LocalDefId,
161 body_def_id: LocalDefId,
162162 param_env: ty::ParamEnv<'tcx>,
163163 trait_ref: impl Upcast<TyCtxt<'tcx>, O>,
164164 ) -> Obligation<'tcx, O> {
165 Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref)
165 Obligation::new(tcx, ObligationCause::misc(span, body_def_id), param_env, trait_ref)
166166 }
167167
168168 pub fn with<P>(
compiler/rustc_lint/src/unused.rs+29-4
......@@ -417,13 +417,19 @@ trait UnusedDelimLint {
417417 }
418418 // either function/method call, or something this lint doesn't care about
419419 ref call_or_other => {
420 let (args_to_check, ctx) = match *call_or_other {
421 Call(_, ref args) => (&args[..], UnusedDelimsCtx::FunctionArg),
422 MethodCall(ref call) => (&call.args[..], UnusedDelimsCtx::MethodArg),
420 let (args_to_check, ctx, callee_from_expansion) = match *call_or_other {
421 Call(ref callee, ref args) => {
422 (&args[..], UnusedDelimsCtx::FunctionArg, callee.span.from_expansion())
423 }
424 MethodCall(ref call) => (
425 &call.args[..],
426 UnusedDelimsCtx::MethodArg,
427 call.seg.ident.span.from_expansion(),
428 ),
423429 Closure(ref closure)
424430 if matches!(closure.fn_decl.output, FnRetTy::Default(_)) =>
425431 {
426 (&[closure.body.clone()][..], UnusedDelimsCtx::ClosureBody)
432 (&[closure.body.clone()][..], UnusedDelimsCtx::ClosureBody, false)
427433 }
428434 // actual catch-all arm
429435 _ => {
......@@ -438,6 +444,11 @@ trait UnusedDelimLint {
438444 return;
439445 }
440446 for arg in args_to_check {
447 // Whether an expression is wrapped in a block can change which `macro_rules!`
448 // arm is taken. Don't report the braces as unused in that case. (Issue #158747)
449 if callee_from_expansion && Self::block_wraps_expanded_expr(arg) {
450 continue;
451 }
441452 self.check_unused_delims_expr(cx, arg, ctx, false, None, None, false);
442453 }
443454 return;
......@@ -516,6 +527,20 @@ trait UnusedDelimLint {
516527 false,
517528 );
518529 }
530
531 // Returns true for a user-written block whose only expression came from a macro expansion.
532 fn block_wraps_expanded_expr(value: &ast::Expr) -> bool {
533 if let ast::ExprKind::Block(ref block, None) = value.kind
534 && block.rules == ast::BlockCheckMode::Default
535 && !value.span.from_expansion()
536 && let [stmt] = block.stmts.as_slice()
537 && let ast::StmtKind::Expr(ref expr) = stmt.kind
538 {
539 expr.span.from_expansion()
540 } else {
541 false
542 }
543 }
519544}
520545
521546declare_lint! {
compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp+4
......@@ -160,6 +160,10 @@ extern "C" void LLVMRustPrintStatisticsJSON(RustStringRef OutBuf) {
160160 llvm::PrintStatisticsJSON(OS);
161161}
162162
163extern "C" bool LLVMRustIsCall(LLVMValueRef V) {
164 return llvm::isa<llvm::CallBase>(llvm::unwrap(V));
165}
166
163167// Some of the functions here rely on LLVM modules that may not always be
164168// available. As such, we only try to build it in the first place, if
165169// llvm.offload is enabled.
compiler/rustc_middle/src/traits/mod.rs+8-8
......@@ -44,13 +44,13 @@ use crate::ty::{self, AdtKind, GenericArgsRef, Ty};
4444pub struct ObligationCause<'tcx> {
4545 pub span: Span,
4646
47 /// The ID of the fn body that triggered this obligation. This is
47 /// The ID of the fn that triggered this obligation. This is
4848 /// used for region obligations to determine the precise
4949 /// environment in which the region obligation should be evaluated
5050 /// (in particular, closures can add new assumptions). See the
5151 /// field `region_obligations` of the `FulfillmentContext` for more
5252 /// information.
53 pub body_id: LocalDefId,
53 pub body_def_id: LocalDefId,
5454
5555 code: ObligationCauseCodeHandle<'tcx>,
5656}
......@@ -62,7 +62,7 @@ pub struct ObligationCause<'tcx> {
6262// which is hashed as an interned pointer. See #90996.
6363impl Hash for ObligationCause<'_> {
6464 fn hash<H: Hasher>(&self, state: &mut H) {
65 self.body_id.hash(state);
65 self.body_def_id.hash(state);
6666 self.span.hash(state);
6767 }
6868}
......@@ -71,14 +71,14 @@ impl<'tcx> ObligationCause<'tcx> {
7171 #[inline]
7272 pub fn new(
7373 span: Span,
74 body_id: LocalDefId,
74 body_def_id: LocalDefId,
7575 code: ObligationCauseCode<'tcx>,
7676 ) -> ObligationCause<'tcx> {
77 ObligationCause { span, body_id, code: code.into() }
77 ObligationCause { span, body_def_id, code: code.into() }
7878 }
7979
80 pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> {
81 ObligationCause::new(span, body_id, ObligationCauseCode::Misc)
80 pub fn misc(span: Span, body_def_id: LocalDefId) -> ObligationCause<'tcx> {
81 ObligationCause::new(span, body_def_id, ObligationCauseCode::Misc)
8282 }
8383
8484 #[inline(always)]
......@@ -88,7 +88,7 @@ impl<'tcx> ObligationCause<'tcx> {
8888
8989 #[inline(always)]
9090 pub fn dummy_with_span(span: Span) -> ObligationCause<'tcx> {
91 ObligationCause { span, body_id: CRATE_DEF_ID, code: Default::default() }
91 ObligationCause { span, body_def_id: CRATE_DEF_ID, code: Default::default() }
9292 }
9393
9494 #[inline]
compiler/rustc_middle/src/ty/typetree.rs+100-97
......@@ -32,12 +32,19 @@ pub fn fnc_typetrees<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>) -> FncTree {
3232 // Create TypeTree for return type
3333 let ret = typetree_from_ty(tcx, sig.output());
3434
35 FncTree { args, ret }
35 let f = FncTree { args, ret };
36 f
3637}
3738
3839/// Generate a TypeTree for a specific type.
3940/// Mainly a convenience wrapper around the actual implementation.
4041pub fn typetree_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> TypeTree {
42 if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
43 return TypeTree::new();
44 }
45 if tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::NoTT) {
46 return TypeTree::new();
47 }
4148 let mut visited = Vec::new();
4249 typetree_from_ty_impl_inner(tcx, ty, 0, &mut visited, false)
4350}
......@@ -46,6 +53,40 @@ pub fn typetree_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> TypeTree {
4653/// from pathological deeply nested types. Combined with cycle detection.
4754const MAX_TYPETREE_DEPTH: usize = 6;
4855
56fn handle_indirection<'a>(
57 ty: Ty<'a>,
58 tcx: TyCtxt<'a>,
59 depth: usize,
60 visited: &mut Vec<Ty<'a>>,
61) -> TypeTree {
62 let Some(inner_ty) = ty.builtin_deref(true) else {
63 bug!("incorrect autodiff typetree handling for type: {}", ty);
64 };
65 // slices are represented as `&'{erased} mut [f32]`
66 // This reads as a reference to a slice of f32.
67 // So we'd end up with ptr->RustSlice->f32 without this extra handling
68 if inner_ty.is_slice() {
69 if let ty::Slice(element_ty) = inner_ty.kind() {
70 let element_tree =
71 typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
72 return TypeTree(vec![Type {
73 offset: -1,
74 size: tcx.data_layout.pointer_size().bytes_usize(),
75 kind: Kind::RustSlice,
76 child: element_tree,
77 }]);
78 }
79 }
80
81 let child = typetree_from_ty_impl_inner(tcx, inner_ty, depth + 1, visited, true);
82 return TypeTree(vec![Type {
83 offset: -1,
84 size: tcx.data_layout.pointer_size().bytes_usize(),
85 kind: Kind::Pointer,
86 child,
87 }]);
88}
89
4990/// Internal implementation with context about whether this is for a reference target.
5091fn typetree_from_ty_impl_inner<'tcx>(
5192 tcx: TyCtxt<'tcx>,
......@@ -64,43 +105,12 @@ fn typetree_from_ty_impl_inner<'tcx>(
64105 }
65106 visited.push(ty);
66107
67 if ty.is_scalar() {
68 let (kind, size) = if ty.is_integral() || ty.is_char() || ty.is_bool() {
69 (Kind::Integer, ty.primitive_size(tcx).bytes_usize())
70 } else if ty.is_floating_point() {
71 match ty {
72 x if x == tcx.types.f16 => (Kind::Half, 2),
73 x if x == tcx.types.f32 => (Kind::Float, 4),
74 x if x == tcx.types.f64 => (Kind::Double, 8),
75 x if x == tcx.types.f128 => (Kind::F128, 16),
76 _ => (Kind::Integer, 0),
77 }
78 } else {
79 (Kind::Integer, 0)
80 };
81
82 // Use offset 0 for scalars that are direct targets of references (like &f64)
83 // Use offset -1 for scalars used directly (like function return types)
84 let offset = if is_reference_target && !ty.is_array() { 0 } else { -1 };
85 return TypeTree(vec![Type { offset, size, kind, child: TypeTree::new() }]);
86 }
87
88 if ty.is_ref() || ty.is_raw_ptr() || ty.is_box() {
89 let Some(inner_ty) = ty.builtin_deref(true) else {
90 return TypeTree::new();
91 };
92
93 let child = typetree_from_ty_impl_inner(tcx, inner_ty, depth + 1, visited, true);
94 return TypeTree(vec![Type {
95 offset: -1,
96 size: tcx.data_layout.pointer_size().bytes_usize(),
97 kind: Kind::Pointer,
98 child,
99 }]);
100 }
101
102 if ty.is_array() {
103 if let ty::Array(element_ty, len_const) = ty.kind() {
108 match ty.kind() {
109 // See handle_indirection for an explanation on why we don't handle it here.
110 ty::Slice(..) => bug!("incorrect autodiff typetree handling for slice: {}", ty),
111 ty::Ref(..) | ty::RawPtr(..) => handle_indirection(ty, tcx, depth, visited),
112 ty::Adt(def, _) if def.is_box() => handle_indirection(ty, tcx, depth, visited),
113 ty::Array(element_ty, len_const) => {
104114 let len = len_const.try_to_target_usize(tcx).unwrap_or(0);
105115 if len == 0 {
106116 return TypeTree::new();
......@@ -109,65 +119,44 @@ fn typetree_from_ty_impl_inner<'tcx>(
109119 typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
110120 let mut types = Vec::new();
111121 for elem_type in &element_tree.0 {
112 types.push(Type {
113 offset: -1,
114 size: elem_type.size,
115 kind: elem_type.kind,
116 child: elem_type.child.clone(),
117 });
122 types.push(Type::from_ty(-1, elem_type));
118123 }
119124
120 return TypeTree(types);
121 }
122 }
123
124 if ty.is_slice() {
125 if let ty::Slice(element_ty) = ty.kind() {
126 let element_tree =
127 typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false);
128 return element_tree;
129 }
130 }
131
132 if let ty::Tuple(tuple_types) = ty.kind() {
133 if tuple_types.is_empty() {
134 return TypeTree::new();
125 TypeTree(types)
135126 }
127 ty::Tuple(tuple_types) => {
128 if tuple_types.is_empty() {
129 return TypeTree::new();
130 }
136131
137 let mut types = Vec::new();
138 let mut current_offset = 0;
132 let mut types = Vec::new();
133 let mut current_offset = 0;
139134
140 for tuple_ty in tuple_types.iter() {
141 let element_tree =
142 typetree_from_ty_impl_inner(tcx, tuple_ty, depth + 1, visited, false);
135 for tuple_ty in tuple_types.iter() {
136 let element_tree =
137 typetree_from_ty_impl_inner(tcx, tuple_ty, depth + 1, visited, false);
143138
144 let element_layout = tcx
145 .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tuple_ty))
146 .ok()
147 .map(|layout| layout.size.bytes_usize())
148 .unwrap_or(0);
139 let element_layout = tcx
140 .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tuple_ty))
141 .ok()
142 .map(|layout| layout.size.bytes_usize())
143 .unwrap_or(0);
149144
150 for elem_type in &element_tree.0 {
151 types.push(Type {
152 offset: if elem_type.offset == -1 {
145 for elem_type in &element_tree.0 {
146 let offset = if elem_type.offset == -1 {
153147 current_offset as isize
154148 } else {
155149 current_offset as isize + elem_type.offset
156 },
157 size: elem_type.size,
158 kind: elem_type.kind,
159 child: elem_type.child.clone(),
160 });
150 };
151 types.push(Type::from_ty(offset, elem_type));
152 }
153
154 current_offset += element_layout;
161155 }
162156
163 current_offset += element_layout;
157 TypeTree(types)
164158 }
165
166 return TypeTree(types);
167 }
168
169 if let ty::Adt(adt_def, args) = ty.kind() {
170 if adt_def.is_struct() {
159 ty::Adt(adt_def, args) if adt_def.is_struct() => {
171160 let struct_layout =
172161 tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty));
173162 if let Ok(layout) = struct_layout {
......@@ -186,23 +175,37 @@ fn typetree_from_ty_impl_inner<'tcx>(
186175 let field_offset = layout.fields.offset(field_idx).bytes_usize();
187176
188177 for elem_type in &field_tree.0 {
189 types.push(Type {
190 offset: if elem_type.offset == -1 {
191 field_offset as isize
192 } else {
193 field_offset as isize + elem_type.offset
194 },
195 size: elem_type.size,
196 kind: elem_type.kind,
197 child: elem_type.child.clone(),
198 });
178 let offset = if elem_type.offset == -1 {
179 field_offset as isize
180 } else {
181 field_offset as isize + elem_type.offset
182 };
183 types.push(Type::from_ty(offset, elem_type));
199184 }
200185 }
201186
202 return TypeTree(types);
187 TypeTree(types)
188 } else {
189 TypeTree::new()
203190 }
204191 }
192 ty::Char | ty::Bool | ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_) => {
193 let kind = Kind::Integer;
194 let size = ty.primitive_size(tcx).bytes_usize();
195 let offset = if is_reference_target { 0 } else { -1 };
196 TypeTree(vec![Type { offset, size, kind, child: TypeTree::new() }])
197 }
198 ty::Float(_) | ty::Infer(ty::FloatVar(_)) => {
199 let (enzyme_ty, size) = match ty {
200 x if x == tcx.types.f16 => (Kind::Half, 2),
201 x if x == tcx.types.f32 => (Kind::Float, 4),
202 x if x == tcx.types.f64 => (Kind::Double, 8),
203 x if x == tcx.types.f128 => (Kind::F128, 16),
204 _ => bug!("Unexpected floating point type: {:?}", ty),
205 };
206 let offset = if is_reference_target { 0 } else { -1 };
207 TypeTree(vec![Type { offset, size, kind: enzyme_ty, child: TypeTree::new() }])
208 }
209 _ => TypeTree::new(),
205210 }
206
207 TypeTree::new()
208211}
compiler/rustc_resolve/src/diagnostics.rs+4
......@@ -407,6 +407,10 @@ pub(crate) struct ParamInNonTrivialAnonConst {
407407 "consider factoring the expression into a `type const` item and use it as the const argument instead"
408408 )]
409409 pub(crate) help_gca: bool,
410 #[help(
411 "alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item"
412 )]
413 pub(crate) help_suggest_gca: bool,
410414}
411415
412416#[derive(Debug)]
compiler/rustc_resolve/src/error_helper.rs+3-1
......@@ -1288,9 +1288,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12881288 span,
12891289 name,
12901290 param_kind: is_type,
1291 help: self.tcx.sess.is_nightly_build(),
1291 help: self.tcx.sess.is_nightly_build()
1292 && !self.tcx.features().min_generic_const_args(),
12921293 is_gca,
12931294 help_gca: is_gca,
1295 help_suggest_gca: self.tcx.sess.is_nightly_build() && !is_gca,
12941296 })
12951297 }
12961298 ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => {
compiler/rustc_resolve/src/late/diagnostics.rs+4-1
......@@ -3983,9 +3983,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
39833983 span: lifetime_ref.ident.span,
39843984 name: lifetime_ref.ident.name,
39853985 param_kind: diagnostics::ParamKindInNonTrivialAnonConst::Lifetime,
3986 help: self.r.tcx.sess.is_nightly_build(),
3986 help: self.r.tcx.sess.is_nightly_build()
3987 && !self.r.features.min_generic_const_args(),
39873988 is_gca: self.r.features.generic_const_args(),
39883989 help_gca: self.r.features.generic_const_args(),
3990 help_suggest_gca: self.r.tcx.sess.is_nightly_build()
3991 && !self.r.features.generic_const_args(),
39893992 })
39903993 .emit()
39913994 }
compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs+4-1
......@@ -1,12 +1,15 @@
11use crate::spec::{
22 Arch, Cc, CfgAbi, LinkerFlavor, Lld, LlvmAbi, StackProbeType, Target, TargetMetadata,
3 TargetOptions, base,
3 TargetOptions, add_link_args, base,
44};
55
66pub(crate) fn target() -> Target {
77 let mut base = base::freebsd::opts();
88 base.cpu = "ppc64le".into();
99 base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
10 // long double is IEEE-128; f128 soft-float ops emit the PPC __*kf* helpers,
11 // which compiler_builtins lacks. Resolve them from base libgcc.
12 add_link_args(&mut base.late_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-lgcc"]);
1013 base.max_atomic_width = Some(64);
1114 base.stack_probes = StackProbeType::Inline;
1215 base.cfg_abi = CfgAbi::ElfV2;
compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs+3-2
......@@ -1813,7 +1813,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18131813 }
18141814 }
18151815
1816 let body_owner_def_id = (cause.body_id != CRATE_DEF_ID).then(|| cause.body_id.to_def_id());
1816 let body_owner_def_id =
1817 (cause.body_def_id != CRATE_DEF_ID).then(|| cause.body_def_id.to_def_id());
18171818 self.note_and_explain_type_err(diag, terr, cause, span, body_owner_def_id);
18181819 if let Some(exp_found) = exp_found
18191820 && let exp_found = TypeError::Sorts(exp_found)
......@@ -1945,7 +1946,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19451946 let TypeError::ArraySize(sz) = terr else {
19461947 return None;
19471948 };
1948 let tykind = match self.tcx.hir_node_by_def_id(trace.cause.body_id) {
1949 let tykind = match self.tcx.hir_node_by_def_id(trace.cause.body_def_id) {
19491950 hir::Node::Item(hir::Item {
19501951 kind: hir::ItemKind::Fn { body: body_id, .. }, ..
19511952 }) => {
compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs+2-2
......@@ -173,7 +173,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
173173 exp_span, exp_found.expected, exp_found.found,
174174 );
175175
176 match self.tcx.coroutine_kind(cause.body_id) {
176 match self.tcx.coroutine_kind(cause.body_def_id) {
177177 Some(hir::CoroutineKind::Desugared(
178178 hir::CoroutineDesugaring::Async | hir::CoroutineDesugaring::AsyncGen,
179179 _,
......@@ -636,7 +636,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
636636 }
637637 }
638638
639 self.tcx.hir_maybe_body_owned_by(cause.body_id).and_then(|body| {
639 self.tcx.hir_maybe_body_owned_by(cause.body_def_id).and_then(|body| {
640640 IfVisitor { err_span: span, found_if: false }
641641 .visit_body(&body)
642642 .is_break()
compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs+14-13
......@@ -144,14 +144,14 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>(
144144 },
145145 );
146146
147 // If our `body_id` has been set (and isn't just from a dummy obligation cause),
147 // If our `body_def_id` has been set (and isn't just from a dummy obligation cause),
148148 // then try to look for a param-env clause that would apply. The way we compute
149149 // this is somewhat manual, since we need the spans, so we elaborate this directly
150150 // from `predicates_of` rather than actually looking at the param-env which
151151 // otherwise would be more appropriate.
152 let body_id = obligation.cause.body_id;
153 if body_id != CRATE_DEF_ID {
154 let predicates = tcx.predicates_of(body_id.to_def_id()).instantiate_identity(tcx);
152 let body_def_id = obligation.cause.body_def_id;
153 if body_def_id != CRATE_DEF_ID {
154 let predicates = tcx.predicates_of(body_def_id.to_def_id()).instantiate_identity(tcx);
155155 for (pred, span) in
156156 elaborate(tcx, predicates.into_iter().map(|(c, s)| (c.skip_norm_wip(), s)))
157157 {
......@@ -231,7 +231,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
231231 return match self.tainted_by_errors() {
232232 None => self
233233 .emit_inference_failure_err(
234 obligation.cause.body_id,
234 obligation.cause.body_def_id,
235235 span,
236236 trait_pred.self_ty().skip_binder().into(),
237237 TypeAnnotationNeeded::E0282,
......@@ -285,7 +285,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
285285 })
286286 .collect();
287287 self.emit_inference_failure_err_with_type_hint(
288 obligation.cause.body_id,
288 obligation.cause.body_def_id,
289289 span,
290290 term,
291291 TypeAnnotationNeeded::E0283,
......@@ -369,7 +369,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
369369 impl_candidates.as_slice(),
370370 obligation,
371371 trait_pred,
372 obligation.cause.body_id,
372 obligation.cause.body_def_id,
373373 &mut err,
374374 false,
375375 obligation.param_env,
......@@ -384,7 +384,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
384384 }
385385
386386 if term.is_some_and(|term| term.as_type().is_some())
387 && let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id)
387 && let Some(body) =
388 self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id)
388389 {
389390 let mut expr_finder = FindExprBySpan::new(span, self.tcx);
390391 expr_finder.visit_expr(&body.value);
......@@ -546,7 +547,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
546547 }
547548
548549 self.emit_inference_failure_err(
549 obligation.cause.body_id,
550 obligation.cause.body_def_id,
550551 span,
551552 term,
552553 TypeAnnotationNeeded::E0282,
......@@ -565,7 +566,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
565566 // both must be type variables, or the other would've been instantiated
566567 assert!(a.is_ty_var() && b.is_ty_var());
567568 self.emit_inference_failure_err(
568 obligation.cause.body_id,
569 obligation.cause.body_def_id,
569570 span,
570571 a.into(),
571572 TypeAnnotationNeeded::E0282,
......@@ -599,7 +600,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
599600 let predicate = self.tcx.short_string(predicate, &mut long_ty_path);
600601 if let Some(term) = term {
601602 self.emit_inference_failure_err(
602 obligation.cause.body_id,
603 obligation.cause.body_def_id,
603604 span,
604605 term,
605606 TypeAnnotationNeeded::E0284,
......@@ -631,7 +632,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
631632 data.walk().filter_map(ty::GenericArg::as_term).find(|term| term.is_infer());
632633 if let Some(term) = term {
633634 self.emit_inference_failure_err(
634 obligation.cause.body_id,
635 obligation.cause.body_def_id,
635636 span,
636637 term,
637638 TypeAnnotationNeeded::E0284,
......@@ -653,7 +654,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
653654
654655 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ..)) => self
655656 .emit_inference_failure_err(
656 obligation.cause.body_id,
657 obligation.cause.body_def_id,
657658 span,
658659 ct.into(),
659660 TypeAnnotationNeeded::E0284,
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+10-10
......@@ -468,7 +468,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
468468 }
469469 }
470470 if let Some(s) = parent_label {
471 let body = obligation.cause.body_id;
471 let body = obligation.cause.body_def_id;
472472 err.span_label(tcx.def_span(body), s);
473473 }
474474
......@@ -689,7 +689,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
689689 violations,
690690 );
691691 if let hir::Node::Item(item) =
692 self.tcx.hir_node_by_def_id(obligation.cause.body_id)
692 self.tcx.hir_node_by_def_id(obligation.cause.body_def_id)
693693 && let hir::ItemKind::Impl(impl_) = item.kind
694694 && let None = impl_.of_trait
695695 && let hir::TyKind::TraitObject(_, tagged_ptr) = impl_.self_ty.kind
......@@ -949,7 +949,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
949949 }
950950 } else if let ty::Param(param) = trait_ref.self_ty().skip_binder().kind()
951951 && let Some(generics) =
952 self.tcx.hir_node_by_def_id(main_obligation.cause.body_id).generics()
952 self.tcx.hir_node_by_def_id(main_obligation.cause.body_def_id).generics()
953953 {
954954 let constraint = ty::print::with_no_trimmed_paths!(format!(
955955 "[const] {}",
......@@ -1144,7 +1144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11441144 }
11451145 }
11461146 }
1147 let hir_id = self.tcx.local_def_id_to_hir_id(obligation.cause.body_id);
1147 let hir_id = self.tcx.local_def_id_to_hir_id(obligation.cause.body_def_id);
11481148 let Some(body_id) = self.tcx.hir_node(hir_id).body_id() else { return (false, false) };
11491149 let ControlFlow::Break(expr) =
11501150 (FindMethodSubexprOfTry { search_span: span }).visit_body(self.tcx.hir_body(body_id))
......@@ -1382,7 +1382,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13821382 ty: Ty<'tcx>,
13831383 obligation: &PredicateObligation<'tcx>,
13841384 ) -> Diag<'a> {
1385 let def_id = obligation.cause.body_id;
1385 let def_id = obligation.cause.body_def_id;
13861386 let span = self.tcx.ty_span(def_id);
13871387
13881388 let mut file = None;
......@@ -2869,7 +2869,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28692869 // message, and fall back to regular note otherwise.
28702870 if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
28712871 self.note_obligation_cause_code(
2872 obligation.cause.body_id,
2872 obligation.cause.body_def_id,
28732873 err,
28742874 obligation.predicate,
28752875 obligation.param_env,
......@@ -2884,7 +2884,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28842884 obligation.cause.code(),
28852885 );
28862886 self.suggest_borrow_for_unsized_closure_return(
2887 obligation.cause.body_id,
2887 obligation.cause.body_def_id,
28882888 err,
28892889 obligation.predicate,
28902890 );
......@@ -3211,7 +3211,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
32113211 is_fn_trait: bool,
32123212 suggested: bool,
32133213 ) {
3214 let body_def_id = obligation.cause.body_id;
3214 let body_def_id = obligation.cause.body_def_id;
32153215 let span = if let ObligationCauseCode::BinOp { rhs_span, .. } = obligation.cause.code() {
32163216 *rhs_span
32173217 } else {
......@@ -3242,7 +3242,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
32423242 err,
32433243 trait_predicate,
32443244 None,
3245 obligation.cause.body_id,
3245 obligation.cause.body_def_id,
32463246 );
32473247 } else if trait_def_id.is_local()
32483248 && self.tcx.trait_impls_of(trait_def_id).is_empty()
......@@ -3798,7 +3798,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
37983798 {
37993799 trait_item_def_id.as_local()
38003800 } else {
3801 Some(obligation.cause.body_id)
3801 Some(obligation.cause.body_def_id)
38023802 };
38033803 if let Some(suggestion_def_id) = suggestion_def_id
38043804 && let Some(generics) = self.tcx.hir_get_generics(suggestion_def_id)
compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs+1-1
......@@ -340,7 +340,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
340340 | ObligationCauseCode::WhereClauseInExpr(..) = code
341341 {
342342 self.note_obligation_cause_code(
343 error.obligation.cause.body_id,
343 error.obligation.cause.body_def_id,
344344 &mut diag,
345345 error.obligation.predicate,
346346 error.obligation.param_env,
compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs+1-1
......@@ -72,7 +72,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7272 // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
7373 // but I guess we could synthesize one here. We don't see any errors that rely on
7474 // that yet, though.
75 let item_context = self.describe_enclosure(obligation.cause.body_id).unwrap_or("");
75 let item_context = self.describe_enclosure(obligation.cause.body_def_id).unwrap_or("");
7676
7777 let direct = match obligation.cause.code() {
7878 ObligationCauseCode::BuiltinDerived(..)
compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs+1-1
......@@ -150,7 +150,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
150150 suggest_increasing_limit,
151151 |err| {
152152 self.note_obligation_cause_code(
153 obligation.cause.body_id,
153 obligation.cause.body_def_id,
154154 err,
155155 predicate,
156156 obligation.param_env,
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs+57-46
......@@ -285,7 +285,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
285285 }
286286
287287 if !cause.span.is_dummy()
288 && let Some(body) = self.tcx.hir_maybe_body_owned_by(cause.body_id)
288 && let Some(body) = self.tcx.hir_maybe_body_owned_by(cause.body_def_id)
289289 {
290290 let mut expr_finder = FindExprBySpan::new(cause.span, self.tcx);
291291 expr_finder.visit_body(body);
......@@ -467,7 +467,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
467467 err: &mut Diag<'_>,
468468 trait_pred: ty::PolyTraitPredicate<'tcx>,
469469 associated_ty: Option<(&'static str, Ty<'tcx>)>,
470 mut body_id: LocalDefId,
470 mut body_def_id: LocalDefId,
471471 ) {
472472 if trait_pred.skip_binder().polarity != ty::PredicatePolarity::Positive {
473473 return;
......@@ -494,7 +494,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
494494 // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
495495 // don't suggest `T: Sized + ?Sized`.
496496 loop {
497 let node = self.tcx.hir_node_by_def_id(body_id);
497 let node = self.tcx.hir_node_by_def_id(body_def_id);
498498 match node {
499499 hir::Node::Item(hir::Item {
500500 kind: hir::ItemKind::Trait { ident, generics, bounds, .. },
......@@ -504,7 +504,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
504504 // Restricting `Self` for a single method.
505505 suggest_restriction(
506506 self.tcx,
507 body_id,
507 body_def_id,
508508 generics,
509509 "`Self`",
510510 err,
......@@ -524,7 +524,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
524524 assert!(param_ty);
525525 // Restricting `Self` for a single method.
526526 suggest_restriction(
527 self.tcx, body_id, generics, "`Self`", err, None, projection, trait_pred,
527 self.tcx,
528 body_def_id,
529 generics,
530 "`Self`",
531 err,
532 None,
533 projection,
534 trait_pred,
528535 None,
529536 );
530537 return;
......@@ -547,7 +554,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
547554 // Missing restriction on associated type of type parameter (unmet projection).
548555 suggest_restriction(
549556 self.tcx,
550 body_id,
557 body_def_id,
551558 generics,
552559 "the associated type",
553560 err,
......@@ -567,7 +574,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
567574 // Missing restriction on associated type of type parameter (unmet projection).
568575 suggest_restriction(
569576 self.tcx,
570 body_id,
577 body_def_id,
571578 generics,
572579 "the associated type",
573580 err,
......@@ -687,7 +694,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
687694
688695 _ => {}
689696 }
690 body_id = self.tcx.local_parent(body_id);
697 body_def_id = self.tcx.local_parent(body_def_id);
691698 }
692699 }
693700
......@@ -1024,7 +1031,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
10241031 );
10251032
10261033 let Some((def_id_or_name, output, inputs)) =
1027 self.extract_callable_info(obligation.cause.body_id, obligation.param_env, self_ty)
1034 self.extract_callable_info(obligation.cause.body_def_id, obligation.param_env, self_ty)
10281035 else {
10291036 return false;
10301037 };
......@@ -1232,7 +1239,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12321239 // Wrap method receivers and `&`-references in parens.
12331240 let suggestion = if self.tcx.sess.source_map().span_followed_by(span, ".").is_some() {
12341241 parenthesized_cast(span)
1235 } else if let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) {
1242 } else if let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) {
12361243 let mut expr_finder = FindExprBySpan::new(span, self.tcx);
12371244 expr_finder.visit_expr(body.value);
12381245 if let Some(expr) = expr_finder.result
......@@ -1271,7 +1278,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12711278 span.remove_mark();
12721279 }
12731280 let mut expr_finder = FindExprBySpan::new(span, self.tcx);
1274 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
1281 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) else {
12751282 return;
12761283 };
12771284 expr_finder.visit_expr(body.value);
......@@ -1350,7 +1357,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13501357 ) -> bool {
13511358 let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty());
13521359 self.enter_forall(self_ty, |ty: Ty<'_>| {
1353 let Some(generics) = self.tcx.hir_get_generics(obligation.cause.body_id) else {
1360 let Some(generics) = self.tcx.hir_get_generics(obligation.cause.body_def_id) else {
13541361 return false;
13551362 };
13561363 let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false };
......@@ -1444,7 +1451,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14441451 /// because the callable type must also be well-formed to be called.
14451452 pub fn extract_callable_info(
14461453 &self,
1447 body_id: LocalDefId,
1454 body_def_id: LocalDefId,
14481455 param_env: ty::ParamEnv<'tcx>,
14491456 found: Ty<'tcx>,
14501457 ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
......@@ -1526,7 +1533,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15261533 }
15271534 }),
15281535 ty::Param(param) => {
1529 let generics = self.tcx.generics_of(body_id);
1536 let generics = self.tcx.generics_of(body_def_id);
15301537 let name = if generics.count() > param.index as usize
15311538 && let def = generics.param_at(param.index as usize, self.tcx)
15321539 && matches!(def.kind, ty::GenericParamDefKind::Type { .. })
......@@ -1597,7 +1604,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15971604 };
15981605 let (Some(typeck_results), Some(body)) = (
15991606 self.typeck_results.as_ref(),
1600 self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id),
1607 self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id),
16011608 ) else {
16021609 return true;
16031610 };
......@@ -1859,7 +1866,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18591866 // Issue #104961, we need to add parentheses properly for compound expressions
18601867 // for example, `x.starts_with("hi".to_string() + "you")`
18611868 // should be `x.starts_with(&("hi".to_string() + "you"))`
1862 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
1869 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) else {
18631870 return false;
18641871 };
18651872 let mut expr_finder = FindExprBySpan::new(span, self.tcx);
......@@ -2085,7 +2092,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20852092 span.remove_mark();
20862093 }
20872094 let mut expr_finder = super::FindExprBySpan::new(span, self.tcx);
2088 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
2095 let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) else {
20892096 return false;
20902097 };
20912098 expr_finder.visit_expr(body.value);
......@@ -2413,7 +2420,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24132420 span: Span,
24142421 trait_pred: ty::PolyTraitPredicate<'tcx>,
24152422 ) -> bool {
2416 let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id);
2423 let node = self.tcx.hir_node_by_def_id(obligation.cause.body_def_id);
24172424 if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn {sig, body: body_id, .. }, .. }) = node
24182425 && let hir::ExprKind::Block(blk, _) = &self.tcx.hir_body(*body_id).value.kind
24192426 && sig.decl.output.span().overlaps(span)
......@@ -2449,7 +2456,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24492456
24502457 pub(super) fn suggest_borrow_for_unsized_closure_return<G: EmissionGuarantee>(
24512458 &self,
2452 body_id: LocalDefId,
2459 body_def_id: LocalDefId,
24532460 err: &mut Diag<'_, G>,
24542461 predicate: ty::Predicate<'tcx>,
24552462 ) {
......@@ -2463,10 +2470,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24632470 let Some(span) = err.span.primary_span() else {
24642471 return;
24652472 };
2466 let Some(node_body_id) = self.tcx.hir_node_by_def_id(body_id).body_id() else {
2473 let Some(body_id) = self.tcx.hir_node_by_def_id(body_def_id).body_id() else {
24672474 return;
24682475 };
2469 let body = self.tcx.hir_body(node_body_id);
2476 let body = self.tcx.hir_body(body_id);
24702477 let mut expr_finder = FindExprBySpan::new(span, self.tcx);
24712478 expr_finder.visit_expr(body.value);
24722479 let Some(expr) = expr_finder.result else {
......@@ -2503,7 +2510,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25032510
25042511 pub(super) fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> {
25052512 let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig, .. }, .. }) =
2506 self.tcx.hir_node_by_def_id(obligation.cause.body_id)
2513 self.tcx.hir_node_by_def_id(obligation.cause.body_def_id)
25072514 else {
25082515 return None;
25092516 };
......@@ -2529,7 +2536,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25292536 if let Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig: fn_sig, .. }, .. })
25302537 | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(fn_sig, _), .. })
25312538 | Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(fn_sig, _), .. }) =
2532 self.tcx.hir_node_by_def_id(obligation.cause.body_id)
2539 self.tcx.hir_node_by_def_id(obligation.cause.body_def_id)
25332540 && let hir::FnRetTy::Return(ty) = fn_sig.decl.output
25342541 && let hir::TyKind::Path(qpath) = ty.kind
25352542 && let hir::QPath::Resolved(None, path) = qpath
......@@ -2559,8 +2566,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25592566
25602567 let mut span = obligation.cause.span;
25612568 let mut is_async_fn_return = false;
2562 if let DefKind::Closure = self.tcx.def_kind(obligation.cause.body_id)
2563 && let parent = self.tcx.local_parent(obligation.cause.body_id)
2569 if let DefKind::Closure = self.tcx.def_kind(obligation.cause.body_def_id)
2570 && let parent = self.tcx.local_parent(obligation.cause.body_def_id)
25642571 && let DefKind::Fn | DefKind::AssocFn = self.tcx.def_kind(parent)
25652572 && self.tcx.asyncness(parent).is_async()
25662573 && let Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig: fn_sig, .. }, .. })
......@@ -2577,11 +2584,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25772584 is_async_fn_return = true;
25782585 err.span(span);
25792586 }
2580 let body = self.tcx.hir_body_owned_by(obligation.cause.body_id);
2587 let body = self.tcx.hir_body_owned_by(obligation.cause.body_def_id);
25812588
25822589 if !is_async_fn_return
25832590 && let Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) =
2584 self.tcx.hir_node_by_def_id(obligation.cause.body_id)
2591 self.tcx.hir_node_by_def_id(obligation.cause.body_def_id)
25852592 && matches!(closure.fn_decl.output, hir::FnRetTy::DefaultReturn(_))
25862593 {
25872594 return true;
......@@ -3447,7 +3454,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34473454 // bound that introduced the obligation (e.g. `T: Send`).
34483455 debug!(?next_code);
34493456 self.note_obligation_cause_code(
3450 obligation.cause.body_id,
3457 obligation.cause.body_def_id,
34513458 err,
34523459 obligation.predicate,
34533460 obligation.param_env,
......@@ -3459,7 +3466,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34593466
34603467 pub(super) fn note_obligation_cause_code<G: EmissionGuarantee, T>(
34613468 &self,
3462 body_id: LocalDefId,
3469 body_def_id: LocalDefId,
34633470 err: &mut Diag<'_, G>,
34643471 predicate: T,
34653472 param_env: ty::ParamEnv<'tcx>,
......@@ -4125,7 +4132,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
41254132 // #74711: avoid a stack overflow
41264133 ensure_sufficient_stack(|| {
41274134 self.note_obligation_cause_code(
4128 body_id,
4135 body_def_id,
41294136 err,
41304137 parent_predicate,
41314138 param_env,
......@@ -4137,7 +4144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
41374144 } else {
41384145 ensure_sufficient_stack(|| {
41394146 self.note_obligation_cause_code(
4140 body_id,
4147 body_def_id,
41414148 err,
41424149 parent_predicate,
41434150 param_env,
......@@ -4167,7 +4174,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
41674174 // Skip PinDerefMutHelper in suggestions, but still show downstream suggestions.
41684175 ensure_sufficient_stack(|| {
41694176 self.note_obligation_cause_code(
4170 body_id,
4177 body_def_id,
41714178 err,
41724179 parent_predicate,
41734180 param_env,
......@@ -4321,7 +4328,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
43214328 // #74711: avoid a stack overflow
43224329 ensure_sufficient_stack(|| {
43234330 self.note_obligation_cause_code(
4324 body_id,
4331 body_def_id,
43254332 err,
43264333 parent_predicate,
43274334 param_env,
......@@ -4364,7 +4371,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
43644371 }
43654372 ensure_sufficient_stack(|| {
43664373 self.note_obligation_cause_code(
4367 body_id,
4374 body_def_id,
43684375 err,
43694376 data.derived.parent_host_pred,
43704377 param_env,
......@@ -4377,7 +4384,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
43774384 ObligationCauseCode::BuiltinDerivedHost(ref data) => {
43784385 ensure_sufficient_stack(|| {
43794386 self.note_obligation_cause_code(
4380 body_id,
4387 body_def_id,
43814388 err,
43824389 data.parent_host_pred,
43834390 param_env,
......@@ -4393,7 +4400,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
43934400 // #74711: avoid a stack overflow
43944401 ensure_sufficient_stack(|| {
43954402 self.note_obligation_cause_code(
4396 body_id,
4403 body_def_id,
43974404 err,
43984405 parent_predicate,
43994406 param_env,
......@@ -4407,7 +4414,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44074414 // #74711: avoid a stack overflow
44084415 ensure_sufficient_stack(|| {
44094416 self.note_obligation_cause_code(
4410 body_id,
4417 body_def_id,
44114418 err,
44124419 predicate,
44134420 param_env,
......@@ -4427,7 +4434,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44274434 arg_hir_id, call_hir_id, ref parent_code, ..
44284435 } => {
44294436 self.note_function_argument_obligation(
4430 body_id,
4437 body_def_id,
44314438 err,
44324439 arg_hir_id,
44334440 parent_code,
......@@ -4437,7 +4444,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44374444 );
44384445 ensure_sufficient_stack(|| {
44394446 self.note_obligation_cause_code(
4440 body_id,
4447 body_def_id,
44414448 err,
44424449 predicate,
44434450 param_env,
......@@ -4481,7 +4488,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44814488 let (expr_ty, expr) = if let Some((expr_ty, hir_id)) = expr_info {
44824489 let expr = tcx.hir_expect_expr(hir_id);
44834490 (expr_ty, expr)
4484 } else if let Some(body_id) = tcx.hir_node_by_def_id(body_id).body_id()
4491 } else if let Some(body_id) = tcx.hir_node_by_def_id(body_def_id).body_id()
44854492 && let body = tcx.hir_body(body_id)
44864493 && let hir::ExprKind::Block(block, _) = body.value.kind
44874494 && let Some(expr) = block.expr
......@@ -4579,7 +4586,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45794586 && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
45804587 && snippet.ends_with('?')
45814588 {
4582 match self.tcx.coroutine_kind(obligation.cause.body_id) {
4589 match self.tcx.coroutine_kind(obligation.cause.body_def_id) {
45834590 Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
45844591 err.span_suggestion_verbose(
45854592 span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(),
......@@ -4591,7 +4598,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45914598 _ => {
45924599 let mut span: MultiSpan = span.with_lo(span.hi() - BytePos(1)).into();
45934600 span.push_span_label(
4594 self.tcx.def_span(obligation.cause.body_id),
4601 self.tcx.def_span(obligation.cause.body_def_id),
45954602 "this is not `async`",
45964603 );
45974604 err.span_note(
......@@ -4732,7 +4739,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
47324739
47334740 fn note_function_argument_obligation<G: EmissionGuarantee>(
47344741 &self,
4735 body_id: LocalDefId,
4742 body_def_id: LocalDefId,
47364743 err: &mut Diag<'_, G>,
47374744 arg_hir_id: HirId,
47384745 parent_code: &ObligationCauseCode<'tcx>,
......@@ -4749,7 +4756,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
47494756 && let Some(failed_pred) = failed_pred.as_trait_clause()
47504757 && let pred = failed_pred.map_bound(|pred| pred.with_replaced_self_ty(tcx, ty))
47514758 && self.predicate_must_hold_modulo_regions(&Obligation::misc(
4752 tcx, expr.span, body_id, param_env, pred,
4759 tcx,
4760 expr.span,
4761 body_def_id,
4762 param_env,
4763 pred,
47534764 ))
47544765 && expr.span.hi() != rcvr.span.hi()
47554766 {
......@@ -4882,7 +4893,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
48824893 for (expected, actual) in zipped {
48834894 self.probe(|_| {
48844895 match self
4885 .at(&ObligationCause::misc(expr.span, body_id), param_env)
4896 .at(&ObligationCause::misc(expr.span, body_def_id), param_env)
48864897 // Doesn't actually matter if we define opaque types here, this is just used for
48874898 // diagnostics, and the result is never kept around.
48884899 .eq(DefineOpaqueTypes::Yes, expected, actual)
......@@ -5880,7 +5891,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
58805891 }
58815892 }
58825893
5883 let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id);
5894 let node = self.tcx.hir_node_by_def_id(obligation.cause.body_def_id);
58845895 if let Some((fn_decl, body_id)) = choose_suggest_items(self.tcx, node)
58855896 && let hir::FnRetTy::DefaultReturn(ret_span) = fn_decl.output
58865897 && self.tcx.is_diagnostic_item(sym::FromResidual, trait_pred.def_id())
compiler/rustc_trait_selection/src/regions.rs+7-7
......@@ -14,16 +14,16 @@ use crate::traits::outlives_bounds::InferCtxtExt;
1414impl<'tcx> OutlivesEnvironment<'tcx> {
1515 fn new(
1616 infcx: &InferCtxt<'tcx>,
17 body_id: LocalDefId,
17 body_def_id: LocalDefId,
1818 param_env: ty::ParamEnv<'tcx>,
1919 assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
2020 ) -> Self {
21 Self::new_with_implied_bounds_compat(infcx, body_id, param_env, assumed_wf_tys, false)
21 Self::new_with_implied_bounds_compat(infcx, body_def_id, param_env, assumed_wf_tys, false)
2222 }
2323
2424 fn new_with_implied_bounds_compat(
2525 infcx: &InferCtxt<'tcx>,
26 body_id: LocalDefId,
26 body_def_id: LocalDefId,
2727 param_env: ty::ParamEnv<'tcx>,
2828 assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
2929 disable_implied_bounds_hack: bool,
......@@ -60,7 +60,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
6060 param_env,
6161 bounds,
6262 infcx.implied_bounds_tys(
63 body_id,
63 body_def_id,
6464 param_env,
6565 assumed_wf_tys,
6666 disable_implied_bounds_hack,
......@@ -82,13 +82,13 @@ impl<'tcx> InferCtxt<'tcx> {
8282 /// This function assumes that all infer variables are already constrained.
8383 fn resolve_regions(
8484 &self,
85 body_id: LocalDefId,
85 body_def_id: LocalDefId,
8686 param_env: ty::ParamEnv<'tcx>,
8787 assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
8888 ) -> Vec<RegionResolutionError<'tcx>> {
8989 self.resolve_regions_with_outlives_env(
90 &OutlivesEnvironment::new(self, body_id, param_env, assumed_wf_tys),
91 self.tcx.def_span(body_id),
90 &OutlivesEnvironment::new(self, body_def_id, param_env, assumed_wf_tys),
91 self.tcx.def_span(body_def_id),
9292 )
9393 }
9494
compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs+4-3
......@@ -258,10 +258,11 @@ impl<'tcx> BestObligation<'tcx> {
258258 ) -> ControlFlow<PredicateObligation<'tcx>> {
259259 let infcx = candidate.goal().infcx();
260260 let param_env = candidate.goal().goal().param_env;
261 let body_id = self.obligation.cause.body_id;
261 let body_def_id = self.obligation.cause.body_def_id;
262262
263 for obligation in wf::unnormalized_obligations(infcx, param_env, term, self.span(), body_id)
264 .into_flat_iter()
263 for obligation in
264 wf::unnormalized_obligations(infcx, param_env, term, self.span(), body_def_id)
265 .into_flat_iter()
265266 {
266267 let nested_goal = candidate.instantiate_proof_tree_for_nested_goal(
267268 GoalSource::Misc,
compiler/rustc_trait_selection/src/traits/effects.rs+1-1
......@@ -574,7 +574,7 @@ fn evaluate_host_effect_for_fn_goal<'tcx>(
574574 .map(|(c, span)| {
575575 let code = ObligationCauseCode::WhereClause(def, span);
576576 let cause =
577 ObligationCause::new(obligation.cause.span, obligation.cause.body_id, code);
577 ObligationCause::new(obligation.cause.span, obligation.cause.body_def_id, code);
578578 Obligation::new(
579579 tcx,
580580 cause,
compiler/rustc_trait_selection/src/traits/engine.rs+5-5
......@@ -246,15 +246,15 @@ where
246246 /// will result in region constraints getting ignored.
247247 pub fn resolve_regions_and_report_errors(
248248 self,
249 body_id: LocalDefId,
249 body_def_id: LocalDefId,
250250 param_env: ty::ParamEnv<'tcx>,
251251 assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
252252 ) -> Result<(), ErrorGuaranteed> {
253 let errors = self.infcx.resolve_regions(body_id, param_env, assumed_wf_tys);
253 let errors = self.infcx.resolve_regions(body_def_id, param_env, assumed_wf_tys);
254254 if errors.is_empty() {
255255 Ok(())
256256 } else {
257 Err(self.infcx.err_ctxt().report_region_errors(body_id, &errors))
257 Err(self.infcx.err_ctxt().report_region_errors(body_def_id, &errors))
258258 }
259259 }
260260
......@@ -265,11 +265,11 @@ where
265265 #[must_use]
266266 pub fn resolve_regions(
267267 self,
268 body_id: LocalDefId,
268 body_def_id: LocalDefId,
269269 param_env: ty::ParamEnv<'tcx>,
270270 assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
271271 ) -> Vec<RegionResolutionError<'tcx>> {
272 self.infcx.resolve_regions(body_id, param_env, assumed_wf_tys)
272 self.infcx.resolve_regions(body_def_id, param_env, assumed_wf_tys)
273273 }
274274}
275275
compiler/rustc_trait_selection/src/traits/fulfill.rs+1-1
......@@ -611,7 +611,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
611611 match wf::obligations(
612612 self.selcx.infcx,
613613 obligation.param_env,
614 obligation.cause.body_id,
614 obligation.cause.body_def_id,
615615 obligation.recursion_depth + 1,
616616 term,
617617 obligation.cause.span,
compiler/rustc_trait_selection/src/traits/misc.rs+2-2
......@@ -190,7 +190,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
190190 }
191191
192192 // Check regions assuming the self type of the impl is WF
193 let errors = infcx.resolve_regions(parent_cause.body_id, param_env, [self_type]);
193 let errors = infcx.resolve_regions(parent_cause.body_def_id, param_env, [self_type]);
194194 if !errors.is_empty() {
195195 infringing_inner_tys.push((inner_ty, InfringingFieldsReason::Regions(errors)));
196196 continue;
......@@ -279,7 +279,7 @@ pub fn all_fields_implement_trait<'tcx>(
279279 }
280280
281281 // Check regions assuming the self type of the impl is WF
282 let errors = infcx.resolve_regions(parent_cause.body_id, param_env, [self_type]);
282 let errors = infcx.resolve_regions(parent_cause.body_def_id, param_env, [self_type]);
283283 if !errors.is_empty() {
284284 infringing.push((field, ty, InfringingFieldsReason::Regions(errors)));
285285 }
compiler/rustc_trait_selection/src/traits/mod.rs+1-1
......@@ -300,7 +300,7 @@ fn do_normalize_predicates<'tcx>(
300300 //
301301 // This is required by trait-system-refactor-initiative#166. The new solver encounters
302302 // this more frequently as we entirely ignore outlives predicates with the old solver.
303 let _errors = infcx.resolve_regions(cause.body_id, elaborated_env, []);
303 let _errors = infcx.resolve_regions(cause.body_def_id, elaborated_env, []);
304304 match infcx.fully_resolve(predicates) {
305305 Ok(predicates) => Ok(predicates),
306306 Err(fixup_err) => {
compiler/rustc_trait_selection/src/traits/outlives_bounds.rs+7-7
......@@ -27,15 +27,15 @@ use crate::traits::ObligationCause;
2727/// # Parameters
2828///
2929/// - `param_env`, the where-clauses in scope
30/// - `body_id`, the body-id to use when normalizing assoc types.
30/// - `body_def_id`, the body_def_id to use when normalizing assoc types.
3131/// Note that this may cause outlives obligations to be injected
3232/// into the inference context with this body-id.
3333/// - `ty`, the type that we are supposed to assume is WF.
34#[instrument(level = "debug", skip(infcx, param_env, body_id), ret)]
34#[instrument(level = "debug", skip(infcx, param_env, body_def_id), ret)]
3535fn implied_outlives_bounds<'a, 'tcx>(
3636 infcx: &'a InferCtxt<'tcx>,
3737 param_env: ty::ParamEnv<'tcx>,
38 body_id: LocalDefId,
38 body_def_id: LocalDefId,
3939 ty: Ty<'tcx>,
4040 disable_implied_bounds_hack: bool,
4141) -> Vec<OutlivesBound<'tcx>> {
......@@ -60,7 +60,7 @@ fn implied_outlives_bounds<'a, 'tcx>(
6060 };
6161
6262 let mut constraints = QueryRegionConstraints::default();
63 let span = infcx.tcx.def_span(body_id);
63 let span = infcx.tcx.def_span(body_def_id);
6464 let Ok(InferOk { value: mut bounds, obligations }) = infcx
6565 .instantiate_nll_query_response_and_region_obligations(
6666 &ObligationCause::dummy_with_span(span),
......@@ -83,7 +83,7 @@ fn implied_outlives_bounds<'a, 'tcx>(
8383 // We otherwise would get spurious errors if normalizing an implied
8484 // outlives bound required proving some higher-ranked coroutine obl.
8585 let QueryRegionConstraints { constraints, assumptions: _ } = constraints;
86 let cause = ObligationCause::misc(span, body_id);
86 let cause = ObligationCause::misc(span, body_def_id);
8787 for &QueryRegionConstraint { constraint, visible_for_leak_check: vis, .. } in &constraints {
8888 match constraint {
8989 ty::RegionConstraint::Outlives(predicate) => {
......@@ -105,13 +105,13 @@ impl<'tcx> InferCtxt<'tcx> {
105105 /// instead if you're interested in the implied bounds for a given signature.
106106 fn implied_bounds_tys<Tys: IntoIterator<Item = Ty<'tcx>>>(
107107 &self,
108 body_id: LocalDefId,
108 body_def_id: LocalDefId,
109109 param_env: ParamEnv<'tcx>,
110110 tys: Tys,
111111 disable_implied_bounds_hack: bool,
112112 ) -> impl Iterator<Item = OutlivesBound<'tcx>> {
113113 tys.into_iter().flat_map(move |ty| {
114 implied_outlives_bounds(self, param_env, body_id, ty, disable_implied_bounds_hack)
114 implied_outlives_bounds(self, param_env, body_def_id, ty, disable_implied_bounds_hack)
115115 })
116116 }
117117}
compiler/rustc_trait_selection/src/traits/project.rs+3-3
......@@ -230,7 +230,7 @@ fn project_and_unify_term<'cx, 'tcx>(
230230 let InferOk { value: actual, obligations: new } =
231231 selcx.infcx.replace_opaque_types_with_inference_vars(
232232 actual,
233 obligation.cause.body_id,
233 obligation.cause.body_def_id,
234234 obligation.cause.span,
235235 obligation.param_env,
236236 );
......@@ -557,7 +557,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
557557
558558 let nested_cause = ObligationCause::new(
559559 cause.span,
560 cause.body_id,
560 cause.body_def_id,
561561 // FIXME(inherent_associated_types): Since we can't pass along the self type to the
562562 // cause code, inherent projections will be printed with identity instantiation in
563563 // diagnostics which is not ideal.
......@@ -2149,7 +2149,7 @@ fn assoc_term_own_obligations<'cx, 'tcx>(
21492149 } else {
21502150 ObligationCause::new(
21512151 obligation.cause.span,
2152 obligation.cause.body_id,
2152 obligation.cause.body_def_id,
21532153 ObligationCauseCode::WhereClause(def_id, span),
21542154 )
21552155 };
compiler/rustc_trait_selection/src/traits/select/mod.rs+2-2
......@@ -727,7 +727,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
727727 match wf::obligations(
728728 self.infcx,
729729 obligation.param_env,
730 obligation.cause.body_id,
730 obligation.cause.body_def_id,
731731 obligation.recursion_depth + 1,
732732 term,
733733 obligation.cause.span,
......@@ -2557,7 +2557,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25572557
25582558 let cause = ObligationCause::new(
25592559 obligation.cause.span,
2560 obligation.cause.body_id,
2560 obligation.cause.body_def_id,
25612561 ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id),
25622562 );
25632563
compiler/rustc_trait_selection/src/traits/wf.rs+13-13
......@@ -30,7 +30,7 @@ use crate::traits;
3030pub fn obligations<'tcx>(
3131 infcx: &InferCtxt<'tcx>,
3232 param_env: ty::ParamEnv<'tcx>,
33 body_id: LocalDefId,
33 body_def_id: LocalDefId,
3434 recursion_depth: usize,
3535 term: Term<'tcx>,
3636 span: Span,
......@@ -72,17 +72,17 @@ pub fn obligations<'tcx>(
7272 let mut wf = WfPredicates {
7373 infcx,
7474 param_env,
75 body_id,
75 body_def_id,
7676 span,
7777 out: PredicateObligations::new(),
7878 recursion_depth,
7979 item: None,
8080 };
8181 wf.add_wf_preds_for_term(term);
82 debug!("wf::obligations({:?}, body_id={:?}) = {:?}", term, body_id, wf.out);
82 debug!("wf::obligations({:?}, body_def_id={:?}) = {:?}", term, body_def_id, wf.out);
8383
8484 let result = wf.normalize(infcx);
85 debug!("wf::obligations({:?}, body_id={:?}) ~~> {:?}", term, body_id, result);
85 debug!("wf::obligations({:?}, body_def_id={:?}) ~~> {:?}", term, body_def_id, result);
8686 Some(result)
8787}
8888
......@@ -95,7 +95,7 @@ pub fn unnormalized_obligations<'tcx>(
9595 param_env: ty::ParamEnv<'tcx>,
9696 term: Term<'tcx>,
9797 span: Span,
98 body_id: LocalDefId,
98 body_def_id: LocalDefId,
9999) -> Option<PredicateObligations<'tcx>> {
100100 debug_assert_eq!(term, infcx.resolve_vars_if_possible(term));
101101
......@@ -109,7 +109,7 @@ pub fn unnormalized_obligations<'tcx>(
109109 let mut wf = WfPredicates {
110110 infcx,
111111 param_env,
112 body_id,
112 body_def_id,
113113 span,
114114 out: PredicateObligations::new(),
115115 recursion_depth: 0,
......@@ -126,7 +126,7 @@ pub fn unnormalized_obligations<'tcx>(
126126pub fn trait_obligations<'tcx>(
127127 infcx: &InferCtxt<'tcx>,
128128 param_env: ty::ParamEnv<'tcx>,
129 body_id: LocalDefId,
129 body_def_id: LocalDefId,
130130 trait_pred: ty::TraitPredicate<'tcx>,
131131 span: Span,
132132 item: &'tcx hir::Item<'tcx>,
......@@ -134,7 +134,7 @@ pub fn trait_obligations<'tcx>(
134134 let mut wf = WfPredicates {
135135 infcx,
136136 param_env,
137 body_id,
137 body_def_id,
138138 span,
139139 out: PredicateObligations::new(),
140140 recursion_depth: 0,
......@@ -154,14 +154,14 @@ pub fn trait_obligations<'tcx>(
154154pub fn clause_obligations<'tcx>(
155155 infcx: &InferCtxt<'tcx>,
156156 param_env: ty::ParamEnv<'tcx>,
157 body_id: LocalDefId,
157 body_def_id: LocalDefId,
158158 clause: ty::Clause<'tcx>,
159159 span: Span,
160160) -> PredicateObligations<'tcx> {
161161 let mut wf = WfPredicates {
162162 infcx,
163163 param_env,
164 body_id,
164 body_def_id,
165165 span,
166166 out: PredicateObligations::new(),
167167 recursion_depth: 0,
......@@ -205,7 +205,7 @@ pub fn clause_obligations<'tcx>(
205205struct WfPredicates<'a, 'tcx> {
206206 infcx: &'a InferCtxt<'tcx>,
207207 param_env: ty::ParamEnv<'tcx>,
208 body_id: LocalDefId,
208 body_def_id: LocalDefId,
209209 span: Span,
210210 out: PredicateObligations<'tcx>,
211211 recursion_depth: usize,
......@@ -334,7 +334,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
334334 }
335335
336336 fn cause(&self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> {
337 traits::ObligationCause::new(self.span, self.body_id, code)
337 traits::ObligationCause::new(self.span, self.body_def_id, code)
338338 }
339339
340340 fn normalize(self, infcx: &InferCtxt<'tcx>) -> PredicateObligations<'tcx> {
......@@ -423,7 +423,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
423423 .filter_map(|(i, arg)| arg.as_term().map(|t| (i, t)))
424424 .filter(|(_, term)| !term.has_escaping_bound_vars())
425425 .map(|(i, term)| {
426 let mut cause = traits::ObligationCause::misc(self.span, self.body_id);
426 let mut cause = traits::ObligationCause::misc(self.span, self.body_def_id);
427427 // The first arg is the self ty - use the correct span for it.
428428 if i == 0 {
429429 if let Some(hir::ItemKind::Impl(hir::Impl { self_ty, .. })) =
compiler/rustc_ty_utils/src/ty.rs+2-3
......@@ -196,12 +196,11 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
196196 ));
197197 }
198198
199 let local_did = def_id.as_local();
199 let local_did = def_id.as_local().unwrap_or(CRATE_DEF_ID);
200200
201201 let unnormalized_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates));
202202
203 let body_id = local_did.unwrap_or(CRATE_DEF_ID);
204 let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
203 let cause = traits::ObligationCause::misc(tcx.def_span(def_id), local_did);
205204 traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
206205}
207206
src/ci/docker/host-x86_64/armhf-gnu/Dockerfile+2-2
......@@ -47,7 +47,7 @@ RUN curl https://ci-mirrors.rust-lang.org/rustc/linux-4.14.336.tar.gz | \
4747# Compile an instance of busybox as this provides a lightweight system and init
4848# binary which we will boot into. Only trick here is configuring busybox to
4949# build static binaries.
50RUN curl https://www.busybox.net/downloads/busybox-1.32.1.tar.bz2 | tar xjf - && \
50RUN curl https://ci-mirrors.rust-lang.org/rustc/busybox/busybox-1.32.1.tar.bz2 | tar xjf - && \
5151 cd busybox-1.32.1 && \
5252 make defconfig && \
5353 sed -i 's/.*CONFIG_STATIC.*/CONFIG_STATIC=y/' .config && \
......@@ -60,7 +60,7 @@ RUN curl https://www.busybox.net/downloads/busybox-1.32.1.tar.bz2 | tar xjf - &&
6060# Download the ubuntu rootfs, which we'll use as a chroot for all our tests.
6161WORKDIR /tmp
6262RUN mkdir rootfs/ubuntu
63RUN curl https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04.2-base-armhf.tar.gz | \
63RUN curl https://ci-mirrors.rust-lang.org/rustc/ubuntu/ubuntu-base-22.04.2-base-armhf.tar.gz | \
6464 tar xzf - -C rootfs/ubuntu && \
6565 cd rootfs && mkdir proc sys dev etc etc/init.d
6666
tests/assembly-llvm/x86_64-windows-float-abi.rs+9-2
......@@ -3,6 +3,9 @@
33//@ compile-flags: --target x86_64-pc-windows-msvc
44//@ needs-llvm-components: x86
55//@ add-minicore
6//@ revisions: LLVM22 LLVM23
7//@ [LLVM22] max-llvm-major-version: 22
8//@ [LLVM23] min-llvm-version: 23
69
710#![feature(f16, f128)]
811#![feature(no_core)]
......@@ -37,8 +40,12 @@ pub extern "C" fn second_f64(_: f64, x: f64) -> f64 {
3740}
3841
3942// CHECK-LABEL: second_f128
40// CHECK: movaps (%rdx), %xmm0
41// CHECK-NEXT: retq
43// LLVM22: movaps (%rdx), %xmm0
44// LLVM22-NEXT: retq
45// LLVM23: movq %rcx, %rax
46// LLVM23-NEXT: movaps (%r8), %xmm0
47// LLVM23-NEXT: movaps %xmm0, (%rcx)
48// LLVM23-NEXT: retq
4249#[no_mangle]
4350pub extern "C" fn second_f128(_: f128, x: f128) -> f128 {
4451 x
tests/run-make/autodiff/type-trees/iter/rmake.rs created+25
......@@ -0,0 +1,25 @@
1//@ needs-enzyme
2//@ ignore-cross-compile
3
4use run_make_support::{llvm_filecheck, rfs, rustc};
5
6// This test passes in release mode. If we run it in Debug mode and don't lower any MIR info to
7// LLVM TypeTrees, then it fails on deducing the type of a memcpy. If we lower info it still fails,
8// but at a later location based on an extractvalue call. We will fix this in a future PR.
9
10fn main() {
11 rustc()
12 .input("window.rs")
13 .arg("-Zautodiff=Enable,NoTT")
14 .arg("-Clto=fat")
15 .run_fail()
16 .assert_stderr_contains("Enzyme: Cannot deduce type of copy");
17 rustc()
18 .input("window.rs")
19 .arg("-Zautodiff=Enable")
20 .arg("-Clto=fat")
21 .emit("llvm-ir")
22 .run_fail()
23 .assert_stderr_contains("Enzyme: Cannot deduce type of extract");
24 rustc().input("window.rs").arg("-Zautodiff=Enable,NoTT").arg("-Clto=fat").arg("-O").run();
25}
tests/run-make/autodiff/type-trees/iter/window.rs created+53
......@@ -0,0 +1,53 @@
1#![feature(autodiff)]
2
3use std::autodiff::autodiff_reverse;
4
5// This tests verifies that Enzyme can differentiate the iterator and window version of the for
6// loops given below. Iterators (especially the windows use here) cause a lot of extra abstractions
7// and indirections. Without extra typetree hints, Enzyme failed to differentiate them in debug
8// mode.
9
10//@revisions: tt no_tt
11//@[tt] compile-flags: -Z autodiff=Enable
12//@[no_tt] compile-flags: -Z autodiff=Enable,NoTT
13//@[no_tt] build-fail
14
15#[unsafe(no_mangle)]
16#[inline(never)]
17#[autodiff_reverse(f_rev, 2, Duplicated, Const, Duplicated)]
18fn f(x: &[f64; 3], args: &[f64; 3], y: &mut [f64; 2]) {
19 y[0] = x.iter().map(|i| args[0] * i.powi(2)).sum();
20 y[1] = x
21 .windows(2)
22 .map(|w| (args[1] - w[0]).powi(2) + args[2] * (w[1] - w[0].powi(2)).powi(2))
23 .sum();
24 // The iterators above are equivalent to the two following for loops.
25 // for i in 0..3 {
26 // y[0] += args[0] * x[i].powi(2);
27 // }
28 // for i in 0..2 {
29 // y[1] += (args[1] - x[i]).powi(2) + args[2] * (x[i + 1] - x[i].powi(2)).powi(2);
30 // }
31}
32
33// Not generally recommended, but since we rewrite llvm-ir, it should be good enough.
34fn assert_abs_diff_eq<const N: usize>(x: &[f64; N], y: &[f64; N]) {
35 for i in 0..N {
36 assert_eq!(x[i], y[i]);
37 }
38}
39
40fn main() {
41 let x = [3.0, 5.0, 7.0];
42 let args = [2.0, 1.0, 100.0];
43
44 let mut vjp = ([0.0; 3], [0.0; 3]);
45 let mut y = [0.0; 2];
46 let mut dy = ([1.0, 0.0], [0.0, 1.0]);
47
48 f_rev(&x, &mut vjp.0, &mut vjp.1, &args, &mut y, &mut dy.0, &mut dy.1);
49
50 assert_abs_diff_eq::<2>(&y, &[166.0, 34020.0]);
51 assert_abs_diff_eq::<3>(&vjp.0, &[12.0, 20.0, 28.0]);
52 assert_abs_diff_eq::<3>(&vjp.1, &[4804.0, 35208.0, -3600.0]);
53}
tests/ui/associated-consts/associated-const-type-parameter-arrays.stderr+1
......@@ -6,6 +6,7 @@ LL | let _array: [u32; <A as Foo>::Y];
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/associated-consts/issue-47814.stderr+2
......@@ -9,6 +9,8 @@ note: not a concrete type
99 |
1010LL | impl<'a> ArpIPv4<'a> {
1111 | ^^^^^^^^^^^
12 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
13 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1214
1315error: aborting due to 1 previous error
1416
tests/ui/associated-item/associated-item-duplicate-bounds.stderr+1
......@@ -6,6 +6,7 @@ LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr+2
......@@ -6,6 +6,7 @@ LL | let x: &'b ();
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/index-oob-ice-83993.rs:18:17
......@@ -15,6 +16,7 @@ LL | let _: &'b ();
1516 |
1617 = note: lifetime parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: aborting due to 2 previous errors
2022
tests/ui/const-generics/const-arg-in-const-arg.min.stderr+23
......@@ -6,6 +6,7 @@ LL | let _: [u8; foo::<T>()];
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/const-arg-in-const-arg.rs:16:23
......@@ -15,6 +16,7 @@ LL | let _: [u8; bar::<N>()];
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: generic parameters may not be used in const operations
2022 --> $DIR/const-arg-in-const-arg.rs:18:23
......@@ -24,6 +26,7 @@ LL | let _: [u8; faz::<'a>(&())];
2426 |
2527 = note: lifetime parameters may not be used in const expressions
2628 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
29 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2730
2831error: generic parameters may not be used in const operations
2932 --> $DIR/const-arg-in-const-arg.rs:20:23
......@@ -33,6 +36,7 @@ LL | let _: [u8; baz::<'a>(&())];
3336 |
3437 = note: lifetime parameters may not be used in const expressions
3538 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
39 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3640
3741error: generic parameters may not be used in const operations
3842 --> $DIR/const-arg-in-const-arg.rs:21:23
......@@ -42,6 +46,7 @@ LL | let _: [u8; faz::<'b>(&())];
4246 |
4347 = note: lifetime parameters may not be used in const expressions
4448 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
49 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
4550
4651error: generic parameters may not be used in const operations
4752 --> $DIR/const-arg-in-const-arg.rs:23:23
......@@ -51,6 +56,7 @@ LL | let _: [u8; baz::<'b>(&())];
5156 |
5257 = note: lifetime parameters may not be used in const expressions
5358 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
59 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
5460
5561error: generic parameters may not be used in const operations
5662 --> $DIR/const-arg-in-const-arg.rs:27:23
......@@ -60,6 +66,7 @@ LL | let _ = [0; bar::<N>()];
6066 |
6167 = help: const parameters may only be used as standalone arguments here, i.e. `N`
6268 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
69 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
6370
6471error: generic parameters may not be used in const operations
6572 --> $DIR/const-arg-in-const-arg.rs:29:23
......@@ -69,6 +76,7 @@ LL | let _ = [0; faz::<'a>(&())];
6976 |
7077 = note: lifetime parameters may not be used in const expressions
7178 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
79 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
7280
7381error: generic parameters may not be used in const operations
7482 --> $DIR/const-arg-in-const-arg.rs:31:23
......@@ -78,6 +86,7 @@ LL | let _ = [0; baz::<'a>(&())];
7886 |
7987 = note: lifetime parameters may not be used in const expressions
8088 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
89 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
8190
8291error: generic parameters may not be used in const operations
8392 --> $DIR/const-arg-in-const-arg.rs:32:23
......@@ -87,6 +96,7 @@ LL | let _ = [0; faz::<'b>(&())];
8796 |
8897 = note: lifetime parameters may not be used in const expressions
8998 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
99 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
90100
91101error: generic parameters may not be used in const operations
92102 --> $DIR/const-arg-in-const-arg.rs:34:23
......@@ -96,6 +106,7 @@ LL | let _ = [0; baz::<'b>(&())];
96106 |
97107 = note: lifetime parameters may not be used in const expressions
98108 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
109 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
99110
100111error: generic parameters may not be used in const operations
101112 --> $DIR/const-arg-in-const-arg.rs:35:24
......@@ -105,6 +116,7 @@ LL | let _: Foo<{ foo::<T>() }>;
105116 |
106117 = note: type parameters may not be used in const expressions
107118 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
119 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
108120
109121error: generic parameters may not be used in const operations
110122 --> $DIR/const-arg-in-const-arg.rs:36:24
......@@ -114,6 +126,7 @@ LL | let _: Foo<{ bar::<N>() }>;
114126 |
115127 = help: const parameters may only be used as standalone arguments here, i.e. `N`
116128 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
129 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
117130
118131error: generic parameters may not be used in const operations
119132 --> $DIR/const-arg-in-const-arg.rs:38:24
......@@ -123,6 +136,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>;
123136 |
124137 = note: lifetime parameters may not be used in const expressions
125138 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
139 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
126140
127141error: generic parameters may not be used in const operations
128142 --> $DIR/const-arg-in-const-arg.rs:40:24
......@@ -132,6 +146,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>;
132146 |
133147 = note: lifetime parameters may not be used in const expressions
134148 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
149 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
135150
136151error: generic parameters may not be used in const operations
137152 --> $DIR/const-arg-in-const-arg.rs:41:24
......@@ -141,6 +156,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>;
141156 |
142157 = note: lifetime parameters may not be used in const expressions
143158 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
159 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
144160
145161error: generic parameters may not be used in const operations
146162 --> $DIR/const-arg-in-const-arg.rs:43:24
......@@ -150,6 +166,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>;
150166 |
151167 = note: lifetime parameters may not be used in const expressions
152168 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
169 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
153170
154171error: generic parameters may not be used in const operations
155172 --> $DIR/const-arg-in-const-arg.rs:44:27
......@@ -159,6 +176,7 @@ LL | let _ = Foo::<{ foo::<T>() }>;
159176 |
160177 = note: type parameters may not be used in const expressions
161178 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
179 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
162180
163181error: generic parameters may not be used in const operations
164182 --> $DIR/const-arg-in-const-arg.rs:45:27
......@@ -168,6 +186,7 @@ LL | let _ = Foo::<{ bar::<N>() }>;
168186 |
169187 = help: const parameters may only be used as standalone arguments here, i.e. `N`
170188 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
189 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
171190
172191error: generic parameters may not be used in const operations
173192 --> $DIR/const-arg-in-const-arg.rs:47:27
......@@ -177,6 +196,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>;
177196 |
178197 = note: lifetime parameters may not be used in const expressions
179198 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
199 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
180200
181201error: generic parameters may not be used in const operations
182202 --> $DIR/const-arg-in-const-arg.rs:49:27
......@@ -186,6 +206,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>;
186206 |
187207 = note: lifetime parameters may not be used in const expressions
188208 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
209 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
189210
190211error: generic parameters may not be used in const operations
191212 --> $DIR/const-arg-in-const-arg.rs:50:27
......@@ -195,6 +216,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>;
195216 |
196217 = note: lifetime parameters may not be used in const expressions
197218 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
219 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
198220
199221error: generic parameters may not be used in const operations
200222 --> $DIR/const-arg-in-const-arg.rs:52:27
......@@ -204,6 +226,7 @@ LL | let _ = Foo::<{ baz::<'b>(&()) }>;
204226 |
205227 = note: lifetime parameters may not be used in const expressions
206228 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
229 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
207230
208231error[E0747]: unresolved item provided when a constant was expected
209232 --> $DIR/const-arg-in-const-arg.rs:16:23
tests/ui/const-generics/const-argument-if-length.min.stderr+1
......@@ -6,6 +6,7 @@ LL | pad: [u8; is_zst::<T>()],
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0277]: the size for values of type `T` cannot be known at compilation time
1112 --> $DIR/const-argument-if-length.rs:16:12
tests/ui/const-generics/const-argument-non-static-lifetime.min.stderr+1
......@@ -6,6 +6,7 @@ LL | let _: &'a ();
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/defaults/complex-generic-default-expr.min.stderr+2
......@@ -6,6 +6,7 @@ LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/complex-generic-default-expr.rs:9:62
......@@ -15,6 +16,7 @@ LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
1516 |
1617 = note: type parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: aborting due to 2 previous errors
2022
tests/ui/const-generics/early/const_arg_trivial_macro_expansion-4.stderr+3
......@@ -9,6 +9,7 @@ LL | fn foo<const N: usize>() -> Foo<{ arg!{} arg!{} }> { loop {} }
99 |
1010 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1111 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
12 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1213 = note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info)
1314
1415error: generic parameters may not be used in const operations
......@@ -22,6 +23,7 @@ LL | fn foo<const N: usize>() -> Foo<{ arg!{} arg!{} }> { loop {} }
2223 |
2324 = help: const parameters may only be used as standalone arguments here, i.e. `N`
2425 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
26 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2527 = note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info)
2628
2729error: generic parameters may not be used in const operations
......@@ -32,6 +34,7 @@ LL | fn bar<const N: usize>() -> [(); { empty!{}; N }] { loop {} }
3234 |
3335 = help: const parameters may only be used as standalone arguments here, i.e. `N`
3436 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
37 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3538
3639error: aborting due to 3 previous errors
3740
tests/ui/const-generics/early/macro_rules-braces.stderr+4
......@@ -28,6 +28,7 @@ LL | let _: foo!({{ N }});
2828 |
2929 = help: const parameters may only be used as standalone arguments here, i.e. `N`
3030 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
31 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3132
3233error: generic parameters may not be used in const operations
3334 --> $DIR/macro_rules-braces.rs:36:19
......@@ -37,6 +38,7 @@ LL | let _: bar!({ N });
3738 |
3839 = help: const parameters may only be used as standalone arguments here, i.e. `N`
3940 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
41 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
4042
4143error: generic parameters may not be used in const operations
4244 --> $DIR/macro_rules-braces.rs:41:20
......@@ -46,6 +48,7 @@ LL | let _: baz!({{ N }});
4648 |
4749 = help: const parameters may only be used as standalone arguments here, i.e. `N`
4850 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
51 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
4952
5053error: generic parameters may not be used in const operations
5154 --> $DIR/macro_rules-braces.rs:46:19
......@@ -55,6 +58,7 @@ LL | let _: biz!({ N });
5558 |
5659 = help: const parameters may only be used as standalone arguments here, i.e. `N`
5760 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
61 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
5862
5963error: aborting due to 6 previous errors
6064
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.stderr+1
......@@ -9,6 +9,7 @@ LL | fn foo<const N: usize>() -> A<{{ y!() }}> {
99 |
1010 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1111 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
12 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1213 = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
1314
1415error: aborting due to 1 previous error
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.stderr+1
......@@ -9,6 +9,7 @@ LL | fn foo<const N: usize>() -> A<{ y!() }> {
99 |
1010 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1111 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
12 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1213 = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
1314
1415error: aborting due to 1 previous error
tests/ui/const-generics/early/trivial-const-arg-nested-braces.stderr+1
......@@ -6,6 +6,7 @@ LL | fn foo<const N: usize>() -> A<{ { N } }> {
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs created+26
......@@ -0,0 +1,26 @@
1// Regression test for https://github.com/rust-lang/rust/issues/156729
2//
3// When a generic parameter is used in a const operation, the diagnostic should
4// suggest creating a `type const` item as an alternative to `generic_const_exprs`.
5
6use std::mem::size_of;
7
8// Exact case from the issue: `Self` in a trait method.
9pub unsafe trait TrivialType: Copy {
10 fn as_bytes(&self) -> &[u8; size_of::<Self>()] {
11 //~^ ERROR generic parameters may not be used in const operations
12 todo!()
13 }
14}
15
16fn foo<T>() -> [u8; size_of::<T>()] {
17 //~^ ERROR generic parameters may not be used in const operations
18 todo!()
19}
20
21fn bar<const N: usize>() -> [u8; N + 1] {
22 //~^ ERROR generic parameters may not be used in const operations
23 todo!()
24}
25
26fn main() {}
tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.stderr created+32
......@@ -0,0 +1,32 @@
1error: generic parameters may not be used in const operations
2 --> $DIR/suggest-const-item-for-generic-expr.rs:10:43
3 |
4LL | fn as_bytes(&self) -> &[u8; size_of::<Self>()] {
5 | ^^^^ cannot perform const operation using `Self`
6 |
7 = note: type parameters may not be used in const expressions
8 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
10
11error: generic parameters may not be used in const operations
12 --> $DIR/suggest-const-item-for-generic-expr.rs:16:31
13 |
14LL | fn foo<T>() -> [u8; size_of::<T>()] {
15 | ^ cannot perform const operation using `T`
16 |
17 = note: type parameters may not be used in const expressions
18 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
20
21error: generic parameters may not be used in const operations
22 --> $DIR/suggest-const-item-for-generic-expr.rs:21:34
23 |
24LL | fn bar<const N: usize>() -> [u8; N + 1] {
25 | ^ cannot perform const operation using `N`
26 |
27 = help: const parameters may only be used as standalone arguments here, i.e. `N`
28 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
29 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
30
31error: aborting due to 3 previous errors
32
tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr+2
......@@ -6,6 +6,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/array-size-in-generic-struct-param.rs:23:15
......@@ -15,6 +16,7 @@ LL | arr: [u8; CFG.arr_size],
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `CFG`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: `Config` is forbidden as the type of a const generic parameter
2022 --> $DIR/array-size-in-generic-struct-param.rs:21:21
tests/ui/const-generics/generic_const_exprs/bad-multiply.stderr+1
......@@ -6,6 +6,7 @@ LL | SmallVec<{ D * 2 }>:,
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `D`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0747]: constant provided when a type was expected
1112 --> $DIR/bad-multiply.rs:7:14
tests/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr+2
......@@ -6,6 +6,7 @@ LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/dependence_lint.rs:22:37
......@@ -15,6 +16,7 @@ LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable,
1516 |
1617 = note: type parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921warning: cannot use constants which depend on generic parameters in types
2022 --> $DIR/dependence_lint.rs:10:9
tests/ui/const-generics/generic_const_exprs/feature-attribute-missing-in-dependent-crate-ice.stderr+2
......@@ -9,6 +9,8 @@ note: not a concrete type
99 |
1010LL | impl<const F: usize> aux::FromSlice for Wrapper<F> {
1111 | ^^^^^^^^^^
12 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
13 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1214
1315error: aborting due to 1 previous error
1416
tests/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr+1
......@@ -6,6 +6,7 @@ LL | type Arr<const N: usize> = [u8; N - 1];
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/generic_const_exprs/issue-72787.min.stderr+4
......@@ -6,6 +6,7 @@ LL | Condition<{ LHS <= RHS }>: True
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `LHS`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/issue-72787.rs:11:24
......@@ -15,6 +16,7 @@ LL | Condition<{ LHS <= RHS }>: True
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `RHS`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: generic parameters may not be used in const operations
2022 --> $DIR/issue-72787.rs:23:25
......@@ -24,6 +26,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
2426 |
2527 = help: const parameters may only be used as standalone arguments here, i.e. `I`
2628 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
29 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2730
2831error: generic parameters may not be used in const operations
2932 --> $DIR/issue-72787.rs:23:36
......@@ -33,6 +36,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
3336 |
3437 = help: const parameters may only be used as standalone arguments here, i.e. `J`
3538 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
39 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3640
3741error: aborting due to 4 previous errors
3842
tests/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr+1
......@@ -6,6 +6,7 @@ LL | where Assert::<{N < usize::MAX / 2}>: IsTrue,
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/generic_const_exprs/issue-74713.stderr+1
......@@ -6,6 +6,7 @@ LL | let _: &'a ();
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0308]: mismatched types
1112 --> $DIR/issue-74713.rs:3:10
tests/ui/const-generics/generic_const_exprs/trivial-anon-const-use-cases.min.stderr+1
......@@ -6,6 +6,7 @@ LL | stuff: [u8; { S + 1 }], // `S + 1` is NOT a valid const expression in t
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `S`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/ice-68875.stderr+3
......@@ -3,6 +3,9 @@ error: generic `Self` types are currently not permitted in anonymous constants
33 |
44LL | data: &'a [u8; Self::SIZE],
55 | ^^^^
6 |
7 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
8 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
69
710error: aborting due to 1 previous error
811
tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr+1
......@@ -6,6 +6,7 @@ LL | T: Trait<{ std::intrinsics::type_name::<T>() }>,
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: `&'static str` is forbidden as the type of a const generic parameter
1112 --> $DIR/intrinsics-type_name-as-const-argument.rs:9:22
tests/ui/const-generics/issue-46511.stderr+1
......@@ -6,6 +6,7 @@ LL | _a: [u8; std::mem::size_of::<&'a mut u8>()]
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0392]: lifetime parameter `'a` is never used
1112 --> $DIR/issue-46511.rs:3:12
tests/ui/const-generics/issues/issue-56445-2.stderr+2
......@@ -9,6 +9,8 @@ note: not a concrete type
99 |
1010LL | impl<'a> OnDiskDirEntry<'a> {
1111 | ^^^^^^^^^^^^^^^^^^
12 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
13 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1214
1315error: aborting due to 1 previous error
1416
tests/ui/const-generics/issues/issue-56445-3.stderr+3
......@@ -3,6 +3,9 @@ error: generic `Self` types are currently not permitted in anonymous constants
33 |
44LL | ram: [u8; Self::SIZE],
55 | ^^^^
6 |
7 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
8 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
69
710error: aborting due to 1 previous error
811
tests/ui/const-generics/issues/issue-67375.min.stderr+1
......@@ -6,6 +6,7 @@ LL | inner: [(); { [|_: &T| {}; 0].len() }],
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0392]: type parameter `T` is never used
1112 --> $DIR/issue-67375.rs:5:12
tests/ui/const-generics/issues/issue-67945-1.min.stderr+2
......@@ -6,6 +6,7 @@ LL | let x: S = MaybeUninit::uninit();
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/issue-67945-1.rs:13:45
......@@ -15,6 +16,7 @@ LL | let b = &*(&x as *const _ as *const S);
1516 |
1617 = note: type parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error[E0392]: type parameter `S` is never used
2022 --> $DIR/issue-67945-1.rs:7:12
tests/ui/const-generics/issues/issue-67945-2.min.stderr+3
......@@ -3,6 +3,9 @@ error: generic `Self` types are currently not permitted in anonymous constants
33 |
44LL | let x: Option<Box<Self>> = None;
55 | ^^^^
6 |
7 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
8 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
69
710error: aborting due to 1 previous error
811
tests/ui/const-generics/issues/issue-67945-3.min.stderr+1
......@@ -6,6 +6,7 @@ LL | let x: Option<S> = None;
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0392]: type parameter `S` is never used
1112 --> $DIR/issue-67945-3.rs:9:12
tests/ui/const-generics/issues/issue-67945-4.min.stderr+1
......@@ -6,6 +6,7 @@ LL | let x: Option<Box<S>> = None;
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0392]: type parameter `S` is never used
1112 --> $DIR/issue-67945-4.rs:8:12
tests/ui/const-generics/issues/issue-68366.min.stderr+1
......@@ -6,6 +6,7 @@ LL | impl <const N: usize> Collatz<{Some(N)}> {}
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: `Option<usize>` is forbidden as the type of a const generic parameter
1112 --> $DIR/issue-68366.rs:9:25
tests/ui/const-generics/issues/issue-76701-ty-param-in-const.stderr+2
......@@ -6,6 +6,7 @@ LL | fn ty_param<T>() -> [u8; std::mem::size_of::<T>()] {
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/issue-76701-ty-param-in-const.rs:6:42
......@@ -15,6 +16,7 @@ LL | fn const_param<const N: usize>() -> [u8; N + 1] {
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: aborting due to 2 previous errors
2022
tests/ui/const-generics/issues/issue-80062.stderr+1
......@@ -6,6 +6,7 @@ LL | let _: [u8; sof::<T>()];
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/issues/issue-80375.stderr+1
......@@ -6,6 +6,7 @@ LL | struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `COUNT`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/legacy-const-generics-bad.stderr+1
......@@ -18,6 +18,7 @@ LL | legacy_const_generics::foo(0, N + 1, 2);
1818 |
1919 = help: const parameters may only be used as standalone arguments here, i.e. `N`
2020 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
21 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2122
2223error: aborting due to 2 previous errors
2324
tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr+1-1
......@@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations
1010LL | foo::<{ Some::<u32> { 0: const { N + 1 } } }>();
1111 | ^
1212 |
13 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
13 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1414
1515error: aborting due to 2 previous errors
1616
tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr+1-1
......@@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations
44LL | T: Trait<const { let a: &'a (); 1 }>
55 | ^^
66 |
7 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
7 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
88
99error: aborting due to 1 previous error
1010
tests/ui/const-generics/mgca/explicit_anon_consts.stderr+7-7
......@@ -40,7 +40,7 @@ error: generic parameters may not be used in const operations
4040LL | type const ITEM3<const N: usize>: usize = const { N };
4141 | ^
4242 |
43 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
43 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
4444
4545error: generic parameters may not be used in const operations
4646 --> $DIR/explicit_anon_consts.rs:60:31
......@@ -48,7 +48,7 @@ error: generic parameters may not be used in const operations
4848LL | T3: Trait<ASSOC = const { N }>,
4949 | ^
5050 |
51 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
51 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
5252
5353error: generic parameters may not be used in const operations
5454 --> $DIR/explicit_anon_consts.rs:69:58
......@@ -56,7 +56,7 @@ error: generic parameters may not be used in const operations
5656LL | struct Default3<const N: usize, const M: usize = const { N }>;
5757 | ^
5858 |
59 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
59 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
6060
6161error: generic parameters may not be used in const operations
6262 --> $DIR/explicit_anon_consts.rs:28:27
......@@ -64,7 +64,7 @@ error: generic parameters may not be used in const operations
6464LL | let _3 = [(); const { N }];
6565 | ^
6666 |
67 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
67 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
6868
6969error: generic parameters may not be used in const operations
7070 --> $DIR/explicit_anon_consts.rs:33:26
......@@ -72,7 +72,7 @@ error: generic parameters may not be used in const operations
7272LL | let _6: [(); const { N }] = todo!();
7373 | ^
7474 |
75 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
75 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
7676
7777error: generic parameters may not be used in const operations
7878 --> $DIR/explicit_anon_consts.rs:11:41
......@@ -80,7 +80,7 @@ error: generic parameters may not be used in const operations
8080LL | type Adt3<const N: usize> = Foo<const { N }>;
8181 | ^
8282 |
83 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
83 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
8484
8585error: generic parameters may not be used in const operations
8686 --> $DIR/explicit_anon_consts.rs:19:42
......@@ -88,7 +88,7 @@ error: generic parameters may not be used in const operations
8888LL | type Arr3<const N: usize> = [(); const { N }];
8989 | ^
9090 |
91 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
91 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
9292
9393error: aborting due to 13 previous errors
9494
tests/ui/const-generics/mgca/selftyalias-containing-param.stderr+1-1
......@@ -9,7 +9,7 @@ note: not a concrete type
99 |
1010LL | impl<const N: usize> S<N> {
1111 | ^^^^
12 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
12 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1313
1414error: aborting due to 1 previous error
1515
tests/ui/const-generics/mgca/selftyparam.stderr+1-1
......@@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations
44LL | fn foo() -> [(); const { let _: Self; 1 }];
55 | ^^^^
66 |
7 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
7 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
88
99error: aborting due to 1 previous error
1010
tests/ui/const-generics/mgca/size-of-generic-ptr-in-array-len.stderr+1-1
......@@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations
1010LL | [0; const { size_of::<*mut T>() }];
1111 | ^
1212 |
13 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
13 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1414
1515error: aborting due to 2 previous errors
1616
tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr+1-1
......@@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations
1010LL | with_point::<{ Point(const { N + 1 }, N) }>();
1111 | ^
1212 |
13 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
13 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1414
1515error: aborting due to 2 previous errors
1616
tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr+1-1
......@@ -22,7 +22,7 @@ error: generic parameters may not be used in const operations
2222LL | takes_nested_tuple::<{ (N, (N, const { N + 1 })) }>();
2323 | ^
2424 |
25 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
25 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2626
2727error: aborting due to 4 previous errors
2828
tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr+2-2
......@@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations
44LL | type const FREE1<T>: usize = const { std::mem::size_of::<T>() };
55 | ^
66 |
7 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
7 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
88
99error: generic parameters may not be used in const operations
1010 --> $DIR/type_const-on-generic-expr.rs:8:51
......@@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations
1212LL | type const FREE2<const I: usize>: usize = const { I + 1 };
1313 | ^
1414 |
15 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
15 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1616
1717error: aborting due to 2 previous errors
1818
tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr+3-3
......@@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations
44LL | type const N1<T>: usize = const { std::mem::size_of::<T>() };
55 | ^
66 |
7 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
7 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
88
99error: generic parameters may not be used in const operations
1010 --> $DIR/type_const-on-generic_expr-2.rs:15:52
......@@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations
1212LL | type const N2<const I: usize>: usize = const { I + 1 };
1313 | ^
1414 |
15 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
15 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1616
1717error: generic parameters may not be used in const operations
1818 --> $DIR/type_const-on-generic_expr-2.rs:17:40
......@@ -20,7 +20,7 @@ error: generic parameters may not be used in const operations
2020LL | type const N3: usize = const { 2 & X };
2121 | ^
2222 |
23 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
23 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2424
2525error: aborting due to 3 previous errors
2626
tests/ui/const-generics/min_const_generics/complex-expression.stderr+7
......@@ -6,6 +6,7 @@ LL | struct Break0<const N: usize>([u8; { N + 1 }]);
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/complex-expression.rs:13:40
......@@ -15,6 +16,7 @@ LL | struct Break1<const N: usize>([u8; { { N } }]);
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: generic parameters may not be used in const operations
2022 --> $DIR/complex-expression.rs:17:17
......@@ -24,6 +26,7 @@ LL | let _: [u8; N + 1];
2426 |
2527 = help: const parameters may only be used as standalone arguments here, i.e. `N`
2628 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
29 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2730
2831error: generic parameters may not be used in const operations
2932 --> $DIR/complex-expression.rs:22:17
......@@ -33,6 +36,7 @@ LL | let _ = [0; N + 1];
3336 |
3437 = help: const parameters may only be used as standalone arguments here, i.e. `N`
3538 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
39 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3640
3741error: generic parameters may not be used in const operations
3842 --> $DIR/complex-expression.rs:26:45
......@@ -42,6 +46,7 @@ LL | struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]);
4246 |
4347 = note: type parameters may not be used in const expressions
4448 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
49 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
4550
4651error: generic parameters may not be used in const operations
4752 --> $DIR/complex-expression.rs:29:47
......@@ -51,6 +56,7 @@ LL | struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]);
5156 |
5257 = note: type parameters may not be used in const expressions
5358 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
59 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
5460
5561error: generic parameters may not be used in const operations
5662 --> $DIR/complex-expression.rs:33:32
......@@ -60,6 +66,7 @@ LL | let _: [u8; size_of::<*mut T>() + 1];
6066 |
6167 = note: type parameters may not be used in const expressions
6268 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
69 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
6370
6471warning: cannot use constants which depend on generic parameters in types
6572 --> $DIR/complex-expression.rs:38:17
tests/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.stderr+2
......@@ -6,6 +6,7 @@ LL | test::<{ let _: &'a (); 3 },>();
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/forbid-non-static-lifetimes.rs:21:16
......@@ -15,6 +16,7 @@ LL | [(); (|_: &'a u8| (), 0).1];
1516 |
1617 = note: lifetime parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: aborting due to 2 previous errors
2022
tests/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr+2
......@@ -9,6 +9,8 @@ note: not a concrete type
99 |
1010LL | impl<T> BindsParam<T> for <T as AlwaysApplicable>::Assoc {
1111 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
13 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1214
1315error: aborting due to 1 previous error
1416
tests/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr+3
......@@ -6,6 +6,7 @@ LL | fn t1() -> [u8; std::mem::size_of::<Self>()];
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic `Self` types are currently not permitted in anonymous constants
1112 --> $DIR/self-ty-in-const-1.rs:12:41
......@@ -18,6 +19,8 @@ note: not a concrete type
1819 |
1920LL | impl<T> Bar<T> {
2021 | ^^^^^^
22 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
23 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2124
2225error: aborting due to 2 previous errors
2326
tests/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr+2
......@@ -9,6 +9,8 @@ note: not a concrete type
99 |
1010LL | impl<T> Baz for Bar<T> {
1111 | ^^^^^^
12 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
13 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1214
1315error: aborting due to 1 previous error
1416
tests/ui/const-generics/outer-lifetime-in-const-generic-default.stderr+1
......@@ -6,6 +6,7 @@ LL | let x: &'a ();
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr+1
......@@ -12,6 +12,7 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
1212 |
1313 = note: type parameters may not be used in const expressions
1414 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
15 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1516
1617error[E0128]: generic parameter defaults cannot reference parameters before they are declared
1718 --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
tests/ui/const-generics/repeat_expr_hack_gives_right_generics.stderr+2
......@@ -6,6 +6,7 @@ LL | bar::<{ [1; N] }>();
66 |
77 = help: const parameters may only be used as standalone arguments here, i.e. `N`
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/repeat_expr_hack_gives_right_generics.rs:22:19
......@@ -15,6 +16,7 @@ LL | bar::<{ [1; { N + 1 }] }>();
1516 |
1617 = help: const parameters may only be used as standalone arguments here, i.e. `N`
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: aborting due to 2 previous errors
2022
tests/ui/const-generics/type-relative-path-144547.min.stderr+3
......@@ -3,6 +3,9 @@ error: generic parameters may not be used in const operations
33 |
44LL | type SupportedArray<T> = [T; <Self::InfoType as LevelInfo>::SUPPORTED_SLOTS];
55 | ^^^^^^^^^^^^^^
6 |
7 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
8 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
69
710error: aborting due to 1 previous error
811
tests/ui/consts/const-eval/size-of-t.stderr+1
......@@ -6,6 +6,7 @@ LL | let _arr: [u8; size_of::<T>()];
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/delegation/bad-resolve.rs+1
......@@ -33,6 +33,7 @@ impl Trait for S {
3333
3434 reuse foo { &self.0 }
3535 //~^ ERROR cannot find function `foo` in this scope
36 //~| ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl
3637 reuse Trait::foo2 { self.0 }
3738 //~^ ERROR cannot find function `foo2` in trait `Trait`
3839 //~| ERROR method `foo2` is not a member of trait `Trait`
tests/ui/delegation/bad-resolve.stderr+16-7
......@@ -26,7 +26,7 @@ LL | reuse <F as Trait>::baz;
2626 | not a member of trait `Trait`
2727
2828error[E0407]: method `foo2` is not a member of trait `Trait`
29 --> $DIR/bad-resolve.rs:36:5
29 --> $DIR/bad-resolve.rs:37:5
3030 |
3131LL | reuse Trait::foo2 { self.0 }
3232 | ^^^^^^^^^^^^^----^^^^^^^^^^^
......@@ -68,7 +68,7 @@ LL | reuse foo { &self.0 }
6868 | ^^^ not found in this scope
6969
7070error[E0425]: cannot find function `foo2` in trait `Trait`
71 --> $DIR/bad-resolve.rs:36:18
71 --> $DIR/bad-resolve.rs:37:18
7272 |
7373LL | fn foo(&self, x: i32) -> i32 { x }
7474 | ---------------------------- similarly named associated function `foo` defined here
......@@ -83,11 +83,20 @@ LL + reuse Trait::foo { self.0 }
8383 |
8484
8585error[E0423]: expected function, found module `prefix::self`
86 --> $DIR/bad-resolve.rs:43:7
86 --> $DIR/bad-resolve.rs:44:7
8787 |
8888LL | reuse prefix::{self, super, crate};
8989 | ^^^^^^ not a function
9090
91error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
92 --> $DIR/bad-resolve.rs:34:11
93 |
94LL | fn foo(&self, x: i32) -> i32 { x }
95 | ---------------------------- `&self` used in trait
96...
97LL | reuse foo { &self.0 }
98 | ^^^ expected `&self` in impl
99
91100error[E0046]: not all trait items implemented, missing: `Type`
92101 --> $DIR/bad-resolve.rs:21:1
93102 |
......@@ -98,7 +107,7 @@ LL | impl Trait for S {
98107 | ^^^^^^^^^^^^^^^^ missing `Type` in implementation
99108
100109error[E0433]: cannot find module or crate `unresolved_prefix` in this scope
101 --> $DIR/bad-resolve.rs:42:7
110 --> $DIR/bad-resolve.rs:43:7
102111 |
103112LL | reuse unresolved_prefix::{a, b, c};
104113 | ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `unresolved_prefix`
......@@ -106,12 +115,12 @@ LL | reuse unresolved_prefix::{a, b, c};
106115 = help: you might be missing a crate named `unresolved_prefix`
107116
108117error[E0433]: `crate` in paths can only be used in start position
109 --> $DIR/bad-resolve.rs:43:29
118 --> $DIR/bad-resolve.rs:44:29
110119 |
111120LL | reuse prefix::{self, super, crate};
112121 | ^^^^^ can only be used in path start position
113122
114error: aborting due to 13 previous errors
123error: aborting due to 14 previous errors
115124
116Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576.
125Some errors have detailed explanations: E0046, E0186, E0324, E0407, E0423, E0425, E0433, E0575, E0576.
117126For more information about an error, try `rustc --explain E0046`.
tests/ui/delegation/constraints-in-generic-args-ice-158812.rs created+13
......@@ -0,0 +1,13 @@
1#![feature(fn_delegation)]
2
3pub trait Trait<'a> {
4 fn foo(&self);
5}
6
7pub struct S<'a, A>(&'a A);
8impl<'a, A> Trait<'a> for S<'a, A> {
9 reuse Trait::<A = ()>::foo;
10 //~^ ERROR: associated item constraints are not allowed here
11}
12
13fn main() {}
tests/ui/delegation/constraints-in-generic-args-ice-158812.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0229]: associated item constraints are not allowed here
2 --> $DIR/constraints-in-generic-args-ice-158812.rs:9:19
3 |
4LL | reuse Trait::<A = ()>::foo;
5 | ^^^^^^ associated item constraint not allowed here
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0229`.
tests/ui/delegation/self-mapping-arguments-errors.rs created+47
......@@ -0,0 +1,47 @@
1#![feature(fn_delegation)]
2
3mod target_expr_doesnt_relower_when_defs_inside {
4 trait MyAdd {
5 fn add(self, other: Self) -> Self;
6 }
7
8 impl MyAdd for usize {
9 fn add(self, other: usize) -> usize { self + other }
10 }
11
12 #[derive(Eq, PartialEq, Debug)]
13 struct W(usize);
14 reuse impl MyAdd for W {
15 //~^ ERROR: attempted to lower target expression with definitions more than once while mapping argument
16 //~| ERROR: method `add` has a `self` declaration in the trait, but not in the impl
17 //~| ERROR: the trait bound `(): target_expr_doesnt_relower_when_defs_inside::MyAdd` is not satisfied
18 //~| ERROR: this function takes 2 arguments but 1 argument was supplied
19 println!("{self:?}");
20 fn foo() {
21 println!("hello");
22 }
23
24 reuse foo as bar;
25 bar();
26 bar();
27
28 self.0
29 }
30}
31
32mod complex_Self_doesnt_map {
33 trait MyAdd {
34 fn add(self, other: Box<Self>) -> Self;
35 }
36
37 impl MyAdd for usize {
38 fn add(self, other: Box<usize>) -> usize { self + *other.as_ref() }
39 }
40
41 #[derive(Eq, PartialEq, Debug)]
42 struct W(usize);
43 reuse impl MyAdd for W { self.0 }
44 //~^ ERROR: mismatched types
45}
46
47fn main() {}
tests/ui/delegation/self-mapping-arguments-errors.stderr created+98
......@@ -0,0 +1,98 @@
1error: attempted to lower target expression with definitions more than once while mapping argument
2 --> $DIR/self-mapping-arguments-errors.rs:14:5
3 |
4LL | / reuse impl MyAdd for W {
5... |
6LL | | self.0
7LL | | }
8 | |_____^
9
10error[E0186]: method `add` has a `self` declaration in the trait, but not in the impl
11 --> $DIR/self-mapping-arguments-errors.rs:14:5
12 |
13LL | fn add(self, other: Self) -> Self;
14 | ---------------------------------- `self` used in trait
15...
16LL | / reuse impl MyAdd for W {
17... |
18LL | | self.0
19LL | | }
20 | |_____^ expected `self` in impl
21
22error[E0277]: the trait bound `(): target_expr_doesnt_relower_when_defs_inside::MyAdd` is not satisfied
23 --> $DIR/self-mapping-arguments-errors.rs:14:5
24 |
25LL | / reuse impl MyAdd for W {
26... |
27LL | | self.0
28LL | | }
29 | |_____^ the trait `target_expr_doesnt_relower_when_defs_inside::MyAdd` is not implemented for `()`
30 |
31help: the following other types implement trait `target_expr_doesnt_relower_when_defs_inside::MyAdd`
32 --> $DIR/self-mapping-arguments-errors.rs:8:5
33 |
34LL | impl MyAdd for usize {
35 | ^^^^^^^^^^^^^^^^^^^^ `usize`
36...
37LL | reuse impl MyAdd for W {
38 | ^^^^^^^^^^^^^^^^^^^^^^ `target_expr_doesnt_relower_when_defs_inside::W`
39
40error[E0061]: this function takes 2 arguments but 1 argument was supplied
41 --> $DIR/self-mapping-arguments-errors.rs:14:5
42 |
43LL | / reuse impl MyAdd for W {
44... |
45LL | | self.0
46LL | | }
47 | | ^
48 | | |
49 | |_____argument #2 of type `()` is missing
50 | this implicit `()` return type influences the call expression's return type
51 |
52note: method defined here
53 --> $DIR/self-mapping-arguments-errors.rs:5:12
54 |
55LL | fn add(self, other: Self) -> Self;
56 | ^^^ -----
57help: provide the argument
58 |
59LL ~ }({
60LL +
61LL +
62LL +
63LL +
64LL + println!("{self:?}");
65LL + fn foo() {
66LL + println!("hello");
67LL + }
68LL +
69LL + reuse foo as bar;
70LL + bar();
71LL + bar();
72LL +
73LL + self.0
74LL + }, ())
75 |
76
77error[E0308]: mismatched types
78 --> $DIR/self-mapping-arguments-errors.rs:43:5
79 |
80LL | reuse impl MyAdd for W { self.0 }
81 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82 | |
83 | expected `Box<usize>`, found `Box<W>`
84 | arguments to this function are incorrect
85 | this return type influences the call expression's return type
86 |
87 = note: expected struct `Box<usize>`
88 found struct `Box<complex_Self_doesnt_map::W>`
89note: method defined here
90 --> $DIR/self-mapping-arguments-errors.rs:34:12
91 |
92LL | fn add(self, other: Box<Self>) -> Self;
93 | ^^^ -----
94
95error: aborting due to 5 previous errors
96
97Some errors have detailed explanations: E0061, E0186, E0277, E0308.
98For more information about an error, try `rustc --explain E0061`.
tests/ui/delegation/self-mapping-arguments.rs created+59
......@@ -0,0 +1,59 @@
1//@ run-pass
2//@ check-run-results
3
4#![feature(fn_delegation)]
5
6
7mod default_test {
8 trait MyAdd {
9 fn add(self, other: Self) -> Self;
10 }
11
12 impl MyAdd for usize {
13 fn add(self, other: usize) -> usize { self + other }
14 }
15
16 #[derive(Eq, PartialEq, Debug)]
17 struct W(usize);
18 reuse impl MyAdd for W {
19 println!("{self:?}");
20 let _x = 213;
21
22 self.0
23 }
24
25 pub fn check() {
26 assert_eq!(W(1).add(W(2)), W(3))
27 }
28}
29
30mod arguments_mapping_works_without_return_self {
31 trait MyAdd {
32 fn add(self, other: Self);
33 }
34
35 impl MyAdd for usize {
36 fn add(self, other: usize) {
37 let result = self + other;
38 println!("{result}");
39 }
40 }
41
42 #[derive(Eq, PartialEq, Debug)]
43 struct W(usize);
44 reuse impl MyAdd for W {
45 println!("{self:?}");
46 let _x = 213;
47
48 self.0
49 }
50
51 pub fn check() {
52 W(2).add(W(10));
53 }
54}
55
56fn main() {
57 default_test::check();
58 arguments_mapping_works_without_return_self::check();
59}
tests/ui/delegation/self-mapping-arguments.run.stdout created+5
......@@ -0,0 +1,5 @@
1W(1)
2W(2)
3W(2)
4W(10)
512
tests/ui/dyn-compatibility/ice-generics-of-crate-root-152335.rs+1-1
......@@ -1,7 +1,7 @@
11// Regression test for #152335.
22// The compiler used to ICE in `generics_of` when `note_and_explain_type_err`
33// was called with `CRATE_DEF_ID` as the body owner during dyn-compatibility
4// checking. This happened because `ObligationCause::dummy()` sets `body_id`
4// checking. This happened because `ObligationCause::dummy()` sets `body_def_id`
55// to `CRATE_DEF_ID`, and error reporting tried to look up generics on it.
66
77struct ActuallySuper;
tests/ui/feature-gates/feature-gate-generic-const-args.stderr+1-1
......@@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations
44LL | type const INC<const N: usize>: usize = const { N + 1 };
55 | ^
66 |
7 = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items
7 = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item
88
99error: aborting due to 1 previous error
1010
tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr+1
......@@ -6,6 +6,7 @@ LL | fn foo<T: Trait>() -> [u8; <T as Trait>::ASSOC] {
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0658]: `type const` syntax is experimental
1112 --> $DIR/feature-gate-min-generic-const-args.rs:2:5
tests/ui/generics/param-in-ct-in-ty-param-default.stderr+1
......@@ -6,6 +6,7 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/lifetimes/issue-64173-unused-lifetimes.stderr+4
......@@ -6,6 +6,7 @@ LL | beta: [(); foo::<&'a ()>()],
66 |
77 = note: lifetime parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error[E0392]: lifetime parameter `'s` is never used
1112 --> $DIR/issue-64173-unused-lifetimes.rs:3:12
......@@ -20,6 +21,9 @@ error: generic `Self` types are currently not permitted in anonymous constants
2021 |
2122LL | array: [(); size_of::<&Self>()],
2223 | ^^^^
24 |
25 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
26 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2327
2428error[E0392]: lifetime parameter `'a` is never used
2529 --> $DIR/issue-64173-unused-lifetimes.rs:15:12
tests/ui/lint/unused-braces-macro-arg-issue-158747.fixed created+40
......@@ -0,0 +1,40 @@
1//@ check-pass
2//@ run-rustfix
3
4// Removing block braces can change how macro-generated calls match macro arguments.
5
6#![warn(unused_braces)]
7
8macro_rules! type_or_expr {
9 ($x:ty) => {
10 identity(stringify!($x))
11 };
12 ($x:expr) => {
13 identity($x)
14 };
15}
16
17macro_rules! call_expr {
18 ($e:expr) => {
19 identity($e)
20 };
21}
22
23macro_rules! call_block {
24 ($b:block) => {
25 identity($b)
26 };
27}
28
29fn identity<T>(x: T) -> T {
30 x
31}
32
33fn main() {
34 // should not warn
35 let _ = type_or_expr!({ format!("{}", 1) });
36 // should not warn
37 let _ = call_expr!(1);
38 //~^ WARN unnecessary braces around function argument
39 let _ = call_block!({ 1 });
40}
tests/ui/lint/unused-braces-macro-arg-issue-158747.rs created+40
......@@ -0,0 +1,40 @@
1//@ check-pass
2//@ run-rustfix
3
4// Removing block braces can change how macro-generated calls match macro arguments.
5
6#![warn(unused_braces)]
7
8macro_rules! type_or_expr {
9 ($x:ty) => {
10 identity(stringify!($x))
11 };
12 ($x:expr) => {
13 identity($x)
14 };
15}
16
17macro_rules! call_expr {
18 ($e:expr) => {
19 identity($e)
20 };
21}
22
23macro_rules! call_block {
24 ($b:block) => {
25 identity($b)
26 };
27}
28
29fn identity<T>(x: T) -> T {
30 x
31}
32
33fn main() {
34 // should not warn
35 let _ = type_or_expr!({ format!("{}", 1) });
36 // should not warn
37 let _ = call_expr!({ 1 });
38 //~^ WARN unnecessary braces around function argument
39 let _ = call_block!({ 1 });
40}
tests/ui/lint/unused-braces-macro-arg-issue-158747.stderr created+19
......@@ -0,0 +1,19 @@
1warning: unnecessary braces around function argument
2 --> $DIR/unused-braces-macro-arg-issue-158747.rs:37:24
3 |
4LL | let _ = call_expr!({ 1 });
5 | ^^ ^^
6 |
7note: the lint level is defined here
8 --> $DIR/unused-braces-macro-arg-issue-158747.rs:6:9
9 |
10LL | #![warn(unused_braces)]
11 | ^^^^^^^^^^^^^
12help: remove these braces
13 |
14LL - let _ = call_expr!({ 1 });
15LL + let _ = call_expr!(1);
16 |
17
18warning: 1 warning emitted
19
tests/ui/resolve/issue-39559.stderr+1
......@@ -6,6 +6,7 @@ LL | entries: [T; D::dim()],
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: aborting due to 1 previous error
1112
tests/ui/type/pattern_types/assoc_const.default.stderr+4
......@@ -6,6 +6,7 @@ LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)
66 |
77 = note: type parameters may not be used in const expressions
88 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
9 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
910
1011error: generic parameters may not be used in const operations
1112 --> $DIR/assoc_const.rs:17:61
......@@ -15,6 +16,7 @@ LL | fn foo<T: Foo>(_: pattern_type!(u32 is <T as Foo>::START..=<T as Foo>::END)
1516 |
1617 = note: type parameters may not be used in const expressions
1718 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
19 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
1820
1921error: generic parameters may not be used in const operations
2022 --> $DIR/assoc_const.rs:20:40
......@@ -24,6 +26,7 @@ LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
2426 |
2527 = note: type parameters may not be used in const expressions
2628 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
29 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
2730
2831error: generic parameters may not be used in const operations
2932 --> $DIR/assoc_const.rs:20:51
......@@ -33,6 +36,7 @@ LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {}
3336 |
3437 = note: type parameters may not be used in const expressions
3538 = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
39 = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
3640
3741error: aborting due to 4 previous errors
3842