1
Fork 0
This commit is contained in:
bjorn3 2025-02-08 22:12:13 +00:00
parent 3183b44a1e
commit 1fcae03369
287 changed files with 5888 additions and 4608 deletions

View file

@ -1184,10 +1184,13 @@ impl Scalar {
#[inline] #[inline]
pub fn is_bool(&self) -> bool { pub fn is_bool(&self) -> bool {
use Integer::*; use Integer::*;
matches!(self, Scalar::Initialized { matches!(
self,
Scalar::Initialized {
value: Primitive::Int(I8, false), value: Primitive::Int(I8, false),
valid_range: WrappingRange { start: 0, end: 1 } valid_range: WrappingRange { start: 0, end: 1 }
}) }
)
} }
/// Get the primitive representation of this type, ignoring the valid range and whether the /// Get the primitive representation of this type, ignoring the valid range and whether the

View file

@ -828,7 +828,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
span, span,
Some(Arc::clone(&self.allow_gen_future)), Some(Arc::clone(&self.allow_gen_future)),
); );
self.lower_attrs(inner_hir_id, &[Attribute { self.lower_attrs(
inner_hir_id,
&[Attribute {
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new( kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
sym::track_caller, sym::track_caller,
span, span,
@ -836,7 +838,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(), id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
style: AttrStyle::Outer, style: AttrStyle::Outer,
span: unstable_span, span: unstable_span,
}]); }],
);
} }
} }

View file

@ -362,13 +362,16 @@ fn make_format_spec<'hir>(
debug_hex, debug_hex,
} = &placeholder.format_options; } = &placeholder.format_options;
let fill = ctx.expr_char(sp, fill.unwrap_or(' ')); let fill = ctx.expr_char(sp, fill.unwrap_or(' '));
let align = let align = ctx.expr_lang_item_type_relative(
ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatAlignment, match alignment { sp,
hir::LangItem::FormatAlignment,
match alignment {
Some(FormatAlignment::Left) => sym::Left, Some(FormatAlignment::Left) => sym::Left,
Some(FormatAlignment::Right) => sym::Right, Some(FormatAlignment::Right) => sym::Right,
Some(FormatAlignment::Center) => sym::Center, Some(FormatAlignment::Center) => sym::Center,
None => sym::Unknown, None => sym::Unknown,
}); },
);
// This needs to match `Flag` in library/core/src/fmt/rt.rs. // This needs to match `Flag` in library/core/src/fmt/rt.rs.
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32) let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
| ((sign == Some(FormatSign::Minus)) as u32) << 1 | ((sign == Some(FormatSign::Minus)) as u32) << 1

View file

@ -304,12 +304,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
); );
this.arena.alloc(this.ty(span, hir::TyKind::Err(guar))) this.arena.alloc(this.ty(span, hir::TyKind::Err(guar)))
} }
Some(ty) => this.lower_ty(ty, ImplTraitContext::OpaqueTy { Some(ty) => this.lower_ty(
ty,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { origin: hir::OpaqueTyOrigin::TyAlias {
parent: this.local_def_id(id), parent: this.local_def_id(id),
in_assoc_ty: false, in_assoc_ty: false,
}, },
}), },
),
}, },
); );
hir::ItemKind::TyAlias(ty, generics) hir::ItemKind::TyAlias(ty, generics)
@ -966,12 +969,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ImplItemKind::Type(ty) hir::ImplItemKind::Type(ty)
} }
Some(ty) => { Some(ty) => {
let ty = this.lower_ty(ty, ImplTraitContext::OpaqueTy { let ty = this.lower_ty(
ty,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { origin: hir::OpaqueTyOrigin::TyAlias {
parent: this.local_def_id(i.id), parent: this.local_def_id(i.id),
in_assoc_ty: true, in_assoc_ty: true,
}, },
}); },
);
hir::ImplItemKind::Type(ty) hir::ImplItemKind::Type(ty)
} }
}, },
@ -1152,10 +1158,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_const_body(&mut self, span: Span, expr: Option<&Expr>) -> hir::BodyId { pub(super) fn lower_const_body(&mut self, span: Span, expr: Option<&Expr>) -> hir::BodyId {
self.lower_body(|this| { self.lower_body(|this| {
(&[], match expr { (
&[],
match expr {
Some(expr) => this.lower_expr_mut(expr), Some(expr) => this.lower_expr_mut(expr),
None => this.expr_err(span, this.dcx().span_delayed_bug(span, "no block")), None => this.expr_err(span, this.dcx().span_delayed_bug(span, "no block")),
}) },
)
}) })
} }

View file

@ -204,8 +204,13 @@ pub(crate) struct UnsupportedLiteral {
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
let mut diag = Diag::new(dcx, level, match self.reason { let mut diag = Diag::new(
UnsupportedLiteralReason::Generic => fluent::attr_parsing_unsupported_literal_generic, dcx,
level,
match self.reason {
UnsupportedLiteralReason::Generic => {
fluent::attr_parsing_unsupported_literal_generic
}
UnsupportedLiteralReason::CfgString => { UnsupportedLiteralReason::CfgString => {
fluent::attr_parsing_unsupported_literal_cfg_string fluent::attr_parsing_unsupported_literal_cfg_string
} }
@ -218,7 +223,8 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
UnsupportedLiteralReason::DeprecatedKvPair => { UnsupportedLiteralReason::DeprecatedKvPair => {
fluent::attr_parsing_unsupported_literal_deprecated_kv_pair fluent::attr_parsing_unsupported_literal_deprecated_kv_pair
} }
}); },
);
diag.span(self.span); diag.span(self.span);
diag.code(E0565); diag.code(E0565);
if self.is_bytestr { if self.is_bytestr {

View file

@ -156,20 +156,21 @@ pub(crate) trait TypeOpInfo<'tcx> {
return; return;
}; };
let placeholder_region = ty::Region::new_placeholder(tcx, ty::Placeholder { let placeholder_region = ty::Region::new_placeholder(
universe: adjusted_universe.into(), tcx,
bound: placeholder.bound, ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
}); );
let error_region = let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element { error_element
{
let adjusted_universe = let adjusted_universe =
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32()); error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
adjusted_universe.map(|adjusted| { adjusted_universe.map(|adjusted| {
ty::Region::new_placeholder(tcx, ty::Placeholder { ty::Region::new_placeholder(
universe: adjusted.into(), tcx,
bound: error_placeholder.bound, ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
}) )
}) })
} else { } else {
None None

View file

@ -147,10 +147,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
span, span,
desired_action.as_noun(), desired_action.as_noun(),
partially_str, partially_str,
self.describe_place_with_options(moved_place, DescribePlaceOpt { self.describe_place_with_options(
including_downcast: true, moved_place,
including_tuple_field: true, DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
}), ),
); );
let reinit_spans = maybe_reinitialized_locations let reinit_spans = maybe_reinitialized_locations
@ -280,10 +280,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
self.suggest_adding_bounds(&mut err, ty, copy_did, span); self.suggest_adding_bounds(&mut err, ty, copy_did, span);
} }
let opt_name = self.describe_place_with_options(place.as_ref(), DescribePlaceOpt { let opt_name = self.describe_place_with_options(
including_downcast: true, place.as_ref(),
including_tuple_field: true, DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
}); );
let note_msg = match opt_name { let note_msg = match opt_name {
Some(name) => format!("`{name}`"), Some(name) => format!("`{name}`"),
None => "value".to_owned(), None => "value".to_owned(),
@ -765,17 +765,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
} }
let spans: Vec<_> = spans_set.into_iter().collect(); let spans: Vec<_> = spans_set.into_iter().collect();
let (name, desc) = match self.describe_place_with_options(moved_place, DescribePlaceOpt { let (name, desc) = match self.describe_place_with_options(
including_downcast: true, moved_place,
including_tuple_field: true, DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
}) { ) {
Some(name) => (format!("`{name}`"), format!("`{name}` ")), Some(name) => (format!("`{name}`"), format!("`{name}` ")),
None => ("the variable".to_string(), String::new()), None => ("the variable".to_string(), String::new()),
}; };
let path = match self.describe_place_with_options(used_place, DescribePlaceOpt { let path = match self.describe_place_with_options(
including_downcast: true, used_place,
including_tuple_field: true, DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
}) { ) {
Some(name) => format!("`{name}`"), Some(name) => format!("`{name}`"),
None => "value".to_string(), None => "value".to_string(),
}; };

View file

@ -304,10 +304,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// End-user visible description of `place` if one can be found. /// End-user visible description of `place` if one can be found.
/// If the place is a temporary for instance, `None` will be returned. /// If the place is a temporary for instance, `None` will be returned.
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> { pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
self.describe_place_with_options(place_ref, DescribePlaceOpt { self.describe_place_with_options(
including_downcast: false, place_ref,
including_tuple_field: true, DescribePlaceOpt { including_downcast: false, including_tuple_field: true },
}) )
} }
/// End-user visible description of `place` if one can be found. If the place is a temporary /// End-user visible description of `place` if one can be found. If the place is a temporary

View file

@ -1100,12 +1100,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let closure_ty = Ty::new_closure( let closure_ty = Ty::new_closure(
tcx, tcx,
closure_def_id.to_def_id(), closure_def_id.to_def_id(),
ty::ClosureArgs::new(tcx, ty::ClosureArgsParts { ty::ClosureArgs::new(
tcx,
ty::ClosureArgsParts {
parent_args: args.parent_args(), parent_args: args.parent_args(),
closure_kind_ty: args.kind_ty(), closure_kind_ty: args.kind_ty(),
tupled_upvars_ty: args.tupled_upvars_ty(), tupled_upvars_ty: args.tupled_upvars_ty(),
closure_sig_as_fn_ptr_ty, closure_sig_as_fn_ptr_ty,
}) },
)
.args, .args,
); );

View file

@ -1668,9 +1668,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
match elem { match elem {
ProjectionElem::Deref => match place_ty.ty.kind() { ProjectionElem::Deref => match place_ty.ty.kind() {
ty::Ref(..) | ty::RawPtr(..) => { ty::Ref(..) | ty::RawPtr(..) => {
self.move_errors.push(MoveError::new(place, location, BorrowedContent { self.move_errors.push(MoveError::new(
place,
location,
BorrowedContent {
target_place: place_ref.project_deeper(&[elem], tcx), target_place: place_ref.project_deeper(&[elem], tcx),
})); },
));
return; return;
} }
ty::Adt(adt, _) => { ty::Adt(adt, _) => {

View file

@ -166,10 +166,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road. // FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
prev.span = prev.span.substitute_dummy(concrete_type.span); prev.span = prev.span.substitute_dummy(concrete_type.span);
} else { } else {
result.insert(opaque_type_key.def_id, OpaqueHiddenType { result.insert(
ty, opaque_type_key.def_id,
span: concrete_type.span, OpaqueHiddenType { ty, span: concrete_type.span },
}); );
} }
// Check that all opaque types have the same region parameters if they have the same // Check that all opaque types have the same region parameters if they have the same

View file

@ -75,7 +75,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let output_ty = Ty::new_coroutine( let output_ty = Ty::new_coroutine(
self.tcx(), self.tcx(),
self.tcx().coroutine_for_closure(mir_def_id), self.tcx().coroutine_for_closure(mir_def_id),
ty::CoroutineArgs::new(self.tcx(), ty::CoroutineArgsParts { ty::CoroutineArgs::new(
self.tcx(),
ty::CoroutineArgsParts {
parent_args: args.parent_args(), parent_args: args.parent_args(),
kind_ty: Ty::from_coroutine_closure_kind(self.tcx(), args.kind()), kind_ty: Ty::from_coroutine_closure_kind(self.tcx(), args.kind()),
return_ty: user_provided_sig.output(), return_ty: user_provided_sig.output(),
@ -85,7 +87,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
resume_ty: next_ty_var(), resume_ty: next_ty_var(),
yield_ty: next_ty_var(), yield_ty: next_ty_var(),
witness: next_ty_var(), witness: next_ty_var(),
}) },
)
.args, .args,
); );

View file

@ -411,10 +411,10 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
} else { } else {
self.typeck.ascribe_user_type( self.typeck.ascribe_user_type(
constant.const_.ty(), constant.const_.ty(),
ty::UserType::new(ty::UserTypeKind::TypeOf(uv.def, UserArgs { ty::UserType::new(ty::UserTypeKind::TypeOf(
args: uv.args, uv.def,
user_self_ty: None, UserArgs { args: uv.args, user_self_ty: None },
})), )),
locations.span(self.typeck.body), locations.span(self.typeck.body),
); );
} }
@ -1642,10 +1642,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => { &Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref = let trait_ref = ty::TraitRef::new(
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, Some(span)), [ tcx,
ty, tcx.require_lang_item(LangItem::Sized, Some(span)),
]); [ty],
);
self.prove_trait_ref( self.prove_trait_ref(
trait_ref, trait_ref,
@ -1659,10 +1660,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::ShallowInitBox(operand, ty) => { Rvalue::ShallowInitBox(operand, ty) => {
self.check_operand(operand, location); self.check_operand(operand, location);
let trait_ref = let trait_ref = ty::TraitRef::new(
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, Some(span)), [ tcx,
*ty, tcx.require_lang_item(LangItem::Sized, Some(span)),
]); [*ty],
);
self.prove_trait_ref( self.prove_trait_ref(
trait_ref, trait_ref,

View file

@ -620,10 +620,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let ty = tcx let ty = tcx
.typeck(self.mir_def) .typeck(self.mir_def)
.node_type(tcx.local_def_id_to_hir_id(self.mir_def)); .node_type(tcx.local_def_id_to_hir_id(self.mir_def));
let args = InlineConstArgs::new(tcx, InlineConstArgsParts { let args = InlineConstArgs::new(
parent_args: identity_args, tcx,
ty, InlineConstArgsParts { parent_args: identity_args, ty },
}) )
.args; .args;
let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args); let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args);
DefiningTy::InlineConst(self.mir_def.to_def_id(), args) DefiningTy::InlineConst(self.mir_def.to_def_id(), args)

View file

@ -67,10 +67,11 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]); let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
let layout_new = cx.expr_path(cx.path(span, layout_new)); let layout_new = cx.expr_path(cx.path(span, layout_new));
let layout = cx.expr_call(span, layout_new, thin_vec![ let layout = cx.expr_call(
cx.expr_ident(span, size), span,
cx.expr_ident(span, align) layout_new,
]); thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)],
);
let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]); let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]);

View file

@ -406,19 +406,21 @@ mod llvm_enzyme {
let unsf_expr = ecx.expr_block(P(unsf_block)); let unsf_expr = ecx.expr_block(P(unsf_block));
let blackbox_call_expr = ecx.expr_path(ecx.path(span, blackbox_path)); let blackbox_call_expr = ecx.expr_path(ecx.path(span, blackbox_path));
let primal_call = gen_primal_call(ecx, span, primal, idents); let primal_call = gen_primal_call(ecx, span, primal, idents);
let black_box_primal_call = let black_box_primal_call = ecx.expr_call(
ecx.expr_call(new_decl_span, blackbox_call_expr.clone(), thin_vec![ new_decl_span,
primal_call.clone() blackbox_call_expr.clone(),
]); thin_vec![primal_call.clone()],
);
let tup_args = new_names let tup_args = new_names
.iter() .iter()
.map(|arg| ecx.expr_path(ecx.path_ident(span, Ident::from_str(arg)))) .map(|arg| ecx.expr_path(ecx.path_ident(span, Ident::from_str(arg))))
.collect(); .collect();
let black_box_remaining_args = let black_box_remaining_args = ecx.expr_call(
ecx.expr_call(sig_span, blackbox_call_expr.clone(), thin_vec![ sig_span,
ecx.expr_tuple(sig_span, tup_args) blackbox_call_expr.clone(),
]); thin_vec![ecx.expr_tuple(sig_span, tup_args)],
);
let mut body = ecx.block(span, ThinVec::new()); let mut body = ecx.block(span, ThinVec::new());
body.stmts.push(ecx.stmt_semi(unsf_expr)); body.stmts.push(ecx.stmt_semi(unsf_expr));
@ -532,8 +534,11 @@ mod llvm_enzyme {
return body; return body;
} }
[arg] => { [arg] => {
ret = ecx ret = ecx.expr_call(
.expr_call(new_decl_span, blackbox_call_expr.clone(), thin_vec![arg.clone()]); new_decl_span,
blackbox_call_expr.clone(),
thin_vec![arg.clone()],
);
} }
args => { args => {
let ret_tuple: P<ast::Expr> = ecx.expr_tuple(span, args.into()); let ret_tuple: P<ast::Expr> = ecx.expr_tuple(span, args.into());

View file

@ -114,10 +114,13 @@ fn cs_clone_simple(
// type parameters. // type parameters.
} else { } else {
// let _: AssertParamIsClone<FieldTy>; // let _: AssertParamIsClone<FieldTy>;
super::assert_ty_bounds(cx, &mut stmts, field.ty.clone(), field.span, &[ super::assert_ty_bounds(
sym::clone, cx,
sym::AssertParamIsClone, &mut stmts,
]); field.ty.clone(),
field.span,
&[sym::clone, sym::AssertParamIsClone],
);
} }
} }
}; };
@ -126,10 +129,13 @@ fn cs_clone_simple(
// Just a single assertion for unions, that the union impls `Copy`. // Just a single assertion for unions, that the union impls `Copy`.
// let _: AssertParamIsCopy<Self>; // let _: AssertParamIsCopy<Self>;
let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper))); let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper)));
super::assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, &[ super::assert_ty_bounds(
sym::clone, cx,
sym::AssertParamIsCopy, &mut stmts,
]); self_ty,
trait_span,
&[sym::clone, sym::AssertParamIsCopy],
);
} else { } else {
match *substr.fields { match *substr.fields {
StaticStruct(vdata, ..) => { StaticStruct(vdata, ..) => {

View file

@ -65,10 +65,13 @@ fn cs_total_eq_assert(
// Already produced an assertion for this type. // Already produced an assertion for this type.
} else { } else {
// let _: AssertParamIsEq<FieldTy>; // let _: AssertParamIsEq<FieldTy>;
super::assert_ty_bounds(cx, &mut stmts, field.ty.clone(), field.span, &[ super::assert_ty_bounds(
sym::cmp, cx,
sym::AssertParamIsEq, &mut stmts,
]); field.ty.clone(),
field.span,
&[sym::cmp, sym::AssertParamIsEq],
);
} }
} }
}; };

View file

@ -108,30 +108,38 @@ fn default_enum_substructure(
Ok(default_variant) => { Ok(default_variant) => {
// We now know there is exactly one unit variant with exactly one `#[default]` attribute. // We now know there is exactly one unit variant with exactly one `#[default]` attribute.
match &default_variant.data { match &default_variant.data {
VariantData::Unit(_) => cx.expr_path(cx.path(default_variant.span, vec![ VariantData::Unit(_) => cx.expr_path(cx.path(
Ident::new(kw::SelfUpper, default_variant.span), default_variant.span,
default_variant.ident, vec![Ident::new(kw::SelfUpper, default_variant.span), default_variant.ident],
])), )),
VariantData::Struct { fields, .. } => { VariantData::Struct { fields, .. } => {
// This only happens if `#![feature(default_field_values)]`. We have validated // This only happens if `#![feature(default_field_values)]`. We have validated
// all fields have default values in the definition. // all fields have default values in the definition.
let default_fields = fields let default_fields = fields
.iter() .iter()
.map(|field| { .map(|field| {
cx.field_imm(field.span, field.ident.unwrap(), match &field.default { cx.field_imm(
field.span,
field.ident.unwrap(),
match &field.default {
// We use `Default::default()`. // We use `Default::default()`.
None => default_call(cx, field.span), None => default_call(cx, field.span),
// We use the field default const expression. // We use the field default const expression.
Some(val) => { Some(val) => cx.expr(
cx.expr(val.value.span, ast::ExprKind::ConstBlock(val.clone())) val.value.span,
} ast::ExprKind::ConstBlock(val.clone()),
}) ),
},
)
}) })
.collect(); .collect();
let path = cx.path(default_variant.span, vec![ let path = cx.path(
default_variant.span,
vec![
Ident::new(kw::SelfUpper, default_variant.span), Ident::new(kw::SelfUpper, default_variant.span),
default_variant.ident, default_variant.ident,
]); ],
);
cx.expr_struct(default_variant.span, path, default_fields) cx.expr_struct(default_variant.span, path, default_fields)
} }
// Logic error in `extract_default_variant`. // Logic error in `extract_default_variant`.

View file

@ -1220,10 +1220,12 @@ impl<'a> MethodDef<'a> {
let discr_let_stmts: ThinVec<_> = iter::zip(&discr_idents, &selflike_args) let discr_let_stmts: ThinVec<_> = iter::zip(&discr_idents, &selflike_args)
.map(|(&ident, selflike_arg)| { .map(|(&ident, selflike_arg)| {
let variant_value = let variant_value = deriving::call_intrinsic(
deriving::call_intrinsic(cx, span, sym::discriminant_value, thin_vec![ cx,
selflike_arg.clone() span,
]); sym::discriminant_value,
thin_vec![selflike_arg.clone()],
);
cx.stmt_let(span, false, ident, variant_value) cx.stmt_let(span, false, ident, variant_value)
}) })
.collect(); .collect();

View file

@ -77,11 +77,11 @@ pub(crate) fn expand_option_env<'cx>(
let guar = cx.dcx().emit_err(errors::EnvNotUnicode { span: sp, var: *symbol }); let guar = cx.dcx().emit_err(errors::EnvNotUnicode { span: sp, var: *symbol });
return ExpandResult::Ready(DummyResult::any(sp, guar)); return ExpandResult::Ready(DummyResult::any(sp, guar));
} }
Ok(value) => { Ok(value) => cx.expr_call_global(
cx.expr_call_global(sp, cx.std_path(&[sym::option, sym::Option, sym::Some]), thin_vec![ sp,
cx.expr_str(sp, value) cx.std_path(&[sym::option, sym::Option, sym::Some]),
]) thin_vec![cx.expr_str(sp, value)],
} ),
}; };
ExpandResult::Ready(MacEager::expr(e)) ExpandResult::Ready(MacEager::expr(e))
} }

