Auto merge of #3183 - rust-lang:rustup-2023-11-23, r=RalfJung
Automatic Rustup
This commit is contained in:
commit
933bdbc579
13
Cargo.lock
13
Cargo.lock
@ -2060,9 +2060,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
@ -3471,6 +3471,7 @@ dependencies = [
|
||||
name = "rustc_ast_pretty"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"rustc_ast",
|
||||
"rustc_span",
|
||||
"thin-vec",
|
||||
@ -3523,7 +3524,6 @@ dependencies = [
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_mir_dataflow",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -3934,7 +3934,6 @@ dependencies = [
|
||||
"rustc_lint",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -3997,7 +3996,6 @@ dependencies = [
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"smallvec",
|
||||
@ -4215,7 +4213,6 @@ dependencies = [
|
||||
"rustc_infer",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -4239,7 +4236,6 @@ dependencies = [
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"smallvec",
|
||||
@ -4266,7 +4262,6 @@ dependencies = [
|
||||
"rustc_middle",
|
||||
"rustc_mir_build",
|
||||
"rustc_mir_dataflow",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -4340,7 +4335,6 @@ dependencies = [
|
||||
"rustc_lexer",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -4564,7 +4558,6 @@ dependencies = [
|
||||
"rustc_middle",
|
||||
"rustc_parse_format",
|
||||
"rustc_query_system",
|
||||
"rustc_serialize",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
|
@ -111,8 +111,8 @@ pub trait LayoutCalculator {
|
||||
alt_tail_space,
|
||||
layout.fields.count(),
|
||||
prefer_alt_layout,
|
||||
format_field_niches(&layout, &fields, &dl),
|
||||
format_field_niches(&alt_layout, &fields, &dl),
|
||||
format_field_niches(layout, fields, dl),
|
||||
format_field_niches(&alt_layout, fields, dl),
|
||||
);
|
||||
|
||||
if prefer_alt_layout {
|
||||
@ -1025,7 +1025,7 @@ fn univariant<
|
||||
// At the bottom of this function, we invert `inverse_memory_index` to
|
||||
// produce `memory_index` (see `invert_mapping`).
|
||||
let mut sized = true;
|
||||
let mut offsets = IndexVec::from_elem(Size::ZERO, &fields);
|
||||
let mut offsets = IndexVec::from_elem(Size::ZERO, fields);
|
||||
let mut offset = Size::ZERO;
|
||||
let mut largest_niche = None;
|
||||
let mut largest_niche_available = 0;
|
||||
|
@ -2574,7 +2574,7 @@ pub enum AttrStyle {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[custom_encodable]
|
||||
#[orderable]
|
||||
#[debug_format = "AttrId({})"]
|
||||
pub struct AttrId {}
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ impl MetaItemKind {
|
||||
MetaItemKind::name_value_from_tokens(&mut inner_tokens.trees())
|
||||
}
|
||||
Some(TokenTree::Token(token, _)) => {
|
||||
MetaItemLit::from_token(&token).map(MetaItemKind::NameValue)
|
||||
MetaItemLit::from_token(token).map(MetaItemKind::NameValue)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ rustc_index::newtype_index! {
|
||||
/// This is later turned into [`DefId`] and `HirId` for the HIR.
|
||||
///
|
||||
/// [`DefId`]: rustc_span::def_id::DefId
|
||||
#[encodable]
|
||||
#[orderable]
|
||||
#[debug_format = "NodeId({})"]
|
||||
pub struct NodeId {
|
||||
/// The [`NodeId`] used to represent the root of the crate.
|
||||
|
@ -959,7 +959,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
e
|
||||
});
|
||||
let coroutine_option =
|
||||
this.coroutine_movability_for_fn(&decl, fn_decl_span, coroutine_kind, movability);
|
||||
this.coroutine_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
|
||||
this.current_item = prev;
|
||||
(body_id, coroutine_option)
|
||||
});
|
||||
@ -1057,7 +1057,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let body_id = this.lower_fn_body(&outer_decl, |this| {
|
||||
let async_ret_ty = if let FnRetTy::Ty(ty) = &decl.output {
|
||||
let itctx = ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock);
|
||||
Some(hir::FnRetTy::Return(this.lower_ty(&ty, &itctx)))
|
||||
Some(hir::FnRetTy::Return(this.lower_ty(ty, &itctx)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -1156,7 +1156,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
.alloc_from_iter(std::iter::once(destructure_let).chain(assignments.into_iter()));
|
||||
|
||||
// Wrap everything in a block.
|
||||
hir::ExprKind::Block(&self.block_all(whole_span, stmts, None), None)
|
||||
hir::ExprKind::Block(self.block_all(whole_span, stmts, None), None)
|
||||
}
|
||||
|
||||
/// If the given expression is a path to a tuple struct, returns that path.
|
||||
@ -1413,7 +1413,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let fields = self.arena.alloc_from_iter(
|
||||
e1.iter().map(|e| (sym::start, e)).chain(e2.iter().map(|e| (sym::end, e))).map(
|
||||
|(s, e)| {
|
||||
let expr = self.lower_expr(&e);
|
||||
let expr = self.lower_expr(e);
|
||||
let ident = Ident::new(s, self.lower_span(e.span));
|
||||
self.expr_field(ident, expr, e.span)
|
||||
},
|
||||
|
@ -338,8 +338,8 @@ fn make_format_spec<'hir>(
|
||||
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
|
||||
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
|
||||
let flags = ctx.expr_u32(sp, flags);
|
||||
let precision = make_count(ctx, sp, &precision, argmap);
|
||||
let width = make_count(ctx, sp, &width, argmap);
|
||||
let precision = make_count(ctx, sp, precision, argmap);
|
||||
let width = make_count(ctx, sp, width, argmap);
|
||||
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
|
||||
sp,
|
||||
hir::LangItem::FormatPlaceholder,
|
||||
|
@ -47,7 +47,7 @@ pub(super) fn index_hir<'hir>(
|
||||
|
||||
match item {
|
||||
OwnerNode::Crate(citem) => {
|
||||
collector.visit_mod(&citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
|
||||
collector.visit_mod(citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
|
||||
}
|
||||
OwnerNode::Item(item) => collector.visit_item(item),
|
||||
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
|
||||
|
@ -276,19 +276,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
// only cares about the input argument patterns in the function
|
||||
// declaration (decl), not the return types.
|
||||
let asyncness = header.asyncness;
|
||||
let body_id = this.lower_maybe_async_body(
|
||||
span,
|
||||
hir_id,
|
||||
&decl,
|
||||
asyncness,
|
||||
body.as_deref(),
|
||||
);
|
||||
let body_id =
|
||||
this.lower_maybe_async_body(span, hir_id, decl, asyncness, body.as_deref());
|
||||
|
||||
let itctx = ImplTraitContext::Universal;
|
||||
let (generics, decl) =
|
||||
this.lower_generics(generics, header.constness, id, &itctx, |this| {
|
||||
let ret_id = asyncness.opt_return_id();
|
||||
this.lower_fn_decl(&decl, id, *fn_sig_span, FnDeclKind::Fn, ret_id)
|
||||
this.lower_fn_decl(decl, id, *fn_sig_span, FnDeclKind::Fn, ret_id)
|
||||
});
|
||||
let sig = hir::FnSig {
|
||||
decl,
|
||||
@ -744,7 +739,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let (generics, kind, has_default) = match &i.kind {
|
||||
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => {
|
||||
let (generics, kind) = self.lower_generics(
|
||||
&generics,
|
||||
generics,
|
||||
Const::No,
|
||||
i.id,
|
||||
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||
@ -775,7 +770,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
AssocItemKind::Fn(box Fn { sig, generics, body: Some(body), .. }) => {
|
||||
let asyncness = sig.header.asyncness;
|
||||
let body_id =
|
||||
self.lower_maybe_async_body(i.span, hir_id, &sig.decl, asyncness, Some(&body));
|
||||
self.lower_maybe_async_body(i.span, hir_id, &sig.decl, asyncness, Some(body));
|
||||
let (generics, sig) = self.lower_method_sig(
|
||||
generics,
|
||||
sig,
|
||||
@ -857,7 +852,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
|
||||
let (generics, kind) = match &i.kind {
|
||||
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => self.lower_generics(
|
||||
&generics,
|
||||
generics,
|
||||
Const::No,
|
||||
i.id,
|
||||
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||
|
@ -1157,7 +1157,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
itctx: &ImplTraitContext,
|
||||
) -> hir::GenericArg<'hir> {
|
||||
match arg {
|
||||
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)),
|
||||
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
|
||||
ast::GenericArg::Type(ty) => {
|
||||
match &ty.kind {
|
||||
TyKind::Infer if self.tcx.features().generic_arg_infer => {
|
||||
@ -1221,10 +1221,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
GenericArg::Type(self.lower_ty(&ty, itctx))
|
||||
GenericArg::Type(self.lower_ty(ty, itctx))
|
||||
}
|
||||
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
|
||||
value: self.lower_anon_const(&ct),
|
||||
value: self.lower_anon_const(ct),
|
||||
span: self.lower_span(ct.value.span),
|
||||
is_desugared_from_effects: false,
|
||||
}),
|
||||
@ -1267,7 +1267,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let lifetime_bound = this.elided_dyn_bound(t.span);
|
||||
(bounds, lifetime_bound)
|
||||
});
|
||||
let kind = hir::TyKind::TraitObject(bounds, &lifetime_bound, TraitObjectSyntax::None);
|
||||
let kind = hir::TyKind::TraitObject(bounds, lifetime_bound, TraitObjectSyntax::None);
|
||||
return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
|
||||
}
|
||||
|
||||
@ -1551,7 +1551,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a`
|
||||
// example, we only need to duplicate lifetimes that appear in the
|
||||
// bounds, since those are the only ones that are captured by the opaque.
|
||||
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
|
||||
lifetime_collector::lifetimes_in_bounds(self.resolver, bounds)
|
||||
}
|
||||
}
|
||||
hir::OpaqueTyOrigin::AsyncFn(..) => {
|
||||
@ -2067,10 +2067,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
||||
}
|
||||
GenericParamKind::Const { ty, kw_span: _, default } => {
|
||||
let ty = self.lower_ty(
|
||||
&ty,
|
||||
&ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
|
||||
);
|
||||
let ty = self
|
||||
.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
|
||||
let default = default.as_ref().map(|def| self.lower_anon_const(def));
|
||||
(
|
||||
hir::ParamName::Plain(self.lower_ident(param.ident)),
|
||||
|
@ -372,10 +372,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
// ```
|
||||
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. }) => {
|
||||
if self.tcx.features().impl_trait_in_fn_trait_return {
|
||||
self.lower_ty(&ty, itctx)
|
||||
self.lower_ty(ty, itctx)
|
||||
} else {
|
||||
self.lower_ty(
|
||||
&ty,
|
||||
ty,
|
||||
&ImplTraitContext::FeatureGated(
|
||||
ImplTraitPosition::FnTraitReturn,
|
||||
sym::impl_trait_in_fn_trait_return,
|
||||
@ -384,7 +384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
}
|
||||
FnRetTy::Ty(ty) => {
|
||||
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
|
||||
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
|
||||
}
|
||||
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
itertools = "0.10.1"
|
||||
itertools = "0.11"
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||
rustc_attr = { path = "../rustc_attr" }
|
||||
|
@ -221,7 +221,7 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
|
||||
fn err_handler(&self) -> &rustc_errors::Handler {
|
||||
&self.session.diagnostic()
|
||||
self.session.diagnostic()
|
||||
}
|
||||
|
||||
fn check_lifetime(&self, ident: Ident) {
|
||||
@ -622,7 +622,7 @@ impl<'a> AstValidator<'a> {
|
||||
data: data.span,
|
||||
constraint_spans: errors::EmptyLabelManySpans(constraint_spans),
|
||||
arg_spans2: errors::EmptyLabelManySpans(arg_spans),
|
||||
suggestion: self.correct_generic_order_suggestion(&data),
|
||||
suggestion: self.correct_generic_order_suggestion(data),
|
||||
constraint_len,
|
||||
args_len,
|
||||
});
|
||||
@ -738,7 +738,7 @@ fn validate_generic_param_order(
|
||||
|
||||
if !bounds.is_empty() {
|
||||
ordered_params += ": ";
|
||||
ordered_params += &pprust::bounds_to_string(&bounds);
|
||||
ordered_params += &pprust::bounds_to_string(bounds);
|
||||
}
|
||||
|
||||
match kind {
|
||||
|
@ -88,7 +88,7 @@ impl<'a> PostExpansionVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
match abi::is_enabled(&self.features, span, symbol_unescaped.as_str()) {
|
||||
match abi::is_enabled(self.features, span, symbol_unescaped.as_str()) {
|
||||
Ok(()) => (),
|
||||
Err(abi::AbiDisabled::Unstable { feature, explain }) => {
|
||||
feature_err_issue(
|
||||
@ -182,7 +182,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
..
|
||||
}) = attr_info
|
||||
{
|
||||
gate_alt!(self, has_feature(&self.features), *name, attr.span, *descr);
|
||||
gate_alt!(self, has_feature(self.features), *name, attr.span, *descr);
|
||||
}
|
||||
// Check unstable flavors of the `#[doc]` attribute.
|
||||
if attr.has_name(sym::doc) {
|
||||
@ -300,7 +300,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
|
||||
ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ty), .. }) => {
|
||||
self.check_impl_trait(&ty, false)
|
||||
self.check_impl_trait(ty, false)
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
itertools = "0.11"
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
thin-vec = "0.2.12"
|
||||
|
@ -3,9 +3,7 @@
|
||||
#![doc(rust_logo)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(with_negative_coherence)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
mod helpers;
|
||||
|
@ -165,20 +165,20 @@ enum IndentStyle {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
pub struct BreakToken {
|
||||
pub(crate) struct BreakToken {
|
||||
offset: isize,
|
||||
blank_space: isize,
|
||||
pre_break: Option<char>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct BeginToken {
|
||||
pub(crate) struct BeginToken {
|
||||
indent: IndentStyle,
|
||||
breaks: Breaks,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum Token {
|
||||
#[derive(PartialEq)]
|
||||
pub(crate) enum Token {
|
||||
// In practice a string token contains either a `&'static str` or a
|
||||
// `String`. `Cow` is overkill for this because we never modify the data,
|
||||
// but it's more convenient than rolling our own more specialized type.
|
||||
@ -229,7 +229,6 @@ pub struct Printer {
|
||||
last_printed: Option<Token>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct BufEntry {
|
||||
token: Token,
|
||||
size: isize,
|
||||
@ -251,16 +250,16 @@ impl Printer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn last_token(&self) -> Option<&Token> {
|
||||
pub(crate) fn last_token(&self) -> Option<&Token> {
|
||||
self.last_token_still_buffered().or_else(|| self.last_printed.as_ref())
|
||||
}
|
||||
|
||||
pub fn last_token_still_buffered(&self) -> Option<&Token> {
|
||||
pub(crate) fn last_token_still_buffered(&self) -> Option<&Token> {
|
||||
self.buf.last().map(|last| &last.token)
|
||||
}
|
||||
|
||||
/// Be very careful with this!
|
||||
pub fn replace_last_token_still_buffered(&mut self, token: Token) {
|
||||
pub(crate) fn replace_last_token_still_buffered(&mut self, token: Token) {
|
||||
self.buf.last_mut().unwrap().token = token;
|
||||
}
|
||||
|
||||
@ -314,7 +313,7 @@ impl Printer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn offset(&mut self, offset: isize) {
|
||||
pub(crate) fn offset(&mut self, offset: isize) {
|
||||
if let Some(BufEntry { token: Token::Break(token), .. }) = &mut self.buf.last_mut() {
|
||||
token.offset += offset;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl Printer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hardbreak_tok_offset(off: isize) -> Token {
|
||||
pub(crate) fn hardbreak_tok_offset(off: isize) -> Token {
|
||||
Token::Break(BreakToken {
|
||||
offset: off,
|
||||
blank_space: SIZE_INFINITY,
|
||||
|
@ -1,4 +1,7 @@
|
||||
mod delimited;
|
||||
//! AST pretty printing.
|
||||
//!
|
||||
//! Note that HIR pretty printing is layered on top of this crate.
|
||||
|
||||
mod expr;
|
||||
mod item;
|
||||
|
||||
@ -23,8 +26,6 @@ use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
|
||||
use std::borrow::Cow;
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
pub use self::delimited::IterDelimited;
|
||||
|
||||
pub enum MacHeader<'a> {
|
||||
Path(&'a ast::Path),
|
||||
Keyword(&'static str),
|
||||
@ -46,8 +47,7 @@ pub trait PpAnn {
|
||||
fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) {}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct NoAnn;
|
||||
struct NoAnn;
|
||||
|
||||
impl PpAnn for NoAnn {}
|
||||
|
||||
@ -64,11 +64,11 @@ impl<'a> Comments<'a> {
|
||||
}
|
||||
|
||||
// FIXME: This shouldn't probably clone lmao
|
||||
pub fn next(&self) -> Option<Comment> {
|
||||
fn next(&self) -> Option<Comment> {
|
||||
self.comments.get(self.current).cloned()
|
||||
}
|
||||
|
||||
pub fn trailing_comment(
|
||||
fn trailing_comment(
|
||||
&self,
|
||||
span: rustc_span::Span,
|
||||
next_pos: Option<BytePos>,
|
||||
@ -95,7 +95,7 @@ pub struct State<'a> {
|
||||
ann: &'a (dyn PpAnn + 'a),
|
||||
}
|
||||
|
||||
pub(crate) const INDENT_UNIT: isize = 4;
|
||||
const INDENT_UNIT: isize = 4;
|
||||
|
||||
/// Requires you to pass an input filename and reader so that
|
||||
/// it can scan the input text for comments to copy forward.
|
||||
@ -220,7 +220,7 @@ fn doc_comment_to_string(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn literal_to_string(lit: token::Lit) -> String {
|
||||
fn literal_to_string(lit: token::Lit) -> String {
|
||||
let token::Lit { kind, symbol, suffix } = lit;
|
||||
let mut out = match kind {
|
||||
token::Byte => format!("b'{symbol}'"),
|
||||
@ -260,11 +260,17 @@ impl std::ops::DerefMut for State<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait is used for both AST and HIR pretty-printing.
|
||||
pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::DerefMut {
|
||||
fn comments(&mut self) -> &mut Option<Comments<'a>>;
|
||||
fn print_ident(&mut self, ident: Ident);
|
||||
fn ann_post(&mut self, ident: Ident);
|
||||
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool);
|
||||
|
||||
fn print_ident(&mut self, ident: Ident) {
|
||||
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
|
||||
self.ann_post(ident)
|
||||
}
|
||||
|
||||
fn strsep<T, F>(
|
||||
&mut self,
|
||||
sep: &'static str,
|
||||
@ -401,15 +407,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
}
|
||||
}
|
||||
|
||||
fn print_meta_item_lit(&mut self, lit: &ast::MetaItemLit) {
|
||||
self.print_token_literal(lit.as_token_lit(), lit.span)
|
||||
}
|
||||
|
||||
fn print_token_literal(&mut self, token_lit: token::Lit, span: Span) {
|
||||
self.maybe_print_comment(span.lo());
|
||||
self.word(token_lit.to_string())
|
||||
}
|
||||
|
||||
fn print_string(&mut self, st: &str, style: ast::StrStyle) {
|
||||
let st = match style {
|
||||
ast::StrStyle::Cooked => format!("\"{}\"", st.escape_debug()),
|
||||
@ -420,30 +417,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
self.word(st)
|
||||
}
|
||||
|
||||
fn print_symbol(&mut self, sym: Symbol, style: ast::StrStyle) {
|
||||
self.print_string(sym.as_str(), style);
|
||||
}
|
||||
|
||||
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
|
||||
}
|
||||
|
||||
fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
|
||||
}
|
||||
|
||||
fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
|
||||
}
|
||||
|
||||
fn print_inner_attributes_inline(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Inner, true, true)
|
||||
}
|
||||
|
||||
fn print_outer_attributes_inline(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Outer, true, true)
|
||||
}
|
||||
|
||||
fn print_either_attributes(
|
||||
&mut self,
|
||||
attrs: &[ast::Attribute],
|
||||
@ -467,10 +448,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
printed
|
||||
}
|
||||
|
||||
fn print_attribute(&mut self, attr: &ast::Attribute) {
|
||||
self.print_attribute_inline(attr, false)
|
||||
}
|
||||
|
||||
fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) {
|
||||
if !is_inline {
|
||||
self.hardbreak_if_not_bol();
|
||||
@ -525,33 +502,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
self.end();
|
||||
}
|
||||
|
||||
fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
|
||||
match item {
|
||||
ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
|
||||
ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_meta_item(&mut self, item: &ast::MetaItem) {
|
||||
self.ibox(INDENT_UNIT);
|
||||
match &item.kind {
|
||||
ast::MetaItemKind::Word => self.print_path(&item.path, false, 0),
|
||||
ast::MetaItemKind::NameValue(value) => {
|
||||
self.print_path(&item.path, false, 0);
|
||||
self.space();
|
||||
self.word_space("=");
|
||||
self.print_meta_item_lit(value);
|
||||
}
|
||||
ast::MetaItemKind::List(items) => {
|
||||
self.print_path(&item.path, false, 0);
|
||||
self.popen();
|
||||
self.commasep(Consistent, items, |s, i| s.print_meta_list_item(i));
|
||||
self.pclose();
|
||||
}
|
||||
}
|
||||
self.end();
|
||||
}
|
||||
|
||||
/// This doesn't deserve to be called "pretty" printing, but it should be
|
||||
/// meaning-preserving. A quick hack that might help would be to look at the
|
||||
/// spans embedded in the TTs to decide where to put spaces and newlines.
|
||||
@ -843,17 +793,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
Self::to_string(|s| s.print_type(ty))
|
||||
}
|
||||
|
||||
fn bounds_to_string(&self, bounds: &[ast::GenericBound]) -> String {
|
||||
Self::to_string(|s| s.print_type_bounds(bounds))
|
||||
}
|
||||
|
||||
fn where_bound_predicate_to_string(
|
||||
&self,
|
||||
where_bound_predicate: &ast::WhereBoundPredicate,
|
||||
) -> String {
|
||||
Self::to_string(|s| s.print_where_bound_predicate(where_bound_predicate))
|
||||
}
|
||||
|
||||
fn pat_to_string(&self, pat: &ast::Pat) -> String {
|
||||
Self::to_string(|s| s.print_pat(pat))
|
||||
}
|
||||
@ -866,14 +805,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
Self::to_string(|s| s.print_meta_item_lit(lit))
|
||||
}
|
||||
|
||||
fn tt_to_string(&self, tt: &TokenTree) -> String {
|
||||
Self::to_string(|s| s.print_tt(tt, false))
|
||||
}
|
||||
|
||||
fn tts_to_string(&self, tokens: &TokenStream) -> String {
|
||||
Self::to_string(|s| s.print_tts(tokens, false))
|
||||
}
|
||||
|
||||
fn stmt_to_string(&self, stmt: &ast::Stmt) -> String {
|
||||
Self::to_string(|s| s.print_stmt(stmt))
|
||||
}
|
||||
@ -882,26 +813,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
Self::to_string(|s| s.print_item(i))
|
||||
}
|
||||
|
||||
fn assoc_item_to_string(&self, i: &ast::AssocItem) -> String {
|
||||
Self::to_string(|s| s.print_assoc_item(i))
|
||||
}
|
||||
|
||||
fn foreign_item_to_string(&self, i: &ast::ForeignItem) -> String {
|
||||
Self::to_string(|s| s.print_foreign_item(i))
|
||||
}
|
||||
|
||||
fn generic_params_to_string(&self, generic_params: &[ast::GenericParam]) -> String {
|
||||
Self::to_string(|s| s.print_generic_params(generic_params))
|
||||
}
|
||||
|
||||
fn path_to_string(&self, p: &ast::Path) -> String {
|
||||
Self::to_string(|s| s.print_path(p, false, 0))
|
||||
}
|
||||
|
||||
fn path_segment_to_string(&self, p: &ast::PathSegment) -> String {
|
||||
Self::to_string(|s| s.print_path_segment(p, false))
|
||||
}
|
||||
|
||||
fn vis_to_string(&self, v: &ast::Visibility) -> String {
|
||||
Self::to_string(|s| s.print_visibility(v))
|
||||
}
|
||||
@ -916,22 +831,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
})
|
||||
}
|
||||
|
||||
fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
|
||||
Self::to_string(|s| s.print_meta_list_item(li))
|
||||
}
|
||||
|
||||
fn attr_item_to_string(&self, ai: &ast::AttrItem) -> String {
|
||||
Self::to_string(|s| s.print_attr_item(ai, ai.path.span))
|
||||
}
|
||||
|
||||
fn attribute_to_string(&self, attr: &ast::Attribute) -> String {
|
||||
Self::to_string(|s| s.print_attribute(attr))
|
||||
}
|
||||
|
||||
fn param_to_string(&self, arg: &ast::Param) -> String {
|
||||
Self::to_string(|s| s.print_param(arg, false))
|
||||
}
|
||||
|
||||
fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
|
||||
let mut printer = State::new();
|
||||
f(&mut printer);
|
||||
@ -944,9 +847,8 @@ impl<'a> PrintState<'a> for State<'a> {
|
||||
&mut self.comments
|
||||
}
|
||||
|
||||
fn print_ident(&mut self, ident: Ident) {
|
||||
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
|
||||
self.ann.post(self, AnnNode::Ident(&ident))
|
||||
fn ann_post(&mut self, ident: Ident) {
|
||||
self.ann.post(self, AnnNode::Ident(&ident));
|
||||
}
|
||||
|
||||
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool) {
|
||||
@ -979,13 +881,8 @@ impl<'a> State<'a> {
|
||||
State { s: pp::Printer::new(), comments: None, ann: &NoAnn }
|
||||
}
|
||||
|
||||
pub(crate) fn commasep_cmnt<T, F, G>(
|
||||
&mut self,
|
||||
b: Breaks,
|
||||
elts: &[T],
|
||||
mut op: F,
|
||||
mut get_span: G,
|
||||
) where
|
||||
fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
|
||||
where
|
||||
F: FnMut(&mut State<'_>, &T),
|
||||
G: FnMut(&T) -> rustc_span::Span,
|
||||
{
|
||||
@ -1005,7 +902,7 @@ impl<'a> State<'a> {
|
||||
self.end();
|
||||
}
|
||||
|
||||
pub(crate) fn commasep_exprs(&mut self, b: Breaks, exprs: &[P<ast::Expr>]) {
|
||||
fn commasep_exprs(&mut self, b: Breaks, exprs: &[P<ast::Expr>]) {
|
||||
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span)
|
||||
}
|
||||
|
||||
@ -1078,11 +975,11 @@ impl<'a> State<'a> {
|
||||
}
|
||||
ast::TyKind::AnonStruct(fields) => {
|
||||
self.head("struct");
|
||||
self.print_record_struct_body(&fields, ty.span);
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::AnonUnion(fields) => {
|
||||
self.head("union");
|
||||
self.print_record_struct_body(&fields, ty.span);
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::Paren(typ) => {
|
||||
self.popen();
|
||||
@ -1156,7 +1053,7 @@ impl<'a> State<'a> {
|
||||
self.print_trait_ref(&t.trait_ref)
|
||||
}
|
||||
|
||||
pub(crate) fn print_stmt(&mut self, st: &ast::Stmt) {
|
||||
fn print_stmt(&mut self, st: &ast::Stmt) {
|
||||
self.maybe_print_comment(st.span.lo());
|
||||
match &st.kind {
|
||||
ast::StmtKind::Local(loc) => {
|
||||
@ -1211,19 +1108,19 @@ impl<'a> State<'a> {
|
||||
self.maybe_print_trailing_comment(st.span, None)
|
||||
}
|
||||
|
||||
pub(crate) fn print_block(&mut self, blk: &ast::Block) {
|
||||
fn print_block(&mut self, blk: &ast::Block) {
|
||||
self.print_block_with_attrs(blk, &[])
|
||||
}
|
||||
|
||||
pub(crate) fn print_block_unclosed_indent(&mut self, blk: &ast::Block) {
|
||||
fn print_block_unclosed_indent(&mut self, blk: &ast::Block) {
|
||||
self.print_block_maybe_unclosed(blk, &[], false)
|
||||
}
|
||||
|
||||
pub(crate) fn print_block_with_attrs(&mut self, blk: &ast::Block, attrs: &[ast::Attribute]) {
|
||||
fn print_block_with_attrs(&mut self, blk: &ast::Block, attrs: &[ast::Attribute]) {
|
||||
self.print_block_maybe_unclosed(blk, attrs, true)
|
||||
}
|
||||
|
||||
pub(crate) fn print_block_maybe_unclosed(
|
||||
fn print_block_maybe_unclosed(
|
||||
&mut self,
|
||||
blk: &ast::Block,
|
||||
attrs: &[ast::Attribute],
|
||||
@ -1257,7 +1154,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
/// Print a `let pat = expr` expression.
|
||||
pub(crate) fn print_let(&mut self, pat: &ast::Pat, expr: &ast::Expr) {
|
||||
fn print_let(&mut self, pat: &ast::Pat, expr: &ast::Expr) {
|
||||
self.word("let ");
|
||||
self.print_pat(pat);
|
||||
self.space();
|
||||
@ -1266,7 +1163,7 @@ impl<'a> State<'a> {
|
||||
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals())
|
||||
}
|
||||
|
||||
pub(crate) fn print_mac(&mut self, m: &ast::MacCall) {
|
||||
fn print_mac(&mut self, m: &ast::MacCall) {
|
||||
self.print_mac_common(
|
||||
Some(MacHeader::Path(&m.path)),
|
||||
true,
|
||||
@ -1407,7 +1304,7 @@ impl<'a> State<'a> {
|
||||
self.pclose();
|
||||
}
|
||||
|
||||
pub(crate) fn print_local_decl(&mut self, loc: &ast::Local) {
|
||||
fn print_local_decl(&mut self, loc: &ast::Local) {
|
||||
self.print_pat(&loc.pat);
|
||||
if let Some(ty) = &loc.ty {
|
||||
self.word_space(":");
|
||||
@ -1415,7 +1312,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_name(&mut self, name: Symbol) {
|
||||
fn print_name(&mut self, name: Symbol) {
|
||||
self.word(name.to_string());
|
||||
self.ann.post(self, AnnNode::Name(&name))
|
||||
}
|
||||
@ -1439,7 +1336,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_pat(&mut self, pat: &ast::Pat) {
|
||||
fn print_pat(&mut self, pat: &ast::Pat) {
|
||||
self.maybe_print_comment(pat.span.lo());
|
||||
self.ann.pre(self, AnnNode::Pat(pat));
|
||||
/* Pat isn't normalized, but the beauty of it
|
||||
@ -1592,7 +1489,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_asyncness(&mut self, asyncness: ast::Async) {
|
||||
fn print_asyncness(&mut self, asyncness: ast::Async) {
|
||||
if asyncness.is_async() {
|
||||
self.word_nbsp("async");
|
||||
}
|
||||
@ -1637,11 +1534,11 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_lifetime(&mut self, lifetime: ast::Lifetime) {
|
||||
fn print_lifetime(&mut self, lifetime: ast::Lifetime) {
|
||||
self.print_name(lifetime.ident.name)
|
||||
}
|
||||
|
||||
pub(crate) fn print_lifetime_bounds(&mut self, bounds: &ast::GenericBounds) {
|
||||
fn print_lifetime_bounds(&mut self, bounds: &ast::GenericBounds) {
|
||||
for (i, bound) in bounds.iter().enumerate() {
|
||||
if i != 0 {
|
||||
self.word(" + ");
|
||||
@ -1653,7 +1550,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_generic_params(&mut self, generic_params: &[ast::GenericParam]) {
|
||||
fn print_generic_params(&mut self, generic_params: &[ast::GenericParam]) {
|
||||
if generic_params.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -1717,12 +1614,12 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_mt(&mut self, mt: &ast::MutTy, print_const: bool) {
|
||||
fn print_mt(&mut self, mt: &ast::MutTy, print_const: bool) {
|
||||
self.print_mutability(mt.mutbl, print_const);
|
||||
self.print_type(&mt.ty)
|
||||
}
|
||||
|
||||
pub(crate) fn print_param(&mut self, input: &ast::Param, is_closure: bool) {
|
||||
fn print_param(&mut self, input: &ast::Param, is_closure: bool) {
|
||||
self.ibox(INDENT_UNIT);
|
||||
|
||||
self.print_outer_attributes_inline(&input.attrs);
|
||||
@ -1750,7 +1647,7 @@ impl<'a> State<'a> {
|
||||
self.end();
|
||||
}
|
||||
|
||||
pub(crate) fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FnRetTy) {
|
||||
fn print_fn_ret_ty(&mut self, fn_ret_ty: &ast::FnRetTy) {
|
||||
if let ast::FnRetTy::Ty(ty) = fn_ret_ty {
|
||||
self.space_if_not_bol();
|
||||
self.ibox(INDENT_UNIT);
|
||||
@ -1761,7 +1658,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_ty_fn(
|
||||
fn print_ty_fn(
|
||||
&mut self,
|
||||
ext: ast::Extern,
|
||||
unsafety: ast::Unsafe,
|
||||
@ -1785,7 +1682,7 @@ impl<'a> State<'a> {
|
||||
self.end();
|
||||
}
|
||||
|
||||
pub(crate) fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
self.print_constness(header.constness);
|
||||
self.print_asyncness(header.asyncness);
|
||||
self.print_unsafety(header.unsafety);
|
||||
@ -1805,24 +1702,107 @@ impl<'a> State<'a> {
|
||||
self.word("fn")
|
||||
}
|
||||
|
||||
pub(crate) fn print_unsafety(&mut self, s: ast::Unsafe) {
|
||||
fn print_unsafety(&mut self, s: ast::Unsafe) {
|
||||
match s {
|
||||
ast::Unsafe::No => {}
|
||||
ast::Unsafe::Yes(_) => self.word_nbsp("unsafe"),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_constness(&mut self, s: ast::Const) {
|
||||
fn print_constness(&mut self, s: ast::Const) {
|
||||
match s {
|
||||
ast::Const::No => {}
|
||||
ast::Const::Yes(_) => self.word_nbsp("const"),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_is_auto(&mut self, s: ast::IsAuto) {
|
||||
fn print_is_auto(&mut self, s: ast::IsAuto) {
|
||||
match s {
|
||||
ast::IsAuto::Yes => self.word_nbsp("auto"),
|
||||
ast::IsAuto::No => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_meta_item_lit(&mut self, lit: &ast::MetaItemLit) {
|
||||
self.print_token_literal(lit.as_token_lit(), lit.span)
|
||||
}
|
||||
|
||||
fn print_token_literal(&mut self, token_lit: token::Lit, span: Span) {
|
||||
self.maybe_print_comment(span.lo());
|
||||
self.word(token_lit.to_string())
|
||||
}
|
||||
|
||||
fn print_symbol(&mut self, sym: Symbol, style: ast::StrStyle) {
|
||||
self.print_string(sym.as_str(), style);
|
||||
}
|
||||
|
||||
fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
|
||||
}
|
||||
|
||||
fn print_outer_attributes_inline(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
self.print_either_attributes(attrs, ast::AttrStyle::Outer, true, true)
|
||||
}
|
||||
|
||||
fn print_attribute(&mut self, attr: &ast::Attribute) {
|
||||
self.print_attribute_inline(attr, false)
|
||||
}
|
||||
|
||||
fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
|
||||
match item {
|
||||
ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
|
||||
ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_meta_item(&mut self, item: &ast::MetaItem) {
|
||||
self.ibox(INDENT_UNIT);
|
||||
match &item.kind {
|
||||
ast::MetaItemKind::Word => self.print_path(&item.path, false, 0),
|
||||
ast::MetaItemKind::NameValue(value) => {
|
||||
self.print_path(&item.path, false, 0);
|
||||
self.space();
|
||||
self.word_space("=");
|
||||
self.print_meta_item_lit(value);
|
||||
}
|
||||
ast::MetaItemKind::List(items) => {
|
||||
self.print_path(&item.path, false, 0);
|
||||
self.popen();
|
||||
self.commasep(Consistent, items, |s, i| s.print_meta_list_item(i));
|
||||
self.pclose();
|
||||
}
|
||||
}
|
||||
self.end();
|
||||
}
|
||||
|
||||
pub(crate) fn bounds_to_string(&self, bounds: &[ast::GenericBound]) -> String {
|
||||
Self::to_string(|s| s.print_type_bounds(bounds))
|
||||
}
|
||||
|
||||
pub(crate) fn where_bound_predicate_to_string(
|
||||
&self,
|
||||
where_bound_predicate: &ast::WhereBoundPredicate,
|
||||
) -> String {
|
||||
Self::to_string(|s| s.print_where_bound_predicate(where_bound_predicate))
|
||||
}
|
||||
|
||||
pub(crate) fn tt_to_string(&self, tt: &TokenTree) -> String {
|
||||
Self::to_string(|s| s.print_tt(tt, false))
|
||||
}
|
||||
|
||||
pub(crate) fn tts_to_string(&self, tokens: &TokenStream) -> String {
|
||||
Self::to_string(|s| s.print_tts(tokens, false))
|
||||
}
|
||||
|
||||
pub(crate) fn path_segment_to_string(&self, p: &ast::PathSegment) -> String {
|
||||
Self::to_string(|s| s.print_path_segment(p, false))
|
||||
}
|
||||
|
||||
pub(crate) fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
|
||||
Self::to_string(|s| s.print_meta_list_item(li))
|
||||
}
|
||||
|
||||
pub(crate) fn attribute_to_string(&self, attr: &ast::Attribute) -> String {
|
||||
Self::to_string(|s| s.print_attribute(attr))
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
use std::iter::Peekable;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct Delimited<I: Iterator> {
|
||||
is_first: bool,
|
||||
iter: Peekable<I>,
|
||||
}
|
||||
|
||||
pub trait IterDelimited: Iterator + Sized {
|
||||
fn delimited(self) -> Delimited<Self> {
|
||||
Delimited { is_first: true, iter: self.peekable() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator> IterDelimited for I {}
|
||||
|
||||
pub struct IteratorItem<T> {
|
||||
value: T,
|
||||
pub is_first: bool,
|
||||
pub is_last: bool,
|
||||
}
|
||||
|
||||
impl<I: Iterator> Iterator for Delimited<I> {
|
||||
type Item = IteratorItem<I::Item>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let value = self.iter.next()?;
|
||||
let is_first = mem::replace(&mut self.is_first, false);
|
||||
let is_last = self.iter.peek().is_none();
|
||||
Some(IteratorItem { value, is_first, is_last })
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for IteratorItem<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use crate::pp::Breaks::Inconsistent;
|
||||
use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT};
|
||||
|
||||
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
|
||||
use itertools::{Itertools, Position};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token;
|
||||
use rustc_ast::util::literal::escape_byte_str_symbol;
|
||||
@ -149,10 +149,12 @@ impl<'a> State<'a> {
|
||||
return;
|
||||
}
|
||||
self.cbox(0);
|
||||
for field in fields.iter().delimited() {
|
||||
for (pos, field) in fields.iter().with_position() {
|
||||
let is_first = matches!(pos, Position::First | Position::Only);
|
||||
let is_last = matches!(pos, Position::Last | Position::Only);
|
||||
self.maybe_print_comment(field.span.hi());
|
||||
self.print_outer_attributes(&field.attrs);
|
||||
if field.is_first {
|
||||
if is_first {
|
||||
self.space_if_not_bol();
|
||||
}
|
||||
if !field.is_shorthand {
|
||||
@ -160,7 +162,7 @@ impl<'a> State<'a> {
|
||||
self.word_nbsp(":");
|
||||
}
|
||||
self.print_expr(&field.expr);
|
||||
if !field.is_last || has_rest {
|
||||
if !is_last || has_rest {
|
||||
self.word_space(",");
|
||||
} else {
|
||||
self.trailing_comma_or_space();
|
||||
@ -279,7 +281,7 @@ impl<'a> State<'a> {
|
||||
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)
|
||||
}
|
||||
|
||||
pub fn print_expr(&mut self, expr: &ast::Expr) {
|
||||
pub(super) fn print_expr(&mut self, expr: &ast::Expr) {
|
||||
self.print_expr_outer_attr_style(expr, true)
|
||||
}
|
||||
|
||||
@ -679,7 +681,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> String {
|
||||
fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> String {
|
||||
let mut template = "\"".to_string();
|
||||
for piece in pieces {
|
||||
match piece {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::pp::Breaks::Inconsistent;
|
||||
use crate::pprust::state::delimited::IterDelimited;
|
||||
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
|
||||
|
||||
use ast::StaticItem;
|
||||
use itertools::{Itertools, Position};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::GenericBound;
|
||||
use rustc_ast::ModKind;
|
||||
@ -20,7 +20,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
|
||||
fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
|
||||
let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item;
|
||||
self.ann.pre(self, AnnNode::SubItem(id));
|
||||
self.hardbreak_if_not_bol();
|
||||
@ -368,7 +368,7 @@ impl<'a> State<'a> {
|
||||
self.nbsp();
|
||||
if !bounds.is_empty() {
|
||||
self.word_nbsp("=");
|
||||
self.print_type_bounds(&bounds);
|
||||
self.print_type_bounds(bounds);
|
||||
}
|
||||
self.print_where_clause(&generics.where_clause);
|
||||
self.word(";");
|
||||
@ -518,7 +518,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_assoc_item(&mut self, item: &ast::AssocItem) {
|
||||
fn print_assoc_item(&mut self, item: &ast::AssocItem) {
|
||||
let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item;
|
||||
self.ann.pre(self, AnnNode::SubItem(id));
|
||||
self.hardbreak_if_not_bol();
|
||||
@ -621,7 +621,7 @@ impl<'a> State<'a> {
|
||||
self.print_where_clause_parts(where_clause.has_where_token, &where_clause.predicates);
|
||||
}
|
||||
|
||||
pub(crate) fn print_where_clause_parts(
|
||||
fn print_where_clause_parts(
|
||||
&mut self,
|
||||
has_where_token: bool,
|
||||
predicates: &[ast::WherePredicate],
|
||||
@ -668,7 +668,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_where_bound_predicate(
|
||||
pub(crate) fn print_where_bound_predicate(
|
||||
&mut self,
|
||||
where_bound_predicate: &ast::WhereBoundPredicate,
|
||||
) {
|
||||
@ -712,9 +712,10 @@ impl<'a> State<'a> {
|
||||
self.word("{");
|
||||
self.zerobreak();
|
||||
self.ibox(0);
|
||||
for use_tree in items.iter().delimited() {
|
||||
for (pos, use_tree) in items.iter().with_position() {
|
||||
let is_last = matches!(pos, Position::Last | Position::Only);
|
||||
self.print_use_tree(&use_tree.0);
|
||||
if !use_tree.is_last {
|
||||
if !is_last {
|
||||
self.word(",");
|
||||
if let ast::UseTreeKind::Nested(_) = use_tree.0.kind {
|
||||
self.hardbreak();
|
||||
|
@ -552,7 +552,7 @@ pub fn cfg_matches(
|
||||
fn try_gate_cfg(name: Symbol, span: Span, sess: &ParseSess, features: Option<&Features>) {
|
||||
let gate = find_gated_cfg(|sym| sym == name);
|
||||
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
|
||||
gate_cfg(&gated_cfg, span, sess, feats);
|
||||
gate_cfg(gated_cfg, span, sess, feats);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
either = "1.5.0"
|
||||
itertools = "0.10.1"
|
||||
itertools = "0.11"
|
||||
polonius-engine = "0.13.0"
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_errors = { path = "../rustc_errors" }
|
||||
@ -19,7 +19,6 @@ rustc_lexer = { path = "../rustc_lexer" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
|
@ -107,7 +107,7 @@ impl LocalsStateAtExit {
|
||||
LocalsStateAtExit::AllAreInvalidated
|
||||
} else {
|
||||
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
|
||||
has_storage_dead.visit_body(&body);
|
||||
has_storage_dead.visit_body(body);
|
||||
let mut has_storage_dead_or_moved = has_storage_dead.0;
|
||||
for move_out in &move_data.moves {
|
||||
if let Some(index) = move_data.base_local(move_out.path) {
|
||||
@ -128,7 +128,7 @@ impl<'tcx> BorrowSet<'tcx> {
|
||||
) -> Self {
|
||||
let mut visitor = GatherBorrows {
|
||||
tcx,
|
||||
body: &body,
|
||||
body: body,
|
||||
location_map: Default::default(),
|
||||
activation_map: Default::default(),
|
||||
local_map: Default::default(),
|
||||
@ -140,7 +140,7 @@ impl<'tcx> BorrowSet<'tcx> {
|
||||
),
|
||||
};
|
||||
|
||||
for (block, block_data) in traversal::preorder(&body) {
|
||||
for (block, block_data) in traversal::preorder(body) {
|
||||
visitor.visit_basic_block_data(block, block_data);
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ rustc_index::newtype_index! {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[orderable]
|
||||
#[debug_format = "ConstraintSccIndex({})"]
|
||||
pub struct ConstraintSccIndex {}
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ impl_visitable! {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[orderable]
|
||||
#[debug_format = "bw{}"]
|
||||
pub struct BorrowIndex {}
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let mut spans = vec![];
|
||||
for init_idx in inits {
|
||||
let init = &self.move_data.inits[*init_idx];
|
||||
let span = init.span(&self.body);
|
||||
let span = init.span(self.body);
|
||||
if !span.is_dummy() {
|
||||
spans.push(span);
|
||||
}
|
||||
@ -518,7 +518,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let body = map.body(body_id);
|
||||
|
||||
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
|
||||
visitor.visit_body(&body);
|
||||
visitor.visit_body(body);
|
||||
|
||||
let mut show_assign_sugg = false;
|
||||
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
|
||||
@ -614,7 +614,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
let mut visitor = LetVisitor { decl_span, sugg_span: None };
|
||||
visitor.visit_body(&body);
|
||||
visitor.visit_body(body);
|
||||
if let Some(span) = visitor.sugg_span {
|
||||
self.suggest_assign_value(&mut err, moved_place, span);
|
||||
}
|
||||
@ -779,7 +779,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
return;
|
||||
};
|
||||
// Try to find predicates on *generic params* that would allow copying `ty`
|
||||
let ocx = ObligationCtxt::new(&self.infcx);
|
||||
let ocx = ObligationCtxt::new(self.infcx);
|
||||
let copy_did = tcx.require_lang_item(LangItem::Copy, Some(span));
|
||||
let cause = ObligationCause::misc(span, self.mir_def_id());
|
||||
|
||||
@ -856,7 +856,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||
.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -903,7 +903,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||
.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -1174,7 +1174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
explanation.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
first_borrow_desc,
|
||||
@ -1932,7 +1932,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let place_desc = self.describe_place(borrow.borrowed_place.as_ref());
|
||||
|
||||
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
|
||||
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
|
||||
let explanation = self.explain_why_borrow_contains_point(location, borrow, kind_place);
|
||||
|
||||
debug!(?place_desc, ?explanation);
|
||||
|
||||
@ -2001,14 +2001,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
|
||||
location,
|
||||
&name,
|
||||
&borrow,
|
||||
borrow,
|
||||
drop_span,
|
||||
borrow_spans,
|
||||
explanation,
|
||||
),
|
||||
(None, explanation) => self.report_temporary_value_does_not_live_long_enough(
|
||||
location,
|
||||
&borrow,
|
||||
borrow,
|
||||
drop_span,
|
||||
borrow_spans,
|
||||
proper_span,
|
||||
@ -2098,7 +2098,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
} else {
|
||||
explanation.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -2119,7 +2119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
explanation.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -2180,7 +2180,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
explanation.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -2365,7 +2365,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
explanation.add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -2842,7 +2842,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
self.explain_why_borrow_contains_point(location, loan, None).add_explanation_to_diagnostic(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&mut err,
|
||||
"",
|
||||
@ -3020,7 +3020,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
let mut visitor = FakeReadCauseFinder { place, cause: None };
|
||||
visitor.visit_body(&self.body);
|
||||
visitor.visit_body(self.body);
|
||||
match visitor.cause {
|
||||
Some(FakeReadCause::ForMatchGuard) => Some("match guard"),
|
||||
Some(FakeReadCause::ForIndex) => Some("indexing expression"),
|
||||
|
@ -422,7 +422,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
kind_place: Option<(WriteKind, Place<'tcx>)>,
|
||||
) -> BorrowExplanation<'tcx> {
|
||||
let regioncx = &self.regioncx;
|
||||
let body: &Body<'_> = &self.body;
|
||||
let body: &Body<'_> = self.body;
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
let borrow_region_vid = borrow.region;
|
||||
|
@ -354,7 +354,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
ty::Adt(def, _) => {
|
||||
let variant = if let Some(idx) = variant_index {
|
||||
assert!(def.is_enum());
|
||||
&def.variant(idx)
|
||||
def.variant(idx)
|
||||
} else {
|
||||
def.non_enum_variant()
|
||||
};
|
||||
@ -851,7 +851,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
{
|
||||
let Some((method_did, method_args)) = rustc_middle::util::find_self_call(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
target_temp,
|
||||
location.block,
|
||||
) else {
|
||||
@ -1048,7 +1048,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let ty = moved_place.ty(self.body, tcx).ty;
|
||||
let suggest = match tcx.get_diagnostic_item(sym::IntoIterator) {
|
||||
Some(def_id) => type_known_to_meet_bound_modulo_regions(
|
||||
&self.infcx,
|
||||
self.infcx,
|
||||
self.param_env,
|
||||
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty),
|
||||
def_id,
|
||||
|
@ -321,7 +321,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
let deref_base = match deref_target_place.projection.as_ref() {
|
||||
[proj_base @ .., ProjectionElem::Deref] => {
|
||||
PlaceRef { local: deref_target_place.local, projection: &proj_base }
|
||||
PlaceRef { local: deref_target_place.local, projection: proj_base }
|
||||
}
|
||||
_ => bug!("deref_target_place is not a deref projection"),
|
||||
};
|
||||
@ -583,7 +583,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
|
||||
is_partial_move: false,
|
||||
ty: bind_to.ty,
|
||||
place: &place_desc,
|
||||
place: place_desc,
|
||||
span: binding_span,
|
||||
});
|
||||
}
|
||||
|
@ -650,14 +650,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&self.upvars,
|
||||
errci.fr,
|
||||
);
|
||||
let outlived_fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
&self.upvars,
|
||||
errci.outlived_fr,
|
||||
@ -971,7 +971,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
for found_did in found_dids {
|
||||
let mut traits = vec![];
|
||||
let mut hir_v = HirTraitObjectVisitor(&mut traits, *found_did);
|
||||
hir_v.visit_ty(&self_ty);
|
||||
hir_v.visit_ty(self_ty);
|
||||
debug!("trait spans found: {:?}", traits);
|
||||
for span in &traits {
|
||||
let mut multi_span: MultiSpan = vec![*span].into();
|
||||
|
@ -387,7 +387,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
|
||||
[implicit_inputs + argument_index];
|
||||
let (_, span) = self.regioncx.get_argument_name_and_span_for_region(
|
||||
&self.body,
|
||||
self.body,
|
||||
&self.local_names,
|
||||
argument_index,
|
||||
);
|
||||
|
@ -34,7 +34,7 @@ pub(super) fn generate_invalidates<'tcx>(
|
||||
borrow_set,
|
||||
tcx,
|
||||
location_table,
|
||||
body: &body,
|
||||
body: body,
|
||||
dominators,
|
||||
};
|
||||
ig.visit_body(body);
|
||||
@ -383,7 +383,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
|
||||
|
||||
(Read(_), BorrowKind::Mut { .. }) => {
|
||||
// Reading from mere reservations of mutable-borrows is OK.
|
||||
if !is_active(&this.dominators, borrow, location) {
|
||||
if !is_active(this.dominators, borrow, location) {
|
||||
// If the borrow isn't active yet, reads don't invalidate it
|
||||
assert!(allow_two_phase_borrow(borrow.kind));
|
||||
return Control::Continue;
|
||||
|
@ -219,18 +219,18 @@ fn do_mir_borrowck<'tcx>(
|
||||
let location_table_owned = LocationTable::new(body);
|
||||
let location_table = &location_table_owned;
|
||||
|
||||
let move_data = MoveData::gather_moves(&body, tcx, param_env, |_| true);
|
||||
let move_data = MoveData::gather_moves(body, tcx, param_env, |_| true);
|
||||
let promoted_move_data = promoted
|
||||
.iter_enumerated()
|
||||
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env, |_| true)));
|
||||
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, param_env, |_| true)));
|
||||
|
||||
let mdpe = MoveDataParamEnv { move_data, param_env };
|
||||
|
||||
let mut flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe)
|
||||
.into_engine(tcx, &body)
|
||||
let mut flow_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
|
||||
.into_engine(tcx, body)
|
||||
.pass_name("borrowck")
|
||||
.iterate_to_fixpoint()
|
||||
.into_results_cursor(&body);
|
||||
.into_results_cursor(body);
|
||||
|
||||
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
|
||||
let borrow_set =
|
||||
@ -260,13 +260,13 @@ fn do_mir_borrowck<'tcx>(
|
||||
|
||||
// Dump MIR results into a file, if that is enabled. This let us
|
||||
// write unit-tests, as well as helping with debugging.
|
||||
nll::dump_mir_results(&infcx, &body, ®ioncx, &opt_closure_req);
|
||||
nll::dump_mir_results(&infcx, body, ®ioncx, &opt_closure_req);
|
||||
|
||||
// We also have a `#[rustc_regions]` annotation that causes us to dump
|
||||
// information.
|
||||
nll::dump_annotation(
|
||||
&infcx,
|
||||
&body,
|
||||
body,
|
||||
®ioncx,
|
||||
&opt_closure_req,
|
||||
&opaque_type_values,
|
||||
@ -1538,7 +1538,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
if places_conflict::borrow_conflicts_with_place(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
self.body,
|
||||
place,
|
||||
borrow.kind,
|
||||
root_place,
|
||||
@ -2193,7 +2193,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// If this is a mutate access to an immutable local variable with no projections
|
||||
// report the error as an illegal reassignment
|
||||
let init = &self.move_data.inits[init_index];
|
||||
let assigned_span = init.span(&self.body);
|
||||
let assigned_span = init.span(self.body);
|
||||
self.report_illegal_reassignment(location, (place, span), assigned_span, place);
|
||||
} else {
|
||||
self.report_mutability_error(place, span, the_place_err, error_access, location)
|
||||
|
@ -20,6 +20,7 @@ pub struct LocationTable {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[orderable]
|
||||
#[debug_format = "LocationIndex({})"]
|
||||
pub struct LocationIndex {}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
|
||||
let universal_regions = Rc::new(universal_regions);
|
||||
|
||||
let elements = &Rc::new(RegionValueElements::new(&body));
|
||||
let elements = &Rc::new(RegionValueElements::new(body));
|
||||
|
||||
// Run the MIR type-checker.
|
||||
let MirTypeckResults {
|
||||
@ -206,7 +206,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
if let Some(all_facts) = &mut all_facts {
|
||||
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
|
||||
all_facts.universal_region.extend(universal_regions.universal_regions());
|
||||
populate_polonius_move_facts(all_facts, move_data, location_table, &body);
|
||||
populate_polonius_move_facts(all_facts, move_data, location_table, body);
|
||||
|
||||
// Emit universal regions facts, and their relations, for Polonius.
|
||||
//
|
||||
@ -263,7 +263,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
&mut liveness_constraints,
|
||||
&mut all_facts,
|
||||
location_table,
|
||||
&body,
|
||||
body,
|
||||
borrow_set,
|
||||
);
|
||||
|
||||
@ -302,7 +302,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
let algorithm = Algorithm::from_str(&algorithm).unwrap();
|
||||
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
|
||||
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");
|
||||
Some(Rc::new(Output::compute(&all_facts, algorithm, false)))
|
||||
Some(Rc::new(Output::compute(all_facts, algorithm, false)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -310,7 +310,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
|
||||
// Solve the region constraints.
|
||||
let (closure_region_requirements, nll_errors) =
|
||||
regioncx.solve(infcx, param_env, &body, polonius_output.clone());
|
||||
regioncx.solve(infcx, param_env, body, polonius_output.clone());
|
||||
|
||||
if !nll_errors.is_empty() {
|
||||
// Suppress unhelpful extra errors in `infer_opaque_types`.
|
||||
@ -320,7 +320,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
));
|
||||
}
|
||||
|
||||
let remapped_opaque_tys = regioncx.infer_opaque_types(&infcx, opaque_type_values);
|
||||
let remapped_opaque_tys = regioncx.infer_opaque_types(infcx, opaque_type_values);
|
||||
|
||||
NllOutput {
|
||||
regioncx,
|
||||
|
@ -90,6 +90,7 @@ impl RegionValueElements {
|
||||
rustc_index::newtype_index! {
|
||||
/// A single integer representing a `Location` in the MIR control-flow
|
||||
/// graph. Constructed efficiently from `RegionValueElements`.
|
||||
#[orderable]
|
||||
#[debug_format = "PointIndex({})"]
|
||||
pub struct PointIndex {}
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
||||
Locations::All(span),
|
||||
span,
|
||||
ConstraintCategory::Internal,
|
||||
&mut self.constraints,
|
||||
self.constraints,
|
||||
)
|
||||
.convert_all(data);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ impl LocalUseMap {
|
||||
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
|
||||
|
||||
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
|
||||
.visit_body(&body);
|
||||
.visit_body(body);
|
||||
|
||||
local_use_map
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ pub(super) fn generate<'mir, 'tcx>(
|
||||
|
||||
let free_regions = regions_that_outlive_free_regions(
|
||||
typeck.infcx.num_region_vars(),
|
||||
&typeck.borrowck_context.universal_regions,
|
||||
typeck.borrowck_context.universal_regions,
|
||||
&typeck.borrowck_context.constraints.outlives_constraints,
|
||||
);
|
||||
let (relevant_live_locals, boring_locals) =
|
||||
compute_relevant_live_locals(typeck.tcx(), &free_regions, &body);
|
||||
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
|
||||
let facts_enabled = use_polonius || AllFacts::enabled(typeck.tcx());
|
||||
|
||||
let polonius_drop_used = facts_enabled.then(|| {
|
||||
|
@ -100,7 +100,7 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
|
||||
location_table,
|
||||
move_data,
|
||||
};
|
||||
extractor.visit_body(&body);
|
||||
extractor.visit_body(body);
|
||||
|
||||
facts.var_dropped_at.extend(
|
||||
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
|
||||
|
@ -64,7 +64,7 @@ pub(super) fn trace<'mir, 'tcx>(
|
||||
let num_region_vars = typeck.infcx.num_region_vars();
|
||||
let graph = constraint_set.graph(num_region_vars);
|
||||
let region_graph =
|
||||
graph.region_graph(&constraint_set, borrowck_context.universal_regions.fr_static);
|
||||
graph.region_graph(constraint_set, borrowck_context.universal_regions.fr_static);
|
||||
|
||||
// Traverse each issuing region's constraints, and record the loan as flowing into the
|
||||
// outlived region.
|
||||
@ -489,7 +489,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
}
|
||||
|
||||
let move_paths = &self.flow_inits.analysis().move_data().move_paths;
|
||||
move_paths[mpi].find_descendant(&move_paths, |mpi| state.contains(mpi)).is_some()
|
||||
move_paths[mpi].find_descendant(move_paths, |mpi| state.contains(mpi)).is_some()
|
||||
}
|
||||
|
||||
/// Returns `true` if the local variable (or some part of it) is initialized in
|
||||
@ -522,7 +522,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
|
||||
Self::make_all_regions_live(
|
||||
self.elements,
|
||||
&mut self.typeck,
|
||||
self.typeck,
|
||||
value,
|
||||
live_at,
|
||||
&self.inflowing_loans,
|
||||
@ -579,13 +579,13 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
for &kind in &drop_data.dropck_result.kinds {
|
||||
Self::make_all_regions_live(
|
||||
self.elements,
|
||||
&mut self.typeck,
|
||||
self.typeck,
|
||||
kind,
|
||||
live_at,
|
||||
&self.inflowing_loans,
|
||||
);
|
||||
|
||||
polonius::add_drop_of_var_derefs_origin(&mut self.typeck, dropped_local, &kind);
|
||||
polonius::add_drop_of_var_derefs_origin(self.typeck, dropped_local, &kind);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,11 +191,11 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||
checker.check_user_type_annotations();
|
||||
|
||||
let mut verifier = TypeVerifier::new(&mut checker, promoted);
|
||||
verifier.visit_body(&body);
|
||||
verifier.visit_body(body);
|
||||
|
||||
checker.typeck_mir(body);
|
||||
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
||||
checker.check_signature_annotation(&body);
|
||||
checker.equate_inputs_and_outputs(body, universal_regions, &normalized_inputs_and_output);
|
||||
checker.check_signature_annotation(body);
|
||||
|
||||
liveness::generate(
|
||||
&mut checker,
|
||||
@ -389,7 +389,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||
self.cx.ascribe_user_type(
|
||||
constant.const_.ty(),
|
||||
UserType::TypeOf(uv.def, UserArgs { args: uv.args, user_self_ty: None }),
|
||||
locations.span(&self.cx.body),
|
||||
locations.span(self.cx.body),
|
||||
);
|
||||
}
|
||||
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
|
||||
@ -553,7 +553,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
let all_facts = &mut None;
|
||||
let mut constraints = Default::default();
|
||||
let mut liveness_constraints =
|
||||
LivenessValues::new(Rc::new(RegionValueElements::new(&promoted_body)));
|
||||
LivenessValues::new(Rc::new(RegionValueElements::new(promoted_body)));
|
||||
// Don't try to add borrow_region facts for the promoted MIR
|
||||
|
||||
let mut swap_constraints = |this: &mut Self| {
|
||||
@ -570,7 +570,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
|
||||
swap_constraints(self);
|
||||
|
||||
self.visit_body(&promoted_body);
|
||||
self.visit_body(promoted_body);
|
||||
|
||||
self.cx.typeck_mir(promoted_body);
|
||||
|
||||
@ -1127,7 +1127,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
locations,
|
||||
locations.span(self.body),
|
||||
category,
|
||||
&mut self.borrowck_context.constraints,
|
||||
self.borrowck_context.constraints,
|
||||
)
|
||||
.convert_all(data);
|
||||
}
|
||||
@ -1854,7 +1854,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
for op in ops {
|
||||
self.check_operand(op, location);
|
||||
}
|
||||
self.check_aggregate_rvalue(&body, rvalue, ak, ops, location)
|
||||
self.check_aggregate_rvalue(body, rvalue, ak, ops, location)
|
||||
}
|
||||
|
||||
Rvalue::Repeat(operand, len) => {
|
||||
@ -2300,7 +2300,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
|
||||
self.add_reborrow_constraint(&body, location, *region, borrowed_place);
|
||||
self.add_reborrow_constraint(body, location, *region, borrowed_place);
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(
|
||||
@ -2512,7 +2512,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let tcx = self.infcx.tcx;
|
||||
let field = path_utils::is_upvar_field_projection(
|
||||
tcx,
|
||||
&self.borrowck_context.upvars,
|
||||
self.borrowck_context.upvars,
|
||||
borrowed_place.as_ref(),
|
||||
body,
|
||||
);
|
||||
@ -2668,13 +2668,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
location.to_locations(),
|
||||
DUMMY_SP, // irrelevant; will be overridden.
|
||||
ConstraintCategory::Boring, // same as above.
|
||||
&mut self.borrowck_context.constraints,
|
||||
self.borrowck_context.constraints,
|
||||
)
|
||||
.apply_closure_requirements(
|
||||
&closure_requirements,
|
||||
def_id.to_def_id(),
|
||||
args,
|
||||
);
|
||||
.apply_closure_requirements(closure_requirements, def_id.to_def_id(), args);
|
||||
}
|
||||
|
||||
// Now equate closure args to regions inherited from `typeck_root_def_id`. Fixes #98589.
|
||||
@ -2714,7 +2710,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
debug!(?body.span);
|
||||
|
||||
for (local, local_decl) in body.local_decls.iter_enumerated() {
|
||||
self.check_local(&body, local, local_decl);
|
||||
self.check_local(body, local, local_decl);
|
||||
}
|
||||
|
||||
for (block, block_data) in body.basic_blocks.iter_enumerated() {
|
||||
@ -2727,8 +2723,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
location.statement_index += 1;
|
||||
}
|
||||
|
||||
self.check_terminator(&body, block_data.terminator(), location);
|
||||
self.check_iscleanup(&body, block_data);
|
||||
self.check_terminator(body, block_data.terminator(), location);
|
||||
self.check_iscleanup(body, block_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
never_initialized_mut_locals: &mut never_initialized_mut_locals,
|
||||
mbcx: self,
|
||||
};
|
||||
visitor.visit_body(&visitor.mbcx.body);
|
||||
visitor.visit_body(visitor.mbcx.body);
|
||||
}
|
||||
|
||||
// Take the union of the existed `used_mut` set with those variables we've found were
|
||||
|
@ -47,7 +47,7 @@ impl MultiItemModifier for Expander {
|
||||
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
|
||||
validate_attr::check_builtin_meta_item(
|
||||
&ecx.sess.parse_sess,
|
||||
&meta_item,
|
||||
meta_item,
|
||||
ast::AttrStyle::Outer,
|
||||
sym::cfg_accessible,
|
||||
template,
|
||||
|
@ -25,7 +25,7 @@ pub(crate) fn expand(
|
||||
annotatable: Annotatable,
|
||||
) -> Vec<Annotatable> {
|
||||
check_builtin_macro_attribute(ecx, meta_item, sym::cfg_eval);
|
||||
warn_on_duplicate_attribute(&ecx, &annotatable, sym::cfg_eval);
|
||||
warn_on_duplicate_attribute(ecx, &annotatable, sym::cfg_eval);
|
||||
vec![cfg_eval(ecx.sess, ecx.ecfg.features, annotatable, ecx.current_expansion.lint_node_id)]
|
||||
}
|
||||
|
||||
@ -95,19 +95,19 @@ impl CfgFinder {
|
||||
fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
|
||||
let mut finder = CfgFinder { has_cfg_or_cfg_attr: false };
|
||||
match annotatable {
|
||||
Annotatable::Item(item) => finder.visit_item(&item),
|
||||
Annotatable::TraitItem(item) => finder.visit_assoc_item(&item, visit::AssocCtxt::Trait),
|
||||
Annotatable::ImplItem(item) => finder.visit_assoc_item(&item, visit::AssocCtxt::Impl),
|
||||
Annotatable::ForeignItem(item) => finder.visit_foreign_item(&item),
|
||||
Annotatable::Stmt(stmt) => finder.visit_stmt(&stmt),
|
||||
Annotatable::Expr(expr) => finder.visit_expr(&expr),
|
||||
Annotatable::Arm(arm) => finder.visit_arm(&arm),
|
||||
Annotatable::ExprField(field) => finder.visit_expr_field(&field),
|
||||
Annotatable::PatField(field) => finder.visit_pat_field(&field),
|
||||
Annotatable::GenericParam(param) => finder.visit_generic_param(¶m),
|
||||
Annotatable::Param(param) => finder.visit_param(¶m),
|
||||
Annotatable::FieldDef(field) => finder.visit_field_def(&field),
|
||||
Annotatable::Variant(variant) => finder.visit_variant(&variant),
|
||||
Annotatable::Item(item) => finder.visit_item(item),
|
||||
Annotatable::TraitItem(item) => finder.visit_assoc_item(item, visit::AssocCtxt::Trait),
|
||||
Annotatable::ImplItem(item) => finder.visit_assoc_item(item, visit::AssocCtxt::Impl),
|
||||
Annotatable::ForeignItem(item) => finder.visit_foreign_item(item),
|
||||
Annotatable::Stmt(stmt) => finder.visit_stmt(stmt),
|
||||
Annotatable::Expr(expr) => finder.visit_expr(expr),
|
||||
Annotatable::Arm(arm) => finder.visit_arm(arm),
|
||||
Annotatable::ExprField(field) => finder.visit_expr_field(field),
|
||||
Annotatable::PatField(field) => finder.visit_pat_field(field),
|
||||
Annotatable::GenericParam(param) => finder.visit_generic_param(param),
|
||||
Annotatable::Param(param) => finder.visit_param(param),
|
||||
Annotatable::FieldDef(field) => finder.visit_field_def(field),
|
||||
Annotatable::Variant(variant) => finder.visit_variant(variant),
|
||||
Annotatable::Crate(krate) => finder.visit_crate(krate),
|
||||
};
|
||||
finder.has_cfg_or_cfg_attr
|
||||
|
@ -11,7 +11,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
|
||||
for raw_attr in attrs {
|
||||
let mut parser = rustc_parse::new_parser_from_source_str(
|
||||
parse_sess,
|
||||
FileName::cli_crate_attr_source_code(&raw_attr),
|
||||
FileName::cli_crate_attr_source_code(raw_attr),
|
||||
raw_attr.clone(),
|
||||
);
|
||||
|
||||
|
@ -159,7 +159,7 @@ pub fn expand_concat_bytes(
|
||||
accumulator.push(val);
|
||||
}
|
||||
Ok(ast::LitKind::ByteStr(ref bytes, _)) => {
|
||||
accumulator.extend_from_slice(&bytes);
|
||||
accumulator.extend_from_slice(bytes);
|
||||
}
|
||||
_ => {
|
||||
if !has_errors {
|
||||
|
@ -35,7 +35,7 @@ impl MultiItemModifier for Expander {
|
||||
AttributeTemplate { list: Some("Trait1, Trait2, ..."), ..Default::default() };
|
||||
validate_attr::check_builtin_meta_item(
|
||||
&sess.parse_sess,
|
||||
&meta_item,
|
||||
meta_item,
|
||||
ast::AttrStyle::Outer,
|
||||
sym::derive,
|
||||
template,
|
||||
@ -48,14 +48,14 @@ impl MultiItemModifier for Expander {
|
||||
NestedMetaItem::MetaItem(meta) => Some(meta),
|
||||
NestedMetaItem::Lit(lit) => {
|
||||
// Reject `#[derive("Debug")]`.
|
||||
report_unexpected_meta_item_lit(sess, &lit);
|
||||
report_unexpected_meta_item_lit(sess, lit);
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|meta| {
|
||||
// Reject `#[derive(Debug = "value", Debug(abc))]`, but recover the
|
||||
// paths.
|
||||
report_path_args(sess, &meta);
|
||||
report_path_args(sess, meta);
|
||||
meta.path.clone()
|
||||
})
|
||||
.map(|path| (path, dummy_annotatable(), None, self.0))
|
||||
|
@ -467,7 +467,7 @@ impl<'a> TraitDef<'a> {
|
||||
match item {
|
||||
Annotatable::Item(item) => {
|
||||
let is_packed = item.attrs.iter().any(|attr| {
|
||||
for r in attr::find_repr_attrs(&cx.sess, attr) {
|
||||
for r in attr::find_repr_attrs(cx.sess, attr) {
|
||||
if let attr::ReprPacked(_) = r {
|
||||
return true;
|
||||
}
|
||||
@ -478,7 +478,7 @@ impl<'a> TraitDef<'a> {
|
||||
let newitem = match &item.kind {
|
||||
ast::ItemKind::Struct(struct_def, generics) => self.expand_struct_def(
|
||||
cx,
|
||||
&struct_def,
|
||||
struct_def,
|
||||
item.ident,
|
||||
generics,
|
||||
from_scratch,
|
||||
@ -496,7 +496,7 @@ impl<'a> TraitDef<'a> {
|
||||
if self.supports_unions {
|
||||
self.expand_struct_def(
|
||||
cx,
|
||||
&struct_def,
|
||||
struct_def,
|
||||
item.ident,
|
||||
generics,
|
||||
from_scratch,
|
||||
|
@ -182,7 +182,7 @@ impl Bounds {
|
||||
let params = self
|
||||
.bounds
|
||||
.iter()
|
||||
.map(|&(name, ref bounds)| mk_ty_param(cx, span, name, &bounds, self_ty, self_generics))
|
||||
.map(|&(name, ref bounds)| mk_ty_param(cx, span, name, bounds, self_ty, self_generics))
|
||||
.collect();
|
||||
|
||||
Generics {
|
||||
|
@ -547,7 +547,7 @@ fn make_format_args(
|
||||
span: arg_name.span.into(),
|
||||
msg: format!("named argument `{}` is not used by name", arg_name.name).into(),
|
||||
node_id: rustc_ast::CRATE_NODE_ID,
|
||||
lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
|
||||
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
|
||||
diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally {
|
||||
position_sp_to_replace,
|
||||
position_sp_for_msg,
|
||||
@ -632,8 +632,7 @@ fn report_missing_placeholders(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !placeholders.is_empty() {
|
||||
if let Some(mut new_diag) =
|
||||
report_redundant_format_arguments(ecx, &args, used, placeholders)
|
||||
if let Some(mut new_diag) = report_redundant_format_arguments(ecx, args, used, placeholders)
|
||||
{
|
||||
diag.cancel();
|
||||
new_diag.emit();
|
||||
|
@ -133,7 +133,7 @@ pub fn expand_include<'cx>(
|
||||
let r = base::parse_expr(&mut self.p)?;
|
||||
if self.p.token != token::Eof {
|
||||
self.p.sess.buffer_lint(
|
||||
&INCOMPLETE_INCLUDE,
|
||||
INCOMPLETE_INCLUDE,
|
||||
self.p.token.span,
|
||||
self.node_id,
|
||||
"include macro expected single expression in source",
|
||||
@ -189,7 +189,7 @@ pub fn expand_include_str(
|
||||
match cx.source_map().load_binary_file(&file) {
|
||||
Ok(bytes) => match std::str::from_utf8(&bytes) {
|
||||
Ok(src) => {
|
||||
let interned_src = Symbol::intern(&src);
|
||||
let interned_src = Symbol::intern(src);
|
||||
base::MacEager::expr(cx.expr_str(sp, interned_src))
|
||||
}
|
||||
Err(_) => {
|
||||
|
@ -26,7 +26,7 @@ pub fn expand_test_case(
|
||||
anno_item: Annotatable,
|
||||
) -> Vec<Annotatable> {
|
||||
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
|
||||
warn_on_duplicate_attribute(&ecx, &anno_item, sym::test_case);
|
||||
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
|
||||
|
||||
if !ecx.ecfg.should_test {
|
||||
return vec![];
|
||||
@ -79,7 +79,7 @@ pub fn expand_test(
|
||||
item: Annotatable,
|
||||
) -> Vec<Annotatable> {
|
||||
check_builtin_macro_attribute(cx, meta_item, sym::test);
|
||||
warn_on_duplicate_attribute(&cx, &item, sym::test);
|
||||
warn_on_duplicate_attribute(cx, &item, sym::test);
|
||||
expand_test_or_bench(cx, attr_sp, item, false)
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ pub fn expand_bench(
|
||||
item: Annotatable,
|
||||
) -> Vec<Annotatable> {
|
||||
check_builtin_macro_attribute(cx, meta_item, sym::bench);
|
||||
warn_on_duplicate_attribute(&cx, &item, sym::bench);
|
||||
warn_on_duplicate_attribute(cx, &item, sym::bench);
|
||||
expand_test_or_bench(cx, attr_sp, item, true)
|
||||
}
|
||||
|
||||
@ -134,9 +134,9 @@ pub fn expand_test_or_bench(
|
||||
// will fail. We shouldn't try to expand in this case because the errors
|
||||
// would be spurious.
|
||||
let check_result = if is_bench {
|
||||
check_bench_signature(cx, &item, &fn_)
|
||||
check_bench_signature(cx, &item, fn_)
|
||||
} else {
|
||||
check_test_signature(cx, &item, &fn_)
|
||||
check_test_signature(cx, &item, fn_)
|
||||
};
|
||||
if check_result.is_err() {
|
||||
return if is_stmt {
|
||||
|
@ -60,7 +60,7 @@ pub fn inject(
|
||||
|
||||
// Do this here so that the test_runner crate attribute gets marked as used
|
||||
// even in non-test builds
|
||||
let test_runner = get_test_runner(span_diagnostic, &krate);
|
||||
let test_runner = get_test_runner(span_diagnostic, krate);
|
||||
|
||||
if sess.is_test_crate() {
|
||||
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
|
||||
@ -372,7 +372,7 @@ fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
|
||||
let ecx = &cx.ext_cx;
|
||||
|
||||
let mut tests = cx.test_cases.clone();
|
||||
tests.sort_by(|a, b| a.name.as_str().cmp(&b.name.as_str()));
|
||||
tests.sort_by(|a, b| a.name.as_str().cmp(b.name.as_str()));
|
||||
|
||||
ecx.expr_array_ref(
|
||||
sp,
|
||||
|
@ -10,7 +10,7 @@ pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, na
|
||||
let template = AttributeTemplate { word: true, ..Default::default() };
|
||||
validate_attr::check_builtin_meta_item(
|
||||
&ecx.sess.parse_sess,
|
||||
&meta_item,
|
||||
meta_item,
|
||||
AttrStyle::Outer,
|
||||
name,
|
||||
template,
|
||||
|
@ -10,7 +10,7 @@ test = false
|
||||
# tidy-alphabetical-start
|
||||
bitflags = "1.0"
|
||||
cstr = "0.2"
|
||||
itertools = "0.10.5"
|
||||
itertools = "0.11"
|
||||
libc = "0.2"
|
||||
measureme = "10.0.0"
|
||||
object = { version = "0.32.0", default-features = false, features = ["std", "read"] }
|
||||
|
@ -493,7 +493,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
|
||||
PassMode::Cast { cast, pad_i32: _ } => {
|
||||
cast.attrs.apply_attrs_to_callsite(
|
||||
llvm::AttributePlace::ReturnValue,
|
||||
&bx.cx,
|
||||
bx.cx,
|
||||
callsite,
|
||||
);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ pub(crate) unsafe fn codegen(
|
||||
llcx,
|
||||
llmod,
|
||||
"__rust_alloc_error_handler",
|
||||
&alloc_error_handler_name(alloc_error_handler_kind),
|
||||
alloc_error_handler_name(alloc_error_handler_kind),
|
||||
&[usize, usize], // size, align
|
||||
None,
|
||||
true,
|
||||
|
@ -136,7 +136,7 @@ fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'ll Attr
|
||||
attrs.push(llvm::CreateAttrStringValue(
|
||||
cx.llcx,
|
||||
"instrument-function-entry-inlined",
|
||||
&mcount_name,
|
||||
mcount_name,
|
||||
));
|
||||
}
|
||||
if let Some(options) = &cx.sess().opts.unstable_opts.instrument_xray {
|
||||
@ -459,7 +459,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
|
||||
// If this function is an import from the environment but the wasm
|
||||
// import has a specific module/name, apply them here.
|
||||
if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) {
|
||||
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-module", &module));
|
||||
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-module", module));
|
||||
|
||||
let name =
|
||||
codegen_fn_attrs.link_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
|
||||
|
@ -68,7 +68,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
|
||||
) -> io::Result<()> {
|
||||
let mut archive = archive.to_path_buf();
|
||||
if self.sess.target.llvm_target.contains("-apple-macosx") {
|
||||
if let Some(new_archive) = try_extract_macho_fat_archive(&self.sess, &archive)? {
|
||||
if let Some(new_archive) = try_extract_macho_fat_archive(self.sess, &archive)? {
|
||||
archive = new_archive
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMach
|
||||
let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file };
|
||||
|
||||
target_machine_factory(
|
||||
&tcx.sess,
|
||||
tcx.sess,
|
||||
tcx.backend_optimization_level(()),
|
||||
tcx.global_backend_features(()),
|
||||
)(config)
|
||||
@ -1106,7 +1106,7 @@ fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Modu
|
||||
}
|
||||
|
||||
let raw_stats =
|
||||
llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(&llmod, s) })
|
||||
llvm::build_string(|s| unsafe { llvm::LLVMRustModuleInstructionStats(llmod, s) })
|
||||
.expect("cannot get module instruction stats");
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
|
@ -62,7 +62,7 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
|
||||
// exemption for MinGW for backwards compatibility.
|
||||
let llfn = cx.declare_fn(
|
||||
&common::i686_decorated_name(
|
||||
&dllimport,
|
||||
dllimport,
|
||||
common::is_mingw_gnu_toolchain(&tcx.sess.target),
|
||||
true,
|
||||
),
|
||||
|
@ -187,7 +187,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
|
||||
{
|
||||
cx.declare_global(
|
||||
&common::i686_decorated_name(
|
||||
&dllimport,
|
||||
dllimport,
|
||||
common::is_mingw_gnu_toolchain(&cx.tcx.sess.target),
|
||||
true,
|
||||
),
|
||||
|
@ -351,6 +351,16 @@ pub unsafe fn create_module<'ll>(
|
||||
);
|
||||
}
|
||||
|
||||
// Set module flag to enable Windows EHCont Guard (/guard:ehcont).
|
||||
if sess.opts.unstable_opts.ehcont_guard {
|
||||
llvm::LLVMRustAddModuleFlag(
|
||||
llmod,
|
||||
llvm::LLVMModFlagBehavior::Warning,
|
||||
"ehcontguard\0".as_ptr() as *const _,
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
||||
// Insert `llvm.ident` metadata.
|
||||
//
|
||||
// On the wasm targets it will get hooked up to the "producer" sections
|
||||
|
@ -176,7 +176,7 @@ impl GlobalFileTable {
|
||||
// compilation directory can be combined with the relative paths
|
||||
// to get absolute paths, if needed.
|
||||
use rustc_session::RemapFileNameExt;
|
||||
let working_dir: &str = &tcx.sess.opts.working_dir.for_codegen(&tcx.sess).to_string_lossy();
|
||||
let working_dir: &str = &tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
|
||||
|
||||
llvm::build_byte_buffer(|buffer| {
|
||||
coverageinfo::write_filenames_section_to_buffer(
|
||||
@ -189,8 +189,6 @@ impl GlobalFileTable {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
// Tell the newtype macro to not generate `Encode`/`Decode` impls.
|
||||
#[custom_encodable]
|
||||
struct LocalFileId {}
|
||||
}
|
||||
|
||||
|
@ -853,7 +853,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||
|
||||
use rustc_session::RemapFileNameExt;
|
||||
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
|
||||
let work_dir = tcx.sess.opts.working_dir.for_codegen(&tcx.sess).to_string_lossy();
|
||||
let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
|
||||
let flags = "\0";
|
||||
let output_filenames = tcx.output_filenames(());
|
||||
let split_name = if tcx.sess.target_can_use_split_dwarf() {
|
||||
|
@ -715,7 +715,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>(
|
||||
coroutine_type_and_layout,
|
||||
coroutine_type_di_node,
|
||||
coroutine_layout,
|
||||
&common_upvar_names,
|
||||
common_upvar_names,
|
||||
);
|
||||
|
||||
let span = coroutine_layout.variant_source_info[variant_index].span;
|
||||
|
@ -197,7 +197,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
|
||||
coroutine_type_and_layout,
|
||||
coroutine_type_di_node,
|
||||
coroutine_layout,
|
||||
&common_upvar_names,
|
||||
common_upvar_names,
|
||||
),
|
||||
source_info,
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ struct TimeTraceProfiler {
|
||||
impl TimeTraceProfiler {
|
||||
fn new(enabled: bool) -> Self {
|
||||
if enabled {
|
||||
unsafe { llvm::LLVMTimeTraceProfilerInitialize() }
|
||||
unsafe { llvm::LLVMRustTimeTraceProfilerInitialize() }
|
||||
}
|
||||
TimeTraceProfiler { enabled }
|
||||
}
|
||||
@ -113,7 +113,7 @@ impl TimeTraceProfiler {
|
||||
impl Drop for TimeTraceProfiler {
|
||||
fn drop(&mut self) {
|
||||
if self.enabled {
|
||||
unsafe { llvm::LLVMTimeTraceProfilerFinishThread() }
|
||||
unsafe { llvm::LLVMRustTimeTraceProfilerFinishThread() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -823,11 +823,7 @@ pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -
|
||||
pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
|
||||
|
||||
extern "C" {
|
||||
pub fn LLVMRustInstallFatalErrorHandler();
|
||||
pub fn LLVMRustDisableSystemDialogsOnCrash();
|
||||
|
||||
// Create and destroy contexts.
|
||||
pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
|
||||
pub fn LLVMContextDispose(C: &'static mut Context);
|
||||
pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
|
||||
|
||||
@ -843,9 +839,6 @@ extern "C" {
|
||||
/// See Module::setModuleInlineAsm.
|
||||
pub fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
|
||||
|
||||
/// See llvm::LLVMTypeKind::getTypeID.
|
||||
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
|
||||
|
||||
// Operations on integer types
|
||||
pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
|
||||
pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
|
||||
@ -879,7 +872,6 @@ extern "C" {
|
||||
) -> &'a Type;
|
||||
|
||||
// Operations on array, pointer, and vector types (sequence types)
|
||||
pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
|
||||
pub fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type;
|
||||
pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
|
||||
|
||||
@ -898,10 +890,8 @@ extern "C" {
|
||||
pub fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
|
||||
pub fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Node: &'a Value);
|
||||
pub fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
|
||||
pub fn LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
|
||||
pub fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
|
||||
pub fn LLVMIsAFunction(Val: &Value) -> Option<&Value>;
|
||||
pub fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;
|
||||
|
||||
// Operations on constants of any type
|
||||
pub fn LLVMConstNull(Ty: &Type) -> &Value;
|
||||
@ -931,13 +921,6 @@ extern "C" {
|
||||
pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
|
||||
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
|
||||
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
|
||||
pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
|
||||
pub fn LLVMRustConstInt128Get(
|
||||
ConstantVal: &ConstantInt,
|
||||
SExt: bool,
|
||||
high: &mut u64,
|
||||
low: &mut u64,
|
||||
) -> bool;
|
||||
|
||||
// Operations on composite constants
|
||||
pub fn LLVMConstStringInContext(
|
||||
@ -977,12 +960,7 @@ extern "C" {
|
||||
|
||||
// Operations on global variables, functions, and aliases (globals)
|
||||
pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
|
||||
pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
|
||||
pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
|
||||
pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
|
||||
pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
|
||||
pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
|
||||
pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
|
||||
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
|
||||
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
|
||||
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
|
||||
@ -991,13 +969,6 @@ extern "C" {
|
||||
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
|
||||
pub fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
|
||||
pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
|
||||
pub fn LLVMRustGetOrInsertGlobal<'a>(
|
||||
M: &'a Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
T: &'a Type,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
|
||||
pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
|
||||
pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
|
||||
pub fn LLVMDeleteGlobal(GlobalVar: &Value);
|
||||
@ -1007,16 +978,9 @@ extern "C" {
|
||||
pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
|
||||
pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
|
||||
pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
|
||||
pub fn LLVMRustGetNamedValue(
|
||||
M: &Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
) -> Option<&Value>;
|
||||
pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
|
||||
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);
|
||||
|
||||
// Operations on attributes
|
||||
pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
|
||||
pub fn LLVMCreateStringAttribute(
|
||||
C: &Context,
|
||||
Name: *const c_char,
|
||||
@ -1024,31 +988,9 @@ extern "C" {
|
||||
Value: *const c_char,
|
||||
ValueLen: c_uint,
|
||||
) -> &Attribute;
|
||||
pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
|
||||
pub fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
|
||||
pub fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateMemoryEffectsAttr(C: &Context, effects: MemoryEffects) -> &Attribute;
|
||||
|
||||
// Operations on functions
|
||||
pub fn LLVMRustGetOrInsertFunction<'a>(
|
||||
M: &'a Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
FunctionTy: &'a Type,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
|
||||
pub fn LLVMRustAddFunctionAttributes<'a>(
|
||||
Fn: &'a Value,
|
||||
index: c_uint,
|
||||
Attrs: *const &'a Attribute,
|
||||
AttrsLen: size_t,
|
||||
);
|
||||
|
||||
// Operations on parameters
|
||||
pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
|
||||
@ -1069,12 +1011,6 @@ extern "C" {
|
||||
|
||||
// Operations on call sites
|
||||
pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
|
||||
pub fn LLVMRustAddCallSiteAttributes<'a>(
|
||||
Instr: &'a Value,
|
||||
index: c_uint,
|
||||
Attrs: *const &'a Attribute,
|
||||
AttrsLen: size_t,
|
||||
);
|
||||
|
||||
// Operations on load/store instructions (only)
|
||||
pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
|
||||
@ -1112,18 +1048,6 @@ extern "C" {
|
||||
Else: &'a BasicBlock,
|
||||
NumCases: c_uint,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildInvoke<'a>(
|
||||
B: &Builder<'a>,
|
||||
Ty: &'a Type,
|
||||
Fn: &'a Value,
|
||||
Args: *const &'a Value,
|
||||
NumArgs: c_uint,
|
||||
Then: &'a BasicBlock,
|
||||
Catch: &'a BasicBlock,
|
||||
OpBundles: *const &OperandBundleDef<'a>,
|
||||
NumOpBundles: c_uint,
|
||||
Name: *const c_char,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMBuildLandingPad<'a>(
|
||||
B: &Builder<'a>,
|
||||
Ty: &'a Type,
|
||||
@ -1337,7 +1261,6 @@ extern "C" {
|
||||
pub fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
|
||||
pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
|
||||
pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
|
||||
pub fn LLVMRustSetFastMath(Instr: &Value);
|
||||
|
||||
// Memory
|
||||
pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
|
||||
@ -1485,42 +1408,6 @@ extern "C" {
|
||||
|
||||
// Miscellaneous instructions
|
||||
pub fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
|
||||
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
|
||||
pub fn LLVMRustBuildCall<'a>(
|
||||
B: &Builder<'a>,
|
||||
Ty: &'a Type,
|
||||
Fn: &'a Value,
|
||||
Args: *const &'a Value,
|
||||
NumArgs: c_uint,
|
||||
OpBundles: *const &OperandBundleDef<'a>,
|
||||
NumOpBundles: c_uint,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemCpy<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Src: &'a Value,
|
||||
SrcAlign: c_uint,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemMove<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Src: &'a Value,
|
||||
SrcAlign: c_uint,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemSet<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Val: &'a Value,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMBuildSelect<'a>(
|
||||
B: &Builder<'a>,
|
||||
If: &'a Value,
|
||||
@ -1568,6 +1455,202 @@ extern "C" {
|
||||
Name: *const c_char,
|
||||
) -> &'a Value;
|
||||
|
||||
// Atomic Operations
|
||||
pub fn LLVMBuildAtomicCmpXchg<'a>(
|
||||
B: &Builder<'a>,
|
||||
LHS: &'a Value,
|
||||
CMP: &'a Value,
|
||||
RHS: &'a Value,
|
||||
Order: AtomicOrdering,
|
||||
FailureOrder: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
|
||||
|
||||
pub fn LLVMBuildAtomicRMW<'a>(
|
||||
B: &Builder<'a>,
|
||||
Op: AtomicRmwBinOp,
|
||||
LHS: &'a Value,
|
||||
RHS: &'a Value,
|
||||
Order: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMBuildFence<'a>(
|
||||
B: &Builder<'a>,
|
||||
Order: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
Name: *const c_char,
|
||||
) -> &'a Value;
|
||||
|
||||
/// Writes a module to the specified path. Returns 0 on success.
|
||||
pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
|
||||
|
||||
/// Creates a legacy pass manager -- only used for final codegen.
|
||||
pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
|
||||
|
||||
pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
|
||||
|
||||
pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
|
||||
|
||||
pub fn LLVMDisposeMessage(message: *mut c_char);
|
||||
|
||||
pub fn LLVMIsMultithreaded() -> Bool;
|
||||
|
||||
pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
|
||||
|
||||
pub fn LLVMStructSetBody<'a>(
|
||||
StructTy: &'a Type,
|
||||
ElementTypes: *const &'a Type,
|
||||
ElementCount: c_uint,
|
||||
Packed: Bool,
|
||||
);
|
||||
|
||||
pub fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
||||
|
||||
pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
|
||||
|
||||
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
|
||||
}
|
||||
|
||||
#[link(name = "llvm-wrapper", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn LLVMRustInstallFatalErrorHandler();
|
||||
pub fn LLVMRustDisableSystemDialogsOnCrash();
|
||||
|
||||
// Create and destroy contexts.
|
||||
pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
|
||||
|
||||
/// See llvm::LLVMTypeKind::getTypeID.
|
||||
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
|
||||
|
||||
// Operations on array, pointer, and vector types (sequence types)
|
||||
pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
|
||||
|
||||
// Operations on all values
|
||||
pub fn LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
|
||||
pub fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;
|
||||
|
||||
// Operations on scalar constants
|
||||
pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
|
||||
pub fn LLVMRustConstInt128Get(
|
||||
ConstantVal: &ConstantInt,
|
||||
SExt: bool,
|
||||
high: &mut u64,
|
||||
low: &mut u64,
|
||||
) -> bool;
|
||||
|
||||
// Operations on global variables, functions, and aliases (globals)
|
||||
pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
|
||||
pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
|
||||
pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
|
||||
pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
|
||||
pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
|
||||
|
||||
// Operations on global variables
|
||||
pub fn LLVMRustGetOrInsertGlobal<'a>(
|
||||
M: &'a Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
T: &'a Type,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
|
||||
pub fn LLVMRustGetNamedValue(
|
||||
M: &Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
) -> Option<&Value>;
|
||||
pub fn LLVMRustSetTailCallKind(CallInst: &Value, TKC: TailCallKind);
|
||||
|
||||
// Operations on attributes
|
||||
pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
|
||||
pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
|
||||
pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
|
||||
pub fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
|
||||
pub fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
|
||||
pub fn LLVMRustCreateMemoryEffectsAttr(C: &Context, effects: MemoryEffects) -> &Attribute;
|
||||
|
||||
// Operations on functions
|
||||
pub fn LLVMRustGetOrInsertFunction<'a>(
|
||||
M: &'a Module,
|
||||
Name: *const c_char,
|
||||
NameLen: size_t,
|
||||
FunctionTy: &'a Type,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustAddFunctionAttributes<'a>(
|
||||
Fn: &'a Value,
|
||||
index: c_uint,
|
||||
Attrs: *const &'a Attribute,
|
||||
AttrsLen: size_t,
|
||||
);
|
||||
|
||||
// Operations on call sites
|
||||
pub fn LLVMRustAddCallSiteAttributes<'a>(
|
||||
Instr: &'a Value,
|
||||
index: c_uint,
|
||||
Attrs: *const &'a Attribute,
|
||||
AttrsLen: size_t,
|
||||
);
|
||||
|
||||
pub fn LLVMRustBuildInvoke<'a>(
|
||||
B: &Builder<'a>,
|
||||
Ty: &'a Type,
|
||||
Fn: &'a Value,
|
||||
Args: *const &'a Value,
|
||||
NumArgs: c_uint,
|
||||
Then: &'a BasicBlock,
|
||||
Catch: &'a BasicBlock,
|
||||
OpBundles: *const &OperandBundleDef<'a>,
|
||||
NumOpBundles: c_uint,
|
||||
Name: *const c_char,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMRustSetFastMath(Instr: &Value);
|
||||
|
||||
// Miscellaneous instructions
|
||||
pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
|
||||
pub fn LLVMRustBuildCall<'a>(
|
||||
B: &Builder<'a>,
|
||||
Ty: &'a Type,
|
||||
Fn: &'a Value,
|
||||
Args: *const &'a Value,
|
||||
NumArgs: c_uint,
|
||||
OpBundles: *const &OperandBundleDef<'a>,
|
||||
NumOpBundles: c_uint,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemCpy<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Src: &'a Value,
|
||||
SrcAlign: c_uint,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemMove<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Src: &'a Value,
|
||||
SrcAlign: c_uint,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustBuildMemSet<'a>(
|
||||
B: &Builder<'a>,
|
||||
Dst: &'a Value,
|
||||
DstAlign: c_uint,
|
||||
Val: &'a Value,
|
||||
Size: &'a Value,
|
||||
IsVolatile: bool,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMRustBuildVectorReduceFAdd<'a>(
|
||||
B: &Builder<'a>,
|
||||
Acc: &'a Value,
|
||||
@ -1623,53 +1706,11 @@ extern "C" {
|
||||
Order: AtomicOrdering,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMBuildAtomicCmpXchg<'a>(
|
||||
B: &Builder<'a>,
|
||||
LHS: &'a Value,
|
||||
CMP: &'a Value,
|
||||
RHS: &'a Value,
|
||||
Order: AtomicOrdering,
|
||||
FailureOrder: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
) -> &'a Value;
|
||||
pub fn LLVMRustTimeTraceProfilerInitialize();
|
||||
|
||||
pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
|
||||
pub fn LLVMRustTimeTraceProfilerFinishThread();
|
||||
|
||||
pub fn LLVMBuildAtomicRMW<'a>(
|
||||
B: &Builder<'a>,
|
||||
Op: AtomicRmwBinOp,
|
||||
LHS: &'a Value,
|
||||
RHS: &'a Value,
|
||||
Order: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
) -> &'a Value;
|
||||
|
||||
pub fn LLVMBuildFence<'a>(
|
||||
B: &Builder<'a>,
|
||||
Order: AtomicOrdering,
|
||||
SingleThreaded: Bool,
|
||||
Name: *const c_char,
|
||||
) -> &'a Value;
|
||||
|
||||
/// Writes a module to the specified path. Returns 0 on success.
|
||||
pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
|
||||
|
||||
/// Creates a legacy pass manager -- only used for final codegen.
|
||||
pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
|
||||
|
||||
pub fn LLVMTimeTraceProfilerInitialize();
|
||||
|
||||
pub fn LLVMTimeTraceProfilerFinishThread();
|
||||
|
||||
pub fn LLVMTimeTraceProfilerFinish(FileName: *const c_char);
|
||||
|
||||
pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
|
||||
|
||||
pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
|
||||
|
||||
pub fn LLVMDisposeMessage(message: *mut c_char);
|
||||
|
||||
pub fn LLVMIsMultithreaded() -> Bool;
|
||||
pub fn LLVMRustTimeTraceProfilerFinish(FileName: *const c_char);
|
||||
|
||||
/// Returns a string describing the last error caused by an LLVMRust* call.
|
||||
pub fn LLVMRustGetLastError() -> *const c_char;
|
||||
@ -1680,15 +1721,6 @@ extern "C" {
|
||||
/// Print the statistics since static dtors aren't picking them up.
|
||||
pub fn LLVMRustPrintStatistics(size: *const size_t) -> *const c_char;
|
||||
|
||||
pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
|
||||
|
||||
pub fn LLVMStructSetBody<'a>(
|
||||
StructTy: &'a Type,
|
||||
ElementTypes: *const &'a Type,
|
||||
ElementCount: c_uint,
|
||||
Packed: Bool,
|
||||
);
|
||||
|
||||
/// Prepares inline assembly.
|
||||
pub fn LLVMRustInlineAsm(
|
||||
Ty: &Type,
|
||||
@ -1761,8 +1793,6 @@ extern "C" {
|
||||
);
|
||||
pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;
|
||||
|
||||
pub fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
|
||||
|
||||
pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
|
||||
|
||||
pub fn LLVMRustDIBuilderDispose<'a>(Builder: &'a mut DIBuilder<'a>);
|
||||
@ -2052,8 +2082,6 @@ extern "C" {
|
||||
UniqueIdLen: size_t,
|
||||
) -> &'a DIDerivedType;
|
||||
|
||||
pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
|
||||
|
||||
pub fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
|
||||
Builder: &DIBuilder<'a>,
|
||||
Scope: Option<&'a DIScope>,
|
||||
@ -2092,8 +2120,6 @@ extern "C" {
|
||||
#[allow(improper_ctypes)]
|
||||
pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
|
||||
|
||||
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
|
||||
|
||||
pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
|
||||
|
||||
pub fn LLVMRustPrintTargetCPUs(
|
||||
|
@ -121,7 +121,7 @@ unsafe fn configure_llvm(sess: &Session) {
|
||||
}
|
||||
|
||||
if sess.opts.unstable_opts.llvm_time_trace {
|
||||
llvm::LLVMTimeTraceProfilerInitialize();
|
||||
llvm::LLVMRustTimeTraceProfilerInitialize();
|
||||
}
|
||||
|
||||
rustc_llvm::initialize_available_targets();
|
||||
@ -132,7 +132,7 @@ unsafe fn configure_llvm(sess: &Session) {
|
||||
pub fn time_trace_profiler_finish(file_name: &Path) {
|
||||
unsafe {
|
||||
let file_name = path_to_c_string(file_name);
|
||||
llvm::LLVMTimeTraceProfilerFinish(file_name.as_ptr());
|
||||
llvm::LLVMRustTimeTraceProfilerFinish(file_name.as_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,8 +537,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
||||
if feature_state.is_none() {
|
||||
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
|
||||
let llvm_features = to_llvm_features(sess, rust_feature);
|
||||
if llvm_features.contains(&feature)
|
||||
&& !llvm_features.contains(&rust_feature)
|
||||
if llvm_features.contains(feature) && !llvm_features.contains(rust_feature)
|
||||
{
|
||||
Some(rust_feature)
|
||||
} else {
|
||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
||||
ar_archive_writer = "0.1.5"
|
||||
bitflags = "1.2.1"
|
||||
cc = "1.0.69"
|
||||
itertools = "0.10.1"
|
||||
itertools = "0.11"
|
||||
jobserver = "0.1.22"
|
||||
pathdiff = "0.2.0"
|
||||
regex = "1.4"
|
||||
|
@ -149,7 +149,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
|
||||
|
||||
self.cgu_reuse_tracker.set_expectation(
|
||||
cgu_name,
|
||||
&user_path,
|
||||
user_path,
|
||||
attr.span,
|
||||
expected_reuse,
|
||||
comp_kind,
|
||||
|
@ -175,8 +175,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
|
||||
) -> io::Result<()> {
|
||||
let mut archive_path = archive_path.to_path_buf();
|
||||
if self.sess.target.llvm_target.contains("-apple-macosx") {
|
||||
if let Some(new_archive_path) =
|
||||
try_extract_macho_fat_archive(&self.sess, &archive_path)?
|
||||
if let Some(new_archive_path) = try_extract_macho_fat_archive(self.sess, &archive_path)?
|
||||
{
|
||||
archive_path = new_archive_path
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ pub fn each_linked_rlib(
|
||||
let crate_name = info.crate_name[&cnum];
|
||||
let used_crate_source = &info.used_crate_source[&cnum];
|
||||
if let Some((path, _)) = &used_crate_source.rlib {
|
||||
f(cnum, &path);
|
||||
f(cnum, path);
|
||||
} else {
|
||||
if used_crate_source.rmeta.is_some() {
|
||||
return Err(errors::LinkRlibError::OnlyRmetaFound { crate_name });
|
||||
@ -524,7 +524,7 @@ fn link_staticlib<'a>(
|
||||
&& !ignored_for_lto(sess, &codegen_results.crate_info, cnum);
|
||||
|
||||
let native_libs = codegen_results.crate_info.native_libraries[&cnum].iter();
|
||||
let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, &lib));
|
||||
let relevant = native_libs.clone().filter(|lib| relevant_lib(sess, lib));
|
||||
let relevant_libs: FxHashSet<_> = relevant.filter_map(|lib| lib.filename).collect();
|
||||
|
||||
let bundled_libs: FxHashSet<_> = native_libs.filter_map(|lib| lib.filename).collect();
|
||||
@ -689,7 +689,7 @@ fn link_dwarf_object<'a>(
|
||||
// Adding an executable is primarily done to make `thorin` check that all the referenced
|
||||
// dwarf objects are found in the end.
|
||||
package.add_executable(
|
||||
&executable_out_filename,
|
||||
executable_out_filename,
|
||||
thorin::MissingReferencedObjectBehaviour::Skip,
|
||||
)?;
|
||||
|
||||
@ -945,7 +945,7 @@ fn link_natively<'a>(
|
||||
{
|
||||
let is_vs_installed = windows_registry::find_vs_version().is_ok();
|
||||
let has_linker = windows_registry::find_tool(
|
||||
&sess.opts.target_triple.triple(),
|
||||
sess.opts.target_triple.triple(),
|
||||
"link.exe",
|
||||
)
|
||||
.is_some();
|
||||
@ -1038,14 +1038,14 @@ fn link_natively<'a>(
|
||||
if sess.target.is_like_osx {
|
||||
match (strip, crate_type) {
|
||||
(Strip::Debuginfo, _) => {
|
||||
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-S"))
|
||||
strip_symbols_with_external_utility(sess, "strip", out_filename, Some("-S"))
|
||||
}
|
||||
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
|
||||
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
|
||||
strip_symbols_with_external_utility(sess, "strip", &out_filename, Some("-x"))
|
||||
strip_symbols_with_external_utility(sess, "strip", out_filename, Some("-x"))
|
||||
}
|
||||
(Strip::Symbols, _) => {
|
||||
strip_symbols_with_external_utility(sess, "strip", &out_filename, None)
|
||||
strip_symbols_with_external_utility(sess, "strip", out_filename, None)
|
||||
}
|
||||
(Strip::None, _) => {}
|
||||
}
|
||||
@ -1059,7 +1059,7 @@ fn link_natively<'a>(
|
||||
match strip {
|
||||
// Always preserve the symbol table (-x).
|
||||
Strip::Debuginfo => {
|
||||
strip_symbols_with_external_utility(sess, stripcmd, &out_filename, Some("-x"))
|
||||
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-x"))
|
||||
}
|
||||
// Strip::Symbols is handled via the --strip-all linker option.
|
||||
Strip::Symbols => {}
|
||||
@ -1245,13 +1245,13 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
|
||||
// rpath to the library as well (the rpath should be absolute, see
|
||||
// PR #41352 for details).
|
||||
let filename = format!("rustc{channel}_rt.{name}");
|
||||
let path = find_sanitizer_runtime(&sess, &filename);
|
||||
let path = find_sanitizer_runtime(sess, &filename);
|
||||
let rpath = path.to_str().expect("non-utf8 component in path");
|
||||
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
|
||||
linker.link_dylib(&filename, false, true);
|
||||
} else {
|
||||
let filename = format!("librustc{channel}_rt.{name}.a");
|
||||
let path = find_sanitizer_runtime(&sess, &filename).join(&filename);
|
||||
let path = find_sanitizer_runtime(sess, &filename).join(&filename);
|
||||
linker.link_whole_rlib(&path);
|
||||
}
|
||||
}
|
||||
@ -1685,7 +1685,7 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
|
||||
|
||||
// Returns true if linker is located within sysroot
|
||||
fn detect_self_contained_mingw(sess: &Session) -> bool {
|
||||
let (linker, _) = linker_and_flavor(&sess);
|
||||
let (linker, _) = linker_and_flavor(sess);
|
||||
// Assume `-C linker=rust-lld` as self-contained mode
|
||||
if linker == Path::new("rust-lld") {
|
||||
return true;
|
||||
@ -1737,7 +1737,7 @@ fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfC
|
||||
LinkSelfContainedDefault::InferredForMingw => {
|
||||
sess.host == sess.target
|
||||
&& sess.target.vendor != "uwp"
|
||||
&& detect_self_contained_mingw(&sess)
|
||||
&& detect_self_contained_mingw(sess)
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -2378,6 +2378,11 @@ fn add_order_independent_options(
|
||||
cmd.control_flow_guard();
|
||||
}
|
||||
|
||||
// OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.opts.unstable_opts.ehcont_guard {
|
||||
cmd.ehcont_guard();
|
||||
}
|
||||
|
||||
add_rpath_args(cmd, sess, codegen_results, out_filename);
|
||||
}
|
||||
|
||||
@ -2432,7 +2437,7 @@ fn add_native_libs_from_crate(
|
||||
// If rlib contains native libs as archives, unpack them to tmpdir.
|
||||
let rlib = &codegen_results.crate_info.used_crate_source[&cnum].rlib.as_ref().unwrap().0;
|
||||
archive_builder_builder
|
||||
.extract_bundled_libs(rlib, tmpdir, &bundled_libs)
|
||||
.extract_bundled_libs(rlib, tmpdir, bundled_libs)
|
||||
.unwrap_or_else(|e| sess.emit_fatal(e));
|
||||
}
|
||||
|
||||
@ -2485,7 +2490,7 @@ fn add_native_libs_from_crate(
|
||||
cmd.link_whole_staticlib(
|
||||
name,
|
||||
verbatim,
|
||||
&search_paths.get_or_init(|| archive_search_paths(sess)),
|
||||
search_paths.get_or_init(|| archive_search_paths(sess)),
|
||||
);
|
||||
} else {
|
||||
cmd.link_staticlib(name, verbatim)
|
||||
@ -2719,7 +2724,7 @@ fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf {
|
||||
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
|
||||
sysroot_lib_path
|
||||
} else {
|
||||
fix_windows_verbatim_for_gcc(&lib_dir)
|
||||
fix_windows_verbatim_for_gcc(lib_dir)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2756,7 +2761,7 @@ fn add_static_crate<'a>(
|
||||
let mut link_upstream = |path: &Path| {
|
||||
let rlib_path = if let Some(dir) = path.parent() {
|
||||
let file_name = path.file_name().expect("rlib path has no file name path component");
|
||||
rehome_sysroot_lib_dir(sess, &dir).join(file_name)
|
||||
rehome_sysroot_lib_dir(sess, dir).join(file_name)
|
||||
} else {
|
||||
fix_windows_verbatim_for_gcc(path)
|
||||
};
|
||||
@ -2793,7 +2798,7 @@ fn add_static_crate<'a>(
|
||||
let canonical = f.replace('-', "_");
|
||||
|
||||
let is_rust_object =
|
||||
canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f);
|
||||
canonical.starts_with(&canonical_name) && looks_like_rust_object_file(f);
|
||||
|
||||
// If we're performing LTO and this is a rust-generated object
|
||||
// file, then we don't need the object file as it's part of the
|
||||
|
@ -45,7 +45,7 @@ pub fn get_linker<'a>(
|
||||
self_contained: bool,
|
||||
target_cpu: &'a str,
|
||||
) -> Box<dyn Linker + 'a> {
|
||||
let msvc_tool = windows_registry::find_tool(&sess.opts.target_triple.triple(), "link.exe");
|
||||
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.triple(), "link.exe");
|
||||
|
||||
// If our linker looks like a batch script on Windows then to execute this
|
||||
// we'll need to spawn `cmd` explicitly. This is primarily done to handle
|
||||
@ -78,7 +78,7 @@ pub fn get_linker<'a>(
|
||||
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == "uwp" {
|
||||
if let Some(ref tool) = msvc_tool {
|
||||
let original_path = tool.path();
|
||||
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
|
||||
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
|
||||
let arch = match t.arch.as_ref() {
|
||||
"x86_64" => Some("x64"),
|
||||
"x86" => Some("x86"),
|
||||
@ -185,6 +185,7 @@ pub trait Linker {
|
||||
fn optimize(&mut self);
|
||||
fn pgo_gen(&mut self);
|
||||
fn control_flow_guard(&mut self);
|
||||
fn ehcont_guard(&mut self);
|
||||
fn debuginfo(&mut self, strip: Strip, natvis_debugger_visualizers: &[PathBuf]);
|
||||
fn no_crt_objects(&mut self);
|
||||
fn no_default_libraries(&mut self);
|
||||
@ -519,7 +520,7 @@ impl<'a> Linker for GccLinker<'a> {
|
||||
// -force_load is the macOS equivalent of --whole-archive, but it
|
||||
// involves passing the full path to the library to link.
|
||||
self.linker_arg("-force_load");
|
||||
let lib = find_native_static_library(lib, verbatim, search_path, &self.sess);
|
||||
let lib = find_native_static_library(lib, verbatim, search_path, self.sess);
|
||||
self.linker_arg(&lib);
|
||||
}
|
||||
}
|
||||
@ -605,6 +606,8 @@ impl<'a> Linker for GccLinker<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
|
||||
// MacOS linker doesn't support stripping symbols directly anymore.
|
||||
if self.sess.target.is_like_osx {
|
||||
@ -914,6 +917,12 @@ impl<'a> Linker for MsvcLinker<'a> {
|
||||
self.cmd.arg("/guard:cf");
|
||||
}
|
||||
|
||||
fn ehcont_guard(&mut self) {
|
||||
if self.sess.target.pointer_width == 64 {
|
||||
self.cmd.arg("/guard:ehcont");
|
||||
}
|
||||
}
|
||||
|
||||
fn debuginfo(&mut self, strip: Strip, natvis_debugger_visualizers: &[PathBuf]) {
|
||||
match strip {
|
||||
Strip::None => {
|
||||
@ -1127,6 +1136,8 @@ impl<'a> Linker for EmLinker<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
|
||||
// Preserve names or generate source maps depending on debug info
|
||||
// For more information see https://emscripten.org/docs/tools_reference/emcc.html#emcc-g
|
||||
@ -1319,6 +1330,8 @@ impl<'a> Linker for WasmLd<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn no_crt_objects(&mut self) {}
|
||||
|
||||
fn no_default_libraries(&mut self) {}
|
||||
@ -1472,6 +1485,8 @@ impl<'a> Linker for L4Bender<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn no_crt_objects(&mut self) {}
|
||||
}
|
||||
|
||||
@ -1590,7 +1605,7 @@ impl<'a> Linker for AixLinker<'a> {
|
||||
|
||||
fn link_whole_staticlib(&mut self, lib: &str, verbatim: bool, search_path: &[PathBuf]) {
|
||||
self.hint_static();
|
||||
let lib = find_native_static_library(lib, verbatim, search_path, &self.sess);
|
||||
let lib = find_native_static_library(lib, verbatim, search_path, self.sess);
|
||||
self.cmd.arg(format!("-bkeepfile:{}", lib.to_str().unwrap()));
|
||||
}
|
||||
|
||||
@ -1613,6 +1628,8 @@ impl<'a> Linker for AixLinker<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
|
||||
match strip {
|
||||
Strip::None => {}
|
||||
@ -1835,6 +1852,8 @@ impl<'a> Linker for PtxLinker<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType, _symbols: &[String]) {}
|
||||
|
||||
fn subsystem(&mut self, _subsystem: &str) {}
|
||||
@ -1931,6 +1950,8 @@ impl<'a> Linker for BpfLinker<'a> {
|
||||
|
||||
fn control_flow_guard(&mut self) {}
|
||||
|
||||
fn ehcont_guard(&mut self) {}
|
||||
|
||||
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
|
||||
let path = tmpdir.join("symbols");
|
||||
let res: io::Result<()> = try {
|
||||
|
@ -621,7 +621,7 @@ fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, S
|
||||
|
||||
let mut ret = FxHashMap::default();
|
||||
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
|
||||
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module());
|
||||
let module = def_id_to_native_lib.get(def_id).and_then(|s| s.wasm_import_module());
|
||||
let Some(module) = module else { continue };
|
||||
ret.extend(lib.foreign_items.iter().map(|id| {
|
||||
assert_eq!(id.krate, cnum);
|
||||
|
@ -892,7 +892,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
|
||||
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
|
||||
|
||||
let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| {
|
||||
let source_file = in_incr_comp_dir(&incr_comp_session_dir, saved_path);
|
||||
let source_file = in_incr_comp_dir(incr_comp_session_dir, saved_path);
|
||||
debug!(
|
||||
"copying preexisting module `{}` from {:?} to {}",
|
||||
module.name,
|
||||
@ -914,7 +914,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
|
||||
|
||||
let object = load_from_incr_comp_dir(
|
||||
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
|
||||
&module.source.saved_files.get("o").expect("no saved object file in work product"),
|
||||
module.source.saved_files.get("o").expect("no saved object file in work product"),
|
||||
);
|
||||
let dwarf_object =
|
||||
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {
|
||||
@ -924,7 +924,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
|
||||
.expect(
|
||||
"saved dwarf object in work product but `split_dwarf_path` returned `None`",
|
||||
);
|
||||
load_from_incr_comp_dir(dwarf_obj_out, &saved_dwarf_object_file)
|
||||
load_from_incr_comp_dir(dwarf_obj_out, saved_dwarf_object_file)
|
||||
});
|
||||
|
||||
WorkItemResult::Finished(CompiledModule {
|
||||
|
@ -148,10 +148,9 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
(&ty::Array(_, len), &ty::Slice(_)) => {
|
||||
cx.const_usize(len.eval_target_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
|
||||
}
|
||||
(
|
||||
&ty::Dynamic(ref data_a, _, src_dyn_kind),
|
||||
&ty::Dynamic(ref data_b, _, target_dyn_kind),
|
||||
) if src_dyn_kind == target_dyn_kind => {
|
||||
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
|
||||
if src_dyn_kind == target_dyn_kind =>
|
||||
{
|
||||
let old_info =
|
||||
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
|
||||
if data_a.principal_def_id() == data_b.principal_def_id() {
|
||||
@ -458,8 +457,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
cx.set_frame_pointer_type(llfn);
|
||||
cx.apply_target_cpu_attr(llfn);
|
||||
|
||||
let llbb = Bx::append_block(&cx, llfn, "top");
|
||||
let mut bx = Bx::build(&cx, llbb);
|
||||
let llbb = Bx::append_block(cx, llfn, "top");
|
||||
let mut bx = Bx::build(cx, llbb);
|
||||
|
||||
bx.insert_reference_to_gdb_debug_scripts_section_global();
|
||||
|
||||
@ -685,7 +684,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
||||
|
||||
// Calculate the CGU reuse
|
||||
let cgu_reuse = tcx.sess.time("find_cgu_reuse", || {
|
||||
codegen_units.iter().map(|cgu| determine_cgu_reuse(tcx, &cgu)).collect::<Vec<_>>()
|
||||
codegen_units.iter().map(|cgu| determine_cgu_reuse(tcx, cgu)).collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
crate::assert_module_sources::assert_module_sources(tcx, &|cgu_reuse_tracker| {
|
||||
|
@ -477,9 +477,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||
)
|
||||
.emit();
|
||||
InlineAttr::None
|
||||
} else if list_contains_name(&items, sym::always) {
|
||||
} else if list_contains_name(items, sym::always) {
|
||||
InlineAttr::Always
|
||||
} else if list_contains_name(&items, sym::never) {
|
||||
} else if list_contains_name(items, sym::never) {
|
||||
InlineAttr::Never
|
||||
} else {
|
||||
struct_span_err!(
|
||||
@ -514,9 +514,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||
if items.len() != 1 {
|
||||
err(attr.span, "expected one argument");
|
||||
OptimizeAttr::None
|
||||
} else if list_contains_name(&items, sym::size) {
|
||||
} else if list_contains_name(items, sym::size) {
|
||||
OptimizeAttr::Size
|
||||
} else if list_contains_name(&items, sym::speed) {
|
||||
} else if list_contains_name(items, sym::speed) {
|
||||
OptimizeAttr::Speed
|
||||
} else {
|
||||
err(items[0].span(), "invalid argument");
|
||||
|
@ -216,7 +216,7 @@ fn push_debuginfo_type_name<'tcx>(
|
||||
output.push(']');
|
||||
}
|
||||
}
|
||||
ty::Dynamic(ref trait_data, ..) => {
|
||||
ty::Dynamic(trait_data, ..) => {
|
||||
let auto_traits: SmallVec<[DefId; 4]> = trait_data.auto_traits().collect();
|
||||
|
||||
let has_enclosing_parens = if cpp_like_debuginfo {
|
||||
|
@ -42,7 +42,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// If there exists a local definition that dominates all uses of that local,
|
||||
// the definition should be visited first. Traverse blocks in an order that
|
||||
// is a topological sort of dominance partial order.
|
||||
for (bb, data) in traversal::reverse_postorder(&mir) {
|
||||
for (bb, data) in traversal::reverse_postorder(mir) {
|
||||
analyzer.visit_basic_block_data(bb, data);
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
) => match &mut self.locals[local] {
|
||||
LocalKind::ZST => {}
|
||||
LocalKind::Memory => {}
|
||||
LocalKind::SSA(def) if def.dominates(location, &self.dominators) => {}
|
||||
LocalKind::SSA(def) if def.dominates(location, self.dominators) => {}
|
||||
// Reads from uninitialized variables (e.g., in dead code, after
|
||||
// optimizations) require locals to be in (uninitialized) memory.
|
||||
// N.B., there can be uninitialized reads of a local visited after
|
||||
|
@ -47,7 +47,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
&self,
|
||||
fx: &'b mut FunctionCx<'a, 'tcx, Bx>,
|
||||
) -> Option<&'b Bx::Funclet> {
|
||||
let cleanup_kinds = (&fx.cleanup_kinds).as_ref()?;
|
||||
let cleanup_kinds = fx.cleanup_kinds.as_ref()?;
|
||||
let funclet_bb = cleanup_kinds[self.bb].funclet_bb(self.bb)?;
|
||||
// If `landing_pad_for` hasn't been called yet to create the `Funclet`,
|
||||
// it has to be now. This may not seem necessary, as RPO should lead
|
||||
@ -161,7 +161,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
) -> MergingSucc {
|
||||
// If there is a cleanup block and the function we're calling can unwind, then
|
||||
// do an invoke, otherwise do a call.
|
||||
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
|
||||
let fn_ty = bx.fn_decl_backend_type(fn_abi);
|
||||
|
||||
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
|
||||
Some(bx.tcx().codegen_fn_attrs(fx.instance.def_id()))
|
||||
@ -204,9 +204,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
let invokeret = bx.invoke(
|
||||
fn_ty,
|
||||
fn_attrs,
|
||||
Some(&fn_abi),
|
||||
Some(fn_abi),
|
||||
fn_ptr,
|
||||
&llargs,
|
||||
llargs,
|
||||
ret_llbb,
|
||||
unwind_block,
|
||||
self.funclet(fx),
|
||||
@ -225,7 +225,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
}
|
||||
MergingSucc::False
|
||||
} else {
|
||||
let llret = bx.call(fn_ty, fn_attrs, Some(&fn_abi), fn_ptr, &llargs, self.funclet(fx));
|
||||
let llret = bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx));
|
||||
if fx.mir[self.bb].is_cleanup {
|
||||
bx.apply_attrs_to_cleanup_callsite(llret);
|
||||
}
|
||||
@ -273,7 +273,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
|
||||
bx.codegen_inline_asm(
|
||||
template,
|
||||
&operands,
|
||||
operands,
|
||||
options,
|
||||
line_spans,
|
||||
instance,
|
||||
@ -281,7 +281,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
|
||||
);
|
||||
MergingSucc::False
|
||||
} else {
|
||||
bx.codegen_inline_asm(template, &operands, options, line_spans, instance, None);
|
||||
bx.codegen_inline_asm(template, operands, options, line_spans, instance, None);
|
||||
|
||||
if let Some(target) = destination {
|
||||
self.funclet_br(fx, bx, target, mergeable_succ)
|
||||
@ -318,7 +318,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
discr: &mir::Operand<'tcx>,
|
||||
targets: &SwitchTargets,
|
||||
) {
|
||||
let discr = self.codegen_operand(bx, &discr);
|
||||
let discr = self.codegen_operand(bx, discr);
|
||||
let switch_ty = discr.layout.ty;
|
||||
let mut target_iter = targets.iter();
|
||||
if target_iter.len() == 1 {
|
||||
@ -498,7 +498,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
args = &args[..1];
|
||||
(
|
||||
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
|
||||
.get_fn(bx, vtable, ty, &fn_abi),
|
||||
.get_fn(bx, vtable, ty, fn_abi),
|
||||
fn_abi,
|
||||
)
|
||||
}
|
||||
@ -540,7 +540,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
debug!("args' = {:?}", args);
|
||||
(
|
||||
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
|
||||
.get_fn(bx, meta.immediate(), ty, &fn_abi),
|
||||
.get_fn(bx, meta.immediate(), ty, fn_abi),
|
||||
fn_abi,
|
||||
)
|
||||
}
|
||||
@ -864,7 +864,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
// promotes any complex rvalues to constants.
|
||||
if i == 2 && intrinsic == sym::simd_shuffle {
|
||||
if let mir::Operand::Constant(constant) = arg {
|
||||
let (llval, ty) = self.simd_shuffle_indices(&bx, constant);
|
||||
let (llval, ty) = self.simd_shuffle_indices(bx, constant);
|
||||
return OperandRef {
|
||||
val: Immediate(llval),
|
||||
layout: bx.layout_of(ty),
|
||||
@ -881,7 +881,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
Self::codegen_intrinsic_call(
|
||||
bx,
|
||||
*instance.as_ref().unwrap(),
|
||||
&fn_abi,
|
||||
fn_abi,
|
||||
&args,
|
||||
dest,
|
||||
span,
|
||||
@ -937,7 +937,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
bx,
|
||||
meta,
|
||||
op.layout.ty,
|
||||
&fn_abi,
|
||||
fn_abi,
|
||||
));
|
||||
llargs.push(data_ptr);
|
||||
continue 'make_args;
|
||||
@ -948,7 +948,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
bx,
|
||||
meta,
|
||||
op.layout.ty,
|
||||
&fn_abi,
|
||||
fn_abi,
|
||||
));
|
||||
llargs.push(data_ptr);
|
||||
continue;
|
||||
@ -975,7 +975,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
bx,
|
||||
meta.immediate(),
|
||||
op.layout.ty,
|
||||
&fn_abi,
|
||||
fn_abi,
|
||||
));
|
||||
llargs.push(data_ptr.llval);
|
||||
continue;
|
||||
@ -1587,9 +1587,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
|
||||
|
||||
let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, reason.lang_item());
|
||||
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
|
||||
let fn_ty = bx.fn_decl_backend_type(fn_abi);
|
||||
|
||||
let llret = bx.call(fn_ty, None, Some(&fn_abi), fn_ptr, &[], funclet.as_ref());
|
||||
let llret = bx.call(fn_ty, None, Some(fn_abi), fn_ptr, &[], funclet.as_ref());
|
||||
bx.apply_attrs_to_cleanup_callsite(llret);
|
||||
|
||||
bx.unreachable();
|
||||
@ -1662,10 +1662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.codegen_place(
|
||||
bx,
|
||||
mir::PlaceRef { local: dest.local, projection: &dest.projection },
|
||||
)
|
||||
self.codegen_place(bx, mir::PlaceRef { local: dest.local, projection: dest.projection })
|
||||
};
|
||||
if fn_ret.is_indirect() {
|
||||
if dest.align < dest.layout.align.abi {
|
||||
@ -1696,7 +1693,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
|
||||
match dest {
|
||||
Nothing => (),
|
||||
Store(dst) => bx.store_arg(&ret_abi, llval, dst),
|
||||
Store(dst) => bx.store_arg(ret_abi, llval, dst),
|
||||
IndirectOperand(tmp, index) => {
|
||||
let op = bx.load_operand(tmp);
|
||||
tmp.storage_dead(bx);
|
||||
@ -1708,7 +1705,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
let op = if let PassMode::Cast { .. } = ret_abi.mode {
|
||||
let tmp = PlaceRef::alloca(bx, ret_abi.layout);
|
||||
tmp.storage_live(bx);
|
||||
bx.store_arg(&ret_abi, llval, tmp);
|
||||
bx.store_arg(ret_abi, llval, tmp);
|
||||
let op = bx.load_operand(tmp);
|
||||
tmp.storage_dead(bx);
|
||||
op
|
||||
|
@ -398,7 +398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };
|
||||
|
||||
let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
|
||||
calculate_debuginfo_offset(bx, &var.projection, base.layout);
|
||||
calculate_debuginfo_offset(bx, var.projection, base.layout);
|
||||
|
||||
// When targeting MSVC, create extra allocas for arguments instead of pointing multiple
|
||||
// dbg_var_addr() calls into the same alloca with offsets. MSVC uses CodeView records
|
||||
@ -416,7 +416,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
|
||||
if should_create_individual_allocas {
|
||||
let DebugInfoOffset { direct_offset: _, indirect_offsets: _, result: place } =
|
||||
calculate_debuginfo_offset(bx, &var.projection, base);
|
||||
calculate_debuginfo_offset(bx, var.projection, base);
|
||||
|
||||
// Create a variable which will be a pointer to the actual value
|
||||
let ptr_ty = Ty::new_ptr(
|
||||
|
@ -168,7 +168,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
|
||||
debug!("fn_abi: {:?}", fn_abi);
|
||||
|
||||
let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir);
|
||||
let debug_context = cx.create_function_debug_context(instance, fn_abi, llfn, mir);
|
||||
|
||||
let start_llbb = Bx::append_block(cx, llfn, "start");
|
||||
let mut start_bx = Bx::build(cx, start_llbb);
|
||||
@ -180,7 +180,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
}
|
||||
|
||||
let cleanup_kinds =
|
||||
base::wants_new_eh_instructions(cx.tcx().sess).then(|| analyze::cleanup_kinds(&mir));
|
||||
base::wants_new_eh_instructions(cx.tcx().sess).then(|| analyze::cleanup_kinds(mir));
|
||||
|
||||
let cached_llbbs: IndexVec<mir::BasicBlock, CachedLlbb<Bx::BasicBlock>> =
|
||||
mir.basic_blocks
|
||||
@ -261,7 +261,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
drop(start_bx);
|
||||
|
||||
// Codegen the body of each block using reverse postorder
|
||||
for (bb, _) in traversal::reverse_postorder(&mir) {
|
||||
for (bb, _) in traversal::reverse_postorder(mir) {
|
||||
fx.codegen_block(bb);
|
||||
}
|
||||
}
|
||||
|
@ -474,27 +474,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
cg_base.project_index(bx, llindex)
|
||||
}
|
||||
mir::ProjectionElem::ConstantIndex { offset, from_end: false, min_length: _ } => {
|
||||
let lloffset = bx.cx().const_usize(offset as u64);
|
||||
let lloffset = bx.cx().const_usize(offset);
|
||||
cg_base.project_index(bx, lloffset)
|
||||
}
|
||||
mir::ProjectionElem::ConstantIndex { offset, from_end: true, min_length: _ } => {
|
||||
let lloffset = bx.cx().const_usize(offset as u64);
|
||||
let lloffset = bx.cx().const_usize(offset);
|
||||
let lllen = cg_base.len(bx.cx());
|
||||
let llindex = bx.sub(lllen, lloffset);
|
||||
cg_base.project_index(bx, llindex)
|
||||
}
|
||||
mir::ProjectionElem::Subslice { from, to, from_end } => {
|
||||
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from as u64));
|
||||
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from));
|
||||
let projected_ty =
|
||||
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, *elem).ty;
|
||||
subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty));
|
||||
|
||||
if subslice.layout.is_unsized() {
|
||||
assert!(from_end, "slice subslices should be `from_end`");
|
||||
subslice.llextra = Some(bx.sub(
|
||||
cg_base.llextra.unwrap(),
|
||||
bx.cx().const_usize((from as u64) + (to as u64)),
|
||||
));
|
||||
subslice.llextra =
|
||||
Some(bx.sub(cg_base.llextra.unwrap(), bx.cx().const_usize(from + to)));
|
||||
}
|
||||
|
||||
subslice
|
||||
|
@ -702,7 +702,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
};
|
||||
let fn_ptr = bx.get_fn_addr(instance);
|
||||
let fn_abi = bx.fn_abi_of_instance(instance, ty::List::empty());
|
||||
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
|
||||
let fn_ty = bx.fn_decl_backend_type(fn_abi);
|
||||
let fn_attrs = if bx.tcx().def_kind(instance.def_id()).has_codegen_attrs() {
|
||||
Some(bx.tcx().codegen_fn_attrs(instance.def_id()))
|
||||
} else {
|
||||
|
@ -34,7 +34,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
|
||||
}
|
||||
MonoItem::GlobalAsm(item_id) => {
|
||||
let item = cx.tcx().hir().item(item_id);
|
||||
if let hir::ItemKind::GlobalAsm(ref asm) = item.kind {
|
||||
if let hir::ItemKind::GlobalAsm(asm) = item.kind {
|
||||
let operands: Vec<_> = asm
|
||||
.operands
|
||||
.iter()
|
||||
@ -88,7 +88,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
|
||||
}
|
||||
}
|
||||
MonoItem::Fn(instance) => {
|
||||
base::codegen_instance::<Bx>(&cx, instance);
|
||||
base::codegen_instance::<Bx>(cx, instance);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,10 +119,10 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
|
||||
|
||||
match *self {
|
||||
MonoItem::Static(def_id) => {
|
||||
cx.predefine_static(def_id, linkage, visibility, &symbol_name);
|
||||
cx.predefine_static(def_id, linkage, visibility, symbol_name);
|
||||
}
|
||||
MonoItem::Fn(instance) => {
|
||||
cx.predefine_fn(instance, linkage, visibility, &symbol_name);
|
||||
cx.predefine_fn(instance, linkage, visibility, symbol_name);
|
||||
}
|
||||
MonoItem::GlobalAsm(..) => {}
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ pub fn eval_in_interpreter<'mir, 'tcx>(
|
||||
is_static: bool,
|
||||
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
|
||||
let res = ecx.load_mir(cid.instance.def, cid.promoted);
|
||||
match res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body)) {
|
||||
match res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, body)) {
|
||||
Err(error) => {
|
||||
let (error, backtrace) = error.into_parts();
|
||||
backtrace.print_backtrace();
|
||||
|
@ -200,7 +200,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
|
||||
&caller
|
||||
.file
|
||||
.name
|
||||
.for_scope(&self.tcx.sess, RemapPathScopeComponents::DIAGNOSTICS)
|
||||
.for_scope(self.tcx.sess, RemapPathScopeComponents::DIAGNOSTICS)
|
||||
.to_string_lossy(),
|
||||
),
|
||||
u32::try_from(caller.line).unwrap(),
|
||||
@ -493,7 +493,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
||||
};
|
||||
|
||||
let ptr = ecx.allocate_ptr(
|
||||
Size::from_bytes(size as u64),
|
||||
Size::from_bytes(size),
|
||||
align,
|
||||
interpret::MemoryKind::Machine(MemoryKind::Heap),
|
||||
)?;
|
||||
|
@ -387,7 +387,7 @@ fn valtree_into_mplace<'tcx>(
|
||||
|
||||
debug!(?place_inner);
|
||||
valtree_into_mplace(ecx, &place_inner, *inner_valtree);
|
||||
dump_place(&ecx, &place_inner);
|
||||
dump_place(ecx, &place_inner);
|
||||
}
|
||||
|
||||
debug!("dump of place_adjusted:");
|
||||
|
@ -256,7 +256,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let addr = addr.to_target_usize(self)?;
|
||||
|
||||
// Then turn address into pointer.
|
||||
let ptr = M::ptr_from_addr_cast(&self, addr)?;
|
||||
let ptr = M::ptr_from_addr_cast(self, addr)?;
|
||||
Ok(ImmTy::from_scalar(Scalar::from_maybe_pointer(ptr, self), cast_to))
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
|
||||
// to avoid could be expensive: on the potentially larger types, arrays and slices,
|
||||
// rather than on all aggregates unconditionally.
|
||||
if matches!(mplace.layout.ty.kind(), ty::Array(..) | ty::Slice(..)) {
|
||||
let Some((size, _align)) = self.ecx.size_and_align_of_mplace(&mplace)? else {
|
||||
let Some((size, _align)) = self.ecx.size_and_align_of_mplace(mplace)? else {
|
||||
// We do the walk if we can't determine the size of the mplace: we may be
|
||||
// dealing with extern types here in the future.
|
||||
return Ok(true);
|
||||
|
@ -505,7 +505,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// Performs an exact division, resulting in undefined behavior where
|
||||
// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`.
|
||||
// First, check x % y != 0 (or if that computation overflows).
|
||||
let (res, overflow) = self.overflowing_binary_op(BinOp::Rem, &a, &b)?;
|
||||
let (res, overflow) = self.overflowing_binary_op(BinOp::Rem, a, b)?;
|
||||
assert!(!overflow); // All overflow is UB, so this should never return on overflow.
|
||||
if res.to_scalar().assert_bits(a.layout.size) != 0 {
|
||||
throw_ub_custom!(
|
||||
@ -515,7 +515,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
)
|
||||
}
|
||||
// `Rem` says this is all right, so we can let `Div` do its job.
|
||||
self.binop_ignore_overflow(BinOp::Div, &a, &b, dest)
|
||||
self.binop_ignore_overflow(BinOp::Div, a, b, dest)
|
||||
}
|
||||
|
||||
pub fn saturating_arith(
|
||||
|
@ -20,7 +20,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
right: &ImmTy<'tcx, M::Provenance>,
|
||||
dest: &PlaceTy<'tcx, M::Provenance>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let (val, overflowed) = self.overflowing_binary_op(op, &left, &right)?;
|
||||
let (val, overflowed) = self.overflowing_binary_op(op, left, right)?;
|
||||
debug_assert_eq!(
|
||||
Ty::new_tup(self.tcx.tcx, &[val.layout.ty, self.tcx.types.bool]),
|
||||
dest.layout.ty,
|
||||
|
@ -456,7 +456,7 @@ where
|
||||
) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
|
||||
{
|
||||
let (size, _align) = self
|
||||
.size_and_align_of_mplace(&mplace)?
|
||||
.size_and_align_of_mplace(mplace)?
|
||||
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
|
||||
// We check alignment separately, and *after* checking everything else.
|
||||
// If an access is both OOB and misaligned, we want to see the bounds error.
|
||||
@ -472,7 +472,7 @@ where
|
||||
) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
|
||||
{
|
||||
let (size, _align) = self
|
||||
.size_and_align_of_mplace(&mplace)?
|
||||
.size_and_align_of_mplace(mplace)?
|
||||
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
|
||||
// We check alignment separately, and raise that error *after* checking everything else.
|
||||
// If an access is both OOB and misaligned, we want to see the bounds error.
|
||||
|
@ -51,7 +51,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||
match arg {
|
||||
FnArg::Copy(op) => Ok(op.clone()),
|
||||
FnArg::InPlace(place) => self.place_to_op(&place),
|
||||
FnArg::InPlace(place) => self.place_to_op(place),
|
||||
}
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// so we implement a type-based check that reflects the guaranteed rules for ABI compatibility.
|
||||
if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
|
||||
// Ensure that our checks imply actual ABI compatibility for this concrete call.
|
||||
assert!(caller_abi.eq_abi(&callee_abi));
|
||||
assert!(caller_abi.eq_abi(callee_abi));
|
||||
return Ok(true);
|
||||
} else {
|
||||
trace!(
|
||||
@ -464,7 +464,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// We work with a copy of the argument for now; if this is in-place argument passing, we
|
||||
// will later protect the source it comes from. This means the callee cannot observe if we
|
||||
// did in-place of by-copy argument passing, except for pointer equality tests.
|
||||
let caller_arg_copy = self.copy_fn_arg(&caller_arg)?;
|
||||
let caller_arg_copy = self.copy_fn_arg(caller_arg)?;
|
||||
if !already_live {
|
||||
let local = callee_arg.as_local().unwrap();
|
||||
let meta = caller_arg_copy.meta();
|
||||
|
@ -896,7 +896,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let mut visitor = ValidityVisitor { path, ref_tracking, ctfe_mode, ecx: self };
|
||||
|
||||
// Run it.
|
||||
match visitor.visit_value(&op) {
|
||||
match visitor.visit_value(op) {
|
||||
Ok(()) => Ok(()),
|
||||
// Pass through validation failures and "invalid program" issues.
|
||||
Err(err)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user