| author | bors <bors@rust-lang.org> 2026-07-07 13:17:11 UTC |
| committer | GitHub <noreply@github.com> 2026-07-07 13:17:11 UTC |
| log | ba533458e2924a6333b2d89d7b9d8d0126df6906 |
| tree | 7f1b89cb00cd3ee20b32de90c9211e87401ccbf4 |
| parent | f10db292a3733b5c67c8da8c7661195ff4b05774 |
| parent | 75c6569541fc73fc9c1e9298fb024e08b0677049 |
150 files changed, 1472 insertions(+), 554 deletions(-)
compiler/rustc_ast/src/expand/typetree.rs+11| ... | ... | @@ -28,6 +28,9 @@ pub enum Kind { |
| 28 | 28 | Anything, |
| 29 | 29 | Integer, |
| 30 | 30 | 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, | |
| 31 | 34 | Half, |
| 32 | 35 | Float, |
| 33 | 36 | Double, |
| ... | ... | @@ -57,6 +60,9 @@ impl TypeTree { |
| 57 | 60 | } |
| 58 | 61 | Self(ints) |
| 59 | 62 | } |
| 63 | pub fn add_indirection(self) -> Self { | |
| 64 | Self(vec![Type { offset: 0, size: 1, kind: Kind::Pointer, child: self }]) | |
| 65 | } | |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | 68 | #[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, StableHash)] |
| ... | ... | @@ -72,6 +78,11 @@ pub struct Type { |
| 72 | 78 | pub kind: Kind, |
| 73 | 79 | pub child: TypeTree, |
| 74 | 80 | } |
| 81 | impl 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 | } | |
| 75 | 86 | |
| 76 | 87 | impl Type { |
| 77 | 88 | 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; |
| 7 | 7 | use rustc_middle::ty::{GenericParamDefKind, TyCtxt}; |
| 8 | 8 | use rustc_middle::{bug, ty}; |
| 9 | 9 | use rustc_span::symbol::kw; |
| 10 | use rustc_span::{Ident, Span, sym}; | |
| 10 | use rustc_span::{ErrorGuaranteed, Ident, Span, sym}; | |
| 11 | 11 | |
| 12 | 12 | use crate::LoweringContext; |
| 13 | 13 | use crate::delegation::resolution::resolver::DelegationResolver; |
| ... | ... | @@ -281,7 +281,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 281 | 281 | &self, |
| 282 | 282 | delegation: &'a Delegation, |
| 283 | 283 | sig_id: DefId, |
| 284 | ) -> GenericsResolution<'a, 'hir> { | |
| 284 | ) -> Result<GenericsResolution<'a, 'hir>, ErrorGuaranteed> { | |
| 285 | 285 | let tcx = self.tcx(); |
| 286 | 286 | let delegation_parent_kind = tcx.def_kind(tcx.local_parent(self.owner_id())); |
| 287 | 287 | |
| ... | ... | @@ -300,9 +300,8 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 300 | 300 | let qself_is_none = delegation.qself.is_none(); |
| 301 | 301 | |
| 302 | 302 | 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) { | |
| 306 | 305 | sig_parent_params = &tcx.generics_of(sig_parent).own_params; |
| 307 | 306 | self.get_user_args(parent_segment) |
| 308 | 307 | .map(|args| ParentSegmentArgs::Specified(args)) |
| ... | ... | @@ -314,7 +313,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 314 | 313 | ParentSegmentArgs::Invalid |
| 315 | 314 | }; |
| 316 | 315 | |
| 317 | GenericsResolution { | |
| 316 | Ok(GenericsResolution { | |
| 318 | 317 | parent_args, |
| 319 | 318 | sig_parent_params, |
| 320 | 319 | qself_is_none, |
| ... | ... | @@ -326,7 +325,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 326 | 325 | child_args: self.get_user_args( |
| 327 | 326 | delegation.path.segments.last().expect("must be at least one segment"), |
| 328 | 327 | ), |
| 329 | } | |
| 328 | }) | |
| 330 | 329 | } |
| 331 | 330 | |
| 332 | 331 | fn get_user_args<'a>(&self, segment: &'a PathSegment) -> Option<&'a AngleBracketedArgs> { |
| ... | ... | @@ -350,14 +349,14 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 350 | 349 | &self, |
| 351 | 350 | delegation: &Delegation, |
| 352 | 351 | sig_id: DefId, |
| 353 | ) -> GenericsGenerationResults<'hir> { | |
| 352 | ) -> Result<GenericsGenerationResults<'hir>, ErrorGuaranteed> { | |
| 354 | 353 | let res @ GenericsResolution { |
| 355 | 354 | trait_impl, |
| 356 | 355 | generate_self, |
| 357 | 356 | sig_child_params, |
| 358 | 357 | sig_parent_params, |
| 359 | 358 | .. |
| 360 | } = self.resolve_generics(delegation, sig_id); | |
| 359 | } = self.resolve_generics(delegation, sig_id)?; | |
| 361 | 360 | |
| 362 | 361 | // If we are in trait impl always generate function whose generics matches |
| 363 | 362 | // those that are defined in trait. |
| ... | ... | @@ -374,7 +373,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 374 | 373 | |
| 375 | 374 | let child = GenericsGenerationResult::new(child); |
| 376 | 375 | |
| 377 | return GenericsGenerationResults { parent, child, self_ty_propagation_kind: None }; | |
| 376 | return Ok(GenericsGenerationResults { parent, child, self_ty_propagation_kind: None }); | |
| 378 | 377 | } |
| 379 | 378 | |
| 380 | 379 | let tcx = self.tcx(); |
| ... | ... | @@ -421,7 +420,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 421 | 420 | DelegationGenerics::generate_all(sig_child_params, GenericsPosition::Child, trait_impl) |
| 422 | 421 | }; |
| 423 | 422 | |
| 424 | GenericsGenerationResults { | |
| 423 | Ok(GenericsGenerationResults { | |
| 425 | 424 | parent: GenericsGenerationResult::new(parent_generics), |
| 426 | 425 | child: GenericsGenerationResult::new(child_generics), |
| 427 | 426 | self_ty_propagation_kind: match res.free_to_trait_delegation { |
| ... | ... | @@ -435,7 +434,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { |
| 435 | 434 | }), |
| 436 | 435 | false => None, |
| 437 | 436 | }, |
| 438 | } | |
| 437 | }) | |
| 439 | 438 | } |
| 440 | 439 | |
| 441 | 440 | /// 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; |
| 45 | 45 | use rustc_abi::ExternAbi; |
| 46 | 46 | use rustc_ast as ast; |
| 47 | 47 | use rustc_ast::*; |
| 48 | use rustc_hir::def::DefKind; | |
| 48 | 49 | use rustc_hir::{self as hir, FnDeclFlags}; |
| 49 | 50 | use rustc_middle::ty::Asyncness; |
| 50 | 51 | use rustc_span::def_id::DefId; |
| ... | ... | @@ -249,20 +250,19 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 249 | 250 | let mut unused_target_expr = false; |
| 250 | 251 | |
| 251 | 252 | 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; | |
| 256 | 254 | let ParamInfo { param_count, .. } = param_info; |
| 255 | let arguments_to_map = &res.sig_mapping.arguments_to_map; | |
| 257 | 256 | |
| 258 | 257 | let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count); |
| 259 | 258 | let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count); |
| 260 | let mut stmts: &[hir::Stmt<'hir>] = &[]; | |
| 259 | let mut stmts = vec![]; | |
| 261 | 260 | |
| 262 | 261 | // Consider non-specified target expression as generated, |
| 263 | 262 | // as we do not want to emit error when target expression is |
| 264 | 263 | // 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()); | |
| 266 | 266 | |
| 267 | 267 | for idx in 0..param_count { |
| 268 | 268 | let (param, pat_node_id) = this.generate_param(is_method, idx, span); |
| ... | ... | @@ -271,41 +271,38 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 271 | 271 | let generate_arg = |
| 272 | 272 | |this: &mut Self| this.generate_arg(is_method, idx, param.pat.hir_id, span); |
| 273 | 273 | |
| 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)); | |
| 303 | 294 | |
| 304 | 295 | args.push(arg); |
| 305 | 296 | } |
| 306 | 297 | |
| 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 | ); | |
| 309 | 306 | |
| 310 | 307 | call_expr_id = hir_id; |
| 311 | 308 | |
| ... | ... | @@ -317,6 +314,48 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 317 | 314 | (block_id, call_expr_id, unused_target_expr) |
| 318 | 315 | } |
| 319 | 316 | |
| 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 | ||
| 320 | 359 | fn finalize_body_lowering( |
| 321 | 360 | &mut self, |
| 322 | 361 | delegation: &Delegation, |
| ... | ... | @@ -392,8 +431,12 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 392 | 431 | let args = self.arena.alloc_from_iter(args); |
| 393 | 432 | let call = self.mk_expr(hir::ExprKind::Call(callee_path, args), span); |
| 394 | 433 | |
| 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 | ||
| 397 | 440 | let ident = Ident::new(kw::SelfUpper, span); |
| 398 | 441 | let path = self.create_resolved_path(res, ident, span); |
| 399 | 442 | |
| ... | ... | @@ -453,11 +496,14 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 453 | 496 | }) |
| 454 | 497 | .unwrap_or_else(|| self.arena.alloc_from_iter(args_iter.consume_all(self))); |
| 455 | 498 | |
| 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 | ||
| 456 | 502 | // 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(|| { | |
| 458 | 504 | &*self.arena.alloc(hir::GenericArgs { |
| 459 | 505 | args: new_args, |
| 460 | constraints: &[], | |
| 506 | constraints: segment.args.map(|a| a.constraints).unwrap_or(&[]), | |
| 461 | 507 | parenthesized: hir::GenericArgsParentheses::No, |
| 462 | 508 | span_ext: segment.args.map_or(span, |args| args.span_ext), |
| 463 | 509 | }) |
| ... | ... | @@ -538,6 +584,7 @@ struct SelfResolver<'a, 'b, 'hir> { |
| 538 | 584 | ctxt: &'a mut LoweringContext<'b, 'hir>, |
| 539 | 585 | path_id: NodeId, |
| 540 | 586 | self_param_id: NodeId, |
| 587 | overwrites: Vec<NodeId>, | |
| 541 | 588 | } |
| 542 | 589 | |
| 543 | 590 | impl SelfResolver<'_, '_, '_> { |
| ... | ... | @@ -546,6 +593,7 @@ impl SelfResolver<'_, '_, '_> { |
| 546 | 593 | && let Some(Res::Local(sig_id)) = res.full_res() |
| 547 | 594 | && sig_id == self.path_id |
| 548 | 595 | { |
| 596 | self.overwrites.push(id); | |
| 549 | 597 | self.ctxt.partial_res_overrides.insert(id, self.self_param_id); |
| 550 | 598 | } |
| 551 | 599 | } |
compiler/rustc_ast_lowering/src/delegation/resolution.rs+87-39| ... | ... | @@ -6,7 +6,7 @@ use rustc_ast as ast; |
| 6 | 6 | use rustc_ast::*; |
| 7 | 7 | use rustc_data_structures::fx::FxHashSet; |
| 8 | 8 | use rustc_hir as hir; |
| 9 | use rustc_middle::span_bug; | |
| 9 | use rustc_middle::{span_bug, ty}; | |
| 10 | 10 | use rustc_span::def_id::{DefId, LocalDefId}; |
| 11 | 11 | use rustc_span::{ErrorGuaranteed, Span}; |
| 12 | 12 | |
| ... | ... | @@ -14,7 +14,8 @@ use crate::delegation::generics::GenericsGenerationResults; |
| 14 | 14 | use crate::delegation::resolution::resolver::DelegationResolver; |
| 15 | 15 | use crate::diagnostics::{ |
| 16 | 16 | CycleInDelegationSignatureResolution, DelegationAttemptedBlockWithDefsDeletion, |
| 17 | DelegationBlockSpecifiedWhenNoParams, UnresolvedDelegationCallee, | |
| 17 | DelegationAttemptedBlockWithDefsRelowering, DelegationBlockSpecifiedWhenNoParams, | |
| 18 | UnresolvedDelegationCallee, | |
| 18 | 19 | }; |
| 19 | 20 | |
| 20 | 21 | /// Summary info about function parameters. |
| ... | ... | @@ -30,21 +31,28 @@ pub(super) struct ParamInfo { |
| 30 | 31 | pub splatted: Option<u8>, |
| 31 | 32 | } |
| 32 | 33 | |
| 34 | #[derive(Default)] | |
| 35 | pub(super) struct SigMapping { | |
| 36 | pub map_return: bool, | |
| 37 | pub arguments_to_map: FxHashSet<usize>, | |
| 38 | } | |
| 39 | ||
| 33 | 40 | pub(super) struct DelegationResolution { |
| 34 | 41 | pub sig_id: DefId, |
| 35 | 42 | pub is_method: bool, |
| 36 | 43 | pub param_info: ParamInfo, |
| 37 | 44 | pub span: Span, |
| 38 | pub should_generate_block: bool, | |
| 39 | pub call_path_res: Option<DefId>, | |
| 45 | pub call_path_res: DefId, | |
| 40 | 46 | pub source: DelegationSource, |
| 41 | pub output_self_mapping: Option<(LocalDefId, bool)>, | |
| 47 | pub parent: LocalDefId, | |
| 48 | pub sig_mapping: SigMapping, | |
| 42 | 49 | } |
| 43 | 50 | |
| 44 | 51 | pub(super) mod resolver { |
| 45 | 52 | use rustc_ast::NodeId; |
| 46 | 53 | use rustc_hir::def_id::{DefId, LocalDefId}; |
| 47 | 54 | use rustc_middle::ty::TyCtxt; |
| 55 | use rustc_span::ErrorGuaranteed; | |
| 48 | 56 | |
| 49 | 57 | use crate::LoweringContext; |
| 50 | 58 | |
| ... | ... | @@ -87,8 +95,10 @@ pub(super) mod resolver { |
| 87 | 95 | } |
| 88 | 96 | |
| 89 | 97 | #[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 | ) | |
| 92 | 102 | } |
| 93 | 103 | } |
| 94 | 104 | } |
| ... | ... | @@ -126,25 +136,31 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { |
| 126 | 136 | |
| 127 | 137 | let sig = tcx.fn_sig(sig_id).skip_binder().skip_binder(); |
| 128 | 138 | 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)?; | |
| 129 | 143 | |
| 130 | 144 | let res = DelegationResolution { |
| 131 | 145 | is_method, |
| 132 | 146 | span, |
| 133 | 147 | sig_id, |
| 148 | parent, | |
| 134 | 149 | // FIXME(splat): use `sig.splatted()` once FnSig has it |
| 135 | 150 | 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( | |
| 137 | 154 | delegation, |
| 138 | sig_id, | |
| 139 | is_method, | |
| 140 | param_count, | |
| 155 | span, | |
| 156 | should_generate_block, | |
| 157 | parent, | |
| 158 | sig, | |
| 159 | contains_defs, | |
| 141 | 160 | )?, |
| 142 | source: delegation.source, | |
| 143 | call_path_res: self.get_resolution_id(delegation.id), | |
| 144 | output_self_mapping: self.should_map_return_value(delegation), | |
| 145 | 161 | }; |
| 146 | 162 | |
| 147 | Ok((res, self.resolve_and_generate_generics(delegation, sig_id))) | |
| 163 | Ok((res, self.resolve_and_generate_generics(delegation, sig_id)?)) | |
| 148 | 164 | } |
| 149 | 165 | |
| 150 | 166 | fn check_for_cycles(&self, mut def_id: DefId, span: Span) -> Result<(), ErrorGuaranteed> { |
| ... | ... | @@ -180,13 +196,13 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { |
| 180 | 196 | sig_id: DefId, |
| 181 | 197 | is_method: bool, |
| 182 | 198 | param_count: usize, |
| 183 | ) -> Result<bool, ErrorGuaranteed> { | |
| 199 | ) -> Result<(/* should generate block */ bool, /* contains defs */ bool), ErrorGuaranteed> { | |
| 184 | 200 | let tcx = self.tcx(); |
| 185 | 201 | let should_generate_block = is_method |
| 186 | 202 | || matches!(tcx.def_kind(sig_id), DefKind::Fn) |
| 187 | 203 | || matches!(delegation.source, DelegationSource::Single); |
| 188 | 204 | |
| 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)) }; | |
| 190 | 206 | |
| 191 | 207 | // Report an error if user has explicitly specified delegation's target expression |
| 192 | 208 | // in a single delegation when reused function has no params. |
| ... | ... | @@ -194,44 +210,84 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { |
| 194 | 210 | let err = DelegationBlockSpecifiedWhenNoParams { span: block.span }; |
| 195 | 211 | return Err(tcx.dcx().emit_err(err)); |
| 196 | 212 | } |
| 197 | ||
| 198 | 213 | struct DefinitionsFinder<'a, 'hir> { |
| 199 | ctx: &'a DelegationResolver<'a, 'hir>, | |
| 214 | resolver: &'a DelegationResolver<'a, 'hir>, | |
| 200 | 215 | } |
| 201 | 216 | |
| 202 | 217 | impl<'a> Visitor<'a> for DefinitionsFinder<'a, '_> { |
| 203 | 218 | type Result = ControlFlow<()>; |
| 204 | 219 | |
| 205 | 220 | fn visit_id(&mut self, id: NodeId) -> Self::Result { |
| 206 | match self.ctx.is_definition(id) { | |
| 221 | match self.resolver.is_definition(id) { | |
| 207 | 222 | true => ControlFlow::Break(()), |
| 208 | 223 | false => ControlFlow::Continue(()), |
| 209 | 224 | } |
| 210 | 225 | } |
| 211 | 226 | } |
| 212 | 227 | |
| 213 | let mut collector = DefinitionsFinder { ctx: self }; | |
| 228 | let mut collector = DefinitionsFinder { resolver: self }; | |
| 214 | 229 | |
| 215 | 230 | let contains_defs = collector.visit_block(block).is_break(); |
| 216 | 231 | |
| 217 | 232 | // If there are definitions inside and we can't delete target expression, then report an error. |
| 218 | 233 | // FIXME(fn_delegation): support deletion of target expression with defs inside. |
| 219 | 234 | if should_generate_block || !contains_defs { |
| 220 | Ok(should_generate_block) | |
| 235 | Ok((should_generate_block, contains_defs)) | |
| 221 | 236 | } else { |
| 222 | 237 | Err(tcx.dcx().emit_err(DelegationAttemptedBlockWithDefsDeletion { span: block.span })) |
| 223 | 238 | } |
| 224 | 239 | } |
| 225 | 240 | |
| 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> { | |
| 227 | 285 | // Heuristic: don't do wrapping if there is no target expression. |
| 228 | 286 | if delegation.body.is_none() { |
| 229 | return None; | |
| 287 | return Ok(false); | |
| 230 | 288 | } |
| 231 | 289 | |
| 232 | 290 | let tcx = self.tcx(); |
| 233 | let parent = tcx.local_parent(self.owner_id()); | |
| 234 | let parent_kind = tcx.def_kind(parent); | |
| 235 | 291 | |
| 236 | 292 | // Apply wrapping for delegations inside |
| 237 | 293 | // 1) Trait impls, as the return type of both signature function |
| ... | ... | @@ -244,21 +300,13 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { |
| 244 | 300 | // 2) Inherent methods when delegating to trait, as we change the type of |
| 245 | 301 | // `Self` to type of struct or enum we delegate from. |
| 246 | 302 | if !matches!(tcx.def_kind(parent), DefKind::Impl { .. }) { |
| 247 | return None; | |
| 303 | return Ok(false); | |
| 248 | 304 | } |
| 249 | 305 | |
| 250 | let is_trait_impl = parent_kind == DefKind::Impl { of_trait: true }; | |
| 251 | ||
| 252 | 306 | // 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) | |
| 263 | 311 | } |
| 264 | 312 | } |
compiler/rustc_ast_lowering/src/diagnostics.rs+9| ... | ... | @@ -569,3 +569,12 @@ pub(crate) struct DelegationInfersMismatch { |
| 569 | 569 | pub expected: Symbol, |
| 570 | 570 | pub actual: Symbol, |
| 571 | 571 | } |
| 572 | ||
| 573 | #[derive(Diagnostic)] | |
| 574 | #[diag( | |
| 575 | "attempted to lower target expression with definitions more than once while mapping argument" | |
| 576 | )] | |
| 577 | pub(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) { |
| 100 | 100 | providers.lower_to_hir = lower_to_hir; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | #[cfg(debug_assertions)] | |
| 104 | pub(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 | ||
| 103 | 146 | struct LoweringContext<'a, 'hir> { |
| 104 | 147 | tcx: TyCtxt<'hir>, |
| 105 | 148 | resolver: &'a ResolverAstLowering<'hir>, |
| ... | ... | @@ -146,7 +189,7 @@ struct LoweringContext<'a, 'hir> { |
| 146 | 189 | ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>, |
| 147 | 190 | /// NodeIds that are lowered inside the current HIR owner. Only used for duplicate lowering check. |
| 148 | 191 | #[cfg(debug_assertions)] |
| 149 | node_id_to_local_id: NodeMap<hir::ItemLocalId>, | |
| 192 | relowering_checker: re_lowering::ReloweringChecker, | |
| 150 | 193 | /// The `NodeId` space is split in two. |
| 151 | 194 | /// `0..resolver.next_node_id` are created by the resolver on the AST. |
| 152 | 195 | /// The higher part `resolver.next_node_id..next_node_id` are created during lowering. |
| ... | ... | @@ -205,8 +248,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
| 205 | 248 | // and we never call `lower_node_id(owner)`. |
| 206 | 249 | item_local_id_counter: hir::ItemLocalId::new(1), |
| 207 | 250 | ident_and_label_to_local_id: Default::default(), |
| 251 | ||
| 208 | 252 | #[cfg(debug_assertions)] |
| 209 | node_id_to_local_id: Default::default(), | |
| 253 | relowering_checker: Default::default(), | |
| 254 | ||
| 210 | 255 | trait_map: Default::default(), |
| 211 | 256 | next_node_id: resolver.next_node_id, |
| 212 | 257 | node_id_to_def_id: NodeMap::default(), |
| ... | ... | @@ -808,7 +853,7 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 808 | 853 | let current_ident_and_label_to_local_id = mem::take(&mut self.ident_and_label_to_local_id); |
| 809 | 854 | |
| 810 | 855 | #[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); | |
| 812 | 857 | let current_trait_map = mem::take(&mut self.trait_map); |
| 813 | 858 | let current_owner = mem::replace(&mut self.current_hir_id_owner, owner_id); |
| 814 | 859 | let current_local_counter = |
| ... | ... | @@ -824,10 +869,7 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 824 | 869 | |
| 825 | 870 | // Always allocate the first `HirId` for the owner itself. |
| 826 | 871 | #[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); | |
| 831 | 873 | |
| 832 | 874 | let item = f(self); |
| 833 | 875 | assert_eq!(owner_id, item.def_id()); |
| ... | ... | @@ -845,7 +887,7 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 845 | 887 | |
| 846 | 888 | #[cfg(debug_assertions)] |
| 847 | 889 | { |
| 848 | self.node_id_to_local_id = current_node_id_to_local_id; | |
| 890 | self.relowering_checker = current_relowering_checker; | |
| 849 | 891 | } |
| 850 | 892 | self.trait_map = current_trait_map; |
| 851 | 893 | self.current_hir_id_owner = current_owner; |
| ... | ... | @@ -936,10 +978,7 @@ impl<'hir> LoweringContext<'_, 'hir> { |
| 936 | 978 | |
| 937 | 979 | // Check whether the same `NodeId` is lowered more than once. |
| 938 | 980 | #[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); | |
| 943 | 982 | |
| 944 | 983 | hir_id |
| 945 | 984 | } |
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> { |
| 1180 | 1180 | // vs. copying a struct with mixed types requires different derivative handling. |
| 1181 | 1181 | // The TypeTree tells Enzyme exactly what memory layout to expect. |
| 1182 | 1182 | 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); | |
| 1184 | 1184 | } |
| 1185 | 1185 | } |
| 1186 | 1186 |
compiler/rustc_codegen_llvm/src/builder/autodiff.rs+10-17| ... | ... | @@ -143,7 +143,6 @@ pub(crate) fn adjust_activity_to_abi<'tcx>( |
| 143 | 143 | // FIXME(ZuseZ4): This logic is a bit more complicated than it should be, can we simplify it |
| 144 | 144 | // using iterators and peek()? |
| 145 | 145 | fn match_args_from_caller_to_enzyme<'ll, 'tcx>( |
| 146 | cx: &SimpleCx<'ll>, | |
| 147 | 146 | builder: &mut Builder<'_, 'll, 'tcx>, |
| 148 | 147 | width: u32, |
| 149 | 148 | args: &mut Vec<&'ll Value>, |
| ... | ... | @@ -157,6 +156,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( |
| 157 | 156 | // need to match those. |
| 158 | 157 | // FIXME(ZuseZ4): This logic is a bit more complicated than it should be, can we simplify it |
| 159 | 158 | // using iterators and peek()? |
| 159 | let cx = &builder.scx; | |
| 160 | 160 | let mut outer_pos: usize = 0; |
| 161 | 161 | let mut activity_pos = 0; |
| 162 | 162 | |
| ... | ... | @@ -292,8 +292,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( |
| 292 | 292 | // FIXME(ZuseZ4): `outer_fn` should include upstream safety checks to |
| 293 | 293 | // cover some assumptions of enzyme/autodiff, which could lead to UB otherwise. |
| 294 | 294 | pub(crate) fn generate_enzyme_call<'ll, 'tcx>( |
| 295 | builder: &mut Builder<'_, 'll, 'tcx>, | |
| 296 | cx: &SimpleCx<'ll>, | |
| 295 | bx: &mut Builder<'_, 'll, 'tcx>, | |
| 297 | 296 | fn_to_diff: &'ll Value, |
| 298 | 297 | outer_name: &str, |
| 299 | 298 | ret_ty: &'ll Type, |
| ... | ... | @@ -303,6 +302,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>( |
| 303 | 302 | dest_place: Option<PlaceValue<&'ll Value>>, |
| 304 | 303 | fnc_tree: FncTree, |
| 305 | 304 | ) -> IntrinsicResult<'tcx, &'ll Value> { |
| 305 | let cx: &SimpleCx<'ll> = &bx.scx; | |
| 306 | 306 | // We have to pick the name depending on whether we want forward or reverse mode autodiff. |
| 307 | 307 | let mut ad_name: String = match attrs.mode { |
| 308 | 308 | DiffMode::Forward => "__enzyme_fwddiff", |
| ... | ... | @@ -369,34 +369,27 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>( |
| 369 | 369 | args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64)); |
| 370 | 370 | } |
| 371 | 371 | |
| 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); | |
| 380 | 373 | |
| 381 | 374 | 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); | |
| 383 | 376 | } |
| 384 | 377 | |
| 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); | |
| 386 | 379 | |
| 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) { | |
| 389 | 382 | // If we return void or an empty struct, then our caller (due to how we generated it) |
| 390 | 383 | // does not expect a return value. As such, we have no pointer (or place) into which |
| 391 | 384 | // we could store our value, and would store into an undef, which would cause UB. |
| 392 | 385 | // As such, we just ignore the return value in those cases. |
| 393 | 386 | IntrinsicResult::Operand(OperandValue::ZeroSized) |
| 394 | 387 | } else if let Some(dest_place) = dest_place { |
| 395 | builder.store_to_place(call, dest_place); | |
| 388 | bx.store_to_place(call, dest_place); | |
| 396 | 389 | IntrinsicResult::WroteIntoPlace |
| 397 | 390 | } else { |
| 398 | 391 | 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, | |
| 400 | 393 | ) |
| 401 | 394 | } |
| 402 | 395 | } |
compiler/rustc_codegen_llvm/src/intrinsic.rs+2-3| ... | ... | @@ -225,7 +225,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { |
| 225 | 225 | ) |
| 226 | 226 | } |
| 227 | 227 | 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); | |
| 229 | 229 | } |
| 230 | 230 | sym::offload => { |
| 231 | 231 | if tcx.sess.opts.unstable_opts.offload.is_empty() { |
| ... | ... | @@ -1743,12 +1743,12 @@ fn codegen_retag_inner<'ll, 'tcx>( |
| 1743 | 1743 | |
| 1744 | 1744 | fn codegen_autodiff<'ll, 'tcx>( |
| 1745 | 1745 | bx: &mut Builder<'_, 'll, 'tcx>, |
| 1746 | tcx: TyCtxt<'tcx>, | |
| 1747 | 1746 | instance: ty::Instance<'tcx>, |
| 1748 | 1747 | args: &[OperandRef<'tcx, &'ll Value>], |
| 1749 | 1748 | result_layout: ty::layout::TyAndLayout<'tcx>, |
| 1750 | 1749 | result_place: Option<PlaceValue<&'ll Value>>, |
| 1751 | 1750 | ) -> IntrinsicResult<'tcx, &'ll Value> { |
| 1751 | let tcx = bx.tcx; | |
| 1752 | 1752 | if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) { |
| 1753 | 1753 | let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable); |
| 1754 | 1754 | } |
| ... | ... | @@ -1815,7 +1815,6 @@ fn codegen_autodiff<'ll, 'tcx>( |
| 1815 | 1815 | // Build body |
| 1816 | 1816 | generate_enzyme_call( |
| 1817 | 1817 | bx, |
| 1818 | bx.cx, | |
| 1819 | 1818 | fn_to_diff, |
| 1820 | 1819 | &diff_symbol, |
| 1821 | 1820 | llret_ty, |
compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs+6| ... | ... | @@ -66,6 +66,7 @@ unsafe extern "C" { |
| 66 | 66 | NameLen: libc::size_t, |
| 67 | 67 | ) -> Option<&Value>; |
| 68 | 68 | |
| 69 | pub(crate) safe fn LLVMRustIsCall(V: &Value) -> bool; | |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | unsafe extern "C" { |
| ... | ... | @@ -292,6 +293,11 @@ pub(crate) mod Enzyme_AD { |
| 292 | 293 | unsafe { (self.EnzymeTypeTreeToString)(tree) } |
| 293 | 294 | } |
| 294 | 295 | |
| 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 | ||
| 295 | 301 | pub(crate) fn tree_to_string_free(&self, ch: *const c_char) { |
| 296 | 302 | unsafe { (self.EnzymeTypeTreeToStringFree)(ch) } |
| 297 | 303 | } |
compiler/rustc_codegen_llvm/src/llvm/mod.rs+15| ... | ... | @@ -76,6 +76,21 @@ pub(crate) fn CreateAttrStringValue<'ll>( |
| 76 | 76 | ) |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | pub(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 | } | |
| 79 | 94 | |
| 80 | 95 | pub(crate) fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute { |
| 81 | 96 | unsafe { |
compiler/rustc_codegen_llvm/src/typetree.rs+119-50| ... | ... | @@ -1,35 +1,47 @@ |
| 1 | use std::ffi::{CString, c_char, c_uint}; | |
| 1 | use std::ffi::{CString, c_char}; | |
| 2 | 2 | |
| 3 | use rustc_ast::expand::typetree::{FncTree, TypeTree as RustTypeTree}; | |
| 3 | use rustc_ast::expand::typetree::{FncTree, Kind, TypeTree as RustTypeTree}; | |
| 4 | 4 | |
| 5 | 5 | use crate::attributes; |
| 6 | use crate::context::FullCx; | |
| 6 | 7 | use crate::llvm::{self, EnzymeWrapper, Value}; |
| 7 | 8 | |
| 8 | 9 | fn to_enzyme_typetree( |
| 9 | rust_typetree: RustTypeTree, | |
| 10 | rust_typetree: &RustTypeTree, | |
| 10 | 11 | _data_layout: &str, |
| 11 | 12 | llcx: &llvm::Context, |
| 12 | ) -> llvm::TypeTree { | |
| 13 | ) -> (llvm::TypeTree, Vec<llvm::TypeTree>) { | |
| 13 | 14 | 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) | |
| 16 | 25 | } |
| 26 | ||
| 17 | 27 | fn process_typetree_recursive( |
| 18 | 28 | enzyme_tt: &mut llvm::TypeTree, |
| 19 | 29 | rust_typetree: &RustTypeTree, |
| 20 | 30 | parent_indices: &[i64], |
| 21 | 31 | llcx: &llvm::Context, |
| 22 | ) { | |
| 32 | ) -> u32 { | |
| 33 | let mut extra_ints = 0; | |
| 23 | 34 | for rust_type in &rust_typetree.0 { |
| 24 | 35 | 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, | |
| 33 | 45 | }; |
| 34 | 46 | |
| 35 | 47 | let mut indices = parent_indices.to_vec(); |
| ... | ... | @@ -43,21 +55,28 @@ fn process_typetree_recursive( |
| 43 | 55 | |
| 44 | 56 | enzyme_tt.insert(&indices, concrete_type, llcx); |
| 45 | 57 | |
| 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) | |
| 47 | 64 | && !rust_type.child.0.is_empty() |
| 48 | 65 | { |
| 49 | 66 | process_typetree_recursive(enzyme_tt, &rust_type.child, &indices, llcx); |
| 50 | 67 | } |
| 51 | 68 | } |
| 69 | extra_ints | |
| 70 | } | |
| 71 | ||
| 72 | // Describes all the locations in which we know how to apply an Enzyme TypeTree. | |
| 73 | enum TTLocation { | |
| 74 | Definition, | |
| 75 | Callsite, | |
| 52 | 76 | } |
| 53 | 77 | |
| 54 | 78 | #[cfg_attr(not(feature = "llvm_enzyme"), allow(unused))] |
| 55 | pub(crate) fn add_tt<'ll>( | |
| 56 | llmod: &'ll llvm::Module, | |
| 57 | llcx: &'ll llvm::Context, | |
| 58 | fn_def: &'ll Value, | |
| 59 | tt: FncTree, | |
| 60 | ) { | |
| 79 | pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: &'ll Value, tt: FncTree) { | |
| 61 | 80 | // TypeTree processing uses functions from Enzyme, which we might not have available if we did |
| 62 | 81 | // not build this compiler with `llvm_enzyme`. This feature is not strictly necessary, but |
| 63 | 82 | // skipping this function increases the chance that Enzyme fails to compile some code. |
| ... | ... | @@ -66,6 +85,16 @@ pub(crate) fn add_tt<'ll>( |
| 66 | 85 | #[cfg(not(feature = "llvm_enzyme"))] |
| 67 | 86 | return; |
| 68 | 87 | |
| 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; | |
| 69 | 98 | let inputs = tt.args; |
| 70 | 99 | let ret_tt: RustTypeTree = tt.ret; |
| 71 | 100 | |
| ... | ... | @@ -77,41 +106,81 @@ pub(crate) fn add_tt<'ll>( |
| 77 | 106 | let attr_name = "enzyme_type"; |
| 78 | 107 | let c_attr_name = CString::new(attr_name).unwrap(); |
| 79 | 108 | |
| 109 | let tt_location: TTLocation = | |
| 110 | if llvm::LLVMRustIsCall(fn_def) { TTLocation::Callsite } else { TTLocation::Definition }; | |
| 111 | ||
| 112 | let mut offset = 0; | |
| 80 | 113 | 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 | { | |
| 83 | 122 | 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 | } | |
| 96 | 137 | 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 | )); | |
| 97 | 165 | } |
| 98 | 166 | } |
| 99 | 167 | |
| 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() { | |
| 102 | 172 | 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 | } | |
| 115 | 184 | enzyme_wrapper.tree_to_string_free(c_str.as_ptr()); |
| 116 | 185 | } |
| 117 | 186 | } |
compiler/rustc_codegen_ssa/src/traits/builder.rs+8-2| ... | ... | @@ -2,10 +2,12 @@ use std::assert_matches; |
| 2 | 2 | use std::ops::Deref; |
| 3 | 3 | |
| 4 | 4 | use rustc_abi::{Align, Scalar, Size, WrappingRange}; |
| 5 | use rustc_ast::expand::typetree::{FncTree, TypeTree}; | |
| 5 | 6 | use rustc_hir::attrs::AttributeKind; |
| 6 | 7 | use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; |
| 7 | 8 | use rustc_middle::mir; |
| 8 | 9 | use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout}; |
| 10 | use rustc_middle::ty::typetree::typetree_from_ty; | |
| 9 | 11 | use rustc_middle::ty::{AtomicOrdering, Instance, Ty}; |
| 10 | 12 | use rustc_session::config::OptLevel; |
| 11 | 13 | use rustc_span::Span; |
| ... | ... | @@ -456,7 +458,7 @@ pub trait BuilderMethods<'a, 'tcx>: |
| 456 | 458 | src_align: Align, |
| 457 | 459 | size: Self::Value, |
| 458 | 460 | flags: MemFlags, |
| 459 | tt: Option<rustc_ast::expand::typetree::FncTree>, | |
| 461 | tt: Option<FncTree>, | |
| 460 | 462 | ); |
| 461 | 463 | fn memmove( |
| 462 | 464 | &mut self, |
| ... | ... | @@ -517,6 +519,10 @@ pub trait BuilderMethods<'a, 'tcx>: |
| 517 | 519 | let temp = self.load_operand(src.with_type(layout)); |
| 518 | 520 | temp.val.store_with_flags(self, dst.with_type(layout), flags); |
| 519 | 521 | } 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() }; | |
| 520 | 526 | let bytes = self.const_usize(layout.size.bytes()); |
| 521 | 527 | let bytes = if layout.peel_transparent_wrappers(self).ty.is_scalable_vector() { |
| 522 | 528 | let vscale = self.vscale(self.type_i64()); |
| ... | ... | @@ -524,7 +530,7 @@ pub trait BuilderMethods<'a, 'tcx>: |
| 524 | 530 | } else { |
| 525 | 531 | bytes |
| 526 | 532 | }; |
| 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)); | |
| 528 | 534 | } |
| 529 | 535 | } |
| 530 | 536 |
compiler/rustc_hir/src/hir.rs+1-1| ... | ... | @@ -3877,7 +3877,7 @@ pub enum DelegationSelfTyPropagationKind { |
| 3877 | 3877 | #[derive(Debug, Clone, Copy, PartialEq, Eq, StableHash)] |
| 3878 | 3878 | pub struct DelegationInfo { |
| 3879 | 3879 | pub call_expr_id: HirId, |
| 3880 | pub call_path_res: Option<DefId>, | |
| 3880 | pub call_path_res: DefId, | |
| 3881 | 3881 | |
| 3882 | 3882 | /// Id of the child segment in delegation: `reuse Trait::foo`, |
| 3883 | 3883 | /// `child_seg_id` points to `foo`. |
compiler/rustc_hir_analysis/src/autoderef.rs+4-4| ... | ... | @@ -34,7 +34,7 @@ pub struct Autoderef<'a, 'tcx> { |
| 34 | 34 | // Meta infos: |
| 35 | 35 | infcx: &'a InferCtxt<'tcx>, |
| 36 | 36 | span: Span, |
| 37 | body_id: LocalDefId, | |
| 37 | body_def_id: LocalDefId, | |
| 38 | 38 | param_env: ty::ParamEnv<'tcx>, |
| 39 | 39 | |
| 40 | 40 | // Current state: |
| ... | ... | @@ -119,7 +119,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { |
| 119 | 119 | Autoderef { |
| 120 | 120 | infcx, |
| 121 | 121 | span, |
| 122 | body_id: body_def_id, | |
| 122 | body_def_id, | |
| 123 | 123 | param_env, |
| 124 | 124 | state: AutoderefSnapshot { |
| 125 | 125 | steps: vec![], |
| ... | ... | @@ -149,7 +149,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { |
| 149 | 149 | (tcx.lang_items().deref_trait()?, tcx.lang_items().deref_target()?) |
| 150 | 150 | }; |
| 151 | 151 | 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); | |
| 153 | 153 | let obligation = traits::Obligation::new( |
| 154 | 154 | tcx, |
| 155 | 155 | cause.clone(), |
| ... | ... | @@ -181,7 +181,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { |
| 181 | 181 | ) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> { |
| 182 | 182 | let ocx = ObligationCtxt::new(self.infcx); |
| 183 | 183 | let normalized_ty = ocx.normalize( |
| 184 | &traits::ObligationCause::misc(self.span, self.body_id), | |
| 184 | &traits::ObligationCause::misc(self.span, self.body_def_id), | |
| 185 | 185 | self.param_env, |
| 186 | 186 | ty, |
| 187 | 187 | ); |
compiler/rustc_hir_analysis/src/check/compare_impl_item.rs+8-8| ... | ... | @@ -177,10 +177,10 @@ fn compare_method_predicate_entailment<'tcx>( |
| 177 | 177 | trait_m: ty::AssocItem, |
| 178 | 178 | impl_trait_ref: ty::TraitRef<'tcx>, |
| 179 | 179 | ) -> 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 | |
| 181 | 181 | // `ObligationCause` (and the `FnCtxt`). |
| 182 | 182 | // |
| 183 | // FIXME(@lcnr): remove that after removing `cause.body_id` from | |
| 183 | // FIXME(@lcnr): remove that after removing `cause.body_def_id` from | |
| 184 | 184 | // obligations. |
| 185 | 185 | let impl_m_def_id = impl_m.def_id.expect_local(); |
| 186 | 186 | let impl_m_span = tcx.def_span(impl_m_def_id); |
| ... | ... | @@ -798,7 +798,7 @@ struct ImplTraitInTraitCollector<'a, 'tcx, E> { |
| 798 | 798 | types: FxIndexMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>, |
| 799 | 799 | span: Span, |
| 800 | 800 | param_env: ty::ParamEnv<'tcx>, |
| 801 | body_id: LocalDefId, | |
| 801 | impl_m_id: LocalDefId, | |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | impl<'a, 'tcx, E> ImplTraitInTraitCollector<'a, 'tcx, E> |
| ... | ... | @@ -809,9 +809,9 @@ where |
| 809 | 809 | ocx: &'a ObligationCtxt<'a, 'tcx, E>, |
| 810 | 810 | span: Span, |
| 811 | 811 | param_env: ty::ParamEnv<'tcx>, |
| 812 | body_id: LocalDefId, | |
| 812 | impl_m_id: LocalDefId, | |
| 813 | 813 | ) -> Self { |
| 814 | ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id } | |
| 814 | ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, impl_m_id } | |
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | |
| ... | ... | @@ -847,7 +847,7 @@ where |
| 847 | 847 | { |
| 848 | 848 | let pred = pred.fold_with(self); |
| 849 | 849 | let pred = self.ocx.normalize( |
| 850 | &ObligationCause::misc(self.span, self.body_id), | |
| 850 | &ObligationCause::misc(self.span, self.impl_m_id), | |
| 851 | 851 | self.param_env, |
| 852 | 852 | Unnormalized::new_wip(pred), |
| 853 | 853 | ); |
| ... | ... | @@ -856,7 +856,7 @@ where |
| 856 | 856 | self.cx(), |
| 857 | 857 | ObligationCause::new( |
| 858 | 858 | self.span, |
| 859 | self.body_id, | |
| 859 | self.impl_m_id, | |
| 860 | 860 | ObligationCauseCode::WhereClause(def_id, pred_span), |
| 861 | 861 | ), |
| 862 | 862 | self.param_env, |
| ... | ... | @@ -2346,7 +2346,7 @@ fn compare_type_predicate_entailment<'tcx>( |
| 2346 | 2346 | return Ok(()); |
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 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 | |
| 2350 | 2350 | // `ObligationCause` (and the `FnCtxt`). This is what |
| 2351 | 2351 | // `regionck_item` expects. |
| 2352 | 2352 | 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> { |
| 431 | 431 | diag.span_note(impl_.self_ty.span, "not a concrete type"); |
| 432 | 432 | } |
| 433 | 433 | } |
| 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() { | |
| 440 | 436 | 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"); | |
| 441 | 444 | } |
| 442 | 445 | } |
| 443 | 446 | diag.emit() |
compiler/rustc_hir_typeck/src/_match.rs+2-2| ... | ... | @@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 216 | 216 | prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>, |
| 217 | 217 | ) { |
| 218 | 218 | // 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 { | |
| 220 | 220 | return; |
| 221 | 221 | }; |
| 222 | 222 | let hir::ExprKind::Block(block, _) = body.value.kind else { |
| ... | ... | @@ -233,7 +233,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 233 | 233 | |
| 234 | 234 | // Next, make sure that we have no type expectation. |
| 235 | 235 | 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()) | |
| 237 | 237 | else { |
| 238 | 238 | return; |
| 239 | 239 | }; |
compiler/rustc_hir_typeck/src/autoderef.rs+1-1| ... | ... | @@ -15,7 +15,7 @@ use super::{FnCtxt, PlaceOp}; |
| 15 | 15 | |
| 16 | 16 | impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 17 | 17 | 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) | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | 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( |
| 39 | 39 | receiver: Option<Span>, |
| 40 | 40 | expr_span: Span, |
| 41 | 41 | trait_id: DefId, |
| 42 | body_id: DefId, | |
| 42 | body_def_id: DefId, | |
| 43 | 43 | ) -> Result<(), ErrorGuaranteed> { |
| 44 | 44 | if tcx.is_lang_item(trait_id, LangItem::Drop) |
| 45 | 45 | // 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) | |
| 47 | 47 | { |
| 48 | 48 | let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) { |
| 49 | 49 | diagnostics::ExplicitDestructorCallSugg::Snippet { |
| ... | ... | @@ -724,17 +724,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 724 | 724 | return None; |
| 725 | 725 | }; |
| 726 | 726 | |
| 727 | let Some(path_res_id) = info.call_path_res else { return None }; | |
| 728 | ||
| 729 | 727 | // Check that delegation has first provided arg and that the call path |
| 730 | 728 | // resolves to a trait method (inherent methods are not yet supported). |
| 731 | 729 | 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()) | |
| 733 | 731 | { |
| 734 | 732 | return None; |
| 735 | 733 | } |
| 736 | 734 | |
| 737 | Some(ProbeScope::Single(path_res_id)) | |
| 735 | Some(ProbeScope::Single(info.call_path_res)) | |
| 738 | 736 | } |
| 739 | 737 | |
| 740 | 738 | /// Attempts to reinterpret `method(rcvr, args...)` as `rcvr.method(args...)` |
| ... | ... | @@ -1042,7 +1040,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1042 | 1040 | callee_did: DefId, |
| 1043 | 1041 | callee_args: GenericArgsRef<'tcx>, |
| 1044 | 1042 | ) { |
| 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); | |
| 1046 | 1044 | |
| 1047 | 1045 | if let hir::Constness::Const { always: true } = self.tcx.constness(callee_did) { |
| 1048 | 1046 | match const_context { |
| ... | ... | @@ -1062,7 +1060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1062 | 1060 | } |
| 1063 | 1061 | |
| 1064 | 1062 | // 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) { | |
| 1066 | 1064 | return; |
| 1067 | 1065 | } |
| 1068 | 1066 |
compiler/rustc_hir_typeck/src/cast.rs+10-3| ... | ... | @@ -64,7 +64,7 @@ pub(crate) struct CastCheck<'tcx> { |
| 64 | 64 | cast_ty: Ty<'tcx>, |
| 65 | 65 | cast_span: Span, |
| 66 | 66 | span: Span, |
| 67 | pub body_id: LocalDefId, | |
| 67 | pub body_def_id: LocalDefId, | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /// The kind of pointer and associated metadata (thin, length or vtable) - we |
| ... | ... | @@ -247,8 +247,15 @@ impl<'a, 'tcx> CastCheck<'tcx> { |
| 247 | 247 | span: Span, |
| 248 | 248 | ) -> Result<CastCheck<'tcx>, ErrorGuaranteed> { |
| 249 | 249 | 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 | }; | |
| 252 | 259 | |
| 253 | 260 | // For better error messages, check for some obviously unsized |
| 254 | 261 | // 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> { |
| 1258 | 1258 | let sig = if fn_attrs.safe_target_features { |
| 1259 | 1259 | // Allow the coercion if the current function has all the features that would be |
| 1260 | 1260 | // 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()) { | |
| 1262 | 1262 | Some(adjusted_sig) => adjusted_sig, |
| 1263 | 1263 | None if matches!(expected_safety, Some(hir::Safety::Safe)) => { |
| 1264 | 1264 | return Err(TypeError::TargetFeatureCast(def_id)); |
| ... | ... | @@ -1477,12 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1477 | 1477 | pub fn can_coerce<'tcx>( |
| 1478 | 1478 | tcx: TyCtxt<'tcx>, |
| 1479 | 1479 | param_env: ty::ParamEnv<'tcx>, |
| 1480 | body_id: LocalDefId, | |
| 1480 | body_def_id: LocalDefId, | |
| 1481 | 1481 | ty: Ty<'tcx>, |
| 1482 | 1482 | output_ty: Ty<'tcx>, |
| 1483 | 1483 | ) -> 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); | |
| 1486 | 1486 | fn_ctxt.may_coerce(ty, output_ty) |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| ... | ... | @@ -2057,7 +2057,7 @@ impl<'tcx> CoerceMany<'tcx> { |
| 2057 | 2057 | if due_to_block |
| 2058 | 2058 | && let Some(expr) = expression |
| 2059 | 2059 | && 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)) | |
| 2061 | 2061 | { |
| 2062 | 2062 | fcx.suggest_missing_break_or_return_expr( |
| 2063 | 2063 | &mut err, |
| ... | ... | @@ -2066,14 +2066,14 @@ impl<'tcx> CoerceMany<'tcx> { |
| 2066 | 2066 | expected, |
| 2067 | 2067 | found, |
| 2068 | 2068 | block_or_return_id, |
| 2069 | fcx.body_id, | |
| 2069 | fcx.body_def_id, | |
| 2070 | 2070 | ); |
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | let is_return_position = fcx |
| 2074 | 2074 | .tcx |
| 2075 | 2075 | .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)); | |
| 2077 | 2077 | |
| 2078 | 2078 | if is_return_position |
| 2079 | 2079 | && let Some(sp) = fcx.ret_coercion_span.get() |
| ... | ... | @@ -2083,7 +2083,7 @@ impl<'tcx> CoerceMany<'tcx> { |
| 2083 | 2083 | // may occur at the first return expression we see in the closure |
| 2084 | 2084 | // (if it conflicts with the declared return type). Skip adding a |
| 2085 | 2085 | // 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() | |
| 2087 | 2087 | && fn_sig.output().is_ty_var() |
| 2088 | 2088 | { |
| 2089 | 2089 | err.span_note(sp, format!("return type inferred to be `{expected}` here")); |
| ... | ... | @@ -2096,7 +2096,7 @@ impl<'tcx> CoerceMany<'tcx> { |
| 2096 | 2096 | /// sure we consider `dyn Trait: Sized` where clauses, which are trivially |
| 2097 | 2097 | /// false but technically valid for typeck. |
| 2098 | 2098 | 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() { | |
| 2100 | 2100 | !fcx.predicate_may_hold(&Obligation::new( |
| 2101 | 2101 | fcx.tcx, |
| 2102 | 2102 | ObligationCause::dummy(), |
compiler/rustc_hir_typeck/src/demand.rs+1-1| ... | ... | @@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | 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); | |
| 336 | 336 | expr_finder.visit_expr(body.value); |
| 337 | 337 | |
| 338 | 338 | // 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> { |
| 76 | 76 | pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> { |
| 77 | 77 | let span = match ty.kind() { |
| 78 | 78 | 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), | |
| 80 | 80 | }; |
| 81 | let cause = ObligationCause::misc(span, fcx.body_id); | |
| 81 | let cause = ObligationCause::misc(span, fcx.body_def_id); | |
| 82 | 82 | |
| 83 | 83 | // FIXME(#155345): Missing normalization call |
| 84 | 84 | 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> { |
| 965 | 965 | return_expr_ty, |
| 966 | 966 | ); |
| 967 | 967 | |
| 968 | if let Some(fn_sig) = self.body_fn_sig() | |
| 968 | if let Some(fn_sig) = self.fn_sig() | |
| 969 | 969 | && fn_sig.output().has_opaque_types() |
| 970 | 970 | { |
| 971 | 971 | // Point any obligations that were registered due to opaque type |
| ... | ... | @@ -2764,8 +2764,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2764 | 2764 | return Ty::new_error(self.tcx(), guar); |
| 2765 | 2765 | } |
| 2766 | 2766 | |
| 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 | ); | |
| 2769 | 2772 | |
| 2770 | 2773 | if let Some((idx, field)) = self.find_adt_field(*base_def, ident) { |
| 2771 | 2774 | self.write_field_index(expr.hir_id, idx); |
| ... | ... | @@ -2938,7 +2941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2938 | 2941 | field_ident.span, |
| 2939 | 2942 | "field not available in `impl Future`, but it is available in its `Output`", |
| 2940 | 2943 | ); |
| 2941 | match self.tcx.coroutine_kind(self.body_id) { | |
| 2944 | match self.tcx.coroutine_kind(self.body_def_id) { | |
| 2942 | 2945 | Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => { |
| 2943 | 2946 | err.span_suggestion_verbose( |
| 2944 | 2947 | base.span.shrink_to_hi(), |
| ... | ... | @@ -2949,7 +2952,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2949 | 2952 | } |
| 2950 | 2953 | _ => { |
| 2951 | 2954 | 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`"); | |
| 2953 | 2956 | err.span_note( |
| 2954 | 2957 | span, |
| 2955 | 2958 | "this implements `Future` and its output type has the field, \ |
| ... | ... | @@ -3119,7 +3122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3119 | 3122 | } |
| 3120 | 3123 | |
| 3121 | 3124 | 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); | |
| 3123 | 3126 | let generic_param = generics.type_param(param, self.tcx); |
| 3124 | 3127 | if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind { |
| 3125 | 3128 | return; |
| ... | ... | @@ -3703,7 +3706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3703 | 3706 | |
| 3704 | 3707 | fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) -> Ty<'tcx> { |
| 3705 | 3708 | 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(..)) { | |
| 3707 | 3710 | self.tcx.dcx().emit_err(NakedAsmOutsideNakedFn { span }); |
| 3708 | 3711 | } |
| 3709 | 3712 | } |
| ... | ... | @@ -3802,8 +3805,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3802 | 3805 | .emit(); |
| 3803 | 3806 | break; |
| 3804 | 3807 | }; |
| 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 | ); | |
| 3807 | 3813 | |
| 3808 | 3814 | let Some((subindex, field)) = variant |
| 3809 | 3815 | .fields |
| ... | ... | @@ -3854,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3854 | 3860 | let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope( |
| 3855 | 3861 | field, |
| 3856 | 3862 | container_def.did(), |
| 3857 | self.body_id, | |
| 3863 | self.body_def_id, | |
| 3858 | 3864 | ); |
| 3859 | 3865 | |
| 3860 | 3866 | 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> { |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | fn body_owner_def_id(&self) -> LocalDefId { |
| 220 | self.body_id | |
| 220 | self.body_def_id | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | fn tcx(&self) -> TyCtxt<'tcx> { |
compiler/rustc_hir_typeck/src/fallback.rs+7-8| ... | ... | @@ -293,7 +293,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 293 | 293 | root_vid: ty::TyVid, |
| 294 | 294 | ) { |
| 295 | 295 | 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); | |
| 297 | 297 | debug!(?unsafe_infer_vars); |
| 298 | 298 | unsafe_infer_vars |
| 299 | 299 | }); |
| ... | ... | @@ -378,8 +378,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 378 | 378 | let sugg = self.try_to_suggest_annotations(diverging_vids, coercions); |
| 379 | 379 | self.tcx.emit_node_span_lint( |
| 380 | 380 | 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), | |
| 383 | 383 | diagnostics::DependencyOnUnitNeverTypeFallback { |
| 384 | 384 | obligation_span: never_error.obligation.cause.span, |
| 385 | 385 | obligation: never_error.obligation.predicate, |
| ... | ... | @@ -446,8 +446,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 446 | 446 | diverging_vids: &[ty::TyVid], |
| 447 | 447 | coercions: &VecGraph<ty::TyVid, true>, |
| 448 | 448 | ) -> 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); | |
| 451 | 450 | // For each diverging var, look through the HIR for a place to give it |
| 452 | 451 | // a type annotation. We do this per var because we only really need one |
| 453 | 452 | // suggestion to influence a var to be `()`. |
| ... | ... | @@ -633,9 +632,9 @@ pub(crate) enum UnsafeUseReason { |
| 633 | 632 | /// `compute_unsafe_infer_vars` will return `{ id(?X) -> (hir_id, span, Call) }` |
| 634 | 633 | fn compute_unsafe_infer_vars<'a, 'tcx>( |
| 635 | 634 | fcx: &'a FnCtxt<'a, 'tcx>, |
| 636 | body_id: LocalDefId, | |
| 635 | body_def_id: LocalDefId, | |
| 637 | 636 | ) -> 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); | |
| 639 | 638 | let mut res = UnordMap::default(); |
| 640 | 639 | |
| 641 | 640 | struct UnsafeInferVarsVisitor<'a, 'tcx> { |
| ... | ... | @@ -763,7 +762,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>( |
| 763 | 762 | |
| 764 | 763 | UnsafeInferVarsVisitor { fcx, res: &mut res }.visit_expr(&body.value); |
| 765 | 764 | |
| 766 | debug!(?res, "collected the following unsafe vars for {body_id:?}"); | |
| 765 | debug!(?res, "collected the following unsafe vars for {body_def_id:?}"); | |
| 767 | 766 | |
| 768 | 767 | res |
| 769 | 768 | } |
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+5-5| ... | ... | @@ -213,7 +213,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 213 | 213 | // let it keep doing that and just ensure that compilation won't succeed. |
| 214 | 214 | self.dcx().span_delayed_bug( |
| 215 | 215 | 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), | |
| 217 | 217 | ); |
| 218 | 218 | } |
| 219 | 219 | } |
| ... | ... | @@ -1070,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1070 | 1070 | arg_span, |
| 1071 | 1071 | span, |
| 1072 | 1072 | container_id, |
| 1073 | self.body_id.to_def_id(), | |
| 1073 | self.body_def_id.to_def_id(), | |
| 1074 | 1074 | ) { |
| 1075 | 1075 | self.set_tainted_by_errors(e); |
| 1076 | 1076 | } |
| ... | ... | @@ -1192,7 +1192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1192 | 1192 | // error in `validate_res_from_ribs` -- it's just difficult to tell whether the |
| 1193 | 1193 | // self type has any generic types during rustc_resolve, which is what we use |
| 1194 | 1194 | // 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| { | |
| 1196 | 1196 | self.tcx.generics_of(def_id).parent |
| 1197 | 1197 | }) |
| 1198 | 1198 | .all(|def_id| def_id != impl_def_id) |
| ... | ... | @@ -1534,7 +1534,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1534 | 1534 | let guar = self.tainted_by_errors().unwrap_or_else(|| { |
| 1535 | 1535 | self.err_ctxt() |
| 1536 | 1536 | .emit_inference_failure_err( |
| 1537 | self.body_id, | |
| 1537 | self.body_def_id, | |
| 1538 | 1538 | sp, |
| 1539 | 1539 | ty.into(), |
| 1540 | 1540 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -1560,7 +1560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1560 | 1560 | let e = self.tainted_by_errors().unwrap_or_else(|| { |
| 1561 | 1561 | self.err_ctxt() |
| 1562 | 1562 | .emit_inference_failure_err( |
| 1563 | self.body_id, | |
| 1563 | self.body_def_id, | |
| 1564 | 1564 | sp, |
| 1565 | 1565 | ct.into(), |
| 1566 | 1566 | TypeAnnotationNeeded::E0282, |
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+5-5| ... | ... | @@ -68,9 +68,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 68 | 68 | let mut deferred_cast_checks = self.root_ctxt.deferred_cast_checks.borrow_mut(); |
| 69 | 69 | debug!("FnCtxt::check_casts: {} deferred checks", deferred_cast_checks.len()); |
| 70 | 70 | 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); | |
| 72 | 72 | cast.check(self); |
| 73 | self.body_id = body_id; | |
| 73 | self.body_def_id = body_def_id; | |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| ... | ... | @@ -346,7 +346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 346 | 346 | // in `execute_delegation_aware_arguments_check`. |
| 347 | 347 | let checked_ty = self |
| 348 | 348 | .tcx |
| 349 | .hir_opt_delegation_info(self.body_id) | |
| 349 | .hir_opt_delegation_info(self.body_def_id) | |
| 350 | 350 | .and_then(|_| self.typeck_results.borrow().node_type_opt(provided_arg.hir_id)) |
| 351 | 351 | .unwrap_or_else(|| self.check_expr_with_expectation(provided_arg, expectation)); |
| 352 | 352 | |
| ... | ... | @@ -1627,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1627 | 1627 | let callee_ty = callee_ty.peel_refs(); |
| 1628 | 1628 | match *callee_ty.kind() { |
| 1629 | 1629 | 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); | |
| 1631 | 1631 | if param.kind.is_synthetic() { |
| 1632 | 1632 | // if it's `impl Fn() -> ..` then just fall down to the def-id based logic |
| 1633 | 1633 | def_id = param.def_id; |
| ... | ... | @@ -1636,7 +1636,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1636 | 1636 | // and point at that. |
| 1637 | 1637 | let instantiated = self |
| 1638 | 1638 | .tcx |
| 1639 | .explicit_predicates_of(self.body_id) | |
| 1639 | .explicit_predicates_of(self.body_def_id) | |
| 1640 | 1640 | .instantiate_identity(self.tcx); |
| 1641 | 1641 | // FIXME(compiler-errors): This could be problematic if something has two |
| 1642 | 1642 | // 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}; |
| 43 | 43 | /// |
| 44 | 44 | /// [`InferCtxt`]: infer::InferCtxt |
| 45 | 45 | pub(crate) struct FnCtxt<'a, 'tcx> { |
| 46 | pub(super) body_id: LocalDefId, | |
| 46 | pub(super) body_def_id: LocalDefId, | |
| 47 | 47 | |
| 48 | 48 | /// The parameter environment used for proving trait obligations |
| 49 | 49 | /// in this function. This can change when we descend into |
| ... | ... | @@ -138,12 +138,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 138 | 138 | pub(crate) fn new( |
| 139 | 139 | root_ctxt: &'a TypeckRootCtxt<'tcx>, |
| 140 | 140 | param_env: ty::ParamEnv<'tcx>, |
| 141 | body_id: LocalDefId, | |
| 141 | body_def_id: LocalDefId, | |
| 142 | 142 | ) -> FnCtxt<'a, 'tcx> { |
| 143 | 143 | let (diverging_fallback_behavior, diverging_block_behavior) = |
| 144 | 144 | never_type_behavior(root_ctxt.tcx); |
| 145 | 145 | FnCtxt { |
| 146 | body_id, | |
| 146 | body_def_id, | |
| 147 | 147 | param_env, |
| 148 | 148 | ret_coercion: None, |
| 149 | 149 | ret_coercion_span: Cell::new(None), |
| ... | ... | @@ -179,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 179 | 179 | span: Span, |
| 180 | 180 | code: ObligationCauseCode<'tcx>, |
| 181 | 181 | ) -> ObligationCause<'tcx> { |
| 182 | ObligationCause::new(span, self.body_id, code) | |
| 182 | ObligationCause::new(span, self.body_def_id, code) | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | pub(crate) fn misc(&self, span: Span) -> ObligationCause<'tcx> { |
| ... | ... | @@ -230,7 +230,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | fn item_def_id(&self) -> LocalDefId { |
| 233 | self.body_id | |
| 233 | self.body_def_id | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | 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; |
| 40 | 40 | use crate::method::probe::{IsSuggestion, Mode, ProbeScope}; |
| 41 | 41 | |
| 42 | 42 | impl<'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>> { | |
| 44 | 44 | self.typeck_results |
| 45 | 45 | .borrow() |
| 46 | 46 | .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)) | |
| 48 | 48 | .copied() |
| 49 | 49 | } |
| 50 | 50 | |
| ... | ... | @@ -170,7 +170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 170 | 170 | &self, |
| 171 | 171 | ty: Ty<'tcx>, |
| 172 | 172 | ) -> 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) | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | pub(crate) fn suggest_two_fn_call( |
| ... | ... | @@ -2292,7 +2292,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2292 | 2292 | return false; |
| 2293 | 2293 | }; |
| 2294 | 2294 | let ret_ty_matches = |diagnostic_item| { |
| 2295 | let Some(sig) = self.body_fn_sig() else { | |
| 2295 | let Some(sig) = self.fn_sig() else { | |
| 2296 | 2296 | return false; |
| 2297 | 2297 | }; |
| 2298 | 2298 | 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> { |
| 193 | 193 | // ascription, or if it's an implicit `self` parameter |
| 194 | 194 | ObligationCauseCode::SizedArgumentType( |
| 195 | 195 | 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()) | |
| 197 | 197 | { |
| 198 | 198 | None |
| 199 | 199 | } else { |
compiler/rustc_hir_typeck/src/lib.rs+1-1| ... | ... | @@ -378,7 +378,7 @@ fn extend_err_with_const_context( |
| 378 | 378 | |
| 379 | 379 | fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Option<Ty<'tcx>> { |
| 380 | 380 | let tcx = fcx.tcx; |
| 381 | let def_id = fcx.body_id; | |
| 381 | let def_id = fcx.body_def_id; | |
| 382 | 382 | let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer(()), span, .. }) = node.ty() |
| 383 | 383 | { |
| 384 | 384 | 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> { |
| 702 | 702 | Some(self.self_expr.span), |
| 703 | 703 | self.call_expr.span, |
| 704 | 704 | trait_def_id, |
| 705 | self.body_id.to_def_id(), | |
| 705 | self.body_def_id.to_def_id(), | |
| 706 | 706 | ) |
| 707 | 707 | { |
| 708 | 708 | 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> { |
| 511 | 511 | && !self.tcx.features().arbitrary_self_types(); |
| 512 | 512 | |
| 513 | 513 | let mut err = self.err_ctxt().emit_inference_failure_err( |
| 514 | self.body_id, | |
| 514 | self.body_def_id, | |
| 515 | 515 | err_span, |
| 516 | 516 | ty.into(), |
| 517 | 517 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -811,7 +811,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { |
| 811 | 811 | let is_accessible = if let Some(name) = self.method_name { |
| 812 | 812 | let item = candidate.item; |
| 813 | 813 | 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; | |
| 815 | 816 | item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx) |
| 816 | 817 | } else { |
| 817 | 818 | true |
compiler/rustc_hir_typeck/src/method/suggest.rs+9-9| ... | ... | @@ -160,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 160 | 160 | |
| 161 | 161 | match *ty.peel_refs().kind() { |
| 162 | 162 | ty::Param(param) => { |
| 163 | let generics = self.tcx.generics_of(self.body_id); | |
| 163 | let generics = self.tcx.generics_of(self.body_def_id); | |
| 164 | 164 | let generic_param = generics.type_param(param, self.tcx); |
| 165 | 165 | for unsatisfied in unsatisfied_predicates.iter() { |
| 166 | 166 | // The parameter implements `IntoIterator` |
| ... | ... | @@ -634,7 +634,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 634 | 634 | impl<'a, 'tcx> LetVisitor<'a, 'tcx> { |
| 635 | 635 | // Check scope of binding. |
| 636 | 636 | 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); | |
| 638 | 638 | if let Some(sub_var_scope) = scope_tree.var_scope(sub_id) |
| 639 | 639 | && let Some(super_var_scope) = scope_tree.var_scope(super_id) |
| 640 | 640 | && scope_tree.is_subscope_of(sub_var_scope, super_var_scope) |
| ... | ... | @@ -742,7 +742,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 742 | 742 | && let hir::def::Res::Local(recv_id) = path.res |
| 743 | 743 | && let Some(segment) = path.segments.first() |
| 744 | 744 | { |
| 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); | |
| 746 | 746 | |
| 747 | 747 | if let Node::Expr(call_expr) = self.tcx.parent_hir_node(rcvr.hir_id) { |
| 748 | 748 | let mut let_visitor = LetVisitor { |
| ... | ... | @@ -1148,7 +1148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1148 | 1148 | ) { |
| 1149 | 1149 | let mut ty_span = match rcvr_ty.kind() { |
| 1150 | 1150 | 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())) | |
| 1152 | 1152 | } |
| 1153 | 1153 | ty::Adt(def, _) if def.did().is_local() => Some(self.tcx.def_span(def.did())), |
| 1154 | 1154 | _ => None, |
| ... | ... | @@ -1779,7 +1779,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1779 | 1779 | ty::Param(_) => { |
| 1780 | 1780 | // Account for `fn` items like in `issue-35677.rs` to |
| 1781 | 1781 | // 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)) | |
| 1783 | 1783 | } |
| 1784 | 1784 | ty::Adt(def, _) => { |
| 1785 | 1785 | 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> { |
| 2842 | 2842 | _ => None, |
| 2843 | 2843 | }); |
| 2844 | 2844 | 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); | |
| 2846 | 2846 | let is_accessible = field.vis.is_accessible_from(scope, tcx); |
| 2847 | 2847 | |
| 2848 | 2848 | if is_accessible { |
| ... | ... | @@ -3147,7 +3147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3147 | 3147 | seg1.ident.span, |
| 3148 | 3148 | StashKey::CallAssocMethod, |
| 3149 | 3149 | |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); | |
| 3151 | 3151 | struct LetVisitor { |
| 3152 | 3152 | ident_name: Symbol, |
| 3153 | 3153 | } |
| ... | ... | @@ -3997,7 +3997,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3997 | 3997 | { |
| 3998 | 3998 | let parent_map = self.tcx.visible_parent_map(()); |
| 3999 | 3999 | |
| 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); | |
| 4001 | 4001 | let (accessible_candidates, inaccessible_candidates): (Vec<_>, Vec<_>) = |
| 4002 | 4002 | candidates.into_iter().partition(|id| { |
| 4003 | 4003 | let vis = self.tcx.visibility(*id); |
| ... | ... | @@ -4555,7 +4555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 4555 | 4555 | }; |
| 4556 | 4556 | // Obtain the span for `param` and use it for a structured suggestion. |
| 4557 | 4557 | 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()); | |
| 4559 | 4559 | let type_param = generics.type_param(param, self.tcx); |
| 4560 | 4560 | let tcx = self.tcx; |
| 4561 | 4561 | 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> { |
| 517 | 517 | &mut err, |
| 518 | 518 | trait_pred, |
| 519 | 519 | output_associated_item, |
| 520 | self.body_id, | |
| 520 | self.body_def_id, | |
| 521 | 521 | ); |
| 522 | 522 | } |
| 523 | 523 | } |
| ... | ... | @@ -1004,7 +1004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1004 | 1004 | &mut err, |
| 1005 | 1005 | pred, |
| 1006 | 1006 | None, |
| 1007 | self.body_id, | |
| 1007 | self.body_def_id, | |
| 1008 | 1008 | ); |
| 1009 | 1009 | } |
| 1010 | 1010 | } |
compiler/rustc_hir_typeck/src/opaque_types.rs+9-4| ... | ... | @@ -163,13 +163,18 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 163 | 163 | if let Some(guar) = self.tainted_by_errors() { |
| 164 | 164 | guar |
| 165 | 165 | } 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 | ) | |
| 167 | 172 | } |
| 168 | 173 | } |
| 169 | 174 | UsageKind::NonDefiningUse(opaque_type_key, hidden_type) => { |
| 170 | 175 | report_item_does_not_constrain_error( |
| 171 | 176 | self.tcx, |
| 172 | self.body_id, | |
| 177 | self.body_def_id, | |
| 173 | 178 | def_id, |
| 174 | 179 | Some((opaque_type_key, hidden_type.span)), |
| 175 | 180 | ) |
| ... | ... | @@ -186,7 +191,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 186 | 191 | .unwrap_or_else(|| hidden_type.ty.into()); |
| 187 | 192 | self.err_ctxt() |
| 188 | 193 | .emit_inference_failure_err( |
| 189 | self.body_id, | |
| 194 | self.body_def_id, | |
| 190 | 195 | hidden_type.span, |
| 191 | 196 | infer_var, |
| 192 | 197 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -235,7 +240,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 235 | 240 | return UsageKind::UnconstrainedHiddenType(hidden_type); |
| 236 | 241 | } |
| 237 | 242 | |
| 238 | let cause = ObligationCause::misc(hidden_type.span, self.body_id); | |
| 243 | let cause = ObligationCause::misc(hidden_type.span, self.body_def_id); | |
| 239 | 244 | let at = self.at(&cause, self.param_env); |
| 240 | 245 | let hidden_type = match solve::deeply_normalize(at, Unnormalized::new_wip(hidden_type)) { |
| 241 | 246 | Ok(hidden_type) => hidden_type, |
compiler/rustc_hir_typeck/src/writeback.rs+2-2| ... | ... | @@ -948,8 +948,8 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { |
| 948 | 948 | // We must deeply normalize in the new solver, since later lints expect |
| 949 | 949 | // that types that show up in the typeck are fully normalized. |
| 950 | 950 | 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); | |
| 953 | 953 | let at = self.fcx.at(&cause, self.fcx.param_env); |
| 954 | 954 | let universes = vec![None; outer_exclusive_binder(&value).as_usize()]; |
| 955 | 955 | 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> { |
| 26 | 26 | pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<TyCtxt<'tcx>>>( |
| 27 | 27 | &self, |
| 28 | 28 | value: T, |
| 29 | body_id: LocalDefId, | |
| 29 | body_def_id: LocalDefId, | |
| 30 | 30 | span: Span, |
| 31 | 31 | param_env: ty::ParamEnv<'tcx>, |
| 32 | 32 | ) -> InferOk<'tcx, T> { |
| ... | ... | @@ -60,7 +60,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 60 | 60 | self.tcx, |
| 61 | 61 | ObligationCause::new( |
| 62 | 62 | span, |
| 63 | body_id, | |
| 63 | body_def_id, | |
| 64 | 64 | traits::ObligationCauseCode::OpaqueReturnType(None), |
| 65 | 65 | ), |
| 66 | 66 | goal.param_env, |
compiler/rustc_infer/src/traits/mod.rs+2-2| ... | ... | @@ -158,11 +158,11 @@ impl<'tcx, O> Obligation<'tcx, O> { |
| 158 | 158 | pub fn misc( |
| 159 | 159 | tcx: TyCtxt<'tcx>, |
| 160 | 160 | span: Span, |
| 161 | body_id: LocalDefId, | |
| 161 | body_def_id: LocalDefId, | |
| 162 | 162 | param_env: ty::ParamEnv<'tcx>, |
| 163 | 163 | trait_ref: impl Upcast<TyCtxt<'tcx>, O>, |
| 164 | 164 | ) -> 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) | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | pub fn with<P>( |
compiler/rustc_lint/src/unused.rs+29-4| ... | ... | @@ -417,13 +417,19 @@ trait UnusedDelimLint { |
| 417 | 417 | } |
| 418 | 418 | // either function/method call, or something this lint doesn't care about |
| 419 | 419 | 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 | ), | |
| 423 | 429 | Closure(ref closure) |
| 424 | 430 | if matches!(closure.fn_decl.output, FnRetTy::Default(_)) => |
| 425 | 431 | { |
| 426 | (&[closure.body.clone()][..], UnusedDelimsCtx::ClosureBody) | |
| 432 | (&[closure.body.clone()][..], UnusedDelimsCtx::ClosureBody, false) | |
| 427 | 433 | } |
| 428 | 434 | // actual catch-all arm |
| 429 | 435 | _ => { |
| ... | ... | @@ -438,6 +444,11 @@ trait UnusedDelimLint { |
| 438 | 444 | return; |
| 439 | 445 | } |
| 440 | 446 | 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 | } | |
| 441 | 452 | self.check_unused_delims_expr(cx, arg, ctx, false, None, None, false); |
| 442 | 453 | } |
| 443 | 454 | return; |
| ... | ... | @@ -516,6 +527,20 @@ trait UnusedDelimLint { |
| 516 | 527 | false, |
| 517 | 528 | ); |
| 518 | 529 | } |
| 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 | } | |
| 519 | 544 | } |
| 520 | 545 | |
| 521 | 546 | declare_lint! { |
compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp+4| ... | ... | @@ -160,6 +160,10 @@ extern "C" void LLVMRustPrintStatisticsJSON(RustStringRef OutBuf) { |
| 160 | 160 | llvm::PrintStatisticsJSON(OS); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | extern "C" bool LLVMRustIsCall(LLVMValueRef V) { | |
| 164 | return llvm::isa<llvm::CallBase>(llvm::unwrap(V)); | |
| 165 | } | |
| 166 | ||
| 163 | 167 | // Some of the functions here rely on LLVM modules that may not always be |
| 164 | 168 | // available. As such, we only try to build it in the first place, if |
| 165 | 169 | // llvm.offload is enabled. |
compiler/rustc_middle/src/traits/mod.rs+8-8| ... | ... | @@ -44,13 +44,13 @@ use crate::ty::{self, AdtKind, GenericArgsRef, Ty}; |
| 44 | 44 | pub struct ObligationCause<'tcx> { |
| 45 | 45 | pub span: Span, |
| 46 | 46 | |
| 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 | |
| 48 | 48 | /// used for region obligations to determine the precise |
| 49 | 49 | /// environment in which the region obligation should be evaluated |
| 50 | 50 | /// (in particular, closures can add new assumptions). See the |
| 51 | 51 | /// field `region_obligations` of the `FulfillmentContext` for more |
| 52 | 52 | /// information. |
| 53 | pub body_id: LocalDefId, | |
| 53 | pub body_def_id: LocalDefId, | |
| 54 | 54 | |
| 55 | 55 | code: ObligationCauseCodeHandle<'tcx>, |
| 56 | 56 | } |
| ... | ... | @@ -62,7 +62,7 @@ pub struct ObligationCause<'tcx> { |
| 62 | 62 | // which is hashed as an interned pointer. See #90996. |
| 63 | 63 | impl Hash for ObligationCause<'_> { |
| 64 | 64 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 65 | self.body_id.hash(state); | |
| 65 | self.body_def_id.hash(state); | |
| 66 | 66 | self.span.hash(state); |
| 67 | 67 | } |
| 68 | 68 | } |
| ... | ... | @@ -71,14 +71,14 @@ impl<'tcx> ObligationCause<'tcx> { |
| 71 | 71 | #[inline] |
| 72 | 72 | pub fn new( |
| 73 | 73 | span: Span, |
| 74 | body_id: LocalDefId, | |
| 74 | body_def_id: LocalDefId, | |
| 75 | 75 | code: ObligationCauseCode<'tcx>, |
| 76 | 76 | ) -> ObligationCause<'tcx> { |
| 77 | ObligationCause { span, body_id, code: code.into() } | |
| 77 | ObligationCause { span, body_def_id, code: code.into() } | |
| 78 | 78 | } |
| 79 | 79 | |
| 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) | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | #[inline(always)] |
| ... | ... | @@ -88,7 +88,7 @@ impl<'tcx> ObligationCause<'tcx> { |
| 88 | 88 | |
| 89 | 89 | #[inline(always)] |
| 90 | 90 | 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() } | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | #[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 { |
| 32 | 32 | // Create TypeTree for return type |
| 33 | 33 | let ret = typetree_from_ty(tcx, sig.output()); |
| 34 | 34 | |
| 35 | FncTree { args, ret } | |
| 35 | let f = FncTree { args, ret }; | |
| 36 | f | |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | /// Generate a TypeTree for a specific type. |
| 39 | 40 | /// Mainly a convenience wrapper around the actual implementation. |
| 40 | 41 | pub 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 | } | |
| 41 | 48 | let mut visited = Vec::new(); |
| 42 | 49 | typetree_from_ty_impl_inner(tcx, ty, 0, &mut visited, false) |
| 43 | 50 | } |
| ... | ... | @@ -46,6 +53,40 @@ pub fn typetree_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> TypeTree { |
| 46 | 53 | /// from pathological deeply nested types. Combined with cycle detection. |
| 47 | 54 | const MAX_TYPETREE_DEPTH: usize = 6; |
| 48 | 55 | |
| 56 | fn 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 | ||
| 49 | 90 | /// Internal implementation with context about whether this is for a reference target. |
| 50 | 91 | fn typetree_from_ty_impl_inner<'tcx>( |
| 51 | 92 | tcx: TyCtxt<'tcx>, |
| ... | ... | @@ -64,43 +105,12 @@ fn typetree_from_ty_impl_inner<'tcx>( |
| 64 | 105 | } |
| 65 | 106 | visited.push(ty); |
| 66 | 107 | |
| 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) => { | |
| 104 | 114 | let len = len_const.try_to_target_usize(tcx).unwrap_or(0); |
| 105 | 115 | if len == 0 { |
| 106 | 116 | return TypeTree::new(); |
| ... | ... | @@ -109,65 +119,44 @@ fn typetree_from_ty_impl_inner<'tcx>( |
| 109 | 119 | typetree_from_ty_impl_inner(tcx, *element_ty, depth + 1, visited, false); |
| 110 | 120 | let mut types = Vec::new(); |
| 111 | 121 | 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)); | |
| 118 | 123 | } |
| 119 | 124 | |
| 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) | |
| 135 | 126 | } |
| 127 | ty::Tuple(tuple_types) => { | |
| 128 | if tuple_types.is_empty() { | |
| 129 | return TypeTree::new(); | |
| 130 | } | |
| 136 | 131 | |
| 137 | let mut types = Vec::new(); | |
| 138 | let mut current_offset = 0; | |
| 132 | let mut types = Vec::new(); | |
| 133 | let mut current_offset = 0; | |
| 139 | 134 | |
| 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); | |
| 143 | 138 | |
| 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); | |
| 149 | 144 | |
| 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 { | |
| 153 | 147 | current_offset as isize |
| 154 | 148 | } else { |
| 155 | 149 | 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; | |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | current_offset += element_layout; | |
| 157 | TypeTree(types) | |
| 164 | 158 | } |
| 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() => { | |
| 171 | 160 | let struct_layout = |
| 172 | 161 | tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)); |
| 173 | 162 | if let Ok(layout) = struct_layout { |
| ... | ... | @@ -186,23 +175,37 @@ fn typetree_from_ty_impl_inner<'tcx>( |
| 186 | 175 | let field_offset = layout.fields.offset(field_idx).bytes_usize(); |
| 187 | 176 | |
| 188 | 177 | 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)); | |
| 199 | 184 | } |
| 200 | 185 | } |
| 201 | 186 | |
| 202 | return TypeTree(types); | |
| 187 | TypeTree(types) | |
| 188 | } else { | |
| 189 | TypeTree::new() | |
| 203 | 190 | } |
| 204 | 191 | } |
| 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(), | |
| 205 | 210 | } |
| 206 | ||
| 207 | TypeTree::new() | |
| 208 | 211 | } |
compiler/rustc_resolve/src/diagnostics.rs+4| ... | ... | @@ -407,6 +407,10 @@ pub(crate) struct ParamInNonTrivialAnonConst { |
| 407 | 407 | "consider factoring the expression into a `type const` item and use it as the const argument instead" |
| 408 | 408 | )] |
| 409 | 409 | 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, | |
| 410 | 414 | } |
| 411 | 415 | |
| 412 | 416 | #[derive(Debug)] |
compiler/rustc_resolve/src/error_helper.rs+3-1| ... | ... | @@ -1288,9 +1288,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { |
| 1288 | 1288 | span, |
| 1289 | 1289 | name, |
| 1290 | 1290 | 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(), | |
| 1292 | 1293 | is_gca, |
| 1293 | 1294 | help_gca: is_gca, |
| 1295 | help_suggest_gca: self.tcx.sess.is_nightly_build() && !is_gca, | |
| 1294 | 1296 | }) |
| 1295 | 1297 | } |
| 1296 | 1298 | 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> { |
| 3983 | 3983 | span: lifetime_ref.ident.span, |
| 3984 | 3984 | name: lifetime_ref.ident.name, |
| 3985 | 3985 | 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(), | |
| 3987 | 3988 | is_gca: self.r.features.generic_const_args(), |
| 3988 | 3989 | 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(), | |
| 3989 | 3992 | }) |
| 3990 | 3993 | .emit() |
| 3991 | 3994 | } |
compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs+4-1| ... | ... | @@ -1,12 +1,15 @@ |
| 1 | 1 | use crate::spec::{ |
| 2 | 2 | Arch, Cc, CfgAbi, LinkerFlavor, Lld, LlvmAbi, StackProbeType, Target, TargetMetadata, |
| 3 | TargetOptions, base, | |
| 3 | TargetOptions, add_link_args, base, | |
| 4 | 4 | }; |
| 5 | 5 | |
| 6 | 6 | pub(crate) fn target() -> Target { |
| 7 | 7 | let mut base = base::freebsd::opts(); |
| 8 | 8 | base.cpu = "ppc64le".into(); |
| 9 | 9 | 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"]); | |
| 10 | 13 | base.max_atomic_width = Some(64); |
| 11 | 14 | base.stack_probes = StackProbeType::Inline; |
| 12 | 15 | 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> { |
| 1813 | 1813 | } |
| 1814 | 1814 | } |
| 1815 | 1815 | |
| 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()); | |
| 1817 | 1818 | self.note_and_explain_type_err(diag, terr, cause, span, body_owner_def_id); |
| 1818 | 1819 | if let Some(exp_found) = exp_found |
| 1819 | 1820 | && let exp_found = TypeError::Sorts(exp_found) |
| ... | ... | @@ -1945,7 +1946,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1945 | 1946 | let TypeError::ArraySize(sz) = terr else { |
| 1946 | 1947 | return None; |
| 1947 | 1948 | }; |
| 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) { | |
| 1949 | 1950 | hir::Node::Item(hir::Item { |
| 1950 | 1951 | kind: hir::ItemKind::Fn { body: body_id, .. }, .. |
| 1951 | 1952 | }) => { |
compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs+2-2| ... | ... | @@ -173,7 +173,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 173 | 173 | exp_span, exp_found.expected, exp_found.found, |
| 174 | 174 | ); |
| 175 | 175 | |
| 176 | match self.tcx.coroutine_kind(cause.body_id) { | |
| 176 | match self.tcx.coroutine_kind(cause.body_def_id) { | |
| 177 | 177 | Some(hir::CoroutineKind::Desugared( |
| 178 | 178 | hir::CoroutineDesugaring::Async | hir::CoroutineDesugaring::AsyncGen, |
| 179 | 179 | _, |
| ... | ... | @@ -636,7 +636,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | |
| 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| { | |
| 640 | 640 | IfVisitor { err_span: span, found_if: false } |
| 641 | 641 | .visit_body(&body) |
| 642 | 642 | .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>( |
| 144 | 144 | }, |
| 145 | 145 | ); |
| 146 | 146 | |
| 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), | |
| 148 | 148 | // then try to look for a param-env clause that would apply. The way we compute |
| 149 | 149 | // this is somewhat manual, since we need the spans, so we elaborate this directly |
| 150 | 150 | // from `predicates_of` rather than actually looking at the param-env which |
| 151 | 151 | // 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); | |
| 155 | 155 | for (pred, span) in |
| 156 | 156 | elaborate(tcx, predicates.into_iter().map(|(c, s)| (c.skip_norm_wip(), s))) |
| 157 | 157 | { |
| ... | ... | @@ -231,7 +231,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 231 | 231 | return match self.tainted_by_errors() { |
| 232 | 232 | None => self |
| 233 | 233 | .emit_inference_failure_err( |
| 234 | obligation.cause.body_id, | |
| 234 | obligation.cause.body_def_id, | |
| 235 | 235 | span, |
| 236 | 236 | trait_pred.self_ty().skip_binder().into(), |
| 237 | 237 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -285,7 +285,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 285 | 285 | }) |
| 286 | 286 | .collect(); |
| 287 | 287 | self.emit_inference_failure_err_with_type_hint( |
| 288 | obligation.cause.body_id, | |
| 288 | obligation.cause.body_def_id, | |
| 289 | 289 | span, |
| 290 | 290 | term, |
| 291 | 291 | TypeAnnotationNeeded::E0283, |
| ... | ... | @@ -369,7 +369,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 369 | 369 | impl_candidates.as_slice(), |
| 370 | 370 | obligation, |
| 371 | 371 | trait_pred, |
| 372 | obligation.cause.body_id, | |
| 372 | obligation.cause.body_def_id, | |
| 373 | 373 | &mut err, |
| 374 | 374 | false, |
| 375 | 375 | obligation.param_env, |
| ... | ... | @@ -384,7 +384,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | 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) | |
| 388 | 389 | { |
| 389 | 390 | let mut expr_finder = FindExprBySpan::new(span, self.tcx); |
| 390 | 391 | expr_finder.visit_expr(&body.value); |
| ... | ... | @@ -546,7 +547,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 546 | 547 | } |
| 547 | 548 | |
| 548 | 549 | self.emit_inference_failure_err( |
| 549 | obligation.cause.body_id, | |
| 550 | obligation.cause.body_def_id, | |
| 550 | 551 | span, |
| 551 | 552 | term, |
| 552 | 553 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -565,7 +566,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 565 | 566 | // both must be type variables, or the other would've been instantiated |
| 566 | 567 | assert!(a.is_ty_var() && b.is_ty_var()); |
| 567 | 568 | self.emit_inference_failure_err( |
| 568 | obligation.cause.body_id, | |
| 569 | obligation.cause.body_def_id, | |
| 569 | 570 | span, |
| 570 | 571 | a.into(), |
| 571 | 572 | TypeAnnotationNeeded::E0282, |
| ... | ... | @@ -599,7 +600,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 599 | 600 | let predicate = self.tcx.short_string(predicate, &mut long_ty_path); |
| 600 | 601 | if let Some(term) = term { |
| 601 | 602 | self.emit_inference_failure_err( |
| 602 | obligation.cause.body_id, | |
| 603 | obligation.cause.body_def_id, | |
| 603 | 604 | span, |
| 604 | 605 | term, |
| 605 | 606 | TypeAnnotationNeeded::E0284, |
| ... | ... | @@ -631,7 +632,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 631 | 632 | data.walk().filter_map(ty::GenericArg::as_term).find(|term| term.is_infer()); |
| 632 | 633 | if let Some(term) = term { |
| 633 | 634 | self.emit_inference_failure_err( |
| 634 | obligation.cause.body_id, | |
| 635 | obligation.cause.body_def_id, | |
| 635 | 636 | span, |
| 636 | 637 | term, |
| 637 | 638 | TypeAnnotationNeeded::E0284, |
| ... | ... | @@ -653,7 +654,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 653 | 654 | |
| 654 | 655 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ..)) => self |
| 655 | 656 | .emit_inference_failure_err( |
| 656 | obligation.cause.body_id, | |
| 657 | obligation.cause.body_def_id, | |
| 657 | 658 | span, |
| 658 | 659 | ct.into(), |
| 659 | 660 | 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> { |
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | if let Some(s) = parent_label { |
| 471 | let body = obligation.cause.body_id; | |
| 471 | let body = obligation.cause.body_def_id; | |
| 472 | 472 | err.span_label(tcx.def_span(body), s); |
| 473 | 473 | } |
| 474 | 474 | |
| ... | ... | @@ -689,7 +689,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 689 | 689 | violations, |
| 690 | 690 | ); |
| 691 | 691 | 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) | |
| 693 | 693 | && let hir::ItemKind::Impl(impl_) = item.kind |
| 694 | 694 | && let None = impl_.of_trait |
| 695 | 695 | && let hir::TyKind::TraitObject(_, tagged_ptr) = impl_.self_ty.kind |
| ... | ... | @@ -949,7 +949,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 949 | 949 | } |
| 950 | 950 | } else if let ty::Param(param) = trait_ref.self_ty().skip_binder().kind() |
| 951 | 951 | && 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() | |
| 953 | 953 | { |
| 954 | 954 | let constraint = ty::print::with_no_trimmed_paths!(format!( |
| 955 | 955 | "[const] {}", |
| ... | ... | @@ -1144,7 +1144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1144 | 1144 | } |
| 1145 | 1145 | } |
| 1146 | 1146 | } |
| 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); | |
| 1148 | 1148 | let Some(body_id) = self.tcx.hir_node(hir_id).body_id() else { return (false, false) }; |
| 1149 | 1149 | let ControlFlow::Break(expr) = |
| 1150 | 1150 | (FindMethodSubexprOfTry { search_span: span }).visit_body(self.tcx.hir_body(body_id)) |
| ... | ... | @@ -1382,7 +1382,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1382 | 1382 | ty: Ty<'tcx>, |
| 1383 | 1383 | obligation: &PredicateObligation<'tcx>, |
| 1384 | 1384 | ) -> Diag<'a> { |
| 1385 | let def_id = obligation.cause.body_id; | |
| 1385 | let def_id = obligation.cause.body_def_id; | |
| 1386 | 1386 | let span = self.tcx.ty_span(def_id); |
| 1387 | 1387 | |
| 1388 | 1388 | let mut file = None; |
| ... | ... | @@ -2869,7 +2869,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2869 | 2869 | // message, and fall back to regular note otherwise. |
| 2870 | 2870 | if !self.maybe_note_obligation_cause_for_async_await(err, obligation) { |
| 2871 | 2871 | self.note_obligation_cause_code( |
| 2872 | obligation.cause.body_id, | |
| 2872 | obligation.cause.body_def_id, | |
| 2873 | 2873 | err, |
| 2874 | 2874 | obligation.predicate, |
| 2875 | 2875 | obligation.param_env, |
| ... | ... | @@ -2884,7 +2884,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2884 | 2884 | obligation.cause.code(), |
| 2885 | 2885 | ); |
| 2886 | 2886 | self.suggest_borrow_for_unsized_closure_return( |
| 2887 | obligation.cause.body_id, | |
| 2887 | obligation.cause.body_def_id, | |
| 2888 | 2888 | err, |
| 2889 | 2889 | obligation.predicate, |
| 2890 | 2890 | ); |
| ... | ... | @@ -3211,7 +3211,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3211 | 3211 | is_fn_trait: bool, |
| 3212 | 3212 | suggested: bool, |
| 3213 | 3213 | ) { |
| 3214 | let body_def_id = obligation.cause.body_id; | |
| 3214 | let body_def_id = obligation.cause.body_def_id; | |
| 3215 | 3215 | let span = if let ObligationCauseCode::BinOp { rhs_span, .. } = obligation.cause.code() { |
| 3216 | 3216 | *rhs_span |
| 3217 | 3217 | } else { |
| ... | ... | @@ -3242,7 +3242,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3242 | 3242 | err, |
| 3243 | 3243 | trait_predicate, |
| 3244 | 3244 | None, |
| 3245 | obligation.cause.body_id, | |
| 3245 | obligation.cause.body_def_id, | |
| 3246 | 3246 | ); |
| 3247 | 3247 | } else if trait_def_id.is_local() |
| 3248 | 3248 | && self.tcx.trait_impls_of(trait_def_id).is_empty() |
| ... | ... | @@ -3798,7 +3798,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3798 | 3798 | { |
| 3799 | 3799 | trait_item_def_id.as_local() |
| 3800 | 3800 | } else { |
| 3801 | Some(obligation.cause.body_id) | |
| 3801 | Some(obligation.cause.body_def_id) | |
| 3802 | 3802 | }; |
| 3803 | 3803 | if let Some(suggestion_def_id) = suggestion_def_id |
| 3804 | 3804 | && 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> { |
| 340 | 340 | | ObligationCauseCode::WhereClauseInExpr(..) = code |
| 341 | 341 | { |
| 342 | 342 | self.note_obligation_cause_code( |
| 343 | error.obligation.cause.body_id, | |
| 343 | error.obligation.cause.body_def_id, | |
| 344 | 344 | &mut diag, |
| 345 | 345 | error.obligation.predicate, |
| 346 | 346 | 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> { |
| 72 | 72 | // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs, |
| 73 | 73 | // but I guess we could synthesize one here. We don't see any errors that rely on |
| 74 | 74 | // 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(""); | |
| 76 | 76 | |
| 77 | 77 | let direct = match obligation.cause.code() { |
| 78 | 78 | ObligationCauseCode::BuiltinDerived(..) |
compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs+1-1| ... | ... | @@ -150,7 +150,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 150 | 150 | suggest_increasing_limit, |
| 151 | 151 | |err| { |
| 152 | 152 | self.note_obligation_cause_code( |
| 153 | obligation.cause.body_id, | |
| 153 | obligation.cause.body_def_id, | |
| 154 | 154 | err, |
| 155 | 155 | predicate, |
| 156 | 156 | 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> { |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | 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) | |
| 289 | 289 | { |
| 290 | 290 | let mut expr_finder = FindExprBySpan::new(cause.span, self.tcx); |
| 291 | 291 | expr_finder.visit_body(body); |
| ... | ... | @@ -467,7 +467,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 467 | 467 | err: &mut Diag<'_>, |
| 468 | 468 | trait_pred: ty::PolyTraitPredicate<'tcx>, |
| 469 | 469 | associated_ty: Option<(&'static str, Ty<'tcx>)>, |
| 470 | mut body_id: LocalDefId, | |
| 470 | mut body_def_id: LocalDefId, | |
| 471 | 471 | ) { |
| 472 | 472 | if trait_pred.skip_binder().polarity != ty::PredicatePolarity::Positive { |
| 473 | 473 | return; |
| ... | ... | @@ -494,7 +494,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 494 | 494 | // FIXME: Add check for trait bound that is already present, particularly `?Sized` so we |
| 495 | 495 | // don't suggest `T: Sized + ?Sized`. |
| 496 | 496 | 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); | |
| 498 | 498 | match node { |
| 499 | 499 | hir::Node::Item(hir::Item { |
| 500 | 500 | kind: hir::ItemKind::Trait { ident, generics, bounds, .. }, |
| ... | ... | @@ -504,7 +504,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 504 | 504 | // Restricting `Self` for a single method. |
| 505 | 505 | suggest_restriction( |
| 506 | 506 | self.tcx, |
| 507 | body_id, | |
| 507 | body_def_id, | |
| 508 | 508 | generics, |
| 509 | 509 | "`Self`", |
| 510 | 510 | err, |
| ... | ... | @@ -524,7 +524,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 524 | 524 | assert!(param_ty); |
| 525 | 525 | // Restricting `Self` for a single method. |
| 526 | 526 | 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, | |
| 528 | 535 | None, |
| 529 | 536 | ); |
| 530 | 537 | return; |
| ... | ... | @@ -547,7 +554,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 547 | 554 | // Missing restriction on associated type of type parameter (unmet projection). |
| 548 | 555 | suggest_restriction( |
| 549 | 556 | self.tcx, |
| 550 | body_id, | |
| 557 | body_def_id, | |
| 551 | 558 | generics, |
| 552 | 559 | "the associated type", |
| 553 | 560 | err, |
| ... | ... | @@ -567,7 +574,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 567 | 574 | // Missing restriction on associated type of type parameter (unmet projection). |
| 568 | 575 | suggest_restriction( |
| 569 | 576 | self.tcx, |
| 570 | body_id, | |
| 577 | body_def_id, | |
| 571 | 578 | generics, |
| 572 | 579 | "the associated type", |
| 573 | 580 | err, |
| ... | ... | @@ -687,7 +694,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 687 | 694 | |
| 688 | 695 | _ => {} |
| 689 | 696 | } |
| 690 | body_id = self.tcx.local_parent(body_id); | |
| 697 | body_def_id = self.tcx.local_parent(body_def_id); | |
| 691 | 698 | } |
| 692 | 699 | } |
| 693 | 700 | |
| ... | ... | @@ -1024,7 +1031,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1024 | 1031 | ); |
| 1025 | 1032 | |
| 1026 | 1033 | 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) | |
| 1028 | 1035 | else { |
| 1029 | 1036 | return false; |
| 1030 | 1037 | }; |
| ... | ... | @@ -1232,7 +1239,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1232 | 1239 | // Wrap method receivers and `&`-references in parens. |
| 1233 | 1240 | let suggestion = if self.tcx.sess.source_map().span_followed_by(span, ".").is_some() { |
| 1234 | 1241 | 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) { | |
| 1236 | 1243 | let mut expr_finder = FindExprBySpan::new(span, self.tcx); |
| 1237 | 1244 | expr_finder.visit_expr(body.value); |
| 1238 | 1245 | if let Some(expr) = expr_finder.result |
| ... | ... | @@ -1271,7 +1278,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1271 | 1278 | span.remove_mark(); |
| 1272 | 1279 | } |
| 1273 | 1280 | 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 { | |
| 1275 | 1282 | return; |
| 1276 | 1283 | }; |
| 1277 | 1284 | expr_finder.visit_expr(body.value); |
| ... | ... | @@ -1350,7 +1357,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1350 | 1357 | ) -> bool { |
| 1351 | 1358 | let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty()); |
| 1352 | 1359 | 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 { | |
| 1354 | 1361 | return false; |
| 1355 | 1362 | }; |
| 1356 | 1363 | let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false }; |
| ... | ... | @@ -1444,7 +1451,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1444 | 1451 | /// because the callable type must also be well-formed to be called. |
| 1445 | 1452 | pub fn extract_callable_info( |
| 1446 | 1453 | &self, |
| 1447 | body_id: LocalDefId, | |
| 1454 | body_def_id: LocalDefId, | |
| 1448 | 1455 | param_env: ty::ParamEnv<'tcx>, |
| 1449 | 1456 | found: Ty<'tcx>, |
| 1450 | 1457 | ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> { |
| ... | ... | @@ -1526,7 +1533,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1526 | 1533 | } |
| 1527 | 1534 | }), |
| 1528 | 1535 | ty::Param(param) => { |
| 1529 | let generics = self.tcx.generics_of(body_id); | |
| 1536 | let generics = self.tcx.generics_of(body_def_id); | |
| 1530 | 1537 | let name = if generics.count() > param.index as usize |
| 1531 | 1538 | && let def = generics.param_at(param.index as usize, self.tcx) |
| 1532 | 1539 | && matches!(def.kind, ty::GenericParamDefKind::Type { .. }) |
| ... | ... | @@ -1597,7 +1604,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1597 | 1604 | }; |
| 1598 | 1605 | let (Some(typeck_results), Some(body)) = ( |
| 1599 | 1606 | 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), | |
| 1601 | 1608 | ) else { |
| 1602 | 1609 | return true; |
| 1603 | 1610 | }; |
| ... | ... | @@ -1859,7 +1866,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1859 | 1866 | // Issue #104961, we need to add parentheses properly for compound expressions |
| 1860 | 1867 | // for example, `x.starts_with("hi".to_string() + "you")` |
| 1861 | 1868 | // 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 { | |
| 1863 | 1870 | return false; |
| 1864 | 1871 | }; |
| 1865 | 1872 | let mut expr_finder = FindExprBySpan::new(span, self.tcx); |
| ... | ... | @@ -2085,7 +2092,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2085 | 2092 | span.remove_mark(); |
| 2086 | 2093 | } |
| 2087 | 2094 | 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 { | |
| 2089 | 2096 | return false; |
| 2090 | 2097 | }; |
| 2091 | 2098 | expr_finder.visit_expr(body.value); |
| ... | ... | @@ -2413,7 +2420,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2413 | 2420 | span: Span, |
| 2414 | 2421 | trait_pred: ty::PolyTraitPredicate<'tcx>, |
| 2415 | 2422 | ) -> 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); | |
| 2417 | 2424 | if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn {sig, body: body_id, .. }, .. }) = node |
| 2418 | 2425 | && let hir::ExprKind::Block(blk, _) = &self.tcx.hir_body(*body_id).value.kind |
| 2419 | 2426 | && sig.decl.output.span().overlaps(span) |
| ... | ... | @@ -2449,7 +2456,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2449 | 2456 | |
| 2450 | 2457 | pub(super) fn suggest_borrow_for_unsized_closure_return<G: EmissionGuarantee>( |
| 2451 | 2458 | &self, |
| 2452 | body_id: LocalDefId, | |
| 2459 | body_def_id: LocalDefId, | |
| 2453 | 2460 | err: &mut Diag<'_, G>, |
| 2454 | 2461 | predicate: ty::Predicate<'tcx>, |
| 2455 | 2462 | ) { |
| ... | ... | @@ -2463,10 +2470,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2463 | 2470 | let Some(span) = err.span.primary_span() else { |
| 2464 | 2471 | return; |
| 2465 | 2472 | }; |
| 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 { | |
| 2467 | 2474 | return; |
| 2468 | 2475 | }; |
| 2469 | let body = self.tcx.hir_body(node_body_id); | |
| 2476 | let body = self.tcx.hir_body(body_id); | |
| 2470 | 2477 | let mut expr_finder = FindExprBySpan::new(span, self.tcx); |
| 2471 | 2478 | expr_finder.visit_expr(body.value); |
| 2472 | 2479 | let Some(expr) = expr_finder.result else { |
| ... | ... | @@ -2503,7 +2510,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2503 | 2510 | |
| 2504 | 2511 | pub(super) fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> { |
| 2505 | 2512 | 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) | |
| 2507 | 2514 | else { |
| 2508 | 2515 | return None; |
| 2509 | 2516 | }; |
| ... | ... | @@ -2529,7 +2536,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2529 | 2536 | if let Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig: fn_sig, .. }, .. }) |
| 2530 | 2537 | | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(fn_sig, _), .. }) |
| 2531 | 2538 | | 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) | |
| 2533 | 2540 | && let hir::FnRetTy::Return(ty) = fn_sig.decl.output |
| 2534 | 2541 | && let hir::TyKind::Path(qpath) = ty.kind |
| 2535 | 2542 | && let hir::QPath::Resolved(None, path) = qpath |
| ... | ... | @@ -2559,8 +2566,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2559 | 2566 | |
| 2560 | 2567 | let mut span = obligation.cause.span; |
| 2561 | 2568 | 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) | |
| 2564 | 2571 | && let DefKind::Fn | DefKind::AssocFn = self.tcx.def_kind(parent) |
| 2565 | 2572 | && self.tcx.asyncness(parent).is_async() |
| 2566 | 2573 | && let Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig: fn_sig, .. }, .. }) |
| ... | ... | @@ -2577,11 +2584,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2577 | 2584 | is_async_fn_return = true; |
| 2578 | 2585 | err.span(span); |
| 2579 | 2586 | } |
| 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); | |
| 2581 | 2588 | |
| 2582 | 2589 | if !is_async_fn_return |
| 2583 | 2590 | && 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) | |
| 2585 | 2592 | && matches!(closure.fn_decl.output, hir::FnRetTy::DefaultReturn(_)) |
| 2586 | 2593 | { |
| 2587 | 2594 | return true; |
| ... | ... | @@ -3447,7 +3454,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3447 | 3454 | // bound that introduced the obligation (e.g. `T: Send`). |
| 3448 | 3455 | debug!(?next_code); |
| 3449 | 3456 | self.note_obligation_cause_code( |
| 3450 | obligation.cause.body_id, | |
| 3457 | obligation.cause.body_def_id, | |
| 3451 | 3458 | err, |
| 3452 | 3459 | obligation.predicate, |
| 3453 | 3460 | obligation.param_env, |
| ... | ... | @@ -3459,7 +3466,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3459 | 3466 | |
| 3460 | 3467 | pub(super) fn note_obligation_cause_code<G: EmissionGuarantee, T>( |
| 3461 | 3468 | &self, |
| 3462 | body_id: LocalDefId, | |
| 3469 | body_def_id: LocalDefId, | |
| 3463 | 3470 | err: &mut Diag<'_, G>, |
| 3464 | 3471 | predicate: T, |
| 3465 | 3472 | param_env: ty::ParamEnv<'tcx>, |
| ... | ... | @@ -4125,7 +4132,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4125 | 4132 | // #74711: avoid a stack overflow |
| 4126 | 4133 | ensure_sufficient_stack(|| { |
| 4127 | 4134 | self.note_obligation_cause_code( |
| 4128 | body_id, | |
| 4135 | body_def_id, | |
| 4129 | 4136 | err, |
| 4130 | 4137 | parent_predicate, |
| 4131 | 4138 | param_env, |
| ... | ... | @@ -4137,7 +4144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4137 | 4144 | } else { |
| 4138 | 4145 | ensure_sufficient_stack(|| { |
| 4139 | 4146 | self.note_obligation_cause_code( |
| 4140 | body_id, | |
| 4147 | body_def_id, | |
| 4141 | 4148 | err, |
| 4142 | 4149 | parent_predicate, |
| 4143 | 4150 | param_env, |
| ... | ... | @@ -4167,7 +4174,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4167 | 4174 | // Skip PinDerefMutHelper in suggestions, but still show downstream suggestions. |
| 4168 | 4175 | ensure_sufficient_stack(|| { |
| 4169 | 4176 | self.note_obligation_cause_code( |
| 4170 | body_id, | |
| 4177 | body_def_id, | |
| 4171 | 4178 | err, |
| 4172 | 4179 | parent_predicate, |
| 4173 | 4180 | param_env, |
| ... | ... | @@ -4321,7 +4328,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4321 | 4328 | // #74711: avoid a stack overflow |
| 4322 | 4329 | ensure_sufficient_stack(|| { |
| 4323 | 4330 | self.note_obligation_cause_code( |
| 4324 | body_id, | |
| 4331 | body_def_id, | |
| 4325 | 4332 | err, |
| 4326 | 4333 | parent_predicate, |
| 4327 | 4334 | param_env, |
| ... | ... | @@ -4364,7 +4371,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4364 | 4371 | } |
| 4365 | 4372 | ensure_sufficient_stack(|| { |
| 4366 | 4373 | self.note_obligation_cause_code( |
| 4367 | body_id, | |
| 4374 | body_def_id, | |
| 4368 | 4375 | err, |
| 4369 | 4376 | data.derived.parent_host_pred, |
| 4370 | 4377 | param_env, |
| ... | ... | @@ -4377,7 +4384,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4377 | 4384 | ObligationCauseCode::BuiltinDerivedHost(ref data) => { |
| 4378 | 4385 | ensure_sufficient_stack(|| { |
| 4379 | 4386 | self.note_obligation_cause_code( |
| 4380 | body_id, | |
| 4387 | body_def_id, | |
| 4381 | 4388 | err, |
| 4382 | 4389 | data.parent_host_pred, |
| 4383 | 4390 | param_env, |
| ... | ... | @@ -4393,7 +4400,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4393 | 4400 | // #74711: avoid a stack overflow |
| 4394 | 4401 | ensure_sufficient_stack(|| { |
| 4395 | 4402 | self.note_obligation_cause_code( |
| 4396 | body_id, | |
| 4403 | body_def_id, | |
| 4397 | 4404 | err, |
| 4398 | 4405 | parent_predicate, |
| 4399 | 4406 | param_env, |
| ... | ... | @@ -4407,7 +4414,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4407 | 4414 | // #74711: avoid a stack overflow |
| 4408 | 4415 | ensure_sufficient_stack(|| { |
| 4409 | 4416 | self.note_obligation_cause_code( |
| 4410 | body_id, | |
| 4417 | body_def_id, | |
| 4411 | 4418 | err, |
| 4412 | 4419 | predicate, |
| 4413 | 4420 | param_env, |
| ... | ... | @@ -4427,7 +4434,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4427 | 4434 | arg_hir_id, call_hir_id, ref parent_code, .. |
| 4428 | 4435 | } => { |
| 4429 | 4436 | self.note_function_argument_obligation( |
| 4430 | body_id, | |
| 4437 | body_def_id, | |
| 4431 | 4438 | err, |
| 4432 | 4439 | arg_hir_id, |
| 4433 | 4440 | parent_code, |
| ... | ... | @@ -4437,7 +4444,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4437 | 4444 | ); |
| 4438 | 4445 | ensure_sufficient_stack(|| { |
| 4439 | 4446 | self.note_obligation_cause_code( |
| 4440 | body_id, | |
| 4447 | body_def_id, | |
| 4441 | 4448 | err, |
| 4442 | 4449 | predicate, |
| 4443 | 4450 | param_env, |
| ... | ... | @@ -4481,7 +4488,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4481 | 4488 | let (expr_ty, expr) = if let Some((expr_ty, hir_id)) = expr_info { |
| 4482 | 4489 | let expr = tcx.hir_expect_expr(hir_id); |
| 4483 | 4490 | (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() | |
| 4485 | 4492 | && let body = tcx.hir_body(body_id) |
| 4486 | 4493 | && let hir::ExprKind::Block(block, _) = body.value.kind |
| 4487 | 4494 | && let Some(expr) = block.expr |
| ... | ... | @@ -4579,7 +4586,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4579 | 4586 | && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) |
| 4580 | 4587 | && snippet.ends_with('?') |
| 4581 | 4588 | { |
| 4582 | match self.tcx.coroutine_kind(obligation.cause.body_id) { | |
| 4589 | match self.tcx.coroutine_kind(obligation.cause.body_def_id) { | |
| 4583 | 4590 | Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => { |
| 4584 | 4591 | err.span_suggestion_verbose( |
| 4585 | 4592 | span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), |
| ... | ... | @@ -4591,7 +4598,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4591 | 4598 | _ => { |
| 4592 | 4599 | let mut span: MultiSpan = span.with_lo(span.hi() - BytePos(1)).into(); |
| 4593 | 4600 | span.push_span_label( |
| 4594 | self.tcx.def_span(obligation.cause.body_id), | |
| 4601 | self.tcx.def_span(obligation.cause.body_def_id), | |
| 4595 | 4602 | "this is not `async`", |
| 4596 | 4603 | ); |
| 4597 | 4604 | err.span_note( |
| ... | ... | @@ -4732,7 +4739,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4732 | 4739 | |
| 4733 | 4740 | fn note_function_argument_obligation<G: EmissionGuarantee>( |
| 4734 | 4741 | &self, |
| 4735 | body_id: LocalDefId, | |
| 4742 | body_def_id: LocalDefId, | |
| 4736 | 4743 | err: &mut Diag<'_, G>, |
| 4737 | 4744 | arg_hir_id: HirId, |
| 4738 | 4745 | parent_code: &ObligationCauseCode<'tcx>, |
| ... | ... | @@ -4749,7 +4756,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4749 | 4756 | && let Some(failed_pred) = failed_pred.as_trait_clause() |
| 4750 | 4757 | && let pred = failed_pred.map_bound(|pred| pred.with_replaced_self_ty(tcx, ty)) |
| 4751 | 4758 | && 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, | |
| 4753 | 4764 | )) |
| 4754 | 4765 | && expr.span.hi() != rcvr.span.hi() |
| 4755 | 4766 | { |
| ... | ... | @@ -4882,7 +4893,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4882 | 4893 | for (expected, actual) in zipped { |
| 4883 | 4894 | self.probe(|_| { |
| 4884 | 4895 | match self |
| 4885 | .at(&ObligationCause::misc(expr.span, body_id), param_env) | |
| 4896 | .at(&ObligationCause::misc(expr.span, body_def_id), param_env) | |
| 4886 | 4897 | // Doesn't actually matter if we define opaque types here, this is just used for |
| 4887 | 4898 | // diagnostics, and the result is never kept around. |
| 4888 | 4899 | .eq(DefineOpaqueTypes::Yes, expected, actual) |
| ... | ... | @@ -5880,7 +5891,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5880 | 5891 | } |
| 5881 | 5892 | } |
| 5882 | 5893 | |
| 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); | |
| 5884 | 5895 | if let Some((fn_decl, body_id)) = choose_suggest_items(self.tcx, node) |
| 5885 | 5896 | && let hir::FnRetTy::DefaultReturn(ret_span) = fn_decl.output |
| 5886 | 5897 | && 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; |
| 14 | 14 | impl<'tcx> OutlivesEnvironment<'tcx> { |
| 15 | 15 | fn new( |
| 16 | 16 | infcx: &InferCtxt<'tcx>, |
| 17 | body_id: LocalDefId, | |
| 17 | body_def_id: LocalDefId, | |
| 18 | 18 | param_env: ty::ParamEnv<'tcx>, |
| 19 | 19 | assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>, |
| 20 | 20 | ) -> 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) | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | fn new_with_implied_bounds_compat( |
| 25 | 25 | infcx: &InferCtxt<'tcx>, |
| 26 | body_id: LocalDefId, | |
| 26 | body_def_id: LocalDefId, | |
| 27 | 27 | param_env: ty::ParamEnv<'tcx>, |
| 28 | 28 | assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>, |
| 29 | 29 | disable_implied_bounds_hack: bool, |
| ... | ... | @@ -60,7 +60,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> { |
| 60 | 60 | param_env, |
| 61 | 61 | bounds, |
| 62 | 62 | infcx.implied_bounds_tys( |
| 63 | body_id, | |
| 63 | body_def_id, | |
| 64 | 64 | param_env, |
| 65 | 65 | assumed_wf_tys, |
| 66 | 66 | disable_implied_bounds_hack, |
| ... | ... | @@ -82,13 +82,13 @@ impl<'tcx> InferCtxt<'tcx> { |
| 82 | 82 | /// This function assumes that all infer variables are already constrained. |
| 83 | 83 | fn resolve_regions( |
| 84 | 84 | &self, |
| 85 | body_id: LocalDefId, | |
| 85 | body_def_id: LocalDefId, | |
| 86 | 86 | param_env: ty::ParamEnv<'tcx>, |
| 87 | 87 | assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>, |
| 88 | 88 | ) -> Vec<RegionResolutionError<'tcx>> { |
| 89 | 89 | 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), | |
| 92 | 92 | ) |
| 93 | 93 | } |
| 94 | 94 |
compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs+4-3| ... | ... | @@ -258,10 +258,11 @@ impl<'tcx> BestObligation<'tcx> { |
| 258 | 258 | ) -> ControlFlow<PredicateObligation<'tcx>> { |
| 259 | 259 | let infcx = candidate.goal().infcx(); |
| 260 | 260 | 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; | |
| 262 | 262 | |
| 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() | |
| 265 | 266 | { |
| 266 | 267 | let nested_goal = candidate.instantiate_proof_tree_for_nested_goal( |
| 267 | 268 | GoalSource::Misc, |
compiler/rustc_trait_selection/src/traits/effects.rs+1-1| ... | ... | @@ -574,7 +574,7 @@ fn evaluate_host_effect_for_fn_goal<'tcx>( |
| 574 | 574 | .map(|(c, span)| { |
| 575 | 575 | let code = ObligationCauseCode::WhereClause(def, span); |
| 576 | 576 | 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); | |
| 578 | 578 | Obligation::new( |
| 579 | 579 | tcx, |
| 580 | 580 | cause, |
compiler/rustc_trait_selection/src/traits/engine.rs+5-5| ... | ... | @@ -246,15 +246,15 @@ where |
| 246 | 246 | /// will result in region constraints getting ignored. |
| 247 | 247 | pub fn resolve_regions_and_report_errors( |
| 248 | 248 | self, |
| 249 | body_id: LocalDefId, | |
| 249 | body_def_id: LocalDefId, | |
| 250 | 250 | param_env: ty::ParamEnv<'tcx>, |
| 251 | 251 | assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>, |
| 252 | 252 | ) -> 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); | |
| 254 | 254 | if errors.is_empty() { |
| 255 | 255 | Ok(()) |
| 256 | 256 | } 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)) | |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| ... | ... | @@ -265,11 +265,11 @@ where |
| 265 | 265 | #[must_use] |
| 266 | 266 | pub fn resolve_regions( |
| 267 | 267 | self, |
| 268 | body_id: LocalDefId, | |
| 268 | body_def_id: LocalDefId, | |
| 269 | 269 | param_env: ty::ParamEnv<'tcx>, |
| 270 | 270 | assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>, |
| 271 | 271 | ) -> 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) | |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 |
compiler/rustc_trait_selection/src/traits/fulfill.rs+1-1| ... | ... | @@ -611,7 +611,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 611 | 611 | match wf::obligations( |
| 612 | 612 | self.selcx.infcx, |
| 613 | 613 | obligation.param_env, |
| 614 | obligation.cause.body_id, | |
| 614 | obligation.cause.body_def_id, | |
| 615 | 615 | obligation.recursion_depth + 1, |
| 616 | 616 | term, |
| 617 | 617 | 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>( |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // 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]); | |
| 194 | 194 | if !errors.is_empty() { |
| 195 | 195 | infringing_inner_tys.push((inner_ty, InfringingFieldsReason::Regions(errors))); |
| 196 | 196 | continue; |
| ... | ... | @@ -279,7 +279,7 @@ pub fn all_fields_implement_trait<'tcx>( |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // 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]); | |
| 283 | 283 | if !errors.is_empty() { |
| 284 | 284 | infringing.push((field, ty, InfringingFieldsReason::Regions(errors))); |
| 285 | 285 | } |
compiler/rustc_trait_selection/src/traits/mod.rs+1-1| ... | ... | @@ -300,7 +300,7 @@ fn do_normalize_predicates<'tcx>( |
| 300 | 300 | // |
| 301 | 301 | // This is required by trait-system-refactor-initiative#166. The new solver encounters |
| 302 | 302 | // 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, []); | |
| 304 | 304 | match infcx.fully_resolve(predicates) { |
| 305 | 305 | Ok(predicates) => Ok(predicates), |
| 306 | 306 | Err(fixup_err) => { |
compiler/rustc_trait_selection/src/traits/outlives_bounds.rs+7-7| ... | ... | @@ -27,15 +27,15 @@ use crate::traits::ObligationCause; |
| 27 | 27 | /// # Parameters |
| 28 | 28 | /// |
| 29 | 29 | /// - `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. | |
| 31 | 31 | /// Note that this may cause outlives obligations to be injected |
| 32 | 32 | /// into the inference context with this body-id. |
| 33 | 33 | /// - `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)] | |
| 35 | 35 | fn implied_outlives_bounds<'a, 'tcx>( |
| 36 | 36 | infcx: &'a InferCtxt<'tcx>, |
| 37 | 37 | param_env: ty::ParamEnv<'tcx>, |
| 38 | body_id: LocalDefId, | |
| 38 | body_def_id: LocalDefId, | |
| 39 | 39 | ty: Ty<'tcx>, |
| 40 | 40 | disable_implied_bounds_hack: bool, |
| 41 | 41 | ) -> Vec<OutlivesBound<'tcx>> { |
| ... | ... | @@ -60,7 +60,7 @@ fn implied_outlives_bounds<'a, 'tcx>( |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | 62 | let mut constraints = QueryRegionConstraints::default(); |
| 63 | let span = infcx.tcx.def_span(body_id); | |
| 63 | let span = infcx.tcx.def_span(body_def_id); | |
| 64 | 64 | let Ok(InferOk { value: mut bounds, obligations }) = infcx |
| 65 | 65 | .instantiate_nll_query_response_and_region_obligations( |
| 66 | 66 | &ObligationCause::dummy_with_span(span), |
| ... | ... | @@ -83,7 +83,7 @@ fn implied_outlives_bounds<'a, 'tcx>( |
| 83 | 83 | // We otherwise would get spurious errors if normalizing an implied |
| 84 | 84 | // outlives bound required proving some higher-ranked coroutine obl. |
| 85 | 85 | let QueryRegionConstraints { constraints, assumptions: _ } = constraints; |
| 86 | let cause = ObligationCause::misc(span, body_id); | |
| 86 | let cause = ObligationCause::misc(span, body_def_id); | |
| 87 | 87 | for &QueryRegionConstraint { constraint, visible_for_leak_check: vis, .. } in &constraints { |
| 88 | 88 | match constraint { |
| 89 | 89 | ty::RegionConstraint::Outlives(predicate) => { |
| ... | ... | @@ -105,13 +105,13 @@ impl<'tcx> InferCtxt<'tcx> { |
| 105 | 105 | /// instead if you're interested in the implied bounds for a given signature. |
| 106 | 106 | fn implied_bounds_tys<Tys: IntoIterator<Item = Ty<'tcx>>>( |
| 107 | 107 | &self, |
| 108 | body_id: LocalDefId, | |
| 108 | body_def_id: LocalDefId, | |
| 109 | 109 | param_env: ParamEnv<'tcx>, |
| 110 | 110 | tys: Tys, |
| 111 | 111 | disable_implied_bounds_hack: bool, |
| 112 | 112 | ) -> impl Iterator<Item = OutlivesBound<'tcx>> { |
| 113 | 113 | 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) | |
| 115 | 115 | }) |
| 116 | 116 | } |
| 117 | 117 | } |
compiler/rustc_trait_selection/src/traits/project.rs+3-3| ... | ... | @@ -230,7 +230,7 @@ fn project_and_unify_term<'cx, 'tcx>( |
| 230 | 230 | let InferOk { value: actual, obligations: new } = |
| 231 | 231 | selcx.infcx.replace_opaque_types_with_inference_vars( |
| 232 | 232 | actual, |
| 233 | obligation.cause.body_id, | |
| 233 | obligation.cause.body_def_id, | |
| 234 | 234 | obligation.cause.span, |
| 235 | 235 | obligation.param_env, |
| 236 | 236 | ); |
| ... | ... | @@ -557,7 +557,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>( |
| 557 | 557 | |
| 558 | 558 | let nested_cause = ObligationCause::new( |
| 559 | 559 | cause.span, |
| 560 | cause.body_id, | |
| 560 | cause.body_def_id, | |
| 561 | 561 | // FIXME(inherent_associated_types): Since we can't pass along the self type to the |
| 562 | 562 | // cause code, inherent projections will be printed with identity instantiation in |
| 563 | 563 | // diagnostics which is not ideal. |
| ... | ... | @@ -2149,7 +2149,7 @@ fn assoc_term_own_obligations<'cx, 'tcx>( |
| 2149 | 2149 | } else { |
| 2150 | 2150 | ObligationCause::new( |
| 2151 | 2151 | obligation.cause.span, |
| 2152 | obligation.cause.body_id, | |
| 2152 | obligation.cause.body_def_id, | |
| 2153 | 2153 | ObligationCauseCode::WhereClause(def_id, span), |
| 2154 | 2154 | ) |
| 2155 | 2155 | }; |
compiler/rustc_trait_selection/src/traits/select/mod.rs+2-2| ... | ... | @@ -727,7 +727,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 727 | 727 | match wf::obligations( |
| 728 | 728 | self.infcx, |
| 729 | 729 | obligation.param_env, |
| 730 | obligation.cause.body_id, | |
| 730 | obligation.cause.body_def_id, | |
| 731 | 731 | obligation.recursion_depth + 1, |
| 732 | 732 | term, |
| 733 | 733 | obligation.cause.span, |
| ... | ... | @@ -2557,7 +2557,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { |
| 2557 | 2557 | |
| 2558 | 2558 | let cause = ObligationCause::new( |
| 2559 | 2559 | obligation.cause.span, |
| 2560 | obligation.cause.body_id, | |
| 2560 | obligation.cause.body_def_id, | |
| 2561 | 2561 | ObligationCauseCode::MatchImpl(obligation.cause.clone(), impl_def_id), |
| 2562 | 2562 | ); |
| 2563 | 2563 |
compiler/rustc_trait_selection/src/traits/wf.rs+13-13| ... | ... | @@ -30,7 +30,7 @@ use crate::traits; |
| 30 | 30 | pub fn obligations<'tcx>( |
| 31 | 31 | infcx: &InferCtxt<'tcx>, |
| 32 | 32 | param_env: ty::ParamEnv<'tcx>, |
| 33 | body_id: LocalDefId, | |
| 33 | body_def_id: LocalDefId, | |
| 34 | 34 | recursion_depth: usize, |
| 35 | 35 | term: Term<'tcx>, |
| 36 | 36 | span: Span, |
| ... | ... | @@ -72,17 +72,17 @@ pub fn obligations<'tcx>( |
| 72 | 72 | let mut wf = WfPredicates { |
| 73 | 73 | infcx, |
| 74 | 74 | param_env, |
| 75 | body_id, | |
| 75 | body_def_id, | |
| 76 | 76 | span, |
| 77 | 77 | out: PredicateObligations::new(), |
| 78 | 78 | recursion_depth, |
| 79 | 79 | item: None, |
| 80 | 80 | }; |
| 81 | 81 | 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); | |
| 83 | 83 | |
| 84 | 84 | 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); | |
| 86 | 86 | Some(result) |
| 87 | 87 | } |
| 88 | 88 | |
| ... | ... | @@ -95,7 +95,7 @@ pub fn unnormalized_obligations<'tcx>( |
| 95 | 95 | param_env: ty::ParamEnv<'tcx>, |
| 96 | 96 | term: Term<'tcx>, |
| 97 | 97 | span: Span, |
| 98 | body_id: LocalDefId, | |
| 98 | body_def_id: LocalDefId, | |
| 99 | 99 | ) -> Option<PredicateObligations<'tcx>> { |
| 100 | 100 | debug_assert_eq!(term, infcx.resolve_vars_if_possible(term)); |
| 101 | 101 | |
| ... | ... | @@ -109,7 +109,7 @@ pub fn unnormalized_obligations<'tcx>( |
| 109 | 109 | let mut wf = WfPredicates { |
| 110 | 110 | infcx, |
| 111 | 111 | param_env, |
| 112 | body_id, | |
| 112 | body_def_id, | |
| 113 | 113 | span, |
| 114 | 114 | out: PredicateObligations::new(), |
| 115 | 115 | recursion_depth: 0, |
| ... | ... | @@ -126,7 +126,7 @@ pub fn unnormalized_obligations<'tcx>( |
| 126 | 126 | pub fn trait_obligations<'tcx>( |
| 127 | 127 | infcx: &InferCtxt<'tcx>, |
| 128 | 128 | param_env: ty::ParamEnv<'tcx>, |
| 129 | body_id: LocalDefId, | |
| 129 | body_def_id: LocalDefId, | |
| 130 | 130 | trait_pred: ty::TraitPredicate<'tcx>, |
| 131 | 131 | span: Span, |
| 132 | 132 | item: &'tcx hir::Item<'tcx>, |
| ... | ... | @@ -134,7 +134,7 @@ pub fn trait_obligations<'tcx>( |
| 134 | 134 | let mut wf = WfPredicates { |
| 135 | 135 | infcx, |
| 136 | 136 | param_env, |
| 137 | body_id, | |
| 137 | body_def_id, | |
| 138 | 138 | span, |
| 139 | 139 | out: PredicateObligations::new(), |
| 140 | 140 | recursion_depth: 0, |
| ... | ... | @@ -154,14 +154,14 @@ pub fn trait_obligations<'tcx>( |
| 154 | 154 | pub fn clause_obligations<'tcx>( |
| 155 | 155 | infcx: &InferCtxt<'tcx>, |
| 156 | 156 | param_env: ty::ParamEnv<'tcx>, |
| 157 | body_id: LocalDefId, | |
| 157 | body_def_id: LocalDefId, | |
| 158 | 158 | clause: ty::Clause<'tcx>, |
| 159 | 159 | span: Span, |
| 160 | 160 | ) -> PredicateObligations<'tcx> { |
| 161 | 161 | let mut wf = WfPredicates { |
| 162 | 162 | infcx, |
| 163 | 163 | param_env, |
| 164 | body_id, | |
| 164 | body_def_id, | |
| 165 | 165 | span, |
| 166 | 166 | out: PredicateObligations::new(), |
| 167 | 167 | recursion_depth: 0, |
| ... | ... | @@ -205,7 +205,7 @@ pub fn clause_obligations<'tcx>( |
| 205 | 205 | struct WfPredicates<'a, 'tcx> { |
| 206 | 206 | infcx: &'a InferCtxt<'tcx>, |
| 207 | 207 | param_env: ty::ParamEnv<'tcx>, |
| 208 | body_id: LocalDefId, | |
| 208 | body_def_id: LocalDefId, | |
| 209 | 209 | span: Span, |
| 210 | 210 | out: PredicateObligations<'tcx>, |
| 211 | 211 | recursion_depth: usize, |
| ... | ... | @@ -334,7 +334,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | 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) | |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | fn normalize(self, infcx: &InferCtxt<'tcx>) -> PredicateObligations<'tcx> { |
| ... | ... | @@ -423,7 +423,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { |
| 423 | 423 | .filter_map(|(i, arg)| arg.as_term().map(|t| (i, t))) |
| 424 | 424 | .filter(|(_, term)| !term.has_escaping_bound_vars()) |
| 425 | 425 | .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); | |
| 427 | 427 | // The first arg is the self ty - use the correct span for it. |
| 428 | 428 | if i == 0 { |
| 429 | 429 | 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<'_> { |
| 196 | 196 | )); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | let local_did = def_id.as_local(); | |
| 199 | let local_did = def_id.as_local().unwrap_or(CRATE_DEF_ID); | |
| 200 | 200 | |
| 201 | 201 | let unnormalized_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates)); |
| 202 | 202 | |
| 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); | |
| 205 | 204 | traits::normalize_param_env_or_error(tcx, unnormalized_env, cause) |
| 206 | 205 | } |
| 207 | 206 |
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 | \ |
| 47 | 47 | # Compile an instance of busybox as this provides a lightweight system and init |
| 48 | 48 | # binary which we will boot into. Only trick here is configuring busybox to |
| 49 | 49 | # build static binaries. |
| 50 | RUN curl https://www.busybox.net/downloads/busybox-1.32.1.tar.bz2 | tar xjf - && \ | |
| 50 | RUN curl https://ci-mirrors.rust-lang.org/rustc/busybox/busybox-1.32.1.tar.bz2 | tar xjf - && \ | |
| 51 | 51 | cd busybox-1.32.1 && \ |
| 52 | 52 | make defconfig && \ |
| 53 | 53 | 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 - && |
| 60 | 60 | # Download the ubuntu rootfs, which we'll use as a chroot for all our tests. |
| 61 | 61 | WORKDIR /tmp |
| 62 | 62 | RUN mkdir rootfs/ubuntu |
| 63 | RUN curl https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04.2-base-armhf.tar.gz | \ | |
| 63 | RUN curl https://ci-mirrors.rust-lang.org/rustc/ubuntu/ubuntu-base-22.04.2-base-armhf.tar.gz | \ | |
| 64 | 64 | tar xzf - -C rootfs/ubuntu && \ |
| 65 | 65 | cd rootfs && mkdir proc sys dev etc etc/init.d |
| 66 | 66 |
tests/assembly-llvm/x86_64-windows-float-abi.rs+9-2| ... | ... | @@ -3,6 +3,9 @@ |
| 3 | 3 | //@ compile-flags: --target x86_64-pc-windows-msvc |
| 4 | 4 | //@ needs-llvm-components: x86 |
| 5 | 5 | //@ add-minicore |
| 6 | //@ revisions: LLVM22 LLVM23 | |
| 7 | //@ [LLVM22] max-llvm-major-version: 22 | |
| 8 | //@ [LLVM23] min-llvm-version: 23 | |
| 6 | 9 | |
| 7 | 10 | #![feature(f16, f128)] |
| 8 | 11 | #![feature(no_core)] |
| ... | ... | @@ -37,8 +40,12 @@ pub extern "C" fn second_f64(_: f64, x: f64) -> f64 { |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | 42 | // 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 | |
| 42 | 49 | #[no_mangle] |
| 43 | 50 | pub extern "C" fn second_f128(_: f128, x: f128) -> f128 { |
| 44 | 51 | x |
tests/run-make/autodiff/type-trees/iter/rmake.rs created+25| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | //@ needs-enzyme | |
| 2 | //@ ignore-cross-compile | |
| 3 | ||
| 4 | use 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 | ||
| 10 | fn 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 | ||
| 3 | use 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)] | |
| 18 | fn 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. | |
| 34 | fn 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 | ||
| 40 | fn 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]; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/associated-consts/issue-47814.stderr+2| ... | ... | @@ -9,6 +9,8 @@ note: not a concrete type |
| 9 | 9 | | |
| 10 | 10 | LL | impl<'a> ArpIPv4<'a> { |
| 11 | 11 | | ^^^^^^^^^^^ |
| 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 | |
| 12 | 14 | |
| 13 | 15 | error: aborting due to 1 previous error |
| 14 | 16 |
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. |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr+2| ... | ... | @@ -6,6 +6,7 @@ LL | let x: &'b (); |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/index-oob-ice-83993.rs:18:17 |
| ... | ... | @@ -15,6 +16,7 @@ LL | let _: &'b (); |
| 15 | 16 | | |
| 16 | 17 | = note: lifetime parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: aborting due to 2 previous errors |
| 20 | 22 |
tests/ui/const-generics/const-arg-in-const-arg.min.stderr+23| ... | ... | @@ -6,6 +6,7 @@ LL | let _: [u8; foo::<T>()]; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/const-arg-in-const-arg.rs:16:23 |
| ... | ... | @@ -15,6 +16,7 @@ LL | let _: [u8; bar::<N>()]; |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: generic parameters may not be used in const operations |
| 20 | 22 | --> $DIR/const-arg-in-const-arg.rs:18:23 |
| ... | ... | @@ -24,6 +26,7 @@ LL | let _: [u8; faz::<'a>(&())]; |
| 24 | 26 | | |
| 25 | 27 | = note: lifetime parameters may not be used in const expressions |
| 26 | 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 | |
| 27 | 30 | |
| 28 | 31 | error: generic parameters may not be used in const operations |
| 29 | 32 | --> $DIR/const-arg-in-const-arg.rs:20:23 |
| ... | ... | @@ -33,6 +36,7 @@ LL | let _: [u8; baz::<'a>(&())]; |
| 33 | 36 | | |
| 34 | 37 | = note: lifetime parameters may not be used in const expressions |
| 35 | 38 | = 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 | |
| 36 | 40 | |
| 37 | 41 | error: generic parameters may not be used in const operations |
| 38 | 42 | --> $DIR/const-arg-in-const-arg.rs:21:23 |
| ... | ... | @@ -42,6 +46,7 @@ LL | let _: [u8; faz::<'b>(&())]; |
| 42 | 46 | | |
| 43 | 47 | = note: lifetime parameters may not be used in const expressions |
| 44 | 48 | = 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 | |
| 45 | 50 | |
| 46 | 51 | error: generic parameters may not be used in const operations |
| 47 | 52 | --> $DIR/const-arg-in-const-arg.rs:23:23 |
| ... | ... | @@ -51,6 +56,7 @@ LL | let _: [u8; baz::<'b>(&())]; |
| 51 | 56 | | |
| 52 | 57 | = note: lifetime parameters may not be used in const expressions |
| 53 | 58 | = 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 | |
| 54 | 60 | |
| 55 | 61 | error: generic parameters may not be used in const operations |
| 56 | 62 | --> $DIR/const-arg-in-const-arg.rs:27:23 |
| ... | ... | @@ -60,6 +66,7 @@ LL | let _ = [0; bar::<N>()]; |
| 60 | 66 | | |
| 61 | 67 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 62 | 68 | = 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 | |
| 63 | 70 | |
| 64 | 71 | error: generic parameters may not be used in const operations |
| 65 | 72 | --> $DIR/const-arg-in-const-arg.rs:29:23 |
| ... | ... | @@ -69,6 +76,7 @@ LL | let _ = [0; faz::<'a>(&())]; |
| 69 | 76 | | |
| 70 | 77 | = note: lifetime parameters may not be used in const expressions |
| 71 | 78 | = 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 | |
| 72 | 80 | |
| 73 | 81 | error: generic parameters may not be used in const operations |
| 74 | 82 | --> $DIR/const-arg-in-const-arg.rs:31:23 |
| ... | ... | @@ -78,6 +86,7 @@ LL | let _ = [0; baz::<'a>(&())]; |
| 78 | 86 | | |
| 79 | 87 | = note: lifetime parameters may not be used in const expressions |
| 80 | 88 | = 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 | |
| 81 | 90 | |
| 82 | 91 | error: generic parameters may not be used in const operations |
| 83 | 92 | --> $DIR/const-arg-in-const-arg.rs:32:23 |
| ... | ... | @@ -87,6 +96,7 @@ LL | let _ = [0; faz::<'b>(&())]; |
| 87 | 96 | | |
| 88 | 97 | = note: lifetime parameters may not be used in const expressions |
| 89 | 98 | = 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 | |
| 90 | 100 | |
| 91 | 101 | error: generic parameters may not be used in const operations |
| 92 | 102 | --> $DIR/const-arg-in-const-arg.rs:34:23 |
| ... | ... | @@ -96,6 +106,7 @@ LL | let _ = [0; baz::<'b>(&())]; |
| 96 | 106 | | |
| 97 | 107 | = note: lifetime parameters may not be used in const expressions |
| 98 | 108 | = 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 | |
| 99 | 110 | |
| 100 | 111 | error: generic parameters may not be used in const operations |
| 101 | 112 | --> $DIR/const-arg-in-const-arg.rs:35:24 |
| ... | ... | @@ -105,6 +116,7 @@ LL | let _: Foo<{ foo::<T>() }>; |
| 105 | 116 | | |
| 106 | 117 | = note: type parameters may not be used in const expressions |
| 107 | 118 | = 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 | |
| 108 | 120 | |
| 109 | 121 | error: generic parameters may not be used in const operations |
| 110 | 122 | --> $DIR/const-arg-in-const-arg.rs:36:24 |
| ... | ... | @@ -114,6 +126,7 @@ LL | let _: Foo<{ bar::<N>() }>; |
| 114 | 126 | | |
| 115 | 127 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 116 | 128 | = 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 | |
| 117 | 130 | |
| 118 | 131 | error: generic parameters may not be used in const operations |
| 119 | 132 | --> $DIR/const-arg-in-const-arg.rs:38:24 |
| ... | ... | @@ -123,6 +136,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>; |
| 123 | 136 | | |
| 124 | 137 | = note: lifetime parameters may not be used in const expressions |
| 125 | 138 | = 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 | |
| 126 | 140 | |
| 127 | 141 | error: generic parameters may not be used in const operations |
| 128 | 142 | --> $DIR/const-arg-in-const-arg.rs:40:24 |
| ... | ... | @@ -132,6 +146,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>; |
| 132 | 146 | | |
| 133 | 147 | = note: lifetime parameters may not be used in const expressions |
| 134 | 148 | = 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 | |
| 135 | 150 | |
| 136 | 151 | error: generic parameters may not be used in const operations |
| 137 | 152 | --> $DIR/const-arg-in-const-arg.rs:41:24 |
| ... | ... | @@ -141,6 +156,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>; |
| 141 | 156 | | |
| 142 | 157 | = note: lifetime parameters may not be used in const expressions |
| 143 | 158 | = 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 | |
| 144 | 160 | |
| 145 | 161 | error: generic parameters may not be used in const operations |
| 146 | 162 | --> $DIR/const-arg-in-const-arg.rs:43:24 |
| ... | ... | @@ -150,6 +166,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>; |
| 150 | 166 | | |
| 151 | 167 | = note: lifetime parameters may not be used in const expressions |
| 152 | 168 | = 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 | |
| 153 | 170 | |
| 154 | 171 | error: generic parameters may not be used in const operations |
| 155 | 172 | --> $DIR/const-arg-in-const-arg.rs:44:27 |
| ... | ... | @@ -159,6 +176,7 @@ LL | let _ = Foo::<{ foo::<T>() }>; |
| 159 | 176 | | |
| 160 | 177 | = note: type parameters may not be used in const expressions |
| 161 | 178 | = 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 | |
| 162 | 180 | |
| 163 | 181 | error: generic parameters may not be used in const operations |
| 164 | 182 | --> $DIR/const-arg-in-const-arg.rs:45:27 |
| ... | ... | @@ -168,6 +186,7 @@ LL | let _ = Foo::<{ bar::<N>() }>; |
| 168 | 186 | | |
| 169 | 187 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 170 | 188 | = 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 | |
| 171 | 190 | |
| 172 | 191 | error: generic parameters may not be used in const operations |
| 173 | 192 | --> $DIR/const-arg-in-const-arg.rs:47:27 |
| ... | ... | @@ -177,6 +196,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>; |
| 177 | 196 | | |
| 178 | 197 | = note: lifetime parameters may not be used in const expressions |
| 179 | 198 | = 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 | |
| 180 | 200 | |
| 181 | 201 | error: generic parameters may not be used in const operations |
| 182 | 202 | --> $DIR/const-arg-in-const-arg.rs:49:27 |
| ... | ... | @@ -186,6 +206,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>; |
| 186 | 206 | | |
| 187 | 207 | = note: lifetime parameters may not be used in const expressions |
| 188 | 208 | = 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 | |
| 189 | 210 | |
| 190 | 211 | error: generic parameters may not be used in const operations |
| 191 | 212 | --> $DIR/const-arg-in-const-arg.rs:50:27 |
| ... | ... | @@ -195,6 +216,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>; |
| 195 | 216 | | |
| 196 | 217 | = note: lifetime parameters may not be used in const expressions |
| 197 | 218 | = 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 | |
| 198 | 220 | |
| 199 | 221 | error: generic parameters may not be used in const operations |
| 200 | 222 | --> $DIR/const-arg-in-const-arg.rs:52:27 |
| ... | ... | @@ -204,6 +226,7 @@ LL | let _ = Foo::<{ baz::<'b>(&()) }>; |
| 204 | 226 | | |
| 205 | 227 | = note: lifetime parameters may not be used in const expressions |
| 206 | 228 | = 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 | |
| 207 | 230 | |
| 208 | 231 | error[E0747]: unresolved item provided when a constant was expected |
| 209 | 232 | --> $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>()], |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0277]: the size for values of type `T` cannot be known at compilation time |
| 11 | 12 | --> $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 (); |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
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 }>; |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $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); |
| 15 | 16 | | |
| 16 | 17 | = note: type parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: aborting due to 2 previous errors |
| 20 | 22 |
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 {} } |
| 9 | 9 | | |
| 10 | 10 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 11 | 11 | = 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 | |
| 12 | 13 | = note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 13 | 14 | |
| 14 | 15 | error: generic parameters may not be used in const operations |
| ... | ... | @@ -22,6 +23,7 @@ LL | fn foo<const N: usize>() -> Foo<{ arg!{} arg!{} }> { loop {} } |
| 22 | 23 | | |
| 23 | 24 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 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 | |
| 25 | 27 | = note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 26 | 28 | |
| 27 | 29 | error: generic parameters may not be used in const operations |
| ... | ... | @@ -32,6 +34,7 @@ LL | fn bar<const N: usize>() -> [(); { empty!{}; N }] { loop {} } |
| 32 | 34 | | |
| 33 | 35 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 34 | 36 | = 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 | |
| 35 | 38 | |
| 36 | 39 | error: aborting due to 3 previous errors |
| 37 | 40 |
tests/ui/const-generics/early/macro_rules-braces.stderr+4| ... | ... | @@ -28,6 +28,7 @@ LL | let _: foo!({{ N }}); |
| 28 | 28 | | |
| 29 | 29 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 30 | 30 | = 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 | |
| 31 | 32 | |
| 32 | 33 | error: generic parameters may not be used in const operations |
| 33 | 34 | --> $DIR/macro_rules-braces.rs:36:19 |
| ... | ... | @@ -37,6 +38,7 @@ LL | let _: bar!({ N }); |
| 37 | 38 | | |
| 38 | 39 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 39 | 40 | = 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 | |
| 40 | 42 | |
| 41 | 43 | error: generic parameters may not be used in const operations |
| 42 | 44 | --> $DIR/macro_rules-braces.rs:41:20 |
| ... | ... | @@ -46,6 +48,7 @@ LL | let _: baz!({{ N }}); |
| 46 | 48 | | |
| 47 | 49 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 48 | 50 | = 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 | |
| 49 | 52 | |
| 50 | 53 | error: generic parameters may not be used in const operations |
| 51 | 54 | --> $DIR/macro_rules-braces.rs:46:19 |
| ... | ... | @@ -55,6 +58,7 @@ LL | let _: biz!({ N }); |
| 55 | 58 | | |
| 56 | 59 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 57 | 60 | = 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 | |
| 58 | 62 | |
| 59 | 63 | error: aborting due to 6 previous errors |
| 60 | 64 |
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!() }}> { |
| 9 | 9 | | |
| 10 | 10 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 11 | 11 | = 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 | |
| 12 | 13 | = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 13 | 14 | |
| 14 | 15 | error: 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!() }> { |
| 9 | 9 | | |
| 10 | 10 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 11 | 11 | = 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 | |
| 12 | 13 | = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 13 | 14 | |
| 14 | 15 | error: 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 } }> { |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
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 | ||
| 6 | use std::mem::size_of; | |
| 7 | ||
| 8 | // Exact case from the issue: `Self` in a trait method. | |
| 9 | pub 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 | ||
| 16 | fn foo<T>() -> [u8; size_of::<T>()] { | |
| 17 | //~^ ERROR generic parameters may not be used in const operations | |
| 18 | todo!() | |
| 19 | } | |
| 20 | ||
| 21 | fn bar<const N: usize>() -> [u8; N + 1] { | |
| 22 | //~^ ERROR generic parameters may not be used in const operations | |
| 23 | todo!() | |
| 24 | } | |
| 25 | ||
| 26 | fn main() {} |
tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.stderr created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | error: generic parameters may not be used in const operations | |
| 2 | --> $DIR/suggest-const-item-for-generic-expr.rs:10:43 | |
| 3 | | | |
| 4 | LL | 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 | ||
| 11 | error: generic parameters may not be used in const operations | |
| 12 | --> $DIR/suggest-const-item-for-generic-expr.rs:16:31 | |
| 13 | | | |
| 14 | LL | 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 | ||
| 21 | error: generic parameters may not be used in const operations | |
| 22 | --> $DIR/suggest-const-item-for-generic-expr.rs:21:34 | |
| 23 | | | |
| 24 | LL | 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 | ||
| 31 | error: 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]); |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/array-size-in-generic-struct-param.rs:23:15 |
| ... | ... | @@ -15,6 +16,7 @@ LL | arr: [u8; CFG.arr_size], |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `CFG` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: `Config` is forbidden as the type of a const generic parameter |
| 20 | 22 | --> $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 }>:, |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `D` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0747]: constant provided when a type was expected |
| 11 | 12 | --> $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 |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/dependence_lint.rs:22:37 |
| ... | ... | @@ -15,6 +16,7 @@ LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, |
| 15 | 16 | | |
| 16 | 17 | = note: type parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | warning: cannot use constants which depend on generic parameters in types |
| 20 | 22 | --> $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 |
| 9 | 9 | | |
| 10 | 10 | LL | impl<const F: usize> aux::FromSlice for Wrapper<F> { |
| 11 | 11 | | ^^^^^^^^^^ |
| 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 | |
| 12 | 14 | |
| 13 | 15 | error: aborting due to 1 previous error |
| 14 | 16 |
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]; |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/generic_const_exprs/issue-72787.min.stderr+4| ... | ... | @@ -6,6 +6,7 @@ LL | Condition<{ LHS <= RHS }>: True |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `LHS` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/issue-72787.rs:11:24 |
| ... | ... | @@ -15,6 +16,7 @@ LL | Condition<{ LHS <= RHS }>: True |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `RHS` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: generic parameters may not be used in const operations |
| 20 | 22 | --> $DIR/issue-72787.rs:23:25 |
| ... | ... | @@ -24,6 +26,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, |
| 24 | 26 | | |
| 25 | 27 | = help: const parameters may only be used as standalone arguments here, i.e. `I` |
| 26 | 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 | |
| 27 | 30 | |
| 28 | 31 | error: generic parameters may not be used in const operations |
| 29 | 32 | --> $DIR/issue-72787.rs:23:36 |
| ... | ... | @@ -33,6 +36,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, |
| 33 | 36 | | |
| 34 | 37 | = help: const parameters may only be used as standalone arguments here, i.e. `J` |
| 35 | 38 | = 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 | |
| 36 | 40 | |
| 37 | 41 | error: aborting due to 4 previous errors |
| 38 | 42 |
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, |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/generic_const_exprs/issue-74713.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | let _: &'a (); |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0308]: mismatched types |
| 11 | 12 | --> $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 |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `S` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/ice-68875.stderr+3| ... | ... | @@ -3,6 +3,9 @@ error: generic `Self` types are currently not permitted in anonymous constants |
| 3 | 3 | | |
| 4 | 4 | LL | data: &'a [u8; Self::SIZE], |
| 5 | 5 | | ^^^^ |
| 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 | |
| 6 | 9 | |
| 7 | 10 | error: aborting due to 1 previous error |
| 8 | 11 |
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>() }>, |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: `&'static str` is forbidden as the type of a const generic parameter |
| 11 | 12 | --> $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>()] |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0392]: lifetime parameter `'a` is never used |
| 11 | 12 | --> $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 |
| 9 | 9 | | |
| 10 | 10 | LL | impl<'a> OnDiskDirEntry<'a> { |
| 11 | 11 | | ^^^^^^^^^^^^^^^^^^ |
| 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 | |
| 12 | 14 | |
| 13 | 15 | error: aborting due to 1 previous error |
| 14 | 16 |
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 |
| 3 | 3 | | |
| 4 | 4 | LL | ram: [u8; Self::SIZE], |
| 5 | 5 | | ^^^^ |
| 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 | |
| 6 | 9 | |
| 7 | 10 | error: aborting due to 1 previous error |
| 8 | 11 |
tests/ui/const-generics/issues/issue-67375.min.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | inner: [(); { [|_: &T| {}; 0].len() }], |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0392]: type parameter `T` is never used |
| 11 | 12 | --> $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(); |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/issue-67945-1.rs:13:45 |
| ... | ... | @@ -15,6 +16,7 @@ LL | let b = &*(&x as *const _ as *const S); |
| 15 | 16 | | |
| 16 | 17 | = note: type parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error[E0392]: type parameter `S` is never used |
| 20 | 22 | --> $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 |
| 3 | 3 | | |
| 4 | 4 | LL | let x: Option<Box<Self>> = None; |
| 5 | 5 | | ^^^^ |
| 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 | |
| 6 | 9 | |
| 7 | 10 | error: aborting due to 1 previous error |
| 8 | 11 |
tests/ui/const-generics/issues/issue-67945-3.min.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | let x: Option<S> = None; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0392]: type parameter `S` is never used |
| 11 | 12 | --> $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; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0392]: type parameter `S` is never used |
| 11 | 12 | --> $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)}> {} |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: `Option<usize>` is forbidden as the type of a const generic parameter |
| 11 | 12 | --> $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>()] { |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/issue-76701-ty-param-in-const.rs:6:42 |
| ... | ... | @@ -15,6 +16,7 @@ LL | fn const_param<const N: usize>() -> [u8; N + 1] { |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: aborting due to 2 previous errors |
| 20 | 22 |
tests/ui/const-generics/issues/issue-80062.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | let _: [u8; sof::<T>()]; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/issues/issue-80375.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | struct MyArray<const COUNT: usize>([u8; COUNT + 1]); |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `COUNT` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/const-generics/legacy-const-generics-bad.stderr+1| ... | ... | @@ -18,6 +18,7 @@ LL | legacy_const_generics::foo(0, N + 1, 2); |
| 18 | 18 | | |
| 19 | 19 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 20 | 20 | = 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 | |
| 21 | 22 | |
| 22 | 23 | error: aborting due to 2 previous errors |
| 23 | 24 |
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 |
| 10 | 10 | LL | foo::<{ Some::<u32> { 0: const { N + 1 } } }>(); |
| 11 | 11 | | ^ |
| 12 | 12 | | |
| 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 | |
| 14 | 14 | |
| 15 | 15 | error: aborting due to 2 previous errors |
| 16 | 16 |
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 |
| 4 | 4 | LL | T: Trait<const { let a: &'a (); 1 }> |
| 5 | 5 | | ^^ |
| 6 | 6 | | |
| 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 | |
| 8 | 8 | |
| 9 | 9 | error: aborting due to 1 previous error |
| 10 | 10 |
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 |
| 40 | 40 | LL | type const ITEM3<const N: usize>: usize = const { N }; |
| 41 | 41 | | ^ |
| 42 | 42 | | |
| 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 | |
| 44 | 44 | |
| 45 | 45 | error: generic parameters may not be used in const operations |
| 46 | 46 | --> $DIR/explicit_anon_consts.rs:60:31 |
| ... | ... | @@ -48,7 +48,7 @@ error: generic parameters may not be used in const operations |
| 48 | 48 | LL | T3: Trait<ASSOC = const { N }>, |
| 49 | 49 | | ^ |
| 50 | 50 | | |
| 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 | |
| 52 | 52 | |
| 53 | 53 | error: generic parameters may not be used in const operations |
| 54 | 54 | --> $DIR/explicit_anon_consts.rs:69:58 |
| ... | ... | @@ -56,7 +56,7 @@ error: generic parameters may not be used in const operations |
| 56 | 56 | LL | struct Default3<const N: usize, const M: usize = const { N }>; |
| 57 | 57 | | ^ |
| 58 | 58 | | |
| 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 | |
| 60 | 60 | |
| 61 | 61 | error: generic parameters may not be used in const operations |
| 62 | 62 | --> $DIR/explicit_anon_consts.rs:28:27 |
| ... | ... | @@ -64,7 +64,7 @@ error: generic parameters may not be used in const operations |
| 64 | 64 | LL | let _3 = [(); const { N }]; |
| 65 | 65 | | ^ |
| 66 | 66 | | |
| 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 | |
| 68 | 68 | |
| 69 | 69 | error: generic parameters may not be used in const operations |
| 70 | 70 | --> $DIR/explicit_anon_consts.rs:33:26 |
| ... | ... | @@ -72,7 +72,7 @@ error: generic parameters may not be used in const operations |
| 72 | 72 | LL | let _6: [(); const { N }] = todo!(); |
| 73 | 73 | | ^ |
| 74 | 74 | | |
| 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 | |
| 76 | 76 | |
| 77 | 77 | error: generic parameters may not be used in const operations |
| 78 | 78 | --> $DIR/explicit_anon_consts.rs:11:41 |
| ... | ... | @@ -80,7 +80,7 @@ error: generic parameters may not be used in const operations |
| 80 | 80 | LL | type Adt3<const N: usize> = Foo<const { N }>; |
| 81 | 81 | | ^ |
| 82 | 82 | | |
| 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 | |
| 84 | 84 | |
| 85 | 85 | error: generic parameters may not be used in const operations |
| 86 | 86 | --> $DIR/explicit_anon_consts.rs:19:42 |
| ... | ... | @@ -88,7 +88,7 @@ error: generic parameters may not be used in const operations |
| 88 | 88 | LL | type Arr3<const N: usize> = [(); const { N }]; |
| 89 | 89 | | ^ |
| 90 | 90 | | |
| 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 | |
| 92 | 92 | |
| 93 | 93 | error: aborting due to 13 previous errors |
| 94 | 94 |
tests/ui/const-generics/mgca/selftyalias-containing-param.stderr+1-1| ... | ... | @@ -9,7 +9,7 @@ note: not a concrete type |
| 9 | 9 | | |
| 10 | 10 | LL | impl<const N: usize> S<N> { |
| 11 | 11 | | ^^^^ |
| 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 | |
| 13 | 13 | |
| 14 | 14 | error: aborting due to 1 previous error |
| 15 | 15 |
tests/ui/const-generics/mgca/selftyparam.stderr+1-1| ... | ... | @@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations |
| 4 | 4 | LL | fn foo() -> [(); const { let _: Self; 1 }]; |
| 5 | 5 | | ^^^^ |
| 6 | 6 | | |
| 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 | |
| 8 | 8 | |
| 9 | 9 | error: aborting due to 1 previous error |
| 10 | 10 |
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 |
| 10 | 10 | LL | [0; const { size_of::<*mut T>() }]; |
| 11 | 11 | | ^ |
| 12 | 12 | | |
| 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 | |
| 14 | 14 | |
| 15 | 15 | error: aborting due to 2 previous errors |
| 16 | 16 |
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 |
| 10 | 10 | LL | with_point::<{ Point(const { N + 1 }, N) }>(); |
| 11 | 11 | | ^ |
| 12 | 12 | | |
| 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 | |
| 14 | 14 | |
| 15 | 15 | error: aborting due to 2 previous errors |
| 16 | 16 |
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 |
| 22 | 22 | LL | takes_nested_tuple::<{ (N, (N, const { N + 1 })) }>(); |
| 23 | 23 | | ^ |
| 24 | 24 | | |
| 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 | |
| 26 | 26 | |
| 27 | 27 | error: aborting due to 4 previous errors |
| 28 | 28 |
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 |
| 4 | 4 | LL | type const FREE1<T>: usize = const { std::mem::size_of::<T>() }; |
| 5 | 5 | | ^ |
| 6 | 6 | | |
| 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 | |
| 8 | 8 | |
| 9 | 9 | error: generic parameters may not be used in const operations |
| 10 | 10 | --> $DIR/type_const-on-generic-expr.rs:8:51 |
| ... | ... | @@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations |
| 12 | 12 | LL | type const FREE2<const I: usize>: usize = const { I + 1 }; |
| 13 | 13 | | ^ |
| 14 | 14 | | |
| 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 | |
| 16 | 16 | |
| 17 | 17 | error: aborting due to 2 previous errors |
| 18 | 18 |
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 |
| 4 | 4 | LL | type const N1<T>: usize = const { std::mem::size_of::<T>() }; |
| 5 | 5 | | ^ |
| 6 | 6 | | |
| 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 | |
| 8 | 8 | |
| 9 | 9 | error: generic parameters may not be used in const operations |
| 10 | 10 | --> $DIR/type_const-on-generic_expr-2.rs:15:52 |
| ... | ... | @@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations |
| 12 | 12 | LL | type const N2<const I: usize>: usize = const { I + 1 }; |
| 13 | 13 | | ^ |
| 14 | 14 | | |
| 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 | |
| 16 | 16 | |
| 17 | 17 | error: generic parameters may not be used in const operations |
| 18 | 18 | --> $DIR/type_const-on-generic_expr-2.rs:17:40 |
| ... | ... | @@ -20,7 +20,7 @@ error: generic parameters may not be used in const operations |
| 20 | 20 | LL | type const N3: usize = const { 2 & X }; |
| 21 | 21 | | ^ |
| 22 | 22 | | |
| 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 | |
| 24 | 24 | |
| 25 | 25 | error: aborting due to 3 previous errors |
| 26 | 26 |
tests/ui/const-generics/min_const_generics/complex-expression.stderr+7| ... | ... | @@ -6,6 +6,7 @@ LL | struct Break0<const N: usize>([u8; { N + 1 }]); |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/complex-expression.rs:13:40 |
| ... | ... | @@ -15,6 +16,7 @@ LL | struct Break1<const N: usize>([u8; { { N } }]); |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: generic parameters may not be used in const operations |
| 20 | 22 | --> $DIR/complex-expression.rs:17:17 |
| ... | ... | @@ -24,6 +26,7 @@ LL | let _: [u8; N + 1]; |
| 24 | 26 | | |
| 25 | 27 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 26 | 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 | |
| 27 | 30 | |
| 28 | 31 | error: generic parameters may not be used in const operations |
| 29 | 32 | --> $DIR/complex-expression.rs:22:17 |
| ... | ... | @@ -33,6 +36,7 @@ LL | let _ = [0; N + 1]; |
| 33 | 36 | | |
| 34 | 37 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 35 | 38 | = 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 | |
| 36 | 40 | |
| 37 | 41 | error: generic parameters may not be used in const operations |
| 38 | 42 | --> $DIR/complex-expression.rs:26:45 |
| ... | ... | @@ -42,6 +46,7 @@ LL | struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]); |
| 42 | 46 | | |
| 43 | 47 | = note: type parameters may not be used in const expressions |
| 44 | 48 | = 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 | |
| 45 | 50 | |
| 46 | 51 | error: generic parameters may not be used in const operations |
| 47 | 52 | --> $DIR/complex-expression.rs:29:47 |
| ... | ... | @@ -51,6 +56,7 @@ LL | struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]); |
| 51 | 56 | | |
| 52 | 57 | = note: type parameters may not be used in const expressions |
| 53 | 58 | = 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 | |
| 54 | 60 | |
| 55 | 61 | error: generic parameters may not be used in const operations |
| 56 | 62 | --> $DIR/complex-expression.rs:33:32 |
| ... | ... | @@ -60,6 +66,7 @@ LL | let _: [u8; size_of::<*mut T>() + 1]; |
| 60 | 66 | | |
| 61 | 67 | = note: type parameters may not be used in const expressions |
| 62 | 68 | = 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 | |
| 63 | 70 | |
| 64 | 71 | warning: cannot use constants which depend on generic parameters in types |
| 65 | 72 | --> $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 },>(); |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/forbid-non-static-lifetimes.rs:21:16 |
| ... | ... | @@ -15,6 +16,7 @@ LL | [(); (|_: &'a u8| (), 0).1]; |
| 15 | 16 | | |
| 16 | 17 | = note: lifetime parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: aborting due to 2 previous errors |
| 20 | 22 |
tests/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr+2| ... | ... | @@ -9,6 +9,8 @@ note: not a concrete type |
| 9 | 9 | | |
| 10 | 10 | LL | impl<T> BindsParam<T> for <T as AlwaysApplicable>::Assoc { |
| 11 | 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 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 | |
| 12 | 14 | |
| 13 | 15 | error: aborting due to 1 previous error |
| 14 | 16 |
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>()]; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic `Self` types are currently not permitted in anonymous constants |
| 11 | 12 | --> $DIR/self-ty-in-const-1.rs:12:41 |
| ... | ... | @@ -18,6 +19,8 @@ note: not a concrete type |
| 18 | 19 | | |
| 19 | 20 | LL | impl<T> Bar<T> { |
| 20 | 21 | | ^^^^^^ |
| 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 | |
| 21 | 24 | |
| 22 | 25 | error: aborting due to 2 previous errors |
| 23 | 26 |
tests/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr+2| ... | ... | @@ -9,6 +9,8 @@ note: not a concrete type |
| 9 | 9 | | |
| 10 | 10 | LL | impl<T> Baz for Bar<T> { |
| 11 | 11 | | ^^^^^^ |
| 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 | |
| 12 | 14 | |
| 13 | 15 | error: aborting due to 1 previous error |
| 14 | 16 |
tests/ui/const-generics/outer-lifetime-in-const-generic-default.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | let x: &'a (); |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
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); |
| 12 | 12 | | |
| 13 | 13 | = note: type parameters may not be used in const expressions |
| 14 | 14 | = 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 | |
| 15 | 16 | |
| 16 | 17 | error[E0128]: generic parameter defaults cannot reference parameters before they are declared |
| 17 | 18 | --> $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] }>(); |
| 6 | 6 | | |
| 7 | 7 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $DIR/repeat_expr_hack_gives_right_generics.rs:22:19 |
| ... | ... | @@ -15,6 +16,7 @@ LL | bar::<{ [1; { N + 1 }] }>(); |
| 15 | 16 | | |
| 16 | 17 | = help: const parameters may only be used as standalone arguments here, i.e. `N` |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: aborting due to 2 previous errors |
| 20 | 22 |
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 |
| 3 | 3 | | |
| 4 | 4 | LL | type SupportedArray<T> = [T; <Self::InfoType as LevelInfo>::SUPPORTED_SLOTS]; |
| 5 | 5 | | ^^^^^^^^^^^^^^ |
| 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 | |
| 6 | 9 | |
| 7 | 10 | error: aborting due to 1 previous error |
| 8 | 11 |
tests/ui/consts/const-eval/size-of-t.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | let _arr: [u8; size_of::<T>()]; |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/delegation/bad-resolve.rs+1| ... | ... | @@ -33,6 +33,7 @@ impl Trait for S { |
| 33 | 33 | |
| 34 | 34 | reuse foo { &self.0 } |
| 35 | 35 | //~^ ERROR cannot find function `foo` in this scope |
| 36 | //~| ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl | |
| 36 | 37 | reuse Trait::foo2 { self.0 } |
| 37 | 38 | //~^ ERROR cannot find function `foo2` in trait `Trait` |
| 38 | 39 | //~| 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; |
| 26 | 26 | | not a member of trait `Trait` |
| 27 | 27 | |
| 28 | 28 | error[E0407]: method `foo2` is not a member of trait `Trait` |
| 29 | --> $DIR/bad-resolve.rs:36:5 | |
| 29 | --> $DIR/bad-resolve.rs:37:5 | |
| 30 | 30 | | |
| 31 | 31 | LL | reuse Trait::foo2 { self.0 } |
| 32 | 32 | | ^^^^^^^^^^^^^----^^^^^^^^^^^ |
| ... | ... | @@ -68,7 +68,7 @@ LL | reuse foo { &self.0 } |
| 68 | 68 | | ^^^ not found in this scope |
| 69 | 69 | |
| 70 | 70 | error[E0425]: cannot find function `foo2` in trait `Trait` |
| 71 | --> $DIR/bad-resolve.rs:36:18 | |
| 71 | --> $DIR/bad-resolve.rs:37:18 | |
| 72 | 72 | | |
| 73 | 73 | LL | fn foo(&self, x: i32) -> i32 { x } |
| 74 | 74 | | ---------------------------- similarly named associated function `foo` defined here |
| ... | ... | @@ -83,11 +83,20 @@ LL + reuse Trait::foo { self.0 } |
| 83 | 83 | | |
| 84 | 84 | |
| 85 | 85 | error[E0423]: expected function, found module `prefix::self` |
| 86 | --> $DIR/bad-resolve.rs:43:7 | |
| 86 | --> $DIR/bad-resolve.rs:44:7 | |
| 87 | 87 | | |
| 88 | 88 | LL | reuse prefix::{self, super, crate}; |
| 89 | 89 | | ^^^^^^ not a function |
| 90 | 90 | |
| 91 | error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl | |
| 92 | --> $DIR/bad-resolve.rs:34:11 | |
| 93 | | | |
| 94 | LL | fn foo(&self, x: i32) -> i32 { x } | |
| 95 | | ---------------------------- `&self` used in trait | |
| 96 | ... | |
| 97 | LL | reuse foo { &self.0 } | |
| 98 | | ^^^ expected `&self` in impl | |
| 99 | ||
| 91 | 100 | error[E0046]: not all trait items implemented, missing: `Type` |
| 92 | 101 | --> $DIR/bad-resolve.rs:21:1 |
| 93 | 102 | | |
| ... | ... | @@ -98,7 +107,7 @@ LL | impl Trait for S { |
| 98 | 107 | | ^^^^^^^^^^^^^^^^ missing `Type` in implementation |
| 99 | 108 | |
| 100 | 109 | error[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 | |
| 102 | 111 | | |
| 103 | 112 | LL | reuse unresolved_prefix::{a, b, c}; |
| 104 | 113 | | ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `unresolved_prefix` |
| ... | ... | @@ -106,12 +115,12 @@ LL | reuse unresolved_prefix::{a, b, c}; |
| 106 | 115 | = help: you might be missing a crate named `unresolved_prefix` |
| 107 | 116 | |
| 108 | 117 | error[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 | |
| 110 | 119 | | |
| 111 | 120 | LL | reuse prefix::{self, super, crate}; |
| 112 | 121 | | ^^^^^ can only be used in path start position |
| 113 | 122 | |
| 114 | error: aborting due to 13 previous errors | |
| 123 | error: aborting due to 14 previous errors | |
| 115 | 124 | |
| 116 | Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576. | |
| 125 | Some errors have detailed explanations: E0046, E0186, E0324, E0407, E0423, E0425, E0433, E0575, E0576. | |
| 117 | 126 | For 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 | ||
| 3 | pub trait Trait<'a> { | |
| 4 | fn foo(&self); | |
| 5 | } | |
| 6 | ||
| 7 | pub struct S<'a, A>(&'a A); | |
| 8 | impl<'a, A> Trait<'a> for S<'a, A> { | |
| 9 | reuse Trait::<A = ()>::foo; | |
| 10 | //~^ ERROR: associated item constraints are not allowed here | |
| 11 | } | |
| 12 | ||
| 13 | fn main() {} |
tests/ui/delegation/constraints-in-generic-args-ice-158812.stderr created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | error[E0229]: associated item constraints are not allowed here | |
| 2 | --> $DIR/constraints-in-generic-args-ice-158812.rs:9:19 | |
| 3 | | | |
| 4 | LL | reuse Trait::<A = ()>::foo; | |
| 5 | | ^^^^^^ associated item constraint not allowed here | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 3 | mod 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 | ||
| 32 | mod 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 | ||
| 47 | fn main() {} |
tests/ui/delegation/self-mapping-arguments-errors.stderr created+98| ... | ... | @@ -0,0 +1,98 @@ |
| 1 | error: attempted to lower target expression with definitions more than once while mapping argument | |
| 2 | --> $DIR/self-mapping-arguments-errors.rs:14:5 | |
| 3 | | | |
| 4 | LL | / reuse impl MyAdd for W { | |
| 5 | ... | | |
| 6 | LL | | self.0 | |
| 7 | LL | | } | |
| 8 | | |_____^ | |
| 9 | ||
| 10 | error[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 | | | |
| 13 | LL | fn add(self, other: Self) -> Self; | |
| 14 | | ---------------------------------- `self` used in trait | |
| 15 | ... | |
| 16 | LL | / reuse impl MyAdd for W { | |
| 17 | ... | | |
| 18 | LL | | self.0 | |
| 19 | LL | | } | |
| 20 | | |_____^ expected `self` in impl | |
| 21 | ||
| 22 | error[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 | | | |
| 25 | LL | / reuse impl MyAdd for W { | |
| 26 | ... | | |
| 27 | LL | | self.0 | |
| 28 | LL | | } | |
| 29 | | |_____^ the trait `target_expr_doesnt_relower_when_defs_inside::MyAdd` is not implemented for `()` | |
| 30 | | | |
| 31 | help: the following other types implement trait `target_expr_doesnt_relower_when_defs_inside::MyAdd` | |
| 32 | --> $DIR/self-mapping-arguments-errors.rs:8:5 | |
| 33 | | | |
| 34 | LL | impl MyAdd for usize { | |
| 35 | | ^^^^^^^^^^^^^^^^^^^^ `usize` | |
| 36 | ... | |
| 37 | LL | reuse impl MyAdd for W { | |
| 38 | | ^^^^^^^^^^^^^^^^^^^^^^ `target_expr_doesnt_relower_when_defs_inside::W` | |
| 39 | ||
| 40 | error[E0061]: this function takes 2 arguments but 1 argument was supplied | |
| 41 | --> $DIR/self-mapping-arguments-errors.rs:14:5 | |
| 42 | | | |
| 43 | LL | / reuse impl MyAdd for W { | |
| 44 | ... | | |
| 45 | LL | | self.0 | |
| 46 | LL | | } | |
| 47 | | | ^ | |
| 48 | | | | | |
| 49 | | |_____argument #2 of type `()` is missing | |
| 50 | | this implicit `()` return type influences the call expression's return type | |
| 51 | | | |
| 52 | note: method defined here | |
| 53 | --> $DIR/self-mapping-arguments-errors.rs:5:12 | |
| 54 | | | |
| 55 | LL | fn add(self, other: Self) -> Self; | |
| 56 | | ^^^ ----- | |
| 57 | help: provide the argument | |
| 58 | | | |
| 59 | LL ~ }({ | |
| 60 | LL + | |
| 61 | LL + | |
| 62 | LL + | |
| 63 | LL + | |
| 64 | LL + println!("{self:?}"); | |
| 65 | LL + fn foo() { | |
| 66 | LL + println!("hello"); | |
| 67 | LL + } | |
| 68 | LL + | |
| 69 | LL + reuse foo as bar; | |
| 70 | LL + bar(); | |
| 71 | LL + bar(); | |
| 72 | LL + | |
| 73 | LL + self.0 | |
| 74 | LL + }, ()) | |
| 75 | | | |
| 76 | ||
| 77 | error[E0308]: mismatched types | |
| 78 | --> $DIR/self-mapping-arguments-errors.rs:43:5 | |
| 79 | | | |
| 80 | LL | 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>` | |
| 89 | note: method defined here | |
| 90 | --> $DIR/self-mapping-arguments-errors.rs:34:12 | |
| 91 | | | |
| 92 | LL | fn add(self, other: Box<Self>) -> Self; | |
| 93 | | ^^^ ----- | |
| 94 | ||
| 95 | error: aborting due to 5 previous errors | |
| 96 | ||
| 97 | Some errors have detailed explanations: E0061, E0186, E0277, E0308. | |
| 98 | For 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 | ||
| 7 | mod 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 | ||
| 30 | mod 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 | ||
| 56 | fn 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 @@ |
| 1 | W(1) | |
| 2 | W(2) | |
| 3 | W(2) | |
| 4 | W(10) | |
| 5 | 12 |
tests/ui/dyn-compatibility/ice-generics-of-crate-root-152335.rs+1-1| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | // Regression test for #152335. |
| 2 | 2 | // The compiler used to ICE in `generics_of` when `note_and_explain_type_err` |
| 3 | 3 | // 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` | |
| 5 | 5 | // to `CRATE_DEF_ID`, and error reporting tried to look up generics on it. |
| 6 | 6 | |
| 7 | 7 | struct 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 |
| 4 | 4 | LL | type const INC<const N: usize>: usize = const { N + 1 }; |
| 5 | 5 | | ^ |
| 6 | 6 | | |
| 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 | |
| 8 | 8 | |
| 9 | 9 | error: aborting due to 1 previous error |
| 10 | 10 |
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] { |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0658]: `type const` syntax is experimental |
| 11 | 12 | --> $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); |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
tests/ui/lifetimes/issue-64173-unused-lifetimes.stderr+4| ... | ... | @@ -6,6 +6,7 @@ LL | beta: [(); foo::<&'a ()>()], |
| 6 | 6 | | |
| 7 | 7 | = note: lifetime parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error[E0392]: lifetime parameter `'s` is never used |
| 11 | 12 | --> $DIR/issue-64173-unused-lifetimes.rs:3:12 |
| ... | ... | @@ -20,6 +21,9 @@ error: generic `Self` types are currently not permitted in anonymous constants |
| 20 | 21 | | |
| 21 | 22 | LL | array: [(); size_of::<&Self>()], |
| 22 | 23 | | ^^^^ |
| 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 | |
| 23 | 27 | |
| 24 | 28 | error[E0392]: lifetime parameter `'a` is never used |
| 25 | 29 | --> $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 | ||
| 8 | macro_rules! type_or_expr { | |
| 9 | ($x:ty) => { | |
| 10 | identity(stringify!($x)) | |
| 11 | }; | |
| 12 | ($x:expr) => { | |
| 13 | identity($x) | |
| 14 | }; | |
| 15 | } | |
| 16 | ||
| 17 | macro_rules! call_expr { | |
| 18 | ($e:expr) => { | |
| 19 | identity($e) | |
| 20 | }; | |
| 21 | } | |
| 22 | ||
| 23 | macro_rules! call_block { | |
| 24 | ($b:block) => { | |
| 25 | identity($b) | |
| 26 | }; | |
| 27 | } | |
| 28 | ||
| 29 | fn identity<T>(x: T) -> T { | |
| 30 | x | |
| 31 | } | |
| 32 | ||
| 33 | fn 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 | ||
| 8 | macro_rules! type_or_expr { | |
| 9 | ($x:ty) => { | |
| 10 | identity(stringify!($x)) | |
| 11 | }; | |
| 12 | ($x:expr) => { | |
| 13 | identity($x) | |
| 14 | }; | |
| 15 | } | |
| 16 | ||
| 17 | macro_rules! call_expr { | |
| 18 | ($e:expr) => { | |
| 19 | identity($e) | |
| 20 | }; | |
| 21 | } | |
| 22 | ||
| 23 | macro_rules! call_block { | |
| 24 | ($b:block) => { | |
| 25 | identity($b) | |
| 26 | }; | |
| 27 | } | |
| 28 | ||
| 29 | fn identity<T>(x: T) -> T { | |
| 30 | x | |
| 31 | } | |
| 32 | ||
| 33 | fn 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 @@ |
| 1 | warning: unnecessary braces around function argument | |
| 2 | --> $DIR/unused-braces-macro-arg-issue-158747.rs:37:24 | |
| 3 | | | |
| 4 | LL | let _ = call_expr!({ 1 }); | |
| 5 | | ^^ ^^ | |
| 6 | | | |
| 7 | note: the lint level is defined here | |
| 8 | --> $DIR/unused-braces-macro-arg-issue-158747.rs:6:9 | |
| 9 | | | |
| 10 | LL | #![warn(unused_braces)] | |
| 11 | | ^^^^^^^^^^^^^ | |
| 12 | help: remove these braces | |
| 13 | | | |
| 14 | LL - let _ = call_expr!({ 1 }); | |
| 15 | LL + let _ = call_expr!(1); | |
| 16 | | | |
| 17 | ||
| 18 | warning: 1 warning emitted | |
| 19 |
tests/ui/resolve/issue-39559.stderr+1| ... | ... | @@ -6,6 +6,7 @@ LL | entries: [T; D::dim()], |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: aborting due to 1 previous error |
| 11 | 12 |
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) |
| 6 | 6 | | |
| 7 | 7 | = note: type parameters may not be used in const expressions |
| 8 | 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 | |
| 9 | 10 | |
| 10 | 11 | error: generic parameters may not be used in const operations |
| 11 | 12 | --> $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) |
| 15 | 16 | | |
| 16 | 17 | = note: type parameters may not be used in const expressions |
| 17 | 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 | |
| 18 | 20 | |
| 19 | 21 | error: generic parameters may not be used in const operations |
| 20 | 22 | --> $DIR/assoc_const.rs:20:40 |
| ... | ... | @@ -24,6 +26,7 @@ LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {} |
| 24 | 26 | | |
| 25 | 27 | = note: type parameters may not be used in const expressions |
| 26 | 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 | |
| 27 | 30 | |
| 28 | 31 | error: generic parameters may not be used in const operations |
| 29 | 32 | --> $DIR/assoc_const.rs:20:51 |
| ... | ... | @@ -33,6 +36,7 @@ LL | fn bar<T: Foo>(_: pattern_type!(u32 is T::START..=T::END)) {} |
| 33 | 36 | | |
| 34 | 37 | = note: type parameters may not be used in const expressions |
| 35 | 38 | = 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 | |
| 36 | 40 | |
| 37 | 41 | error: aborting due to 4 previous errors |
| 38 | 42 |