View file

@ -183,10 +183,14 @@ pub(crate) mod printf {
s.push('{'); s.push('{');
if let Some(arg) = self.parameter { if let Some(arg) = self.parameter {
match write!(s, "{}", match arg.checked_sub(1) { match write!(
s,
"{}",
match arg.checked_sub(1) {
Some(a) => a, Some(a) => a,
None => return Err(None), None => return Err(None),
}) { }
) {
Err(_) => return Err(None), Err(_) => return Err(None),
_ => {} _ => {}
} }

View file

@ -99,12 +99,10 @@ fn test_parse() {
fn test_iter() { fn test_iter() {
let s = "The %d'th word %% is: `%.*s` %!\n"; let s = "The %d'th word %% is: `%.*s` %!\n";
let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect(); let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect();
assert_eq!(subs.iter().map(Option::as_deref).collect::<Vec<_>>(), vec![ assert_eq!(
Some("{}"), subs.iter().map(Option::as_deref).collect::<Vec<_>>(),
None, vec![Some("{}"), None, Some("{:.*}"), None]
Some("{:.*}"), );
None
]);
} }
/// Checks that the translations are what we expect. /// Checks that the translations are what we expect.

View file

@ -38,11 +38,10 @@ fn test_iter() {
use super::iter_subs; use super::iter_subs;
let s = "The $0'th word $$ is: `$WORD` $!\n"; let s = "The $0'th word $$ is: `$WORD` $!\n";
let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect(); let subs: Vec<_> = iter_subs(s, 0).map(|sub| sub.translate().ok()).collect();
assert_eq!(subs.iter().map(Option::as_deref).collect::<Vec<_>>(), vec![ assert_eq!(
Some("{0}"), subs.iter().map(Option::as_deref).collect::<Vec<_>>(),
None, vec![Some("{0}"), None, Some("{WORD}")]
Some("{WORD}") );
]);
} }
#[test] #[test]

View file

@ -301,13 +301,10 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
}; };
let local_path = |cx: &ExtCtxt<'_>, name| cx.expr_path(cx.path(span, vec![name])); let local_path = |cx: &ExtCtxt<'_>, name| cx.expr_path(cx.path(span, vec![name]));
let proc_macro_ty_method_path = |cx: &ExtCtxt<'_>, method| { let proc_macro_ty_method_path = |cx: &ExtCtxt<'_>, method| {
cx.expr_path(cx.path(span.with_ctxt(harness_span.ctxt()), vec![ cx.expr_path(cx.path(
proc_macro, span.with_ctxt(harness_span.ctxt()),
bridge, vec![proc_macro, bridge, client, proc_macro_ty, method],
client, ))
proc_macro_ty,
method,
]))
}; };
match m { match m {
ProcMacro::Derive(cd) => { ProcMacro::Derive(cd) => {
@ -340,10 +337,14 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
// The call needs to use `harness_span` so that the const stability checker // The call needs to use `harness_span` so that the const stability checker
// accepts it. // accepts it.
cx.expr_call(harness_span, proc_macro_ty_method_path(cx, ident), thin_vec![ cx.expr_call(
harness_span,
proc_macro_ty_method_path(cx, ident),
thin_vec![
cx.expr_str(span, ca.function_name.name), cx.expr_str(span, ca.function_name.name),
local_path(cx, ca.function_name), local_path(cx, ca.function_name),
]) ],
)
} }
} }
}) })
@ -357,12 +358,9 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
span, span,
cx.ty( cx.ty(
span, span,
ast::TyKind::Slice(cx.ty_path(cx.path(span, vec![ ast::TyKind::Slice(
proc_macro, cx.ty_path(cx.path(span, vec![proc_macro, bridge, client, proc_macro_ty])),
bridge, ),
client,
proc_macro_ty,
]))),
), ),
None, None,
ast::Mutability::Not, ast::Mutability::Not,

View file

@ -169,20 +169,26 @@ pub(crate) fn expand_test_or_bench(
// creates test::ShouldPanic::$name // creates test::ShouldPanic::$name
let should_panic_path = |name| { let should_panic_path = |name| {
cx.path(sp, vec![ cx.path(
sp,
vec![
test_id, test_id,
Ident::from_str_and_span("ShouldPanic", sp), Ident::from_str_and_span("ShouldPanic", sp),
Ident::from_str_and_span(name, sp), Ident::from_str_and_span(name, sp),
]) ],
)
}; };
// creates test::TestType::$name // creates test::TestType::$name
let test_type_path = |name| { let test_type_path = |name| {
cx.path(sp, vec![ cx.path(
sp,
vec![
test_id, test_id,
Ident::from_str_and_span("TestType", sp), Ident::from_str_and_span("TestType", sp),
Ident::from_str_and_span(name, sp), Ident::from_str_and_span(name, sp),
]) ],
)
}; };
// creates $name: $expr // creates $name: $expr
@ -202,39 +208,55 @@ pub(crate) fn expand_test_or_bench(
// A simple ident for a lambda // A simple ident for a lambda
let b = Ident::from_str_and_span("b", attr_sp); let b = Ident::from_str_and_span("b", attr_sp);
cx.expr_call(sp, cx.expr_path(test_path("StaticBenchFn")), thin_vec![ cx.expr_call(
sp,
cx.expr_path(test_path("StaticBenchFn")),
thin_vec![
// #[coverage(off)] // #[coverage(off)]
// |b| self::test::assert_test_result( // |b| self::test::assert_test_result(
coverage_off(cx.lambda1( coverage_off(cx.lambda1(
sp, sp,
cx.expr_call(sp, cx.expr_path(test_path("assert_test_result")), thin_vec![ cx.expr_call(
sp,
cx.expr_path(test_path("assert_test_result")),
thin_vec![
// super::$test_fn(b) // super::$test_fn(b)
cx.expr_call( cx.expr_call(
ret_ty_sp, ret_ty_sp,
cx.expr_path(cx.path(sp, vec![item.ident])), cx.expr_path(cx.path(sp, vec![item.ident])),
thin_vec![cx.expr_ident(sp, b)], thin_vec![cx.expr_ident(sp, b)],
), ),
],), ],
),
b, b,
)), // ) )), // )
]) ],
)
} else { } else {
cx.expr_call(sp, cx.expr_path(test_path("StaticTestFn")), thin_vec![ cx.expr_call(
sp,
cx.expr_path(test_path("StaticTestFn")),
thin_vec![
// #[coverage(off)] // #[coverage(off)]
// || { // || {
coverage_off(cx.lambda0( coverage_off(cx.lambda0(
sp, sp,
// test::assert_test_result( // test::assert_test_result(
cx.expr_call(sp, cx.expr_path(test_path("assert_test_result")), thin_vec![ cx.expr_call(
sp,
cx.expr_path(test_path("assert_test_result")),
thin_vec![
// $test_fn() // $test_fn()
cx.expr_call( cx.expr_call(
ret_ty_sp, ret_ty_sp,
cx.expr_path(cx.path(sp, vec![item.ident])), cx.expr_path(cx.path(sp, vec![item.ident])),
ThinVec::new(), ThinVec::new(),
), // ) ), // )
],), // } ],
), // }
)), // ) )), // )
]) ],
)
}; };
let test_path_symbol = Symbol::intern(&item_path( let test_path_symbol = Symbol::intern(&item_path(
@ -245,7 +267,8 @@ pub(crate) fn expand_test_or_bench(
let location_info = get_location_info(cx, &item); let location_info = get_location_info(cx, &item);
let mut test_const = cx.item( let mut test_const =
cx.item(
sp, sp,
Ident::new(item.ident.name, sp), Ident::new(item.ident.name, sp),
thin_vec![ thin_vec![
@ -264,7 +287,10 @@ pub(crate) fn expand_test_or_bench(
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
// test::TestDescAndFn { // test::TestDescAndFn {
expr: Some( expr: Some(
cx.expr_struct(sp, test_path("TestDescAndFn"), thin_vec![ cx.expr_struct(
sp,
test_path("TestDescAndFn"),
thin_vec![
// desc: test::TestDesc { // desc: test::TestDesc {
field( field(
"desc", "desc",
@ -340,7 +366,8 @@ pub(crate) fn expand_test_or_bench(
), ),
// testfn: test::StaticTestFn(...) | test::StaticBenchFn(...) // testfn: test::StaticTestFn(...) | test::StaticBenchFn(...)
field("testfn", test_fn), // } field("testfn", test_fn), // }
]), // } ],
), // }
), ),
} }
.into(), .into(),

View file

@ -241,9 +241,10 @@ unsafe fn test_simd() {
let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x);
assert_eq!((zero0, zero1), (0, 0)); assert_eq!((zero0, zero1), (0, 0));
assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [ assert_eq!(
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff std::mem::transmute::<_, [u16; 8]>(cmp_eq),
]); [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]
);
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]);
test_mm_slli_si128(); test_mm_slli_si128();

View file

@ -96,9 +96,12 @@ pub(crate) fn clif_int_or_float_cast(
}, },
); );
fx.lib_call(&name, vec![AbiParam::new(from_ty)], vec![AbiParam::new(types::I128)], &[ fx.lib_call(
from, &name,
])[0] vec![AbiParam::new(from_ty)],
vec![AbiParam::new(types::I128)],
&[from],
)[0]
} else if to_ty == types::I8 || to_ty == types::I16 { } else if to_ty == types::I8 || to_ty == types::I16 {
// FIXME implement fcvt_to_*int_sat.i8/i16 // FIXME implement fcvt_to_*int_sat.i8/i16
let val = if to_signed { let val = if to_signed {

View file

@ -73,7 +73,9 @@ impl WriteDebugInfo for ObjectProduct {
} }
}; };
self.object self.object
.add_relocation(from.0, Relocation { .add_relocation(
from.0,
Relocation {
offset: u64::from(reloc.offset), offset: u64::from(reloc.offset),
symbol, symbol,
flags: RelocationFlags::Generic { flags: RelocationFlags::Generic {
@ -82,7 +84,8 @@ impl WriteDebugInfo for ObjectProduct {
size: reloc.size * 8, size: reloc.size * 8,
}, },
addend: i64::try_from(symbol_offset).unwrap() + reloc.addend, addend: i64::try_from(symbol_offset).unwrap() + reloc.addend,
}) },
)
.unwrap(); .unwrap();
} }
} }

View file

@ -342,11 +342,15 @@ fn codegen_shim<'tcx>(
let instance_ptr = Box::into_raw(Box::new(inst)); let instance_ptr = Box::into_raw(Box::new(inst));
let jit_fn = module let jit_fn = module
.declare_function("__clif_jit_fn", Linkage::Import, &Signature { .declare_function(
"__clif_jit_fn",
Linkage::Import,
&Signature {
call_conv: module.target_config().default_call_conv, call_conv: module.target_config().default_call_conv,
params: vec![AbiParam::new(pointer_type), AbiParam::new(pointer_type)], params: vec![AbiParam::new(pointer_type), AbiParam::new(pointer_type)],
returns: vec![AbiParam::new(pointer_type)], returns: vec![AbiParam::new(pointer_type)],
}) },
)
.unwrap(); .unwrap();
let context = cached_context; let context = cached_context;

View file

@ -875,11 +875,15 @@ fn call_inline_asm<'tcx>(
let inline_asm_func = fx let inline_asm_func = fx
.module .module
.declare_function(asm_name, Linkage::Import, &Signature { .declare_function(
asm_name,
Linkage::Import,
&Signature {
call_conv: CallConv::SystemV, call_conv: CallConv::SystemV,
params: vec![AbiParam::new(fx.pointer_type)], params: vec![AbiParam::new(fx.pointer_type)],
returns: vec![], returns: vec![],
}) },
)
.unwrap(); .unwrap();
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, fx.bcx.func); let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, fx.bcx.func);
if fx.clif_comments.enabled() { if fx.clif_comments.enabled() {

View file

@ -558,9 +558,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
(sym::simd_round, types::F64) => "round", (sym::simd_round, types::F64) => "round",
_ => unreachable!("{:?}", intrinsic), _ => unreachable!("{:?}", intrinsic),
}; };
fx.lib_call(name, vec![AbiParam::new(lane_ty)], vec![AbiParam::new(lane_ty)], &[ fx.lib_call(
lane, name,
])[0] vec![AbiParam::new(lane_ty)],
vec![AbiParam::new(lane_ty)],
&[lane],
)[0]
}); });
} }

View file

@ -15,9 +15,12 @@ pub(crate) fn maybe_create_entry_wrapper(
is_primary_cgu: bool, is_primary_cgu: bool,
) { ) {
let (main_def_id, sigpipe) = match tcx.entry_fn(()) { let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
Some((def_id, entry_ty)) => (def_id, match entry_ty { Some((def_id, entry_ty)) => (
def_id,
match entry_ty {
EntryFnType::Main { sigpipe } => sigpipe, EntryFnType::Main { sigpipe } => sigpipe,
}), },
),
None => return, None => return,
}; };

View file

@ -5,11 +5,15 @@ use crate::prelude::*;
fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
let puts = fx let puts = fx
.module .module
.declare_function("puts", Linkage::Import, &Signature { .declare_function(
"puts",
Linkage::Import,
&Signature {
call_conv: fx.target_config.default_call_conv, call_conv: fx.target_config.default_call_conv,
params: vec![AbiParam::new(fx.pointer_type)], params: vec![AbiParam::new(fx.pointer_type)],
returns: vec![AbiParam::new(types::I32)], returns: vec![AbiParam::new(types::I32)],
}) },
)
.unwrap(); .unwrap();
let puts = fx.module.declare_func_in_func(puts, &mut fx.bcx.func); let puts = fx.module.declare_func_in_func(puts, &mut fx.bcx.func);
if fx.clif_comments.enabled() { if fx.clif_comments.enabled() {

View file

@ -155,14 +155,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// NOTE: not sure why, but we have the wrong type here. // NOTE: not sure why, but we have the wrong type here.
let int_type = compare_exchange.get_param(2).to_rvalue().get_type(); let int_type = compare_exchange.get_param(2).to_rvalue().get_type();
let src = self.context.new_bitcast(self.location, src, int_type); let src = self.context.new_bitcast(self.location, src, int_type);
self.context.new_call(self.location, compare_exchange, &[ self.context.new_call(
dst, self.location,
expected, compare_exchange,
src, &[dst, expected, src, weak, order, failure_order],
weak, )
order,
failure_order,
])
} }
pub fn assign(&self, lvalue: LValue<'gcc>, value: RValue<'gcc>) { pub fn assign(&self, lvalue: LValue<'gcc>, value: RValue<'gcc>) {
@ -1076,9 +1073,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let align = dest.val.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size); let align = dest.val.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
cg_elem.val.store(self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align)); cg_elem.val.store(self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align));
let next = self.inbounds_gep(self.backend_type(cg_elem.layout), current.to_rvalue(), &[ let next = self.inbounds_gep(
self.const_usize(1), self.backend_type(cg_elem.layout),
]); current.to_rvalue(),
&[self.const_usize(1)],
);
self.llbb().add_assignment(self.location, current, next); self.llbb().add_assignment(self.location, current, next);
self.br(header_bb); self.br(header_bb);

View file

@ -687,11 +687,12 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
let field2 = builder.context.new_field(None, args[1].get_type(), "carryResult"); let field2 = builder.context.new_field(None, args[1].get_type(), "carryResult");
let struct_type = let struct_type =
builder.context.new_struct_type(None, "addcarryResult", &[field1, field2]); builder.context.new_struct_type(None, "addcarryResult", &[field1, field2]);
return_value = return_value = builder.context.new_struct_constructor(
builder.context.new_struct_constructor(None, struct_type.as_type(), None, &[ None,
return_value, struct_type.as_type(),
last_arg.dereference(None).to_rvalue(), None,
]); &[return_value, last_arg.dereference(None).to_rvalue()],
);
} }
} }
"__builtin_ia32_stmxcsr" => { "__builtin_ia32_stmxcsr" => {
@ -716,11 +717,12 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
let field2 = builder.context.new_field(None, return_value.get_type(), "success"); let field2 = builder.context.new_field(None, return_value.get_type(), "success");
let struct_type = let struct_type =
builder.context.new_struct_type(None, "rdrand_result", &[field1, field2]); builder.context.new_struct_type(None, "rdrand_result", &[field1, field2]);
return_value = return_value = builder.context.new_struct_constructor(
builder.context.new_struct_constructor(None, struct_type.as_type(), None, &[ None,
random_number, struct_type.as_type(),
success_variable.to_rvalue(), None,
]); &[random_number, success_variable.to_rvalue()],
);
} }
"fma" => { "fma" => {
let f16_type = builder.context.new_c_type(CType::Float16); let f16_type = builder.context.new_c_type(CType::Float16);

View file

@ -62,11 +62,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
let arg_tys = sig.inputs(); let arg_tys = sig.inputs();
if name == sym::simd_select_bitmask { if name == sym::simd_select_bitmask {
require_simd!(arg_tys[1], InvalidMonomorphization::SimdArgument { require_simd!(
span, arg_tys[1],
name, InvalidMonomorphization::SimdArgument { span, name, ty: arg_tys[1] }
ty: arg_tys[1] );
});
let (len, _) = arg_tys[1].simd_size_and_type(bx.tcx()); let (len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
let expected_int_bits = (len.max(8) - 1).next_power_of_two(); let expected_int_bits = (len.max(8) - 1).next_power_of_two();
@ -140,14 +139,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
require!( require!(
bx.type_kind(bx.element_type(llret_ty)) == TypeKind::Integer, bx.type_kind(bx.element_type(llret_ty)) == TypeKind::Integer,
InvalidMonomorphization::ReturnIntegerType { span, name, ret_ty, out_ty } InvalidMonomorphization::ReturnIntegerType { span, name, ret_ty, out_ty }
@ -269,23 +271,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
let lo_nibble = let lo_nibble =
bx.context.new_rvalue_from_vector(None, long_byte_vector_type, &lo_nibble_elements); bx.context.new_rvalue_from_vector(None, long_byte_vector_type, &lo_nibble_elements);
let mask = bx.context.new_rvalue_from_vector(None, long_byte_vector_type, &vec![ let mask = bx.context.new_rvalue_from_vector(
bx.context None,
.new_rvalue_from_int( long_byte_vector_type,
bx.u8_type, 0x0f &vec![bx.context.new_rvalue_from_int(bx.u8_type, 0x0f); byte_vector_type_size as _],
); );
byte_vector_type_size
as _
]);
let four_vec = bx.context.new_rvalue_from_vector(None, long_byte_vector_type, &vec![ let four_vec = bx.context.new_rvalue_from_vector(
bx.context None,
.new_rvalue_from_int( long_byte_vector_type,
bx.u8_type, 4 &vec![bx.context.new_rvalue_from_int(bx.u8_type, 4); byte_vector_type_size as _],
); );
byte_vector_type_size
as _
]);
// Step 2: Byte-swap the input. // Step 2: Byte-swap the input.
let swapped = simd_bswap(bx, args[0].immediate()); let swapped = simd_bswap(bx, args[0].immediate());
@ -388,21 +384,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
require!(out_len == n, InvalidMonomorphization::ReturnLength { require!(
span, out_len == n,
name, InvalidMonomorphization::ReturnLength { span, name, in_len: n, ret_ty, out_len }
in_len: n, );
ret_ty, require!(
out_len in_elem == out_ty,
}); InvalidMonomorphization::ReturnElement { span, name, in_elem, in_ty, ret_ty, out_ty }
require!(in_elem == out_ty, InvalidMonomorphization::ReturnElement { );
span,
name,
in_elem,
in_ty,
ret_ty,
out_ty
});
let vector = args[2].immediate(); let vector = args[2].immediate();
@ -411,13 +400,16 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
#[cfg(feature = "master")] #[cfg(feature = "master")]
if name == sym::simd_insert { if name == sym::simd_insert {
require!(in_elem == arg_tys[2], InvalidMonomorphization::InsertedType { require!(
in_elem == arg_tys[2],
InvalidMonomorphization::InsertedType {
span, span,
name, name,
in_elem, in_elem,
in_ty, in_ty,
out_ty: arg_tys[2] out_ty: arg_tys[2]
}); }
);
let vector = args[0].immediate(); let vector = args[0].immediate();
let index = args[1].immediate(); let index = args[1].immediate();
let value = args[2].immediate(); let value = args[2].immediate();
@ -431,13 +423,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
#[cfg(feature = "master")] #[cfg(feature = "master")]
if name == sym::simd_extract { if name == sym::simd_extract {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
let vector = args[0].immediate(); let vector = args[0].immediate();
return Ok(bx.context.new_vector_access(None, vector, args[1].immediate()).to_rvalue()); return Ok(bx.context.new_vector_access(None, vector, args[1].immediate()).to_rvalue());
} }
@ -445,18 +434,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
if name == sym::simd_select { if name == sym::simd_select {
let m_elem_ty = in_elem; let m_elem_ty = in_elem;
let m_len = in_len; let m_len = in_len;
require_simd!(arg_tys[1], InvalidMonomorphization::SimdArgument { require_simd!(
span, arg_tys[1],
name, InvalidMonomorphization::SimdArgument { span, name, ty: arg_tys[1] }
ty: arg_tys[1] );
});
let (v_len, _) = arg_tys[1].simd_size_and_type(bx.tcx()); let (v_len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
require!(m_len == v_len, InvalidMonomorphization::MismatchedLengths { require!(
span, m_len == v_len,
name, InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
m_len, );
v_len
});
match *m_elem_ty.kind() { match *m_elem_ty.kind() {
ty::Int(_) => {} ty::Int(_) => {}
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }), _ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
@ -468,25 +454,27 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match *in_elem.kind() { match *in_elem.kind() {
ty::RawPtr(p_ty, _) => { ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty) bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
}); });
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer { require!(
span, metadata.is_unit(),
name, InvalidMonomorphization::CastWidePointer { span, name, ty: in_elem }
ty: in_elem );
});
} }
_ => { _ => {
return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem })
@ -497,11 +485,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty) bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
}); });
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer { require!(
span, metadata.is_unit(),
name, InvalidMonomorphization::CastWidePointer { span, name, ty: out_elem }
ty: out_elem );
});
} }
_ => { _ => {
return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem }) return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem })
@ -524,14 +511,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match *in_elem.kind() { match *in_elem.kind() {
ty::RawPtr(_, _) => {} ty::RawPtr(_, _) => {}
@ -560,14 +550,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match *in_elem.kind() { match *in_elem.kind() {
ty::Uint(ty::UintTy::Usize) => {} ty::Uint(ty::UintTy::Usize) => {}
@ -596,14 +589,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
if name == sym::simd_cast || name == sym::simd_as { if name == sym::simd_cast || name == sym::simd_as {
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
// casting cares about nominal type, not just structural type // casting cares about nominal type, not just structural type
if in_elem == out_elem { if in_elem == out_elem {
return Ok(args[0].immediate()); return Ok(args[0].immediate());
@ -629,14 +625,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match (in_style, out_style) { match (in_style, out_style) {
(Style::Unsupported, Style::Unsupported) => { (Style::Unsupported, Style::Unsupported) => {
require!(false, InvalidMonomorphization::UnsupportedCast { require!(
false,
InvalidMonomorphization::UnsupportedCast {
span, span,
name, name,
in_ty, in_ty,
in_elem, in_elem,
ret_ty, ret_ty,
out_elem out_elem
}); }
);
} }
_ => return Ok(bx.context.convert_vector(None, args[0].immediate(), llret_ty)), _ => return Ok(bx.context.convert_vector(None, args[0].immediate(), llret_ty)),
} }
@ -914,45 +913,47 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
// All types must be simd vector types // All types must be simd vector types
require_simd!(in_ty, InvalidMonomorphization::SimdFirst { span, name, ty: in_ty }); require_simd!(in_ty, InvalidMonomorphization::SimdFirst { span, name, ty: in_ty });
require_simd!(arg_tys[1], InvalidMonomorphization::SimdSecond { require_simd!(
span, arg_tys[1],
name, InvalidMonomorphization::SimdSecond { span, name, ty: arg_tys[1] }
ty: arg_tys[1] );
}); require_simd!(
require_simd!(arg_tys[2], InvalidMonomorphization::SimdThird { arg_tys[2],
span, InvalidMonomorphization::SimdThird { span, name, ty: arg_tys[2] }
name, );
ty: arg_tys[2]
});
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
// Of the same length: // Of the same length:
let (out_len, _) = arg_tys[1].simd_size_and_type(bx.tcx()); let (out_len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
let (out_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx()); let (out_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx());
require!(in_len == out_len, InvalidMonomorphization::SecondArgumentLength { require!(
in_len == out_len,
InvalidMonomorphization::SecondArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[1], arg_ty: arg_tys[1],
out_len out_len
}); }
require!(in_len == out_len2, InvalidMonomorphization::ThirdArgumentLength { );
require!(
in_len == out_len2,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[2], arg_ty: arg_tys[2],
out_len: out_len2 out_len: out_len2
}); }
);
// The return type must match the first argument type // The return type must match the first argument type
require!(ret_ty == in_ty, InvalidMonomorphization::ExpectedReturnType { require!(
span, ret_ty == in_ty,
name, InvalidMonomorphization::ExpectedReturnType { span, name, in_ty, ret_ty }
in_ty, );
ret_ty
});
// This counts how many pointers // This counts how many pointers
fn ptr_count(t: Ty<'_>) -> usize { fn ptr_count(t: Ty<'_>) -> usize {
@ -979,7 +980,9 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
(ptr_count(element_ty1), non_ptr(element_ty1)) (ptr_count(element_ty1), non_ptr(element_ty1))
} }
_ => { _ => {
require!(false, InvalidMonomorphization::ExpectedElementType { require!(
false,
InvalidMonomorphization::ExpectedElementType {
span, span,
name, name,
expected_element: element_ty1, expected_element: element_ty1,
@ -987,7 +990,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
in_elem, in_elem,
in_ty, in_ty,
mutability: ExpectedPointerMutability::Not, mutability: ExpectedPointerMutability::Not,
}); }
);
unreachable!(); unreachable!();
} }
}; };
@ -1000,12 +1004,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *element_ty2.kind() { match *element_ty2.kind() {
ty::Int(_) => (), ty::Int(_) => (),
_ => { _ => {
require!(false, InvalidMonomorphization::ThirdArgElementType { require!(
false,
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: element_ty2, expected_element: element_ty2,
third_arg: arg_tys[2] third_arg: arg_tys[2]
}); }
);
} }
} }
@ -1029,36 +1036,40 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
// All types must be simd vector types // All types must be simd vector types
require_simd!(in_ty, InvalidMonomorphization::SimdFirst { span, name, ty: in_ty }); require_simd!(in_ty, InvalidMonomorphization::SimdFirst { span, name, ty: in_ty });
require_simd!(arg_tys[1], InvalidMonomorphization::SimdSecond { require_simd!(
span, arg_tys[1],
name, InvalidMonomorphization::SimdSecond { span, name, ty: arg_tys[1] }
ty: arg_tys[1] );
}); require_simd!(
require_simd!(arg_tys[2], InvalidMonomorphization::SimdThird { arg_tys[2],
span, InvalidMonomorphization::SimdThird { span, name, ty: arg_tys[2] }
name, );
ty: arg_tys[2]
});
// Of the same length: // Of the same length:
let (element_len1, _) = arg_tys[1].simd_size_and_type(bx.tcx()); let (element_len1, _) = arg_tys[1].simd_size_and_type(bx.tcx());
let (element_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx()); let (element_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx());
require!(in_len == element_len1, InvalidMonomorphization::SecondArgumentLength { require!(
in_len == element_len1,
InvalidMonomorphization::SecondArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[1], arg_ty: arg_tys[1],
out_len: element_len1 out_len: element_len1
}); }
require!(in_len == element_len2, InvalidMonomorphization::ThirdArgumentLength { );
require!(
in_len == element_len2,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[2], arg_ty: arg_tys[2],
out_len: element_len2 out_len: element_len2
}); }
);
// This counts how many pointers // This counts how many pointers
fn ptr_count(t: Ty<'_>) -> usize { fn ptr_count(t: Ty<'_>) -> usize {
@ -1086,7 +1097,9 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
(ptr_count(element_ty1), non_ptr(element_ty1)) (ptr_count(element_ty1), non_ptr(element_ty1))
} }
_ => { _ => {
require!(false, InvalidMonomorphization::ExpectedElementType { require!(
false,
InvalidMonomorphization::ExpectedElementType {
span, span,
name, name,
expected_element: element_ty1, expected_element: element_ty1,
@ -1094,7 +1107,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
in_elem, in_elem,
in_ty, in_ty,
mutability: ExpectedPointerMutability::Mut, mutability: ExpectedPointerMutability::Mut,
}); }
);
unreachable!(); unreachable!();
} }
}; };
@ -1106,12 +1120,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *element_ty2.kind() { match *element_ty2.kind() {
ty::Int(_) => (), ty::Int(_) => (),
_ => { _ => {
require!(false, InvalidMonomorphization::ThirdArgElementType { require!(
false,
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: element_ty2, expected_element: element_ty2,
third_arg: arg_tys[2] third_arg: arg_tys[2]
}); }
);
} }
} }
@ -1278,13 +1295,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
($name:ident : $vec_op:expr, $float_reduce:ident, $ordered:expr, $op:ident, ($name:ident : $vec_op:expr, $float_reduce:ident, $ordered:expr, $op:ident,
$identity:expr) => { $identity:expr) => {
if name == sym::$name { if name == sym::$name {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
return match *in_elem.kind() { return match *in_elem.kind() {
ty::Int(_) | ty::Uint(_) => { ty::Int(_) | ty::Uint(_) => {
let r = bx.vector_reduce_op(args[0].immediate(), $vec_op); let r = bx.vector_reduce_op(args[0].immediate(), $vec_op);
@ -1350,13 +1364,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
macro_rules! minmax_red { macro_rules! minmax_red {
($name:ident: $int_red:ident, $float_red:ident) => { ($name:ident: $int_red:ident, $float_red:ident) => {
if name == sym::$name { if name == sym::$name {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
return match *in_elem.kind() { return match *in_elem.kind() {
ty::Int(_) | ty::Uint(_) => Ok(bx.$int_red(args[0].immediate())), ty::Int(_) | ty::Uint(_) => Ok(bx.$int_red(args[0].immediate())),
ty::Float(_) => Ok(bx.$float_red(args[0].immediate())), ty::Float(_) => Ok(bx.$float_red(args[0].immediate())),
@ -1380,13 +1391,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
($name:ident : $op:expr, $boolean:expr) => { ($name:ident : $op:expr, $boolean:expr) => {
if name == sym::$name { if name == sym::$name {
let input = if !$boolean { let input = if !$boolean {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
args[0].immediate() args[0].immediate()
} else { } else {
match *in_elem.kind() { match *in_elem.kind() {

View file

@ -448,11 +448,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
// LLVM also rejects full range. // LLVM also rejects full range.
&& !scalar.is_always_valid(cx) && !scalar.is_always_valid(cx)
{ {
attributes::apply_to_llfn(llfn, idx, &[llvm::CreateRangeAttr( attributes::apply_to_llfn(
cx.llcx, llfn,
scalar.size(cx), idx,
scalar.valid_range(cx), &[llvm::CreateRangeAttr(cx.llcx, scalar.size(cx), scalar.valid_range(cx))],
)]); );
} }
}; };
@ -472,10 +472,14 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
); );
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[sret]); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[sret]);
if cx.sess().opts.optimize != config::OptLevel::No { if cx.sess().opts.optimize != config::OptLevel::No {
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[ attributes::apply_to_llfn(
llfn,
llvm::AttributePlace::Argument(i),
&[
llvm::AttributeKind::Writable.create_attr(cx.llcx), llvm::AttributeKind::Writable.create_attr(cx.llcx),
llvm::AttributeKind::DeadOnUnwind.create_attr(cx.llcx), llvm::AttributeKind::DeadOnUnwind.create_attr(cx.llcx),
]); ],
);
} }
} }
PassMode::Cast { cast, pad_i32: _ } => { PassMode::Cast { cast, pad_i32: _ } => {
@ -593,9 +597,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
bx.cx.llcx, bx.cx.llcx,
bx.cx.type_array(bx.cx.type_i8(), arg.layout.size.bytes()), bx.cx.type_array(bx.cx.type_i8(), arg.layout.size.bytes()),
); );
attributes::apply_to_callsite(callsite, llvm::AttributePlace::Argument(i), &[ attributes::apply_to_callsite(
byval, callsite,
]); llvm::AttributePlace::Argument(i),
&[byval],
);
} }
PassMode::Direct(attrs) PassMode::Direct(attrs)
| PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => { | PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
@ -627,9 +633,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
// This will probably get ignored on all targets but those supporting the TrustZone-M // This will probably get ignored on all targets but those supporting the TrustZone-M
// extension (thumbv8m targets). // extension (thumbv8m targets).
let cmse_nonsecure_call = llvm::CreateAttrString(bx.cx.llcx, "cmse_nonsecure_call"); let cmse_nonsecure_call = llvm::CreateAttrString(bx.cx.llcx, "cmse_nonsecure_call");
attributes::apply_to_callsite(callsite, llvm::AttributePlace::Function, &[ attributes::apply_to_callsite(
cmse_nonsecure_call, callsite,
]); llvm::AttributePlace::Function,
&[cmse_nonsecure_call],
);
} }
// Some intrinsics require that an elementtype attribute (with the pointee type of a // Some intrinsics require that an elementtype attribute (with the pointee type of a

View file

@ -291,20 +291,26 @@ pub(crate) fn differentiate<'ll>(
let name = item.source.clone(); let name = item.source.clone();
let fn_def: Option<&llvm::Value> = cx.get_function(&name); let fn_def: Option<&llvm::Value> = cx.get_function(&name);
let Some(fn_def) = fn_def else { let Some(fn_def) = fn_def else {
return Err(llvm_err(diag_handler.handle(), LlvmError::PrepareAutoDiff { return Err(llvm_err(
diag_handler.handle(),
LlvmError::PrepareAutoDiff {
src: item.source.clone(), src: item.source.clone(),
target: item.target.clone(), target: item.target.clone(),
error: "could not find source function".to_owned(), error: "could not find source function".to_owned(),
})); },
));
}; };
debug!(?item.target); debug!(?item.target);
let fn_target: Option<&llvm::Value> = cx.get_function(&item.target); let fn_target: Option<&llvm::Value> = cx.get_function(&item.target);
let Some(fn_target) = fn_target else { let Some(fn_target) = fn_target else {
return Err(llvm_err(diag_handler.handle(), LlvmError::PrepareAutoDiff { return Err(llvm_err(
diag_handler.handle(),
LlvmError::PrepareAutoDiff {
src: item.source.clone(), src: item.source.clone(),
target: item.target.clone(), target: item.target.clone(),
error: "could not find target function".to_owned(), error: "could not find target function".to_owned(),
})); },
));
}; };
generate_enzyme_call(&cx, fn_def, fn_target, item.attrs.clone()); generate_enzyme_call(&cx, fn_def, fn_target, item.attrs.clone());

View file

@ -544,14 +544,17 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
} }
} }
let scope = namespace::item_namespace(cx, DefId { let scope = namespace::item_namespace(
cx,
DefId {
krate: instance.def_id().krate, krate: instance.def_id().krate,
index: cx index: cx
.tcx .tcx
.def_key(instance.def_id()) .def_key(instance.def_id())
.parent .parent
.expect("get_containing_scope: missing parent?"), .expect("get_containing_scope: missing parent?"),
}); },
);
(scope, false) (scope, false)
} }
} }

View file

@ -333,12 +333,15 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::prefetch_write_instruction => (1, 0), sym::prefetch_write_instruction => (1, 0),
_ => bug!(), _ => bug!(),
}; };
self.call_intrinsic("llvm.prefetch", &[ self.call_intrinsic(
"llvm.prefetch",
&[
args[0].immediate(), args[0].immediate(),
self.const_i32(rw), self.const_i32(rw),
args[1].immediate(), args[1].immediate(),
self.const_i32(cache_type), self.const_i32(cache_type),
]) ],
)
} }
sym::carrying_mul_add => { sym::carrying_mul_add => {
let (size, signed) = fn_args.type_at(0).int_size_and_signed(self.tcx); let (size, signed) = fn_args.type_at(0).int_size_and_signed(self.tcx);
@ -396,10 +399,10 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
match name { match name {
sym::ctlz | sym::cttz => { sym::ctlz | sym::cttz => {
let y = self.const_bool(false); let y = self.const_bool(false);
let ret = self.call_intrinsic(&format!("llvm.{name}.i{width}"), &[ let ret = self.call_intrinsic(
args[0].immediate(), &format!("llvm.{name}.i{width}"),
y, &[args[0].immediate(), y],
]); );
self.intcast(ret, llret_ty, false) self.intcast(ret, llret_ty, false)
} }
@ -416,24 +419,26 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
self.intcast(ret, llret_ty, false) self.intcast(ret, llret_ty, false)
} }
sym::ctpop => { sym::ctpop => {
let ret = self.call_intrinsic(&format!("llvm.ctpop.i{width}"), &[ let ret = self.call_intrinsic(
args[0].immediate() &format!("llvm.ctpop.i{width}"),
]); &[args[0].immediate()],
);
self.intcast(ret, llret_ty, false) self.intcast(ret, llret_ty, false)
} }
sym::bswap => { sym::bswap => {
if width == 8 { if width == 8 {
args[0].immediate() // byte swap a u8/i8 is just a no-op args[0].immediate() // byte swap a u8/i8 is just a no-op
} else { } else {
self.call_intrinsic(&format!("llvm.bswap.i{width}"), &[ self.call_intrinsic(
args[0].immediate() &format!("llvm.bswap.i{width}"),
]) &[args[0].immediate()],
)
} }
} }
sym::bitreverse => self sym::bitreverse => self.call_intrinsic(
.call_intrinsic(&format!("llvm.bitreverse.i{width}"), &[ &format!("llvm.bitreverse.i{width}"),
args[0].immediate() &[args[0].immediate()],
]), ),
sym::rotate_left | sym::rotate_right => { sym::rotate_left | sym::rotate_right => {
let is_left = name == sym::rotate_left; let is_left = name == sym::rotate_left;
let val = args[0].immediate(); let val = args[0].immediate();
@ -500,11 +505,10 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::compare_bytes => { sym::compare_bytes => {
// Here we assume that the `memcmp` provided by the target is a NOP for size 0. // Here we assume that the `memcmp` provided by the target is a NOP for size 0.
let cmp = self.call_intrinsic("memcmp", &[ let cmp = self.call_intrinsic(
args[0].immediate(), "memcmp",
args[1].immediate(), &[args[0].immediate(), args[1].immediate(), args[2].immediate()],
args[2].immediate(), );
]);
// Some targets have `memcmp` returning `i16`, but the intrinsic is always `i32`. // Some targets have `memcmp` returning `i16`, but the intrinsic is always `i32`.
self.sext(cmp, self.type_ix(32)) self.sext(cmp, self.type_ix(32))
} }
@ -1305,14 +1309,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
if let Some(cmp_op) = comparison { if let Some(cmp_op) = comparison {
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn); let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
require!( require!(
bx.type_kind(bx.element_type(llret_ty)) == TypeKind::Integer, bx.type_kind(bx.element_type(llret_ty)) == TypeKind::Integer,
InvalidMonomorphization::ReturnIntegerType { span, name, ret_ty, out_ty } InvalidMonomorphization::ReturnIntegerType { span, name, ret_ty, out_ty }
@ -1333,21 +1340,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let n = idx.len() as u64; let n = idx.len() as u64;
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn); let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
require!(out_len == n, InvalidMonomorphization::ReturnLength { require!(
span, out_len == n,
name, InvalidMonomorphization::ReturnLength { span, name, in_len: n, ret_ty, out_len }
in_len: n, );
ret_ty, require!(
out_len in_elem == out_ty,
}); InvalidMonomorphization::ReturnElement { span, name, in_elem, in_ty, ret_ty, out_ty }
require!(in_elem == out_ty, InvalidMonomorphization::ReturnElement { );
span,
name,
in_elem,
in_ty,
ret_ty,
out_ty
});
let total_len = in_len * 2; let total_len = in_len * 2;
@ -1392,21 +1392,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
}; };
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn); let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
require!(out_len == n, InvalidMonomorphization::ReturnLength { require!(
span, out_len == n,
name, InvalidMonomorphization::ReturnLength { span, name, in_len: n, ret_ty, out_len }
in_len: n, );
ret_ty, require!(
out_len in_elem == out_ty,
}); InvalidMonomorphization::ReturnElement { span, name, in_elem, in_ty, ret_ty, out_ty }
require!(in_elem == out_ty, InvalidMonomorphization::ReturnElement { );
span,
name,
in_elem,
in_ty,
ret_ty,
out_ty
});
let total_len = u128::from(in_len) * 2; let total_len = u128::from(in_len) * 2;
@ -1431,13 +1424,16 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
} }
if name == sym::simd_insert { if name == sym::simd_insert {
require!(in_elem == arg_tys[2], InvalidMonomorphization::InsertedType { require!(
in_elem == arg_tys[2],
InvalidMonomorphization::InsertedType {
span, span,
name, name,
in_elem, in_elem,
in_ty, in_ty,
out_ty: arg_tys[2] out_ty: arg_tys[2]
}); }
);
let idx = bx let idx = bx
.const_to_opt_u128(args[1].immediate(), false) .const_to_opt_u128(args[1].immediate(), false)
.expect("typeck should have ensure that this is a const"); .expect("typeck should have ensure that this is a const");
@ -1456,13 +1452,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
)); ));
} }
if name == sym::simd_extract { if name == sym::simd_extract {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
let idx = bx let idx = bx
.const_to_opt_u128(args[1].immediate(), false) .const_to_opt_u128(args[1].immediate(), false)
.expect("typeck should have ensure that this is a const"); .expect("typeck should have ensure that this is a const");
@ -1481,18 +1474,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let m_elem_ty = in_elem; let m_elem_ty = in_elem;
let m_len = in_len; let m_len = in_len;
let (v_len, _) = require_simd!(arg_tys[1], SimdArgument); let (v_len, _) = require_simd!(arg_tys[1], SimdArgument);
require!(m_len == v_len, InvalidMonomorphization::MismatchedLengths { require!(
span, m_len == v_len,
name, InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
m_len, );
v_len let in_elem_bitwidth = require_int_ty!(
}); m_elem_ty.kind(),
let in_elem_bitwidth = InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }
require_int_ty!(m_elem_ty.kind(), InvalidMonomorphization::MaskType { );
span,
name,
ty: m_elem_ty
});
let m_i1s = vector_mask_to_bitmask(bx, args[0].immediate(), in_elem_bitwidth, m_len); let m_i1s = vector_mask_to_bitmask(bx, args[0].immediate(), in_elem_bitwidth, m_len);
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate())); return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
} }
@ -1510,13 +1499,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let expected_bytes = in_len.div_ceil(8); let expected_bytes = in_len.div_ceil(8);
// Integer vector <i{in_bitwidth} x in_len>: // Integer vector <i{in_bitwidth} x in_len>:
let in_elem_bitwidth = let in_elem_bitwidth = require_int_or_uint_ty!(
require_int_or_uint_ty!(in_elem.kind(), InvalidMonomorphization::VectorArgument { in_elem.kind(),
span, InvalidMonomorphization::VectorArgument { span, name, in_ty, in_elem }
name, );
in_ty,
in_elem
});
let i1xn = vector_mask_to_bitmask(bx, args[0].immediate(), in_elem_bitwidth, in_len); let i1xn = vector_mask_to_bitmask(bx, args[0].immediate(), in_elem_bitwidth, in_len);
// Bitcast <i1 x N> to iN: // Bitcast <i1 x N> to iN:
@ -1698,30 +1684,34 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
require_simd!(ret_ty, SimdReturn); require_simd!(ret_ty, SimdReturn);
// Of the same length: // Of the same length:
require!(in_len == out_len, InvalidMonomorphization::SecondArgumentLength { require!(
in_len == out_len,
InvalidMonomorphization::SecondArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[1], arg_ty: arg_tys[1],
out_len out_len
}); }
require!(in_len == out_len2, InvalidMonomorphization::ThirdArgumentLength { );
require!(
in_len == out_len2,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[2], arg_ty: arg_tys[2],
out_len: out_len2 out_len: out_len2
}); }
);
// The return type must match the first argument type // The return type must match the first argument type
require!(ret_ty == in_ty, InvalidMonomorphization::ExpectedReturnType { require!(
span, ret_ty == in_ty,
name, InvalidMonomorphization::ExpectedReturnType { span, name, in_ty, ret_ty }
in_ty, );
ret_ty
});
require!( require!(
matches!( matches!(
@ -1739,13 +1729,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
} }
); );
let mask_elem_bitwidth = let mask_elem_bitwidth = require_int_ty!(
require_int_ty!(element_ty2.kind(), InvalidMonomorphization::ThirdArgElementType { element_ty2.kind(),
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: element_ty2, expected_element: element_ty2,
third_arg: arg_tys[2] third_arg: arg_tys[2]
}); }
);
// Alignment of T, must be a constant integer value: // Alignment of T, must be a constant integer value:
let alignment_ty = bx.type_i32(); let alignment_ty = bx.type_i32();
@ -1805,22 +1797,23 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
require_simd!(ret_ty, SimdReturn); require_simd!(ret_ty, SimdReturn);
// Of the same length: // Of the same length:
require!(values_len == mask_len, InvalidMonomorphization::ThirdArgumentLength { require!(
values_len == mask_len,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len: mask_len, in_len: mask_len,
in_ty: mask_ty, in_ty: mask_ty,
arg_ty: values_ty, arg_ty: values_ty,
out_len: values_len out_len: values_len
}); }
);
// The return type must match the last argument type // The return type must match the last argument type
require!(ret_ty == values_ty, InvalidMonomorphization::ExpectedReturnType { require!(
span, ret_ty == values_ty,
name, InvalidMonomorphization::ExpectedReturnType { span, name, in_ty: values_ty, ret_ty }
in_ty: values_ty, );
ret_ty
});
require!( require!(
matches!( matches!(
@ -1838,13 +1831,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
} }
); );
let m_elem_bitwidth = let m_elem_bitwidth = require_int_ty!(
require_int_ty!(mask_elem.kind(), InvalidMonomorphization::ThirdArgElementType { mask_elem.kind(),
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: values_elem, expected_element: values_elem,
third_arg: mask_ty, third_arg: mask_ty,
}); }
);
let mask = vector_mask_to_bitmask(bx, args[0].immediate(), m_elem_bitwidth, mask_len); let mask = vector_mask_to_bitmask(bx, args[0].immediate(), m_elem_bitwidth, mask_len);
let mask_ty = bx.type_vector(bx.type_i1(), mask_len); let mask_ty = bx.type_vector(bx.type_i1(), mask_len);
@ -1896,14 +1891,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let (values_len, values_elem) = require_simd!(values_ty, SimdThird); let (values_len, values_elem) = require_simd!(values_ty, SimdThird);
// Of the same length: // Of the same length:
require!(values_len == mask_len, InvalidMonomorphization::ThirdArgumentLength { require!(
values_len == mask_len,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len: mask_len, in_len: mask_len,
in_ty: mask_ty, in_ty: mask_ty,
arg_ty: values_ty, arg_ty: values_ty,
out_len: values_len out_len: values_len
}); }
);
// The second argument must be a mutable pointer type matching the element type // The second argument must be a mutable pointer type matching the element type
require!( require!(
@ -1923,13 +1921,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
} }
); );
let m_elem_bitwidth = let m_elem_bitwidth = require_int_ty!(
require_int_ty!(mask_elem.kind(), InvalidMonomorphization::ThirdArgElementType { mask_elem.kind(),
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: values_elem, expected_element: values_elem,
third_arg: mask_ty, third_arg: mask_ty,
}); }
);
let mask = vector_mask_to_bitmask(bx, args[0].immediate(), m_elem_bitwidth, mask_len); let mask = vector_mask_to_bitmask(bx, args[0].immediate(), m_elem_bitwidth, mask_len);
let mask_ty = bx.type_vector(bx.type_i1(), mask_len); let mask_ty = bx.type_vector(bx.type_i1(), mask_len);
@ -1976,22 +1976,28 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let (element_len2, element_ty2) = require_simd!(arg_tys[2], SimdThird); let (element_len2, element_ty2) = require_simd!(arg_tys[2], SimdThird);
// Of the same length: // Of the same length:
require!(in_len == element_len1, InvalidMonomorphization::SecondArgumentLength { require!(
in_len == element_len1,
InvalidMonomorphization::SecondArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[1], arg_ty: arg_tys[1],
out_len: element_len1 out_len: element_len1
}); }
require!(in_len == element_len2, InvalidMonomorphization::ThirdArgumentLength { );
require!(
in_len == element_len2,
InvalidMonomorphization::ThirdArgumentLength {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
arg_ty: arg_tys[2], arg_ty: arg_tys[2],
out_len: element_len2 out_len: element_len2
}); }
);
require!( require!(
matches!( matches!(
@ -2011,13 +2017,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
); );
// The element type of the third argument must be a signed integer type of any width: // The element type of the third argument must be a signed integer type of any width:
let mask_elem_bitwidth = let mask_elem_bitwidth = require_int_ty!(
require_int_ty!(element_ty2.kind(), InvalidMonomorphization::ThirdArgElementType { element_ty2.kind(),
InvalidMonomorphization::ThirdArgElementType {
span, span,
name, name,
expected_element: element_ty2, expected_element: element_ty2,
third_arg: arg_tys[2] third_arg: arg_tys[2]
}); }
);
// Alignment of T, must be a constant integer value: // Alignment of T, must be a constant integer value:
let alignment_ty = bx.type_i32(); let alignment_ty = bx.type_i32();
@ -2058,13 +2066,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
($name:ident : $integer_reduce:ident, $float_reduce:ident, $ordered:expr, $op:ident, ($name:ident : $integer_reduce:ident, $float_reduce:ident, $ordered:expr, $op:ident,
$identity:expr) => { $identity:expr) => {
if name == sym::$name { if name == sym::$name {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
return match in_elem.kind() { return match in_elem.kind() {
ty::Int(_) | ty::Uint(_) => { ty::Int(_) | ty::Uint(_) => {
let r = bx.$integer_reduce(args[0].immediate()); let r = bx.$integer_reduce(args[0].immediate());
@ -2133,13 +2138,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
macro_rules! minmax_red { macro_rules! minmax_red {
($name:ident: $int_red:ident, $float_red:ident) => { ($name:ident: $int_red:ident, $float_red:ident) => {
if name == sym::$name { if name == sym::$name {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
return match in_elem.kind() { return match in_elem.kind() {
ty::Int(_i) => Ok(bx.$int_red(args[0].immediate(), true)), ty::Int(_i) => Ok(bx.$int_red(args[0].immediate(), true)),
ty::Uint(_u) => Ok(bx.$int_red(args[0].immediate(), false)), ty::Uint(_u) => Ok(bx.$int_red(args[0].immediate(), false)),
@ -2164,13 +2166,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
($name:ident : $red:ident, $boolean:expr) => { ($name:ident : $red:ident, $boolean:expr) => {
if name == sym::$name { if name == sym::$name {
let input = if !$boolean { let input = if !$boolean {
require!(ret_ty == in_elem, InvalidMonomorphization::ReturnType { require!(
span, ret_ty == in_elem,
name, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
in_elem, );
in_ty,
ret_ty
});
args[0].immediate() args[0].immediate()
} else { } else {
let bitwidth = match in_elem.kind() { let bitwidth = match in_elem.kind() {
@ -2218,25 +2217,27 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
if name == sym::simd_cast_ptr { if name == sym::simd_cast_ptr {
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn); let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match in_elem.kind() { match in_elem.kind() {
ty::RawPtr(p_ty, _) => { ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty) bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
}); });
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer { require!(
span, metadata.is_unit(),
name, InvalidMonomorphization::CastWidePointer { span, name, ty: in_elem }
ty: in_elem );
});
} }
_ => { _ => {
return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem })
@ -2247,11 +2248,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty) bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
}); });
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer { require!(
span, metadata.is_unit(),
name, InvalidMonomorphization::CastWidePointer { span, name, ty: out_elem }
ty: out_elem );
});
} }
_ => { _ => {
return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem }) return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem })
@ -2263,14 +2263,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
if name == sym::simd_expose_provenance { if name == sym::simd_expose_provenance {
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn); let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match in_elem.kind() { match in_elem.kind() {
ty::RawPtr(_, _) => {} ty::RawPtr(_, _) => {}
@ -2288,14 +2291,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
if name == sym::simd_with_exposed_provenance { if name == sym::simd_with_exposed_provenance {
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn); let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
match in_elem.kind() { match in_elem.kind() {
ty::Uint(ty::UintTy::Usize) => {} ty::Uint(ty::UintTy::Usize) => {}
@ -2313,14 +2319,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
if name == sym::simd_cast || name == sym::simd_as { if name == sym::simd_cast || name == sym::simd_as {
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn); let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
require!(in_len == out_len, InvalidMonomorphization::ReturnLengthInputType { require!(
in_len == out_len,
InvalidMonomorphization::ReturnLengthInputType {
span, span,
name, name,
in_len, in_len,
in_ty, in_ty,
ret_ty, ret_ty,
out_len out_len
}); }
);
// casting cares about nominal type, not just structural type // casting cares about nominal type, not just structural type
if in_elem == out_elem { if in_elem == out_elem {
return Ok(args[0].immediate()); return Ok(args[0].immediate());

View file

@ -414,10 +414,10 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
let member_path = archive_path.parent().unwrap().join(Path::new(&file_name)); let member_path = archive_path.parent().unwrap().join(Path::new(&file_name));
self.entries.push((file_name.into_bytes(), ArchiveEntry::File(member_path))); self.entries.push((file_name.into_bytes(), ArchiveEntry::File(member_path)));
} else { } else {
self.entries.push((file_name.into_bytes(), ArchiveEntry::FromArchive { self.entries.push((
archive_index, file_name.into_bytes(),
file_range: entry.file_range(), ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() },
})); ));
} }
} }
} }

View file

@ -10,16 +10,14 @@ fn test_rpaths_to_args() {
#[test] #[test]
fn test_xlinker() { fn test_xlinker() {
let mut cmd = Command::new("foo"); let mut cmd = Command::new("foo");
convert_link_args_to_cc_args(&mut cmd, &[ convert_link_args_to_cc_args(
"arg1", &mut cmd,
"arg2", &["arg1", "arg2", "arg3,with,comma", "arg4,with,comma", "arg5", "arg6,with,comma"],
"arg3,with,comma", );
"arg4,with,comma",
"arg5",
"arg6,with,comma",
]);
assert_eq!(cmd.get_args(), [ assert_eq!(
cmd.get_args(),
[
OsStr::new("-Wl,arg1,arg2"), OsStr::new("-Wl,arg1,arg2"),
OsStr::new("-Xlinker"), OsStr::new("-Xlinker"),
OsStr::new("arg3,with,comma"), OsStr::new("arg3,with,comma"),
@ -28,5 +26,6 @@ fn test_xlinker() {
OsStr::new("-Wl,arg5"), OsStr::new("-Wl,arg5"),
OsStr::new("-Xlinker"), OsStr::new("-Xlinker"),
OsStr::new("arg6,with,comma"), OsStr::new("arg6,with,comma"),
]); ]
);
} }

View file

@ -704,13 +704,17 @@ pub fn create_metadata_file_for_wasm(sess: &Session, data: &[u8], section_name:
let mut imports = wasm_encoder::ImportSection::new(); let mut imports = wasm_encoder::ImportSection::new();
if sess.target.pointer_width == 64 { if sess.target.pointer_width == 64 {
imports.import("env", "__linear_memory", wasm_encoder::MemoryType { imports.import(
"env",
"__linear_memory",
wasm_encoder::MemoryType {
minimum: 0, minimum: 0,
maximum: None, maximum: None,
memory64: true, memory64: true,
shared: false, shared: false,
page_size_log2: None, page_size_log2: None,
}); },
);
} }
if imports.len() > 0 { if imports.len() > 0 {

View file

@ -140,11 +140,14 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
.into(); .into();
if let Some(id) = tcx.proc_macro_decls_static(()) { if let Some(id) = tcx.proc_macro_decls_static(()) {
reachable_non_generics.insert(id.to_def_id(), SymbolExportInfo { reachable_non_generics.insert(
id.to_def_id(),
SymbolExportInfo {
level: SymbolExportLevel::C, level: SymbolExportLevel::C,
kind: SymbolExportKind::Data, kind: SymbolExportKind::Data,
used: false, used: false,
}); },
);
} }
reachable_non_generics reachable_non_generics
@ -185,11 +188,14 @@ fn exported_symbols_provider_local(
if !tcx.sess.target.dll_tls_export { if !tcx.sess.target.dll_tls_export {
symbols.extend(sorted.iter().filter_map(|(&def_id, &info)| { symbols.extend(sorted.iter().filter_map(|(&def_id, &info)| {
tcx.needs_thread_local_shim(def_id).then(|| { tcx.needs_thread_local_shim(def_id).then(|| {
(ExportedSymbol::ThreadLocalShim(def_id), SymbolExportInfo { (
ExportedSymbol::ThreadLocalShim(def_id),
SymbolExportInfo {
level: info.level, level: info.level,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: info.used, used: info.used,
}) },
)
}) })
})) }))
} }
@ -198,11 +204,14 @@ fn exported_symbols_provider_local(
let exported_symbol = let exported_symbol =
ExportedSymbol::NoDefId(SymbolName::new(tcx, tcx.sess.target.entry_name.as_ref())); ExportedSymbol::NoDefId(SymbolName::new(tcx, tcx.sess.target.entry_name.as_ref()));
symbols.push((exported_symbol, SymbolExportInfo { symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C, level: SymbolExportLevel::C,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: false, used: false,
})); },
));
} }
// Mark allocator shim symbols as exported only if they were generated. // Mark allocator shim symbols as exported only if they were generated.
@ -214,20 +223,26 @@ fn exported_symbols_provider_local(
{ {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
symbols.push((exported_symbol, SymbolExportInfo { symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust, level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: false, used: false,
})); },
));
} }
let exported_symbol = let exported_symbol =
ExportedSymbol::NoDefId(SymbolName::new(tcx, NO_ALLOC_SHIM_IS_UNSTABLE)); ExportedSymbol::NoDefId(SymbolName::new(tcx, NO_ALLOC_SHIM_IS_UNSTABLE));
symbols.push((exported_symbol, SymbolExportInfo { symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust, level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Data, kind: SymbolExportKind::Data,
used: false, used: false,
})) },
))
} }
if tcx.sess.instrument_coverage() || tcx.sess.opts.cg.profile_generate.enabled() { if tcx.sess.instrument_coverage() || tcx.sess.opts.cg.profile_generate.enabled() {
@ -239,11 +254,14 @@ fn exported_symbols_provider_local(
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| { symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
(exported_symbol, SymbolExportInfo { (
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C, level: SymbolExportLevel::C,
kind: SymbolExportKind::Data, kind: SymbolExportKind::Data,
used: false, used: false,
}) },
)
})); }));
} }
@ -261,11 +279,14 @@ fn exported_symbols_provider_local(
symbols.extend(msan_weak_symbols.into_iter().map(|sym| { symbols.extend(msan_weak_symbols.into_iter().map(|sym| {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym)); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
(exported_symbol, SymbolExportInfo { (
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C, level: SymbolExportLevel::C,
kind: SymbolExportKind::Data, kind: SymbolExportKind::Data,
used: false, used: false,
}) },
)
})); }));
} }
@ -275,11 +296,14 @@ fn exported_symbols_provider_local(
let symbol_name = metadata_symbol_name(tcx); let symbol_name = metadata_symbol_name(tcx);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
symbols.push((exported_symbol, SymbolExportInfo { symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C, level: SymbolExportLevel::C,
kind: SymbolExportKind::Data, kind: SymbolExportKind::Data,
used: true, used: true,
})); },
));
} }
if tcx.local_crate_exports_generics() { if tcx.local_crate_exports_generics() {
@ -325,21 +349,27 @@ fn exported_symbols_provider_local(
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => { MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
if args.non_erasable_generics().next().is_some() { if args.non_erasable_generics().next().is_some() {
let symbol = ExportedSymbol::Generic(def, args); let symbol = ExportedSymbol::Generic(def, args);
symbols.push((symbol, SymbolExportInfo { symbols.push((
symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust, level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: false, used: false,
})); },
));
} }
} }
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => { MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
// A little sanity-check // A little sanity-check
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty))); assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportInfo { symbols.push((
ExportedSymbol::DropGlue(ty),
SymbolExportInfo {
level: SymbolExportLevel::Rust, level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: false, used: false,
})); },
));
} }
MonoItem::Fn(Instance { MonoItem::Fn(Instance {
def: InstanceKind::AsyncDropGlueCtorShim(_, Some(ty)), def: InstanceKind::AsyncDropGlueCtorShim(_, Some(ty)),
@ -347,11 +377,14 @@ fn exported_symbols_provider_local(
}) => { }) => {
// A little sanity-check // A little sanity-check
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty))); assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
symbols.push((ExportedSymbol::AsyncDropGlueCtorShim(ty), SymbolExportInfo { symbols.push((
ExportedSymbol::AsyncDropGlueCtorShim(ty),
SymbolExportInfo {
level: SymbolExportLevel::Rust, level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text, kind: SymbolExportKind::Text,
used: false, used: false,
})); },
));
} }
_ => { _ => {
// Any other symbols don't qualify for sharing // Any other symbols don't qualify for sharing

View file

@ -1604,10 +1604,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if let Some(slot) = self.personality_slot { if let Some(slot) = self.personality_slot {
slot slot
} else { } else {
let layout = cx.layout_of(Ty::new_tup(cx.tcx(), &[ let layout = cx.layout_of(Ty::new_tup(
Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx(),
cx.tcx().types.i32, &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
])); ));
let slot = PlaceRef::alloca(bx, layout); let slot = PlaceRef::alloca(bx, layout);
self.personality_slot = Some(slot); self.personality_slot = Some(slot);
slot slot

View file

@ -474,10 +474,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
LocalRef::Operand(..) => { LocalRef::Operand(..) => {
if place_ref.is_indirect_first_projection() { if place_ref.is_indirect_first_projection() {
base = 1; base = 1;
let cg_base = self.codegen_consume(bx, mir::PlaceRef { let cg_base = self.codegen_consume(
projection: &place_ref.projection[..0], bx,
..place_ref mir::PlaceRef { projection: &place_ref.projection[..0], ..place_ref },
}); );
cg_base.deref(bx.cx()) cg_base.deref(bx.cx())
} else { } else {
bug!("using operand local {:?} as place", place_ref); bug!("using operand local {:?} as place", place_ref);

View file

@ -188,12 +188,14 @@ impl Qualif for NeedsNonConstDrop {
ObligationCause::misc(cx.body.span, cx.def_id()), ObligationCause::misc(cx.body.span, cx.def_id()),
param_env, param_env,
ty::Binder::dummy(ty::TraitRef::new(cx.tcx, destruct_def_id, [ty])) ty::Binder::dummy(ty::TraitRef::new(cx.tcx, destruct_def_id, [ty]))
.to_host_effect_clause(cx.tcx, match cx.const_kind() { .to_host_effect_clause(
cx.tcx,
match cx.const_kind() {
rustc_hir::ConstContext::ConstFn => ty::BoundConstness::Maybe, rustc_hir::ConstContext::ConstFn => ty::BoundConstness::Maybe,
rustc_hir::ConstContext::Static(_) | rustc_hir::ConstContext::Const { .. } => { rustc_hir::ConstContext::Static(_)
ty::BoundConstness::Const | rustc_hir::ConstContext::Const { .. } => ty::BoundConstness::Const,
} },
}), ),
)); ));
!ocx.select_all_or_error().is_empty() !ocx.select_all_or_error().is_empty()
} }

View file

@ -578,10 +578,13 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
} }
ShiftOverflow { intrinsic, shift_amount } => { ShiftOverflow { intrinsic, shift_amount } => {
diag.arg("intrinsic", intrinsic); diag.arg("intrinsic", intrinsic);
diag.arg("shift_amount", match shift_amount { diag.arg(
"shift_amount",
match shift_amount {
Either::Left(v) => v.to_string(), Either::Left(v) => v.to_string(),
Either::Right(v) => v.to_string(), Either::Right(v) => v.to_string(),
}); },
);
} }
BoundsCheckFailed { len, index } => { BoundsCheckFailed { len, index } => {
diag.arg("len", len); diag.arg("len", len);

View file

@ -381,10 +381,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
"caller ABI: {:#?}, args: {:#?}", "caller ABI: {:#?}, args: {:#?}",
caller_fn_abi, caller_fn_abi,
args.iter() args.iter()
.map(|arg| (arg.layout().ty, match arg { .map(|arg| (
arg.layout().ty,
match arg {
FnArg::Copy(op) => format!("copy({op:?})"), FnArg::Copy(op) => format!("copy({op:?})"),
FnArg::InPlace(mplace) => format!("in-place({mplace:?})"), FnArg::InPlace(mplace) => format!("in-place({mplace:?})"),
})) }
))
.collect::<Vec<_>>() .collect::<Vec<_>>()
); );
trace!( trace!(
@ -874,10 +877,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
); );
// Check `unwinding`. // Check `unwinding`.
assert_eq!(unwinding, match self.frame().loc { assert_eq!(
unwinding,
match self.frame().loc {
Left(loc) => self.body().basic_blocks[loc.block].is_cleanup, Left(loc) => self.body().basic_blocks[loc.block].is_cleanup,
Right(_) => true, Right(_) => true,
}); }
);
if unwinding && self.frame_idx() == 0 { if unwinding && self.frame_idx() == 0 {
throw_ub_custom!(fluent::const_eval_unwind_past_top); throw_ub_custom!(fluent::const_eval_unwind_past_top);
} }

View file

@ -102,11 +102,11 @@ fn intern_as_new_static<'tcx>(
alloc_id: AllocId, alloc_id: AllocId,
alloc: ConstAllocation<'tcx>, alloc: ConstAllocation<'tcx>,
) { ) {
let feed = tcx.create_def(static_id, sym::nested, DefKind::Static { let feed = tcx.create_def(
safety: hir::Safety::Safe, static_id,
mutability: alloc.0.mutability, sym::nested,
nested: true, DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
}); );
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id()); tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
if tcx.is_thread_local_static(static_id.into()) { if tcx.is_thread_local_static(static_id.into()) {

View file

@ -812,10 +812,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
if start == 1 && end == max_value { if start == 1 && end == max_value {
// Only null is the niche. So make sure the ptr is NOT null. // Only null is the niche. So make sure the ptr is NOT null.
if self.ecx.scalar_may_be_null(scalar)? { if self.ecx.scalar_may_be_null(scalar)? {
throw_validation_failure!(self.path, NullablePtrOutOfRange { throw_validation_failure!(
range: valid_range, self.path,
max_value NullablePtrOutOfRange { range: valid_range, max_value }
}) )
} else { } else {
return interp_ok(()); return interp_ok(());
} }
@ -825,10 +825,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
} else { } else {
// Conservatively, we reject, because the pointer *could* have a bad // Conservatively, we reject, because the pointer *could* have a bad
// value. // value.
throw_validation_failure!(self.path, PtrOutOfRange { throw_validation_failure!(
range: valid_range, self.path,
max_value PtrOutOfRange { range: valid_range, max_value }
}) )
} }
} }
}; };
@ -836,11 +836,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
if valid_range.contains(bits) { if valid_range.contains(bits) {
interp_ok(()) interp_ok(())
} else { } else {
throw_validation_failure!(self.path, OutOfRange { throw_validation_failure!(
value: format!("{bits}"), self.path,
range: valid_range, OutOfRange { value: format!("{bits}"), range: valid_range, max_value }
max_value )
})
} }
} }

View file

@ -15,17 +15,10 @@ fn diamond() {
#[test] #[test]
fn paper() { fn paper() {
// example from the paper: // example from the paper:
let graph = TestGraph::new(6, &[ let graph = TestGraph::new(
(6, 5), 6,
(6, 4), &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), (2, 1)],
(5, 1), );
(4, 2),
(4, 3),
(1, 2),
(2, 3),
(3, 2),
(2, 1),
]);
let d = dominators(&graph); let d = dominators(&graph);
assert_eq!(d.immediate_dominator(0), None); // <-- note that 0 is not in graph assert_eq!(d.immediate_dominator(0), None); // <-- note that 0 is not in graph
@ -40,19 +33,10 @@ fn paper() {
#[test] #[test]
fn paper_slt() { fn paper_slt() {
// example from the paper: // example from the paper:
let graph = TestGraph::new(1, &[ let graph = TestGraph::new(
(1, 2), 1,
(1, 3), &[(1, 2), (1, 3), (2, 3), (2, 7), (3, 4), (3, 6), (4, 5), (5, 4), (6, 7), (7, 8), (8, 5)],
(2, 3), );
(2, 7),
(3, 4),
(3, 6),
(4, 5),
(5, 4),
(6, 7),
(7, 8),
(8, 5),
]);
dominators(&graph); dominators(&graph);
} }
@ -69,7 +53,9 @@ fn immediate_dominator() {
#[test] #[test]
fn transitive_dominator() { fn transitive_dominator() {
let graph = TestGraph::new(0, &[ let graph = TestGraph::new(
0,
&[
// First tree branch. // First tree branch.
(0, 1), (0, 1),
(1, 2), (1, 2),
@ -83,7 +69,8 @@ fn transitive_dominator() {
// These links make 0 the dominator for 2 and 3. // These links make 0 the dominator for 2 and 3.
(7, 2), (7, 2),
(5, 3), (5, 3),
]); ],
);
let d = dominators(&graph); let d = dominators(&graph);
assert_eq!(d.immediate_dominator(2), Some(0)); assert_eq!(d.immediate_dominator(2), Some(0));

View file

@ -110,10 +110,13 @@ fn each_adjacent_from_a() {
#[test] #[test]
fn each_adjacent_from_b() { fn each_adjacent_from_b() {
let graph = create_graph(); let graph = create_graph();
test_adjacent_edges(&graph, NodeIndex(1), "B", &[("FB", "F"), ("AB", "A")], &[ test_adjacent_edges(
("BD", "D"), &graph,
("BC", "C"), NodeIndex(1),
]); "B",
&[("FB", "F"), ("AB", "A")],
&[("BD", "D"), ("BC", "C")],
);
} }
#[test] #[test]

View file

@ -326,7 +326,9 @@ fn test_bug_max_leak_minimised() {
#[test] #[test]
fn test_bug_max_leak() { fn test_bug_max_leak() {
let graph = TestGraph::new(8, &[ let graph = TestGraph::new(
8,
&[
(0, 0), (0, 0),
(0, 18), (0, 18),
(0, 19), (0, 19),
@ -365,7 +367,8 @@ fn test_bug_max_leak() {
(10, 14), (10, 14),
(14, 27), (14, 27),
(23, 24), (23, 24),
]); ],
);
let sccs: MaxReachedSccs = Sccs::new_with_annotation(&graph, |w| match w { let sccs: MaxReachedSccs = Sccs::new_with_annotation(&graph, |w| match w {
22 => MaxReached(1), 22 => MaxReached(1),
24 => MaxReached(2), 24 => MaxReached(2),

View file

@ -349,10 +349,10 @@ fn diamond() {
)); ));
assert_eq!(d_count, 1); assert_eq!(d_count, 1);
assert_eq!(ok.len(), 0); assert_eq!(ok.len(), 0);
assert_eq!(err, vec![super::Error { assert_eq!(
error: "operation failed", err,
backtrace: vec!["D'", "A'.1", "A'"] vec![super::Error { error: "operation failed", backtrace: vec!["D'", "A'.1", "A'"] }]
}]); );
let errors = forest.to_errors(()); let errors = forest.to_errors(());
assert_eq!(errors.len(), 0); assert_eq!(errors.len(), 0);

View file

@ -58,11 +58,14 @@ fn concurrent_stress_check() {
#[test] #[test]
fn slot_entries_table() { fn slot_entries_table() {
assert_eq!(ENTRIES_BY_BUCKET, [ assert_eq!(
4096, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, ENTRIES_BY_BUCKET,
8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, [
2147483648 4096, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152,
]); 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912,
1073741824, 2147483648
]
);
} }
#[test] #[test]

View file

@ -69,96 +69,128 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
#[test] #[test]
fn empty() { fn empty() {
test_positions(" ", (0, 1), SpanTestData { test_positions(
" ",
(0, 1),
SpanTestData {
byte_start: 0, byte_start: 0,
byte_end: 1, byte_end: 1,
line_start: 1, line_start: 1,
column_start: 1, column_start: 1,
line_end: 1, line_end: 1,
column_end: 2, column_end: 2,
}) },
)
} }
#[test] #[test]
fn bom() { fn bom() {
test_positions("\u{feff} ", (0, 1), SpanTestData { test_positions(
"\u{feff} ",
(0, 1),
SpanTestData {
byte_start: 3, byte_start: 3,
byte_end: 4, byte_end: 4,
line_start: 1, line_start: 1,
column_start: 1, column_start: 1,
line_end: 1, line_end: 1,
column_end: 2, column_end: 2,
}) },
)
} }
#[test] #[test]
fn lf_newlines() { fn lf_newlines() {
test_positions("\nmod foo;\nmod bar;\n", (5, 12), SpanTestData { test_positions(
"\nmod foo;\nmod bar;\n",
(5, 12),
SpanTestData {
byte_start: 5, byte_start: 5,
byte_end: 12, byte_end: 12,
line_start: 2, line_start: 2,
column_start: 5, column_start: 5,
line_end: 3, line_end: 3,
column_end: 3, column_end: 3,
}) },
)
} }
#[test] #[test]
fn crlf_newlines() { fn crlf_newlines() {
test_positions("\r\nmod foo;\r\nmod bar;\r\n", (5, 12), SpanTestData { test_positions(
"\r\nmod foo;\r\nmod bar;\r\n",
(5, 12),
SpanTestData {
byte_start: 6, byte_start: 6,
byte_end: 14, byte_end: 14,
line_start: 2, line_start: 2,
column_start: 5, column_start: 5,
line_end: 3, line_end: 3,
column_end: 3, column_end: 3,
}) },
)
} }
#[test] #[test]
fn crlf_newlines_with_bom() { fn crlf_newlines_with_bom() {
test_positions("\u{feff}\r\nmod foo;\r\nmod bar;\r\n", (5, 12), SpanTestData { test_positions(
"\u{feff}\r\nmod foo;\r\nmod bar;\r\n",
(5, 12),
SpanTestData {
byte_start: 9, byte_start: 9,
byte_end: 17, byte_end: 17,
line_start: 2, line_start: 2,
column_start: 5, column_start: 5,
line_end: 3, line_end: 3,
column_end: 3, column_end: 3,
}) },
)
} }
#[test] #[test]
fn span_before_crlf() { fn span_before_crlf() {
test_positions("foo\r\nbar", (2, 3), SpanTestData { test_positions(
"foo\r\nbar",
(2, 3),
SpanTestData {
byte_start: 2, byte_start: 2,
byte_end: 3, byte_end: 3,
line_start: 1, line_start: 1,
column_start: 3, column_start: 3,
line_end: 1, line_end: 1,
column_end: 4, column_end: 4,
}) },
)
} }
#[test] #[test]
fn span_on_crlf() { fn span_on_crlf() {
test_positions("foo\r\nbar", (3, 4), SpanTestData { test_positions(
"foo\r\nbar",
(3, 4),
SpanTestData {
byte_start: 3, byte_start: 3,
byte_end: 5, byte_end: 5,
line_start: 1, line_start: 1,
column_start: 4, column_start: 4,
line_end: 2, line_end: 2,
column_end: 1, column_end: 1,
}) },
)
} }
#[test] #[test]
fn span_after_crlf() { fn span_after_crlf() {
test_positions("foo\r\nbar", (4, 5), SpanTestData { test_positions(
"foo\r\nbar",
(4, 5),
SpanTestData {
byte_start: 5, byte_start: 5,
byte_end: 6, byte_end: 6,
line_start: 2, line_start: 2,
column_start: 1, column_start: 1,
line_end: 2, line_end: 2,
column_end: 2, column_end: 2,
}) },
)
} }

View file

@ -233,11 +233,14 @@ impl<'a> ExtCtxt<'a> {
} }
pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
self.block(expr.span, thin_vec![ast::Stmt { self.block(
expr.span,
thin_vec![ast::Stmt {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: expr.span, span: expr.span,
kind: ast::StmtKind::Expr(expr), kind: ast::StmtKind::Expr(expr),
}]) }],
)
} }
pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> P<ast::Block> { pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> P<ast::Block> {
P(ast::Block { P(ast::Block {

View file

@ -405,18 +405,26 @@ pub fn compile_declarative_macro(
// ...quasiquoting this would be nice. // ...quasiquoting this would be nice.
// These spans won't matter, anyways // These spans won't matter, anyways
let argument_gram = vec![ let argument_gram = vec![
mbe::TokenTree::Sequence(DelimSpan::dummy(), mbe::SequenceRepetition { mbe::TokenTree::Sequence(
DelimSpan::dummy(),
mbe::SequenceRepetition {
tts: vec![ tts: vec![
mbe::TokenTree::MetaVarDecl(span, lhs_nm, tt_spec), mbe::TokenTree::MetaVarDecl(span, lhs_nm, tt_spec),
mbe::TokenTree::token(token::FatArrow, span), mbe::TokenTree::token(token::FatArrow, span),
mbe::TokenTree::MetaVarDecl(span, rhs_nm, tt_spec), mbe::TokenTree::MetaVarDecl(span, rhs_nm, tt_spec),
], ],
separator: Some(Token::new(if macro_rules { token::Semi } else { token::Comma }, span)), separator: Some(Token::new(
if macro_rules { token::Semi } else { token::Comma },
span,
)),
kleene: mbe::KleeneToken::new(mbe::KleeneOp::OneOrMore, span), kleene: mbe::KleeneToken::new(mbe::KleeneOp::OneOrMore, span),
num_captures: 2, num_captures: 2,
}), },
),
// to phase into semicolon-termination instead of semicolon-separation // to phase into semicolon-termination instead of semicolon-separation
mbe::TokenTree::Sequence(DelimSpan::dummy(), mbe::SequenceRepetition { mbe::TokenTree::Sequence(
DelimSpan::dummy(),
mbe::SequenceRepetition {
tts: vec![mbe::TokenTree::token( tts: vec![mbe::TokenTree::token(
if macro_rules { token::Semi } else { token::Comma }, if macro_rules { token::Semi } else { token::Comma },
span, span,
@ -424,7 +432,8 @@ pub fn compile_declarative_macro(
separator: None, separator: None,
kleene: mbe::KleeneToken::new(mbe::KleeneOp::ZeroOrMore, span), kleene: mbe::KleeneToken::new(mbe::KleeneOp::ZeroOrMore, span),
num_captures: 0, num_captures: 0,
}), },
),
]; ];
// Convert it into `MatcherLoc` form. // Convert it into `MatcherLoc` form.
let argument_gram = mbe::macro_parser::compute_locs(&argument_gram); let argument_gram = mbe::macro_parser::compute_locs(&argument_gram);

View file

@ -179,10 +179,10 @@ fn parse_tree<'a>(
Some(&tokenstream::TokenTree::Delimited(delim_span, _, delim, ref tts)) => { Some(&tokenstream::TokenTree::Delimited(delim_span, _, delim, ref tts)) => {
if parsing_patterns { if parsing_patterns {
if delim != Delimiter::Parenthesis { if delim != Delimiter::Parenthesis {
span_dollar_dollar_or_metavar_in_the_lhs_err(sess, &Token { span_dollar_dollar_or_metavar_in_the_lhs_err(
kind: token::OpenDelim(delim), sess,
span: delim_span.entire(), &Token { kind: token::OpenDelim(delim), span: delim_span.entire() },
}); );
} }
} else { } else {
match delim { match delim {
@ -235,12 +235,10 @@ fn parse_tree<'a>(
// Count the number of captured "names" (i.e., named metavars) // Count the number of captured "names" (i.e., named metavars)
let num_captures = let num_captures =
if parsing_patterns { count_metavar_decls(&sequence) } else { 0 }; if parsing_patterns { count_metavar_decls(&sequence) } else { 0 };
TokenTree::Sequence(delim_span, SequenceRepetition { TokenTree::Sequence(
tts: sequence, delim_span,
separator, SequenceRepetition { tts: sequence, separator, kleene, num_captures },
kleene, )
num_captures,
})
} }
// `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` // `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate`
@ -261,10 +259,10 @@ fn parse_tree<'a>(
_, _,
)) => { )) => {
if parsing_patterns { if parsing_patterns {
span_dollar_dollar_or_metavar_in_the_lhs_err(sess, &Token { span_dollar_dollar_or_metavar_in_the_lhs_err(
kind: token::Dollar, sess,
span: dollar_span2, &Token { kind: token::Dollar, span: dollar_span2 },
}); );
} else { } else {
maybe_emit_macro_metavar_expr_feature(features, sess, dollar_span2); maybe_emit_macro_metavar_expr_feature(features, sess, dollar_span2);
} }
@ -289,12 +287,14 @@ fn parse_tree<'a>(
// `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to // `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to
// descend into the delimited set and further parse it. // descend into the delimited set and further parse it.
&tokenstream::TokenTree::Delimited(span, spacing, delim, ref tts) => { &tokenstream::TokenTree::Delimited(span, spacing, delim, ref tts) => TokenTree::Delimited(
TokenTree::Delimited(span, spacing, Delimited { span,
spacing,
Delimited {
delim, delim,
tts: parse(tts, parsing_patterns, sess, node_id, features, edition), tts: parse(tts, parsing_patterns, sess, node_id, features, edition),
}) },
} ),
} }
} }

View file

@ -360,12 +360,16 @@ fn left_aligned_text() {
let mut writer = Vec::new(); let mut writer = Vec::new();
let g = LabelledGraphWithEscStrs::new("syntax_tree", labels, vec![ let g = LabelledGraphWithEscStrs::new(
"syntax_tree",
labels,
vec![
edge(0, 1, "then", Style::None), edge(0, 1, "then", Style::None),
edge(0, 2, "else", Style::None), edge(0, 2, "else", Style::None),
edge(1, 3, ";", Style::None), edge(1, 3, ";", Style::None),
edge(2, 3, ";", Style::None), edge(2, 3, ";", Style::None),
]); ],
);
render(&g, &mut writer).unwrap(); render(&g, &mut writer).unwrap();
let mut r = String::new(); let mut r = String::new();

View file

@ -3101,10 +3101,10 @@ impl<'hir> Ty<'hir> {
fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) { fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) {
if matches!( if matches!(
&t.kind, &t.kind,
TyKind::Path(QPath::Resolved(_, Path { TyKind::Path(QPath::Resolved(
res: crate::def::Res::SelfTyAlias { .. }, _,
.. Path { res: crate::def::Res::SelfTyAlias { .. }, .. },
},)) ))
) { ) {
self.0.push(t.span); self.0.push(t.span);
return; return;
@ -3446,11 +3446,10 @@ impl<'hir> InlineAsmOperand<'hir> {
} }
pub fn is_clobber(&self) -> bool { pub fn is_clobber(&self) -> bool {
matches!(self, InlineAsmOperand::Out { matches!(
reg: InlineAsmRegOrRegClass::Reg(_), self,
late: _, InlineAsmOperand::Out { reg: InlineAsmRegOrRegClass::Reg(_), late: _, expr: None }
expr: None )
})
} }
} }

View file

@ -182,12 +182,15 @@ fn compare_method_predicate_entailment<'tcx>(
// obligations. // obligations.
let impl_m_def_id = impl_m.def_id.expect_local(); let impl_m_def_id = impl_m.def_id.expect_local();
let impl_m_span = tcx.def_span(impl_m_def_id); let impl_m_span = tcx.def_span(impl_m_def_id);
let cause = let cause = ObligationCause::new(
ObligationCause::new(impl_m_span, impl_m_def_id, ObligationCauseCode::CompareImplItem { impl_m_span,
impl_m_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
}); },
);
// Create mapping from trait method to impl method. // Create mapping from trait method to impl method.
let impl_def_id = impl_m.container_id(tcx); let impl_def_id = impl_m.container_id(tcx);
@ -248,12 +251,15 @@ fn compare_method_predicate_entailment<'tcx>(
let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id); let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id);
let predicate = ocx.normalize(&normalize_cause, param_env, predicate); let predicate = ocx.normalize(&normalize_cause, param_env, predicate);
let cause = let cause = ObligationCause::new(
ObligationCause::new(span, impl_m_def_id, ObligationCauseCode::CompareImplItem { span,
impl_m_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
}); },
);
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
} }
@ -270,12 +276,15 @@ fn compare_method_predicate_entailment<'tcx>(
let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id); let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id);
let const_condition = ocx.normalize(&normalize_cause, param_env, const_condition); let const_condition = ocx.normalize(&normalize_cause, param_env, const_condition);
let cause = let cause = ObligationCause::new(
ObligationCause::new(span, impl_m_def_id, ObligationCauseCode::CompareImplItem { span,
impl_m_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
}); },
);
ocx.register_obligation(traits::Obligation::new( ocx.register_obligation(traits::Obligation::new(
tcx, tcx,
cause, cause,
@ -493,12 +502,15 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
let impl_m_hir_id = tcx.local_def_id_to_hir_id(impl_m_def_id); let impl_m_hir_id = tcx.local_def_id_to_hir_id(impl_m_def_id);
let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span(); let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
let cause = let cause = ObligationCause::new(
ObligationCause::new(return_span, impl_m_def_id, ObligationCauseCode::CompareImplItem { return_span,
impl_m_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
}); },
);
// Create mapping from trait to impl (i.e. impl trait header + impl method identity args). // Create mapping from trait to impl (i.e. impl trait header + impl method identity args).
let trait_to_impl_args = GenericArgs::identity_for_item(tcx, impl_m.def_id).rebase_onto( let trait_to_impl_args = GenericArgs::identity_for_item(tcx, impl_m.def_id).rebase_onto(
@ -534,12 +546,15 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id); let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id);
let predicate = ocx.normalize(&normalize_cause, param_env, predicate); let predicate = ocx.normalize(&normalize_cause, param_env, predicate);
let cause = let cause = ObligationCause::new(
ObligationCause::new(span, impl_m_def_id, ObligationCauseCode::CompareImplItem { span,
impl_m_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_m_def_id, impl_item_def_id: impl_m_def_id,
trait_item_def_id: trait_m.def_id, trait_item_def_id: trait_m.def_id,
kind: impl_m.kind, kind: impl_m.kind,
}); },
);
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
} }
@ -606,13 +621,16 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
idx += 1; idx += 1;
( (
ty, ty,
Ty::new_placeholder(tcx, ty::Placeholder { Ty::new_placeholder(
tcx,
ty::Placeholder {
universe, universe,
bound: ty::BoundTy { bound: ty::BoundTy {
var: ty::BoundVar::from_usize(idx), var: ty::BoundVar::from_usize(idx),
kind: ty::BoundTyKind::Anon, kind: ty::BoundTyKind::Anon,
}, },
}), },
),
) )
}) })
.collect(); .collect();
@ -969,10 +987,13 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
return Err(guar); return Err(guar);
}; };
Ok(ty::Region::new_early_param(self.tcx, ty::EarlyParamRegion { Ok(ty::Region::new_early_param(
self.tcx,
ty::EarlyParamRegion {
name: e.name, name: e.name,
index: (e.index as usize - self.num_trait_args + self.num_impl_args) as u32, index: (e.index as usize - self.num_trait_args + self.num_impl_args) as u32,
})) },
))
} }
} }
@ -1967,12 +1988,15 @@ fn compare_type_predicate_entailment<'tcx>(
let cause = ObligationCause::misc(span, impl_ty_def_id); let cause = ObligationCause::misc(span, impl_ty_def_id);
let predicate = ocx.normalize(&cause, param_env, predicate); let predicate = ocx.normalize(&cause, param_env, predicate);
let cause = let cause = ObligationCause::new(
ObligationCause::new(span, impl_ty_def_id, ObligationCauseCode::CompareImplItem { span,
impl_ty_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_ty.def_id.expect_local(), impl_item_def_id: impl_ty.def_id.expect_local(),
trait_item_def_id: trait_ty.def_id, trait_item_def_id: trait_ty.def_id,
kind: impl_ty.kind, kind: impl_ty.kind,
}); },
);
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
} }
@ -1984,12 +2008,15 @@ fn compare_type_predicate_entailment<'tcx>(
let normalize_cause = traits::ObligationCause::misc(span, impl_ty_def_id); let normalize_cause = traits::ObligationCause::misc(span, impl_ty_def_id);
let const_condition = ocx.normalize(&normalize_cause, param_env, const_condition); let const_condition = ocx.normalize(&normalize_cause, param_env, const_condition);
let cause = let cause = ObligationCause::new(
ObligationCause::new(span, impl_ty_def_id, ObligationCauseCode::CompareImplItem { span,
impl_ty_def_id,
ObligationCauseCode::CompareImplItem {
impl_item_def_id: impl_ty_def_id, impl_item_def_id: impl_ty_def_id,
trait_item_def_id: trait_ty.def_id, trait_item_def_id: trait_ty.def_id,
kind: impl_ty.kind, kind: impl_ty.kind,
}); },
);
ocx.register_obligation(traits::Obligation::new( ocx.register_obligation(traits::Obligation::new(
tcx, tcx,
cause, cause,
@ -2244,20 +2271,25 @@ fn param_env_with_gat_bounds<'tcx>(
let kind = ty::BoundTyKind::Param(param.def_id, param.name); let kind = ty::BoundTyKind::Param(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Ty(kind); let bound_var = ty::BoundVariableKind::Ty(kind);
bound_vars.push(bound_var); bound_vars.push(bound_var);
Ty::new_bound(tcx, ty::INNERMOST, ty::BoundTy { Ty::new_bound(
var: ty::BoundVar::from_usize(bound_vars.len() - 1), tcx,
kind, ty::INNERMOST,
}) ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
)
.into() .into()
} }
GenericParamDefKind::Lifetime => { GenericParamDefKind::Lifetime => {
let kind = ty::BoundRegionKind::Named(param.def_id, param.name); let kind = ty::BoundRegionKind::Named(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind); let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var); bound_vars.push(bound_var);
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { ty::Region::new_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind, kind,
}) },
)
.into() .into()
} }
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {

View file

@ -185,14 +185,19 @@ pub fn check_intrinsic_type(
]); ]);
let mk_va_list_ty = |mutbl| { let mk_va_list_ty = |mutbl| {
tcx.lang_items().va_list().map(|did| { tcx.lang_items().va_list().map(|did| {
let region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { let region = ty::Region::new_bound(
var: ty::BoundVar::ZERO, tcx,
kind: ty::BoundRegionKind::Anon, ty::INNERMOST,
}); ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon },
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { );
let env_region = ty::Region::new_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_u32(2), var: ty::BoundVar::from_u32(2),
kind: ty::BoundRegionKind::ClosureEnv, kind: ty::BoundRegionKind::ClosureEnv,
}); },
);
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]); let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty) (Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
}) })

View file

@ -675,10 +675,10 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Same for the region. In our example, 'a corresponds // Same for the region. In our example, 'a corresponds
// to the 'me parameter. // to the 'me parameter.
let region_param = gat_generics.param_at(*region_a_idx, tcx); let region_param = gat_generics.param_at(*region_a_idx, tcx);
let region_param = ty::Region::new_early_param(tcx, ty::EarlyParamRegion { let region_param = ty::Region::new_early_param(
index: region_param.index, tcx,
name: region_param.name, ty::EarlyParamRegion { index: region_param.index, name: region_param.name },
}); );
// The predicate we expect to see. (In our example, // The predicate we expect to see. (In our example,
// `Self: 'me`.) // `Self: 'me`.)
bounds.insert( bounds.insert(
@ -704,16 +704,16 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
debug!("required clause: {region_a} must outlive {region_b}"); debug!("required clause: {region_a} must outlive {region_b}");
// Translate into the generic parameters of the GAT. // Translate into the generic parameters of the GAT.
let region_a_param = gat_generics.param_at(*region_a_idx, tcx); let region_a_param = gat_generics.param_at(*region_a_idx, tcx);
let region_a_param = ty::Region::new_early_param(tcx, ty::EarlyParamRegion { let region_a_param = ty::Region::new_early_param(
index: region_a_param.index, tcx,
name: region_a_param.name, ty::EarlyParamRegion { index: region_a_param.index, name: region_a_param.name },
}); );
// Same for the region. // Same for the region.
let region_b_param = gat_generics.param_at(*region_b_idx, tcx); let region_b_param = gat_generics.param_at(*region_b_idx, tcx);
let region_b_param = ty::Region::new_early_param(tcx, ty::EarlyParamRegion { let region_b_param = ty::Region::new_early_param(
index: region_b_param.index, tcx,
name: region_b_param.name, ty::EarlyParamRegion { index: region_b_param.index, name: region_b_param.name },
}); );
// The predicate we expect to see. // The predicate we expect to see.
bounds.insert( bounds.insert(
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
@ -1647,10 +1647,15 @@ fn check_fn_or_method<'tcx>(
} }
// If the function has a body, additionally require that the return type is sized. // If the function has a body, additionally require that the return type is sized.
check_sized_if_body(wfcx, def_id, sig.output(), match hir_decl.output { check_sized_if_body(
wfcx,
def_id,
sig.output(),
match hir_decl.output {
hir::FnRetTy::Return(ty) => Some(ty.span), hir::FnRetTy::Return(ty) => Some(ty.span),
hir::FnRetTy::DefaultReturn(_) => None, hir::FnRetTy::DefaultReturn(_) => None,
}); },
);
} }
fn check_sized_if_body<'tcx>( fn check_sized_if_body<'tcx>(

View file

@ -333,10 +333,11 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
tcx, tcx,
cause.clone(), cause.clone(),
param_env, param_env,
ty::TraitRef::new(tcx, dispatch_from_dyn_trait, [ ty::TraitRef::new(
field.ty(tcx, args_a), tcx,
field.ty(tcx, args_b), dispatch_from_dyn_trait,
]), [field.ty(tcx, args_a), field.ty(tcx, args_b)],
),
)); ));
} }
let errors = ocx.select_all_or_error(); let errors = ocx.select_all_or_error();

View file

@ -251,10 +251,13 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
for ident in &idents_to_add { for ident in &idents_to_add {
connected_region_ids.insert(*ident, id_to_set); connected_region_ids.insert(*ident, id_to_set);
} }
connected_regions.insert(id_to_set, ConnectedRegion { connected_regions.insert(
id_to_set,
ConnectedRegion {
idents: idents_to_add, idents: idents_to_add,
impl_blocks: std::iter::once(i).collect(), impl_blocks: std::iter::once(i).collect(),
}); },
);
} }
// Take the only id inside the list // Take the only id inside the list
&[id_to_set] => { &[id_to_set] => {

View file

@ -242,10 +242,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MapAndCompressBoundVars<'tcx> {
// Allocate a new var idx, and insert a new bound ty. // Allocate a new var idx, and insert a new bound ty.
let var = ty::BoundVar::from_usize(self.still_bound_vars.len()); let var = ty::BoundVar::from_usize(self.still_bound_vars.len());
self.still_bound_vars.push(ty::BoundVariableKind::Ty(old_bound.kind)); self.still_bound_vars.push(ty::BoundVariableKind::Ty(old_bound.kind));
let mapped = Ty::new_bound(self.tcx, ty::INNERMOST, ty::BoundTy { let mapped = Ty::new_bound(
var, self.tcx,
kind: old_bound.kind, ty::INNERMOST,
}); ty::BoundTy { var, kind: old_bound.kind },
);
self.mapping.insert(old_bound.var, mapped.into()); self.mapping.insert(old_bound.var, mapped.into());
mapped mapped
}; };
@ -265,10 +266,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MapAndCompressBoundVars<'tcx> {
} else { } else {
let var = ty::BoundVar::from_usize(self.still_bound_vars.len()); let var = ty::BoundVar::from_usize(self.still_bound_vars.len());
self.still_bound_vars.push(ty::BoundVariableKind::Region(old_bound.kind)); self.still_bound_vars.push(ty::BoundVariableKind::Region(old_bound.kind));
let mapped = ty::Region::new_bound(self.tcx, ty::INNERMOST, ty::BoundRegion { let mapped = ty::Region::new_bound(
var, self.tcx,
kind: old_bound.kind, ty::INNERMOST,
}); ty::BoundRegion { var, kind: old_bound.kind },
);
self.mapping.insert(old_bound.var, mapped.into()); self.mapping.insert(old_bound.var, mapped.into());
mapped mapped
}; };

View file

@ -350,10 +350,10 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
for param in opaque_own_params { for param in opaque_own_params {
let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local()); let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
if let ty::ReEarlyParam(..) = *orig_lifetime { if let ty::ReEarlyParam(..) = *orig_lifetime {
let dup_lifetime = ty::Region::new_early_param(tcx, ty::EarlyParamRegion { let dup_lifetime = ty::Region::new_early_param(
index: param.index, tcx,
name: param.name, ty::EarlyParamRegion { index: param.index, name: param.name },
}); );
let span = tcx.def_span(param.def_id); let span = tcx.def_span(param.def_id);
predicates.push(( predicates.push((
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime)) ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime))

View file

@ -1143,7 +1143,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
.params .params
.iter() .iter()
.map(|param| { .map(|param| {
(param.def_id, match param.kind { (
param.def_id,
match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
if self.tcx.is_late_bound(param.hir_id) { if self.tcx.is_late_bound(param.hir_id) {
let late_bound_idx = named_late_bound_vars; let late_bound_idx = named_late_bound_vars;
@ -1156,7 +1158,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
ResolvedArg::early(param) ResolvedArg::early(param)
} }
}) },
)
}) })
.collect(); .collect();

View file

@ -41,10 +41,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamIndexRemapper<'tcx> {
if let ty::ReEarlyParam(param) = r.kind() if let ty::ReEarlyParam(param) = r.kind()
&& let Some(index) = self.remap_table.get(&param.index).copied() && let Some(index) = self.remap_table.get(&param.index).copied()
{ {
return ty::Region::new_early_param(self.tcx, ty::EarlyParamRegion { return ty::Region::new_early_param(
index, self.tcx,
name: param.name, ty::EarlyParamRegion { index, name: param.name },
}); );
} }
r r
} }

View file

@ -640,13 +640,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let mut num_bound_vars = candidate.bound_vars().len(); let mut num_bound_vars = candidate.bound_vars().len();
let args = candidate.skip_binder().args.extend_to(tcx, item_def_id, |param, _| { let args = candidate.skip_binder().args.extend_to(tcx, item_def_id, |param, _| {
let arg = match param.kind { let arg = match param.kind {
ty::GenericParamDefKind::Lifetime => { ty::GenericParamDefKind::Lifetime => ty::Region::new_bound(
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { tcx,
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(num_bound_vars), var: ty::BoundVar::from_usize(num_bound_vars),
kind: ty::BoundRegionKind::Named(param.def_id, param.name), kind: ty::BoundRegionKind::Named(param.def_id, param.name),
}) },
.into() )
} .into(),
ty::GenericParamDefKind::Type { .. } => { ty::GenericParamDefKind::Type { .. } => {
let guar = *emitted_bad_param_err.get_or_insert_with(|| { let guar = *emitted_bad_param_err.get_or_insert_with(|| {
self.dcx().emit_err(crate::errors::ReturnTypeNotationIllegalParam::Type { self.dcx().emit_err(crate::errors::ReturnTypeNotationIllegalParam::Type {

View file

@ -107,11 +107,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let mut needed_associated_types = FxIndexSet::default(); let mut needed_associated_types = FxIndexSet::default();
if let Some((principal_trait, spans)) = &principal_trait { if let Some((principal_trait, spans)) = &principal_trait {
let pred: ty::Predicate<'tcx> = (*principal_trait).upcast(tcx); let pred: ty::Predicate<'tcx> = (*principal_trait).upcast(tcx);
for ClauseWithSupertraitSpan { pred, supertrait_span } in for ClauseWithSupertraitSpan { pred, supertrait_span } in traits::elaborate(
traits::elaborate(tcx, [ClauseWithSupertraitSpan::new( tcx,
pred, [ClauseWithSupertraitSpan::new(pred, *spans.last().unwrap())],
*spans.last().unwrap(), )
)])
.filter_only_self() .filter_only_self()
{ {
debug!("observing object predicate `{pred:?}`"); debug!("observing object predicate `{pred:?}`");

View file

@ -2219,10 +2219,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
match self.try_lower_anon_const_lit(ty, expr) { match self.try_lower_anon_const_lit(ty, expr) {
Some(v) => v, Some(v) => v,
None => ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst { None => ty::Const::new_unevaluated(
tcx,
ty::UnevaluatedConst {
def: anon.def_id.to_def_id(), def: anon.def_id.to_def_id(),
args: ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()), args: ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()),
}), },
),
} }
} }

View file

@ -2226,10 +2226,13 @@ impl<'a> State<'a> {
let generic_params = generic_params let generic_params = generic_params
.iter() .iter()
.filter(|p| { .filter(|p| {
matches!(p, GenericParam { matches!(
p,
GenericParam {
kind: GenericParamKind::Lifetime { kind: LifetimeParamKind::Explicit }, kind: GenericParamKind::Lifetime { kind: LifetimeParamKind::Explicit },
.. ..
}) }
)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -153,13 +153,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
closure_sig, closure_sig,
); );
let adjustments = self.adjust_steps(autoderef); let adjustments = self.adjust_steps(autoderef);
self.record_deferred_call_resolution(def_id, DeferredCallResolution { self.record_deferred_call_resolution(
def_id,
DeferredCallResolution {
call_expr, call_expr,
callee_expr, callee_expr,
closure_ty: adjusted_ty, closure_ty: adjusted_ty,
adjustments, adjustments,
fn_sig: closure_sig, fn_sig: closure_sig,
}); },
);
return Some(CallStep::DeferredClosure(def_id, closure_sig)); return Some(CallStep::DeferredClosure(def_id, closure_sig));
} }
@ -196,13 +199,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
coroutine_closure_sig.abi, coroutine_closure_sig.abi,
); );
let adjustments = self.adjust_steps(autoderef); let adjustments = self.adjust_steps(autoderef);
self.record_deferred_call_resolution(def_id, DeferredCallResolution { self.record_deferred_call_resolution(
def_id,
DeferredCallResolution {
call_expr, call_expr,
callee_expr, callee_expr,
closure_ty: adjusted_ty, closure_ty: adjusted_ty,
adjustments, adjustments,
fn_sig: call_sig, fn_sig: call_sig,
}); },
);
return Some(CallStep::DeferredClosure(def_id, call_sig)); return Some(CallStep::DeferredClosure(def_id, call_sig));
} }

View file

@ -666,11 +666,12 @@ impl<'a, 'tcx> CastCheck<'tcx> {
}; };
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
fcx.tcx.emit_node_span_lint(lint, self.expr.hir_id, self.span, errors::TrivialCast { fcx.tcx.emit_node_span_lint(
numeric, lint,
expr_ty, self.expr.hir_id,
cast_ty, self.span,
}); errors::TrivialCast { numeric, expr_ty, cast_ty },
);
} }
#[instrument(skip(fcx), level = "debug")] #[instrument(skip(fcx), level = "debug")]

View file

@ -186,18 +186,21 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
let panic_info_did = tcx.require_lang_item(hir::LangItem::PanicInfo, Some(span)); let panic_info_did = tcx.require_lang_item(hir::LangItem::PanicInfo, Some(span));
// build type `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !` // build type `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !`
let panic_info_ty = tcx.type_of(panic_info_did).instantiate(tcx, &[ty::GenericArg::from( let panic_info_ty = tcx.type_of(panic_info_did).instantiate(
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { tcx,
var: ty::BoundVar::from_u32(1), &[ty::GenericArg::from(ty::Region::new_bound(
kind: ty::BoundRegionKind::Anon, tcx,
}), ty::INNERMOST,
)]); ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BoundRegionKind::Anon },
))],
);
let panic_info_ref_ty = Ty::new_imm_ref( let panic_info_ref_ty = Ty::new_imm_ref(
tcx, tcx,
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion { ty::Region::new_bound(
var: ty::BoundVar::ZERO, tcx,
kind: ty::BoundRegionKind::Anon, ty::INNERMOST,
}), ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon },
),
panic_info_ty, panic_info_ty,
); );

View file

@ -103,12 +103,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None => self.next_ty_var(expr_span), None => self.next_ty_var(expr_span),
}; };
let closure_args = ty::ClosureArgs::new(tcx, ty::ClosureArgsParts { let closure_args = ty::ClosureArgs::new(
tcx,
ty::ClosureArgsParts {
parent_args, parent_args,
closure_kind_ty, closure_kind_ty,
closure_sig_as_fn_ptr_ty: Ty::new_fn_ptr(tcx, sig), closure_sig_as_fn_ptr_ty: Ty::new_fn_ptr(tcx, sig),
tupled_upvars_ty, tupled_upvars_ty,
}); },
);
(Ty::new_closure(tcx, expr_def_id.to_def_id(), closure_args.args), None) (Ty::new_closure(tcx, expr_def_id.to_def_id(), closure_args.args), None)
} }
@ -177,7 +180,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => tcx.types.unit, _ => tcx.types.unit,
}; };
let coroutine_args = ty::CoroutineArgs::new(tcx, ty::CoroutineArgsParts { let coroutine_args = ty::CoroutineArgs::new(
tcx,
ty::CoroutineArgsParts {
parent_args, parent_args,
kind_ty, kind_ty,
resume_ty, resume_ty,
@ -185,7 +190,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_ty: liberated_sig.output(), return_ty: liberated_sig.output(),
witness: interior, witness: interior,
tupled_upvars_ty, tupled_upvars_ty,
}); },
);
( (
Ty::new_coroutine(tcx, expr_def_id.to_def_id(), coroutine_args.args), Ty::new_coroutine(tcx, expr_def_id.to_def_id(), coroutine_args.args),
@ -216,8 +222,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span); let coroutine_captures_by_ref_ty = self.next_ty_var(expr_span);
let closure_args = let closure_args = ty::CoroutineClosureArgs::new(
ty::CoroutineClosureArgs::new(tcx, ty::CoroutineClosureArgsParts { tcx,
ty::CoroutineClosureArgsParts {
parent_args, parent_args,
closure_kind_ty, closure_kind_ty,
signature_parts_ty: Ty::new_fn_ptr( signature_parts_ty: Ty::new_fn_ptr(
@ -238,7 +245,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tupled_upvars_ty, tupled_upvars_ty,
coroutine_captures_by_ref_ty, coroutine_captures_by_ref_ty,
coroutine_witness_ty: interior, coroutine_witness_ty: interior,
}); },
);
let coroutine_kind_ty = match expected_kind { let coroutine_kind_ty = match expected_kind {
Some(kind) => Ty::from_coroutine_closure_kind(tcx, kind), Some(kind) => Ty::from_coroutine_closure_kind(tcx, kind),

View file

@ -555,18 +555,24 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// the reborrow in coerce_borrowed_ptr will pick it up. // the reborrow in coerce_borrowed_ptr will pick it up.
let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No); let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
Some((Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { Some((
Adjustment { kind: Adjust::Deref(None), target: ty_a },
Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b), target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
})) },
))
} }
(&ty::Ref(_, ty_a, mt_a), &ty::RawPtr(_, mt_b)) => { (&ty::Ref(_, ty_a, mt_a), &ty::RawPtr(_, mt_b)) => {
coerce_mutbls(mt_a, mt_b)?; coerce_mutbls(mt_a, mt_b)?;
Some((Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { Some((
Adjustment { kind: Adjust::Deref(None), target: ty_a },
Adjustment {
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)), kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
target: Ty::new_ptr(self.tcx, ty_a, mt_b), target: Ty::new_ptr(self.tcx, ty_a, mt_b),
})) },
))
} }
_ => None, _ => None,
}; };
@ -1033,10 +1039,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// regionck knows that the region for `a` must be valid here. // regionck knows that the region for `a` must be valid here.
if is_ref { if is_ref {
self.unify_and(a_unsafe, b, |target| { self.unify_and(a_unsafe, b, |target| {
vec![Adjustment { kind: Adjust::Deref(None), target: mt_a.ty }, Adjustment { vec![
kind: Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)), Adjustment { kind: Adjust::Deref(None), target: mt_a.ty },
target, Adjustment { kind: Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)), target },
}] ]
}) })
} else if mt_a.mutbl != mutbl_b { } else if mt_a.mutbl != mutbl_b {
self.unify_and(a_unsafe, b, simple(Adjust::Pointer(PointerCoercion::MutToConstPointer))) self.unify_and(a_unsafe, b, simple(Adjust::Pointer(PointerCoercion::MutToConstPointer)))
@ -1288,10 +1294,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => span_bug!(new.span, "should not try to coerce a {new_ty} to a fn pointer"), _ => span_bug!(new.span, "should not try to coerce a {new_ty} to a fn pointer"),
}; };
for expr in exprs.iter().map(|e| e.as_coercion_site()) { for expr in exprs.iter().map(|e| e.as_coercion_site()) {
self.apply_adjustments(expr, vec![Adjustment { self.apply_adjustments(
kind: prev_adjustment.clone(), expr,
target: fn_ptr, vec![Adjustment { kind: prev_adjustment.clone(), target: fn_ptr }],
}]); );
} }
self.apply_adjustments(new, vec![Adjustment { kind: next_adjustment, target: fn_ptr }]); self.apply_adjustments(new, vec![Adjustment { kind: next_adjustment, target: fn_ptr }]);
return Ok(fn_ptr); return Ok(fn_ptr);

View file

@ -84,10 +84,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let adj_ty = self.next_ty_var(expr.span); let adj_ty = self.next_ty_var(expr.span);
self.apply_adjustments(expr, vec![Adjustment { self.apply_adjustments(
kind: Adjust::NeverToAny, expr,
target: adj_ty, vec![Adjustment { kind: Adjust::NeverToAny, target: adj_ty }],
}]); );
ty = adj_ty; ty = adj_ty;
} }

View file

@ -290,10 +290,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let autoborrow_mut = adj.iter().any(|adj| { let autoborrow_mut = adj.iter().any(|adj| {
matches!(adj, &Adjustment { matches!(
adj,
&Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })), kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
.. ..
}) }
)
}); });
match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) { match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) {
@ -972,11 +975,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut sp = MultiSpan::from_span(path_segment.ident.span); let mut sp = MultiSpan::from_span(path_segment.ident.span);
sp.push_span_label( sp.push_span_label(
path_segment.ident.span, path_segment.ident.span,
format!("this call modifies {} in-place", match rcvr.kind { format!(
ExprKind::Path(QPath::Resolved(None, hir::Path { segments: [segment], .. })) => "this call modifies {} in-place",
format!("`{}`", segment.ident), match rcvr.kind {
ExprKind::Path(QPath::Resolved(
None,
hir::Path { segments: [segment], .. },
)) => format!("`{}`", segment.ident),
_ => "its receiver".to_string(), _ => "its receiver".to_string(),
}), }
),
); );
let modifies_rcvr_note = let modifies_rcvr_note =

View file

@ -1988,17 +1988,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr.kind, expr.kind,
hir::ExprKind::Call( hir::ExprKind::Call(
hir::Expr { hir::Expr {
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, hir::Path { kind: hir::ExprKind::Path(hir::QPath::Resolved(
res: Res::Def(hir::def::DefKind::Ctor(_, _), _), None,
.. hir::Path { res: Res::Def(hir::def::DefKind::Ctor(_, _), _), .. },
},)), )),
.. ..
}, },
.., ..,
) | hir::ExprKind::Path(hir::QPath::Resolved(None, hir::Path { ) | hir::ExprKind::Path(hir::QPath::Resolved(
res: Res::Def(hir::def::DefKind::Ctor(_, _), _), None,
.. hir::Path { res: Res::Def(hir::def::DefKind::Ctor(_, _), _), .. },
},)), )),
); );
let (article, kind, variant, sugg_operator) = let (article, kind, variant, sugg_operator) =

View file

@ -3922,11 +3922,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let all_suggs = candidate_strs.iter().map(|cand| { let all_suggs = candidate_strs.iter().map(|cand| {
let suggestion = format!("{} {cand}", match introducer { let suggestion = format!(
"{} {cand}",
match introducer {
Introducer::Plus => " +", Introducer::Plus => " +",
Introducer::Colon => ":", Introducer::Colon => ":",
Introducer::Nothing => "", Introducer::Nothing => "",
},); },
);
let mut suggs = vec![]; let mut suggs = vec![];

View file

@ -918,13 +918,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let opname = Ident::with_dummy_span(opname); let opname = Ident::with_dummy_span(opname);
let (opt_rhs_expr, opt_rhs_ty) = opt_rhs.unzip(); let (opt_rhs_expr, opt_rhs_ty) = opt_rhs.unzip();
let cause = self.cause(span, ObligationCauseCode::BinOp { let cause = self.cause(
span,
ObligationCauseCode::BinOp {
lhs_hir_id: lhs_expr.hir_id, lhs_hir_id: lhs_expr.hir_id,
rhs_hir_id: opt_rhs_expr.map(|expr| expr.hir_id), rhs_hir_id: opt_rhs_expr.map(|expr| expr.hir_id),
rhs_span: opt_rhs_expr.map(|expr| expr.span), rhs_span: opt_rhs_expr.map(|expr| expr.span),
rhs_is_lit: opt_rhs_expr.is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Lit(_))), rhs_is_lit: opt_rhs_expr
.is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Lit(_))),
output_ty: expected.only_has_type(self), output_ty: expected.only_has_type(self),
}); },
);
let method = let method =
self.lookup_method_in_trait(cause.clone(), opname, trait_did, lhs_ty, opt_rhs_ty); self.lookup_method_in_trait(cause.clone(), opname, trait_did, lhs_ty, opt_rhs_ty);

View file

@ -30,10 +30,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ok = self.try_overloaded_deref(expr.span, oprnd_ty)?; let ok = self.try_overloaded_deref(expr.span, oprnd_ty)?;
let method = self.register_infer_ok_obligations(ok); let method = self.register_infer_ok_obligations(ok);
if let ty::Ref(_, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { if let ty::Ref(_, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
self.apply_adjustments(oprnd_expr, vec![Adjustment { self.apply_adjustments(
oprnd_expr,
vec![Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)), kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Not)),
target: method.sig.inputs()[0], target: method.sig.inputs()[0],
}]); }],
);
} else { } else {
span_bug!(expr.span, "input to deref is not a ref?"); span_bug!(expr.span, "input to deref is not a ref?");
} }

View file

@ -288,11 +288,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bug!(); bug!();
}; };
let place = self.place_for_root_variable(closure_def_id, local_id); let place = self.place_for_root_variable(closure_def_id, local_id);
delegate.capture_information.push((place, ty::CaptureInfo { delegate.capture_information.push((
place,
ty::CaptureInfo {
capture_kind_expr_id: Some(init.hir_id), capture_kind_expr_id: Some(init.hir_id),
path_expr_id: Some(init.hir_id), path_expr_id: Some(init.hir_id),
capture_kind: UpvarCapture::ByValue, capture_kind: UpvarCapture::ByValue,
})); },
));
} }
} }
@ -379,11 +382,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let UpvarArgs::CoroutineClosure(args) = args if let UpvarArgs::CoroutineClosure(args) = args
&& !args.references_error() && !args.references_error()
{ {
let closure_env_region: ty::Region<'_> = let closure_env_region: ty::Region<'_> = ty::Region::new_bound(
ty::Region::new_bound(self.tcx, ty::INNERMOST, ty::BoundRegion { self.tcx,
var: ty::BoundVar::ZERO, ty::INNERMOST,
kind: ty::BoundRegionKind::ClosureEnv, ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::ClosureEnv },
}); );
let num_args = args let num_args = args
.as_coroutine_closure() .as_coroutine_closure()
@ -2009,11 +2012,14 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return }; let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
assert_eq!(self.closure_def_id, upvar_id.closure_expr_id); assert_eq!(self.closure_def_id, upvar_id.closure_expr_id);
self.capture_information.push((place_with_id.place.clone(), ty::CaptureInfo { self.capture_information.push((
place_with_id.place.clone(),
ty::CaptureInfo {
capture_kind_expr_id: Some(diag_expr_id), capture_kind_expr_id: Some(diag_expr_id),
path_expr_id: Some(diag_expr_id), path_expr_id: Some(diag_expr_id),
capture_kind: ty::UpvarCapture::ByValue, capture_kind: ty::UpvarCapture::ByValue,
})); },
));
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
@ -2040,11 +2046,14 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
capture_kind = ty::UpvarCapture::ByRef(ty::BorrowKind::Immutable); capture_kind = ty::UpvarCapture::ByRef(ty::BorrowKind::Immutable);
} }
self.capture_information.push((place, ty::CaptureInfo { self.capture_information.push((
place,
ty::CaptureInfo {
capture_kind_expr_id: Some(diag_expr_id), capture_kind_expr_id: Some(diag_expr_id),
path_expr_id: Some(diag_expr_id), path_expr_id: Some(diag_expr_id),
capture_kind, capture_kind,
})); },
));
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]

View file

@ -107,11 +107,10 @@ const LABELS_FN_IN_TRAIT: &[&[&str]] =
const LABELS_HIR_ONLY: &[&[&str]] = &[BASE_HIR]; const LABELS_HIR_ONLY: &[&[&str]] = &[BASE_HIR];
/// Impl `DepNode`s. /// Impl `DepNode`s.
const LABELS_TRAIT: &[&[&str]] = &[BASE_HIR, &[ const LABELS_TRAIT: &[&[&str]] = &[
label_strs::associated_item_def_ids, BASE_HIR,
label_strs::predicates_of, &[label_strs::associated_item_def_ids, label_strs::predicates_of, label_strs::generics_of],
label_strs::generics_of, ];
]];
/// Impl `DepNode`s. /// Impl `DepNode`s.
const LABELS_IMPL: &[&[&str]] = &[BASE_HIR, BASE_IMPL]; const LABELS_IMPL: &[&[&str]] = &[BASE_HIR, BASE_IMPL];

View file

@ -118,11 +118,10 @@ fn chunked_bitset() {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
let mut b1 = ChunkedBitSet::<usize>::new_empty(1); let mut b1 = ChunkedBitSet::<usize>::new_empty(1);
assert_eq!(b1, ChunkedBitSet { assert_eq!(
domain_size: 1, b1,
chunks: Box::new([Zeros(1)]), ChunkedBitSet { domain_size: 1, chunks: Box::new([Zeros(1)]), marker: PhantomData }
marker: PhantomData );
});
b1.assert_valid(); b1.assert_valid();
assert!(!b1.contains(0)); assert!(!b1.contains(0));
@ -141,11 +140,10 @@ fn chunked_bitset() {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
let mut b100 = ChunkedBitSet::<usize>::new_filled(100); let mut b100 = ChunkedBitSet::<usize>::new_filled(100);
assert_eq!(b100, ChunkedBitSet { assert_eq!(
domain_size: 100, b100,
chunks: Box::new([Ones(100)]), ChunkedBitSet { domain_size: 100, chunks: Box::new([Ones(100)]), marker: PhantomData }
marker: PhantomData );
});
b100.assert_valid(); b100.assert_valid();
for i in 0..100 { for i in 0..100 {
@ -160,7 +158,9 @@ fn chunked_bitset() {
); );
assert_eq!(b100.count(), 97); assert_eq!(b100.count(), 97);
assert!(!b100.contains(20) && b100.contains(30) && !b100.contains(99) && b100.contains(50)); assert!(!b100.contains(20) && b100.contains(30) && !b100.contains(99) && b100.contains(50));
assert_eq!(b100.chunks(), vec![Mixed( assert_eq!(
b100.chunks(),
vec![Mixed(
100, 100,
97, 97,
#[rustfmt::skip] #[rustfmt::skip]
@ -170,7 +170,8 @@ fn chunked_bitset() {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]) ])
)],); )],
);
b100.assert_valid(); b100.assert_valid();
let mut num_removed = 0; let mut num_removed = 0;
for i in 0..100 { for i in 0..100 {
@ -185,11 +186,14 @@ fn chunked_bitset() {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
let mut b2548 = ChunkedBitSet::<usize>::new_empty(2548); let mut b2548 = ChunkedBitSet::<usize>::new_empty(2548);
assert_eq!(b2548, ChunkedBitSet { assert_eq!(
b2548,
ChunkedBitSet {
domain_size: 2548, domain_size: 2548,
chunks: Box::new([Zeros(2048), Zeros(500)]), chunks: Box::new([Zeros(2048), Zeros(500)]),
marker: PhantomData, marker: PhantomData,
}); }
);
b2548.assert_valid(); b2548.assert_valid();
b2548.insert(14); b2548.insert(14);
@ -206,11 +210,14 @@ fn chunked_bitset() {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
let mut b4096 = ChunkedBitSet::<usize>::new_empty(4096); let mut b4096 = ChunkedBitSet::<usize>::new_empty(4096);
assert_eq!(b4096, ChunkedBitSet { assert_eq!(
b4096,
ChunkedBitSet {
domain_size: 4096, domain_size: 4096,
chunks: Box::new([Zeros(2048), Zeros(2048)]), chunks: Box::new([Zeros(2048), Zeros(2048)]),
marker: PhantomData, marker: PhantomData,
}); }
);
b4096.assert_valid(); b4096.assert_valid();
for i in 0..4096 { for i in 0..4096 {
@ -240,11 +247,14 @@ fn chunked_bitset() {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
let mut b10000 = ChunkedBitSet::<usize>::new_empty(10000); let mut b10000 = ChunkedBitSet::<usize>::new_empty(10000);
assert_eq!(b10000, ChunkedBitSet { assert_eq!(
b10000,
ChunkedBitSet {
domain_size: 10000, domain_size: 10000,
chunks: Box::new([Zeros(2048), Zeros(2048), Zeros(2048), Zeros(2048), Zeros(1808),]), chunks: Box::new([Zeros(2048), Zeros(2048), Zeros(2048), Zeros(2048), Zeros(1808),]),
marker: PhantomData, marker: PhantomData,
}); }
);
b10000.assert_valid(); b10000.assert_valid();
assert!(b10000.insert(3000) && b10000.insert(5000)); assert!(b10000.insert(3000) && b10000.insert(5000));

View file

@ -29,21 +29,19 @@ fn index_size_is_optimized() {
#[test] #[test]
fn range_iterator_iterates_forwards() { fn range_iterator_iterates_forwards() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4); let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(range.collect::<Vec<_>>(), [ assert_eq!(
MyIdx::from_u32(1), range.collect::<Vec<_>>(),
MyIdx::from_u32(2), [MyIdx::from_u32(1), MyIdx::from_u32(2), MyIdx::from_u32(3)]
MyIdx::from_u32(3) );
]);
} }
#[test] #[test]
fn range_iterator_iterates_backwards() { fn range_iterator_iterates_backwards() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4); let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(range.rev().collect::<Vec<_>>(), [ assert_eq!(
MyIdx::from_u32(3), range.rev().collect::<Vec<_>>(),
MyIdx::from_u32(2), [MyIdx::from_u32(3), MyIdx::from_u32(2), MyIdx::from_u32(1)]
MyIdx::from_u32(1) );
]);
} }
#[test] #[test]

View file

@ -100,7 +100,10 @@ impl<'tcx> InferCtxt<'tcx> {
) { ) {
debug!(?sup_type, ?sub_region, ?cause); debug!(?sup_type, ?sub_region, ?cause);
let origin = SubregionOrigin::from_obligation_cause(cause, || { let origin = SubregionOrigin::from_obligation_cause(cause, || {
infer::RelateParamBound(cause.span, sup_type, match cause.code().peel_derives() { infer::RelateParamBound(
cause.span,
sup_type,
match cause.code().peel_derives() {
ObligationCauseCode::WhereClause(_, span) ObligationCauseCode::WhereClause(_, span)
| ObligationCauseCode::WhereClauseInExpr(_, span, ..) | ObligationCauseCode::WhereClauseInExpr(_, span, ..)
| ObligationCauseCode::OpaqueTypeBound(span, _) | ObligationCauseCode::OpaqueTypeBound(span, _)
@ -109,7 +112,8 @@ impl<'tcx> InferCtxt<'tcx> {
Some(*span) Some(*span)
} }
_ => None, _ => None,
}) },
)
}); });
self.register_region_obligation(RegionObligation { sup_type, sub_region, origin }); self.register_region_obligation(RegionObligation { sup_type, sub_region, origin });

View file

@ -34,22 +34,22 @@ impl<'tcx> InferCtxt<'tcx> {
let delegate = FnMutDelegate { let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| { regions: &mut |br: ty::BoundRegion| {
ty::Region::new_placeholder(self.tcx, ty::PlaceholderRegion { ty::Region::new_placeholder(
universe: next_universe, self.tcx,
bound: br, ty::PlaceholderRegion { universe: next_universe, bound: br },
}) )
}, },
types: &mut |bound_ty: ty::BoundTy| { types: &mut |bound_ty: ty::BoundTy| {
Ty::new_placeholder(self.tcx, ty::PlaceholderType { Ty::new_placeholder(
universe: next_universe, self.tcx,
bound: bound_ty, ty::PlaceholderType { universe: next_universe, bound: bound_ty },
}) )
}, },
consts: &mut |bound_var: ty::BoundVar| { consts: &mut |bound_var: ty::BoundVar| {
ty::Const::new_placeholder(self.tcx, ty::PlaceholderConst { ty::Const::new_placeholder(
universe: next_universe, self.tcx,
bound: bound_var, ty::PlaceholderConst { universe: next_universe, bound: bound_var },
}) )
}, },
}; };

View file

@ -45,12 +45,15 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
) { ) {
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]); let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
self.register_predicate_obligation(infcx, Obligation { self.register_predicate_obligation(
infcx,
Obligation {
cause, cause,
recursion_depth: 0, recursion_depth: 0,
param_env, param_env,
predicate: trait_ref.upcast(infcx.tcx), predicate: trait_ref.upcast(infcx.tcx),
}); },
);
} }
fn register_predicate_obligation( fn register_predicate_obligation(

View file

@ -193,10 +193,10 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
if result.must_apply_considering_regions() { if result.must_apply_considering_regions() {
ty.obligations = PredicateObligations::new(); ty.obligations = PredicateObligations::new();
} }
map.insert(key, ProjectionCacheEntry::NormalizedTerm { map.insert(
ty, key,
complete: Some(result), ProjectionCacheEntry::NormalizedTerm { ty, complete: Some(result) },
}); );
} }
ref value => { ref value => {
// Type inference could "strand behind" old cache entries. Leave // Type inference could "strand behind" old cache entries. Leave

View file

@ -770,11 +770,14 @@ fn test_unstable_options_tracking_hash() {
}) })
); );
tracked!(codegen_backend, Some("abc".to_string())); tracked!(codegen_backend, Some("abc".to_string()));
tracked!(coverage_options, CoverageOptions { tracked!(
coverage_options,
CoverageOptions {
level: CoverageLevel::Mcdc, level: CoverageLevel::Mcdc,
no_mir_spans: true, no_mir_spans: true,
discard_all_spans_in_codegen: true discard_all_spans_in_codegen: true
}); }
);
tracked!(crate_attr, vec!["abc".to_string()]); tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(cross_crate_inline_threshold, InliningThreshold::Always); tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
tracked!(debug_info_for_profiling, true); tracked!(debug_info_for_profiling, true);

View file

@ -131,7 +131,9 @@ fn check_lexing(src: &str, expect: Expect) {
#[test] #[test]
fn smoke_test() { fn smoke_test() {
check_lexing("/* my source file */ fn main() { println!(\"zebra\"); }\n", expect![[r#" check_lexing(
"/* my source file */ fn main() { println!(\"zebra\"); }\n",
expect![[r#"
Token { kind: BlockComment { doc_style: None, terminated: true }, len: 20 } Token { kind: BlockComment { doc_style: None, terminated: true }, len: 20 }
Token { kind: Whitespace, len: 1 } Token { kind: Whitespace, len: 1 }
Token { kind: Ident, len: 2 } Token { kind: Ident, len: 2 }
@ -151,7 +153,8 @@ fn smoke_test() {
Token { kind: Whitespace, len: 1 } Token { kind: Whitespace, len: 1 }
Token { kind: CloseBrace, len: 1 } Token { kind: CloseBrace, len: 1 }
Token { kind: Whitespace, len: 1 } Token { kind: Whitespace, len: 1 }
"#]]) "#]],
)
} }
#[test] #[test]
@ -194,35 +197,47 @@ fn comment_flavors() {
#[test] #[test]
fn nested_block_comments() { fn nested_block_comments() {
check_lexing("/* /* */ */'a'", expect![[r#" check_lexing(
"/* /* */ */'a'",
expect![[r#"
Token { kind: BlockComment { doc_style: None, terminated: true }, len: 11 } Token { kind: BlockComment { doc_style: None, terminated: true }, len: 11 }
Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 } Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 }
"#]]) "#]],
)
} }
#[test] #[test]
fn characters() { fn characters() {
check_lexing("'a' ' ' '\\n'", expect![[r#" check_lexing(
"'a' ' ' '\\n'",
expect![[r#"
Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 } Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 }
Token { kind: Whitespace, len: 1 } Token { kind: Whitespace, len: 1 }
Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 } Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 3 }, len: 3 }
Token { kind: Whitespace, len: 1 } Token { kind: Whitespace, len: 1 }
Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 4 }, len: 4 } Token { kind: Literal { kind: Char { terminated: true }, suffix_start: 4 }, len: 4 }
"#]]); "#]],
);
} }
#[test] #[test]
fn lifetime() { fn lifetime() {
check_lexing("'abc", expect![[r#" check_lexing(
"'abc",
expect![[r#"
Token { kind: Lifetime { starts_with_number: false }, len: 4 } Token { kind: Lifetime { starts_with_number: false }, len: 4 }
"#]]); "#]],
);
} }
#[test] #[test]
fn raw_string() { fn raw_string() {
check_lexing("r###\"\"#a\\b\x00c\"\"###", expect![[r#" check_lexing(
"r###\"\"#a\\b\x00c\"\"###",
expect![[r#"
Token { kind: Literal { kind: RawStr { n_hashes: Some(3) }, suffix_start: 17 }, len: 17 } Token { kind: Literal { kind: RawStr { n_hashes: Some(3) }, suffix_start: 17 }, len: 17 }
"#]]) "#]],
)
} }
#[test] #[test]

View file

@ -108,12 +108,15 @@ fn test_unescape_str_warn() {
check("\\\n", &[]); check("\\\n", &[]);
check("\\\n ", &[]); check("\\\n ", &[]);
check("\\\n \u{a0} x", &[ check(
"\\\n \u{a0} x",
&[
(0..5, Err(EscapeError::UnskippedWhitespaceWarning)), (0..5, Err(EscapeError::UnskippedWhitespaceWarning)),
(3..5, Ok('\u{a0}')), (3..5, Ok('\u{a0}')),
(5..6, Ok(' ')), (5..6, Ok(' ')),
(6..7, Ok('x')), (6..7, Ok('x')),
]); ],
);
check("\\\n \n x", &[(0..7, Err(EscapeError::MultipleSkippedLinesWarning)), (7..8, Ok('x'))]); check("\\\n \n x", &[(0..7, Err(EscapeError::MultipleSkippedLinesWarning)), (7..8, Ok('x'))]);
} }

View file

@ -102,10 +102,11 @@ impl EarlyLintPass for WhileTrue {
"{}loop", "{}loop",
label.map_or_else(String::new, |label| format!("{}: ", label.ident,)) label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
); );
cx.emit_span_lint(WHILE_TRUE, condition_span, BuiltinWhileTrue { cx.emit_span_lint(
suggestion: condition_span, WHILE_TRUE,
replace, condition_span,
}); BuiltinWhileTrue { suggestion: condition_span, replace },
);
} }
} }
} }
@ -421,10 +422,11 @@ impl MissingDoc {
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id)); let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc); let has_doc = attrs.iter().any(has_doc);
if !has_doc { if !has_doc {
cx.emit_span_lint(MISSING_DOCS, cx.tcx.def_span(def_id), BuiltinMissingDoc { cx.emit_span_lint(
article, MISSING_DOCS,
desc, cx.tcx.def_span(def_id),
}); BuiltinMissingDoc { article, desc },
);
} }
} }
} }
@ -706,10 +708,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
.next() .next()
.is_some(); .is_some();
if !has_impl { if !has_impl {
cx.emit_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, BuiltinMissingDebugImpl { cx.emit_span_lint(
tcx: cx.tcx, MISSING_DEBUG_IMPLEMENTATIONS,
def_id: debug, item.span,
}); BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
);
} }
} }
} }
@ -831,12 +834,11 @@ impl EarlyLintPass for DeprecatedAttr {
BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span } BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span }
} }
}; };
cx.emit_span_lint(DEPRECATED, attr.span, BuiltinDeprecatedAttrLink { cx.emit_span_lint(
name, DEPRECATED,
reason, attr.span,
link, BuiltinDeprecatedAttrLink { name, reason, link, suggestion },
suggestion, );
});
} }
return; return;
} }
@ -874,11 +876,11 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
BuiltinUnusedDocCommentSub::BlockHelp BuiltinUnusedDocCommentSub::BlockHelp
} }
}; };
cx.emit_span_lint(UNUSED_DOC_COMMENTS, span, BuiltinUnusedDocComment { cx.emit_span_lint(
kind: node_kind, UNUSED_DOC_COMMENTS,
label: node_span, span,
sub, BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
}); );
} }
} }
} }
@ -1008,9 +1010,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
match param.kind { match param.kind {
GenericParamKind::Lifetime { .. } => {} GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
cx.emit_span_lint(NO_MANGLE_GENERIC_ITEMS, span, BuiltinNoMangleGeneric { cx.emit_span_lint(
suggestion: no_mangle_attr.span, NO_MANGLE_GENERIC_ITEMS,
}); span,
BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span },
);
break; break;
} }
} }
@ -1037,9 +1041,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
// Const items do not refer to a particular location in memory, and therefore // Const items do not refer to a particular location in memory, and therefore
// don't have anything to attach a symbol to // don't have anything to attach a symbol to
cx.emit_span_lint(NO_MANGLE_CONST_ITEMS, it.span, BuiltinConstNoMangle { cx.emit_span_lint(
suggestion, NO_MANGLE_CONST_ITEMS,
}); it.span,
BuiltinConstNoMangle { suggestion },
);
} }
} }
hir::ItemKind::Impl(hir::Impl { generics, items, .. }) => { hir::ItemKind::Impl(hir::Impl { generics, items, .. }) => {
@ -1305,12 +1311,16 @@ impl UnreachablePub {
applicability = Applicability::MaybeIncorrect; applicability = Applicability::MaybeIncorrect;
} }
let def_span = cx.tcx.def_span(def_id); let def_span = cx.tcx.def_span(def_id);
cx.emit_span_lint(UNREACHABLE_PUB, def_span, BuiltinUnreachablePub { cx.emit_span_lint(
UNREACHABLE_PUB,
def_span,
BuiltinUnreachablePub {
what, what,
new_vis, new_vis,
suggestion: (vis_span, applicability), suggestion: (vis_span, applicability),
help: exportable, help: exportable,
}); },
);
} }
} }
} }
@ -1454,24 +1464,32 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
let enable_feat_help = cx.tcx.sess.is_nightly_build(); let enable_feat_help = cx.tcx.sess.is_nightly_build();
if let [.., label_sp] = *where_spans { if let [.., label_sp] = *where_spans {
cx.emit_span_lint(TYPE_ALIAS_BOUNDS, where_spans, BuiltinTypeAliasBounds { cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
where_spans,
BuiltinTypeAliasBounds {
in_where_clause: true, in_where_clause: true,
label: label_sp, label: label_sp,
enable_feat_help, enable_feat_help,
suggestions: vec![(generics.where_clause_span, String::new())], suggestions: vec![(generics.where_clause_span, String::new())],
preds: generics.predicates, preds: generics.predicates,
ty: ty.take(), ty: ty.take(),
}); },
);
} }
if let [.., label_sp] = *inline_spans { if let [.., label_sp] = *inline_spans {
cx.emit_span_lint(TYPE_ALIAS_BOUNDS, inline_spans, BuiltinTypeAliasBounds { cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
inline_spans,
BuiltinTypeAliasBounds {
in_where_clause: false, in_where_clause: false,
label: label_sp, label: label_sp,
enable_feat_help, enable_feat_help,
suggestions: inline_sugg, suggestions: inline_sugg,
preds: generics.predicates, preds: generics.predicates,
ty, ty,
}); },
);
} }
} }
} }
@ -1559,10 +1577,11 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
| ty::ClauseKind::HostEffect(..) => continue, | ty::ClauseKind::HostEffect(..) => continue,
}; };
if predicate.is_global() { if predicate.is_global() {
cx.emit_span_lint(TRIVIAL_BOUNDS, span, BuiltinTrivialBounds { cx.emit_span_lint(
predicate_kind_name, TRIVIAL_BOUNDS,
predicate, span,
}); BuiltinTrivialBounds { predicate_kind_name, predicate },
);
} }
} }
} }
@ -1611,12 +1630,16 @@ impl EarlyLintPass for DoubleNegations {
&& let ExprKind::Unary(UnOp::Neg, ref inner2) = inner.kind && let ExprKind::Unary(UnOp::Neg, ref inner2) = inner.kind
&& !matches!(inner2.kind, ExprKind::Unary(UnOp::Neg, _)) && !matches!(inner2.kind, ExprKind::Unary(UnOp::Neg, _))
{ {
cx.emit_span_lint(DOUBLE_NEGATIONS, expr.span, BuiltinDoubleNegations { cx.emit_span_lint(
DOUBLE_NEGATIONS,
expr.span,
BuiltinDoubleNegations {
add_parens: BuiltinDoubleNegationsAddParens { add_parens: BuiltinDoubleNegationsAddParens {
start_span: inner.span.shrink_to_lo(), start_span: inner.span.shrink_to_lo(),
end_span: inner.span.shrink_to_hi(), end_span: inner.span.shrink_to_hi(),
}, },
}); },
);
} }
} }
} }
@ -1931,12 +1954,11 @@ impl KeywordIdents {
return; return;
} }
cx.emit_span_lint(lint, ident.span, BuiltinKeywordIdents { cx.emit_span_lint(
kw: ident, lint,
next: edition, ident.span,
suggestion: ident.span, BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix },
prefix, );
});
} }
} }
@ -2357,11 +2379,11 @@ impl EarlyLintPass for IncompleteInternalFeatures {
let help = let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp); HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_span_lint(INCOMPLETE_FEATURES, span, BuiltinIncompleteFeatures { cx.emit_span_lint(
name, INCOMPLETE_FEATURES,
note, span,
help, BuiltinIncompleteFeatures { name, note, help },
}); );
} else { } else {
cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name }); cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name });
} }
@ -2684,13 +2706,17 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit, InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit,
}; };
let sub = BuiltinUnpermittedTypeInitSub { err }; let sub = BuiltinUnpermittedTypeInitSub { err };
cx.emit_span_lint(INVALID_VALUE, expr.span, BuiltinUnpermittedTypeInit { cx.emit_span_lint(
INVALID_VALUE,
expr.span,
BuiltinUnpermittedTypeInit {
msg, msg,
ty: conjured_ty, ty: conjured_ty,
label: expr.span, label: expr.span,
sub, sub,
tcx: cx.tcx, tcx: cx.tcx,
}); },
);
} }
} }
} }
@ -2776,9 +2802,11 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
{ {
// `&raw *NULL` is ok. // `&raw *NULL` is ok.
} else { } else {
cx.emit_span_lint(DEREF_NULLPTR, expr.span, BuiltinDerefNullptr { cx.emit_span_lint(
label: expr.span, DEREF_NULLPTR,
}); expr.span,
BuiltinDerefNullptr { label: expr.span },
);
} }
} }
} }
@ -2995,14 +3023,18 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
let span = span.unwrap_or(*template_span); let span = span.unwrap_or(*template_span);
match label_kind { match label_kind {
AsmLabelKind::Named => { AsmLabelKind::Named => {
cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::Named { cx.emit_span_lint(
missing_precise_span, NAMED_ASM_LABELS,
}); span,
InvalidAsmLabel::Named { missing_precise_span },
);
} }
AsmLabelKind::FormatArg => { AsmLabelKind::FormatArg => {
cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::FormatArg { cx.emit_span_lint(
missing_precise_span, NAMED_ASM_LABELS,
}); span,
InvalidAsmLabel::FormatArg { missing_precise_span },
);
} }
// the binary asm issue only occurs when using intel syntax on x86 targets // the binary asm issue only occurs when using intel syntax on x86 targets
AsmLabelKind::Binary AsmLabelKind::Binary
@ -3012,10 +3044,11 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
) => ) =>
{ {
cx.emit_span_lint(BINARY_ASM_LABELS, span, InvalidAsmLabel::Binary { cx.emit_span_lint(
missing_precise_span, BINARY_ASM_LABELS,
span, span,
}) InvalidAsmLabel::Binary { missing_precise_span, span },
)
} }
// No lint on anything other than x86 // No lint on anything other than x86
AsmLabelKind::Binary => (), AsmLabelKind::Binary => (),

View file

@ -233,11 +233,14 @@ impl LintStore {
} }
pub fn register_group_alias(&mut self, lint_name: &'static str, alias: &'static str) { pub fn register_group_alias(&mut self, lint_name: &'static str, alias: &'static str) {
self.lint_groups.insert(alias, LintGroup { self.lint_groups.insert(
alias,
LintGroup {
lint_ids: vec![], lint_ids: vec![],
is_externally_loaded: false, is_externally_loaded: false,
depr: Some(LintAlias { name: lint_name, silent: true }), depr: Some(LintAlias { name: lint_name, silent: true }),
}); },
);
} }
pub fn register_group( pub fn register_group(
@ -252,11 +255,14 @@ impl LintStore {
.insert(name, LintGroup { lint_ids: to, is_externally_loaded, depr: None }) .insert(name, LintGroup { lint_ids: to, is_externally_loaded, depr: None })
.is_none(); .is_none();
if let Some(deprecated) = deprecated_name { if let Some(deprecated) = deprecated_name {
self.lint_groups.insert(deprecated, LintGroup { self.lint_groups.insert(
deprecated,
LintGroup {
lint_ids: vec![], lint_ids: vec![],
is_externally_loaded, is_externally_loaded,
depr: Some(LintAlias { name, silent: false }), depr: Some(LintAlias { name, silent: false }),
}); },
);
} }
if !new { if !new {

Some files were not shown because too many files have changed in this diff Show more