mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Remove save-analysis.
Most tests involving save-analysis were removed, but I kept a few where the `-Zsave-analysis` was an add-on to the main thing being tested, rather than the main thing being tested. For `x.py install`, the `rust-analysis` target has been removed. For `x.py dist`, the `rust-analysis` target has been kept in a degenerate form: it just produces a single file `reduced.json` indicating that save-analysis has been removed. This is necessary for rustup to keep working. Closes #43606.
This commit is contained in:
parent
dc7a676778
commit
22a5125a36
41
Cargo.lock
41
Cargo.lock
@ -3495,25 +3495,6 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rls-data"
|
||||
version = "0.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a58135eb039f3a3279a33779192f0ee78b56f57ae636e25cec83530e41debb99"
|
||||
dependencies = [
|
||||
"rls-span",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rls-span"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0eea58478fc06e15f71b03236612173a1b81e9770314edecfa664375e3e4c86"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-demangler"
|
||||
version = "0.0.1"
|
||||
@ -3965,7 +3946,6 @@ dependencies = [
|
||||
"rustc_middle",
|
||||
"rustc_parse",
|
||||
"rustc_plugin_impl",
|
||||
"rustc_save_analysis",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
@ -4625,27 +4605,6 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_save_analysis"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"rls-data",
|
||||
"rls-span",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
"rustc_hir",
|
||||
"rustc_hir_pretty",
|
||||
"rustc_lexer",
|
||||
"rustc_macros",
|
||||
"rustc_middle",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"serde_json",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_serialize"
|
||||
version = "0.0.0"
|
||||
|
@ -22,7 +22,6 @@ rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_metadata = { path = "../rustc_metadata" }
|
||||
rustc_parse = { path = "../rustc_parse" }
|
||||
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
|
||||
rustc_save_analysis = { path = "../rustc_save_analysis" }
|
||||
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_error_codes = { path = "../rustc_error_codes" }
|
||||
|
@ -25,13 +25,10 @@ use rustc_data_structures::sync::SeqCst;
|
||||
use rustc_errors::registry::{InvalidErrorCode, Registry};
|
||||
use rustc_errors::{ErrorGuaranteed, PResult, TerminalUrl};
|
||||
use rustc_feature::find_gated_cfg;
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
|
||||
use rustc_interface::{interface, Queries};
|
||||
use rustc_lint::LintStore;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_save_analysis as save;
|
||||
use rustc_save_analysis::DumpHandler;
|
||||
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
|
||||
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
|
||||
use rustc_session::cstore::MetadataLoader;
|
||||
@ -343,22 +340,7 @@ fn run_compiler(
|
||||
return early_exit();
|
||||
}
|
||||
|
||||
queries.global_ctxt()?.enter(|tcx| {
|
||||
let result = tcx.analysis(());
|
||||
if sess.opts.unstable_opts.save_analysis {
|
||||
let crate_name = tcx.crate_name(LOCAL_CRATE);
|
||||
sess.time("save_analysis", || {
|
||||
save::process_crate(
|
||||
tcx,
|
||||
crate_name,
|
||||
&sess.io.input,
|
||||
None,
|
||||
DumpHandler::new(sess.io.output_dir.as_deref(), crate_name),
|
||||
)
|
||||
});
|
||||
}
|
||||
result
|
||||
})?;
|
||||
queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?;
|
||||
|
||||
if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
|
||||
return early_exit();
|
||||
|
@ -1 +0,0 @@
|
||||
save_analysis_could_not_open = Could not open `{$file_name}`: `{$err}`
|
@ -67,7 +67,6 @@ fluent_messages! {
|
||||
privacy => "../locales/en-US/privacy.ftl",
|
||||
query_system => "../locales/en-US/query_system.ftl",
|
||||
resolve => "../locales/en-US/resolve.ftl",
|
||||
save_analysis => "../locales/en-US/save_analysis.ftl",
|
||||
session => "../locales/en-US/session.ftl",
|
||||
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
|
||||
trait_selection => "../locales/en-US/trait_selection.ftl",
|
||||
|
@ -691,7 +691,6 @@ fn test_unstable_options_tracking_hash() {
|
||||
untracked!(proc_macro_execution_strategy, ProcMacroExecutionStrategy::CrossThread);
|
||||
untracked!(profile_closures, true);
|
||||
untracked!(query_dep_graph, true);
|
||||
untracked!(save_analysis, true);
|
||||
untracked!(self_profile, SwitchWithOptPath::Enabled(None));
|
||||
untracked!(self_profile_events, Some(vec![String::new()]));
|
||||
untracked!(span_debug, true);
|
||||
|
@ -1,21 +0,0 @@
|
||||
[package]
|
||||
name = "rustc_save_analysis"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1"
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_errors = { path = "../rustc_errors" }
|
||||
rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
|
||||
rustc_lexer = { path = "../rustc_lexer" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
serde_json = "1"
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rls-data = "0.19"
|
||||
rls-span = "0.5"
|
File diff suppressed because it is too large
Load Diff
@ -1,91 +0,0 @@
|
||||
use rls_data::config::Config;
|
||||
use rls_data::{
|
||||
self, Analysis, CompilationOptions, CratePreludeData, Def, DefKind, Impl, Import, MacroRef,
|
||||
Ref, RefKind, Relation,
|
||||
};
|
||||
use rls_span::{Column, Row};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Access {
|
||||
pub reachable: bool,
|
||||
pub public: bool,
|
||||
}
|
||||
|
||||
pub struct Dumper {
|
||||
result: Analysis,
|
||||
config: Config,
|
||||
}
|
||||
|
||||
impl Dumper {
|
||||
pub fn new(config: Config) -> Dumper {
|
||||
Dumper { config: config.clone(), result: Analysis::new(config) }
|
||||
}
|
||||
|
||||
pub fn analysis(&self) -> &Analysis {
|
||||
&self.result
|
||||
}
|
||||
}
|
||||
|
||||
impl Dumper {
|
||||
pub fn crate_prelude(&mut self, data: CratePreludeData) {
|
||||
self.result.prelude = Some(data)
|
||||
}
|
||||
|
||||
pub fn compilation_opts(&mut self, data: CompilationOptions) {
|
||||
self.result.compilation = Some(data);
|
||||
}
|
||||
|
||||
pub fn _macro_use(&mut self, data: MacroRef) {
|
||||
if self.config.pub_only || self.config.reachable_only {
|
||||
return;
|
||||
}
|
||||
self.result.macro_refs.push(data);
|
||||
}
|
||||
|
||||
pub fn import(&mut self, access: &Access, import: Import) {
|
||||
if !access.public && self.config.pub_only || !access.reachable && self.config.reachable_only
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.result.imports.push(import);
|
||||
}
|
||||
|
||||
pub fn dump_ref(&mut self, data: Ref) {
|
||||
if self.config.pub_only || self.config.reachable_only {
|
||||
return;
|
||||
}
|
||||
self.result.refs.push(data);
|
||||
}
|
||||
|
||||
pub fn dump_def(&mut self, access: &Access, mut data: Def) {
|
||||
if !access.public && self.config.pub_only || !access.reachable && self.config.reachable_only
|
||||
{
|
||||
return;
|
||||
}
|
||||
if data.kind == DefKind::Mod && data.span.file_name.to_str().unwrap() != data.value {
|
||||
// If the module is an out-of-line definition, then we'll make the
|
||||
// definition the first character in the module's file and turn
|
||||
// the declaration into a reference to it.
|
||||
let rf = Ref { kind: RefKind::Mod, span: data.span, ref_id: data.id };
|
||||
self.result.refs.push(rf);
|
||||
data.span = rls_data::SpanData {
|
||||
file_name: data.value.clone().into(),
|
||||
byte_start: 0,
|
||||
byte_end: 0,
|
||||
line_start: Row::new_one_indexed(1),
|
||||
line_end: Row::new_one_indexed(1),
|
||||
column_start: Column::new_one_indexed(1),
|
||||
column_end: Column::new_one_indexed(1),
|
||||
}
|
||||
}
|
||||
self.result.defs.push(data);
|
||||
}
|
||||
|
||||
pub fn dump_relation(&mut self, data: Relation) {
|
||||
self.result.relations.push(data);
|
||||
}
|
||||
|
||||
pub fn dump_impl(&mut self, data: Impl) {
|
||||
self.result.impls.push(data);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
use rustc_macros::Diagnostic;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(save_analysis_could_not_open)]
|
||||
pub(crate) struct CouldNotOpen<'a> {
|
||||
pub file_name: &'a Path,
|
||||
pub err: std::io::Error,
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,931 +0,0 @@
|
||||
// A signature is a string representation of an item's type signature, excluding
|
||||
// any body. It also includes ids for any defs or refs in the signature. For
|
||||
// example:
|
||||
//
|
||||
// ```
|
||||
// fn foo(x: String) {
|
||||
// println!("{}", x);
|
||||
// }
|
||||
// ```
|
||||
// The signature string is something like "fn foo(x: String) {}" and the signature
|
||||
// will have defs for `foo` and `x` and a ref for `String`.
|
||||
//
|
||||
// All signature text should parse in the correct context (i.e., in a module or
|
||||
// impl, etc.). Clients may want to trim trailing `{}` or `;`. The text of a
|
||||
// signature is not guaranteed to be stable (it may improve or change as the
|
||||
// syntax changes, or whitespace or punctuation may change). It is also likely
|
||||
// not to be pretty - no attempt is made to prettify the text. It is recommended
|
||||
// that clients run the text through Rustfmt.
|
||||
//
|
||||
// This module generates Signatures for items by walking the AST and looking up
|
||||
// references.
|
||||
//
|
||||
// Signatures do not include visibility info. I'm not sure if this is a feature
|
||||
// or an omission (FIXME).
|
||||
//
|
||||
// FIXME where clauses need implementing, defs/refs in generics are mostly missing.
|
||||
|
||||
use crate::{id_from_def_id, SaveContext};
|
||||
|
||||
use rls_data::{SigElement, Signature};
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir_pretty::id_to_string;
|
||||
use rustc_hir_pretty::{bounds_to_string, path_segment_to_string, path_to_string, ty_to_string};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
|
||||
pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
item.make(0, None, scx).ok()
|
||||
}
|
||||
|
||||
pub fn foreign_item_signature(
|
||||
item: &hir::ForeignItem<'_>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
item.make(0, None, scx).ok()
|
||||
}
|
||||
|
||||
/// Signature for a struct or tuple field declaration.
|
||||
/// Does not include a trailing comma.
|
||||
pub fn field_signature(field: &hir::FieldDef<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
field.make(0, None, scx).ok()
|
||||
}
|
||||
|
||||
/// Does not include a trailing comma.
|
||||
pub fn variant_signature(variant: &hir::Variant<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
variant.make(0, None, scx).ok()
|
||||
}
|
||||
|
||||
pub fn method_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Ident,
|
||||
generics: &hir::Generics<'_>,
|
||||
m: &hir::FnSig<'_>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
make_method_signature(id, ident, generics, m, scx).ok()
|
||||
}
|
||||
|
||||
pub fn assoc_const_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Symbol,
|
||||
ty: &hir::Ty<'_>,
|
||||
default: Option<&hir::Expr<'_>>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
make_assoc_const_signature(id, ident, ty, default, scx).ok()
|
||||
}
|
||||
|
||||
pub fn assoc_type_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Ident,
|
||||
bounds: Option<hir::GenericBounds<'_>>,
|
||||
default: Option<&hir::Ty<'_>>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Option<Signature> {
|
||||
if !scx.config.signatures {
|
||||
return None;
|
||||
}
|
||||
make_assoc_type_signature(id, ident, bounds, default, scx).ok()
|
||||
}
|
||||
|
||||
type Result = std::result::Result<Signature, &'static str>;
|
||||
|
||||
trait Sig {
|
||||
type Parent;
|
||||
fn make(&self, offset: usize, id: Option<Self::Parent>, scx: &SaveContext<'_>) -> Result;
|
||||
}
|
||||
|
||||
fn extend_sig(
|
||||
mut sig: Signature,
|
||||
text: String,
|
||||
defs: Vec<SigElement>,
|
||||
refs: Vec<SigElement>,
|
||||
) -> Signature {
|
||||
sig.text = text;
|
||||
sig.defs.extend(defs.into_iter());
|
||||
sig.refs.extend(refs.into_iter());
|
||||
sig
|
||||
}
|
||||
|
||||
fn replace_text(mut sig: Signature, text: String) -> Signature {
|
||||
sig.text = text;
|
||||
sig
|
||||
}
|
||||
|
||||
fn merge_sigs(text: String, sigs: Vec<Signature>) -> Signature {
|
||||
let mut result = Signature { text, defs: vec![], refs: vec![] };
|
||||
|
||||
let (defs, refs): (Vec<_>, Vec<_>) = sigs.into_iter().map(|s| (s.defs, s.refs)).unzip();
|
||||
|
||||
result.defs.extend(defs.into_iter().flat_map(|ds| ds.into_iter()));
|
||||
result.refs.extend(refs.into_iter().flat_map(|rs| rs.into_iter()));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn text_sig(text: String) -> Signature {
|
||||
Signature { text, defs: vec![], refs: vec![] }
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::Ty<'hir> {
|
||||
type Parent = hir::HirId;
|
||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||
let id = Some(self.hir_id);
|
||||
match self.kind {
|
||||
hir::TyKind::Slice(ref ty) => {
|
||||
let nested = ty.make(offset + 1, id, scx)?;
|
||||
let text = format!("[{}]", nested.text);
|
||||
Ok(replace_text(nested, text))
|
||||
}
|
||||
hir::TyKind::Ptr(ref mt) => {
|
||||
let prefix = match mt.mutbl {
|
||||
hir::Mutability::Mut => "*mut ",
|
||||
hir::Mutability::Not => "*const ",
|
||||
};
|
||||
let nested = mt.ty.make(offset + prefix.len(), id, scx)?;
|
||||
let text = format!("{}{}", prefix, nested.text);
|
||||
Ok(replace_text(nested, text))
|
||||
}
|
||||
hir::TyKind::Ref(ref lifetime, ref mt) => {
|
||||
let mut prefix = "&".to_owned();
|
||||
prefix.push_str(&lifetime.ident.to_string());
|
||||
prefix.push(' ');
|
||||
if mt.mutbl.is_mut() {
|
||||
prefix.push_str("mut ");
|
||||
};
|
||||
|
||||
let nested = mt.ty.make(offset + prefix.len(), id, scx)?;
|
||||
let text = format!("{}{}", prefix, nested.text);
|
||||
Ok(replace_text(nested, text))
|
||||
}
|
||||
hir::TyKind::Never => Ok(text_sig("!".to_owned())),
|
||||
hir::TyKind::Tup(ts) => {
|
||||
let mut text = "(".to_owned();
|
||||
let mut defs = vec![];
|
||||
let mut refs = vec![];
|
||||
for t in ts {
|
||||
let nested = t.make(offset + text.len(), id, scx)?;
|
||||
text.push_str(&nested.text);
|
||||
text.push(',');
|
||||
defs.extend(nested.defs.into_iter());
|
||||
refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
text.push(')');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::TyKind::BareFn(ref f) => {
|
||||
let mut text = String::new();
|
||||
if !f.generic_params.is_empty() {
|
||||
// FIXME defs, bounds on lifetimes
|
||||
text.push_str("for<");
|
||||
text.push_str(
|
||||
&f.generic_params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => {
|
||||
Some(param.name.ident().to_string())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
);
|
||||
text.push('>');
|
||||
}
|
||||
|
||||
if let hir::Unsafety::Unsafe = f.unsafety {
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("fn(");
|
||||
|
||||
let mut defs = vec![];
|
||||
let mut refs = vec![];
|
||||
for i in f.decl.inputs {
|
||||
let nested = i.make(offset + text.len(), Some(i.hir_id), scx)?;
|
||||
text.push_str(&nested.text);
|
||||
text.push(',');
|
||||
defs.extend(nested.defs.into_iter());
|
||||
refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
text.push(')');
|
||||
if let hir::FnRetTy::Return(ref t) = f.decl.output {
|
||||
text.push_str(" -> ");
|
||||
let nested = t.make(offset + text.len(), None, scx)?;
|
||||
text.push_str(&nested.text);
|
||||
text.push(',');
|
||||
defs.extend(nested.defs.into_iter());
|
||||
refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => path.make(offset, id, scx),
|
||||
hir::TyKind::Path(hir::QPath::Resolved(Some(ref qself), ref path)) => {
|
||||
let nested_ty = qself.make(offset + 1, id, scx)?;
|
||||
let prefix = format!(
|
||||
"<{} as {}>::",
|
||||
nested_ty.text,
|
||||
path_segment_to_string(&path.segments[0])
|
||||
);
|
||||
|
||||
let name = path_segment_to_string(path.segments.last().ok_or("Bad path")?);
|
||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||
let id = id_from_def_id(res.def_id());
|
||||
if path.segments.len() == 2 {
|
||||
let start = offset + prefix.len();
|
||||
let end = start + name.len();
|
||||
|
||||
Ok(Signature {
|
||||
text: prefix + &name,
|
||||
defs: vec![],
|
||||
refs: vec![SigElement { id, start, end }],
|
||||
})
|
||||
} else {
|
||||
let start = offset + prefix.len() + 5;
|
||||
let end = start + name.len();
|
||||
// FIXME should put the proper path in there, not ellipsis.
|
||||
Ok(Signature {
|
||||
text: prefix + "...::" + &name,
|
||||
defs: vec![],
|
||||
refs: vec![SigElement { id, start, end }],
|
||||
})
|
||||
}
|
||||
}
|
||||
hir::TyKind::Path(hir::QPath::TypeRelative(ty, segment)) => {
|
||||
let nested_ty = ty.make(offset + 1, id, scx)?;
|
||||
let prefix = format!("<{}>::", nested_ty.text);
|
||||
|
||||
let name = path_segment_to_string(segment);
|
||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||
let id = id_from_def_id(res.def_id());
|
||||
|
||||
let start = offset + prefix.len();
|
||||
let end = start + name.len();
|
||||
Ok(Signature {
|
||||
text: prefix + &name,
|
||||
defs: vec![],
|
||||
refs: vec![SigElement { id, start, end }],
|
||||
})
|
||||
}
|
||||
hir::TyKind::Path(hir::QPath::LangItem(lang_item, _, _)) => {
|
||||
Ok(text_sig(format!("#[lang = \"{}\"]", lang_item.name())))
|
||||
}
|
||||
hir::TyKind::TraitObject(bounds, ..) => {
|
||||
// FIXME recurse into bounds
|
||||
let bounds: Vec<hir::GenericBound<'_>> = bounds
|
||||
.iter()
|
||||
.map(|hir::PolyTraitRef { bound_generic_params, trait_ref, span }| {
|
||||
hir::GenericBound::Trait(
|
||||
hir::PolyTraitRef {
|
||||
bound_generic_params,
|
||||
trait_ref: hir::TraitRef {
|
||||
path: trait_ref.path,
|
||||
hir_ref_id: trait_ref.hir_ref_id,
|
||||
},
|
||||
span: *span,
|
||||
},
|
||||
hir::TraitBoundModifier::None,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let nested = bounds_to_string(&bounds);
|
||||
Ok(text_sig(nested))
|
||||
}
|
||||
hir::TyKind::Array(ref ty, ref length) => {
|
||||
let nested_ty = ty.make(offset + 1, id, scx)?;
|
||||
let expr = id_to_string(&scx.tcx.hir(), length.hir_id()).replace('\n', " ");
|
||||
let text = format!("[{}; {}]", nested_ty.text, expr);
|
||||
Ok(replace_text(nested_ty, text))
|
||||
}
|
||||
hir::TyKind::OpaqueDef(item_id, _, _) => {
|
||||
let item = scx.tcx.hir().item(item_id);
|
||||
item.make(offset, Some(item_id.hir_id()), scx)
|
||||
}
|
||||
hir::TyKind::Typeof(_) | hir::TyKind::Infer | hir::TyKind::Err => Err("Ty"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::Item<'hir> {
|
||||
type Parent = hir::HirId;
|
||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||
let id = Some(self.hir_id());
|
||||
|
||||
match self.kind {
|
||||
hir::ItemKind::Static(ref ty, m, ref body) => {
|
||||
let mut text = "static ".to_owned();
|
||||
if m.is_mut() {
|
||||
text.push_str("mut ");
|
||||
}
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_def_id(self.owner_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
let ty = ty.make(offset + text.len(), id, scx)?;
|
||||
text.push_str(&ty.text);
|
||||
|
||||
text.push_str(" = ");
|
||||
let expr = id_to_string(&scx.tcx.hir(), body.hir_id).replace('\n', " ");
|
||||
text.push_str(&expr);
|
||||
|
||||
text.push(';');
|
||||
|
||||
Ok(extend_sig(ty, text, defs, vec![]))
|
||||
}
|
||||
hir::ItemKind::Const(ref ty, ref body) => {
|
||||
let mut text = "const ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_def_id(self.owner_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
let ty = ty.make(offset + text.len(), id, scx)?;
|
||||
text.push_str(&ty.text);
|
||||
|
||||
text.push_str(" = ");
|
||||
let expr = id_to_string(&scx.tcx.hir(), body.hir_id).replace('\n', " ");
|
||||
text.push_str(&expr);
|
||||
|
||||
text.push(';');
|
||||
|
||||
Ok(extend_sig(ty, text, defs, vec![]))
|
||||
}
|
||||
hir::ItemKind::Fn(hir::FnSig { ref decl, header, span: _ }, ref generics, _) => {
|
||||
let mut text = String::new();
|
||||
if let hir::Constness::Const = header.constness {
|
||||
text.push_str("const ");
|
||||
}
|
||||
if hir::IsAsync::Async == header.asyncness {
|
||||
text.push_str("async ");
|
||||
}
|
||||
if let hir::Unsafety::Unsafe = header.unsafety {
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in decl.inputs {
|
||||
// FIXME should descend into patterns to add defs.
|
||||
sig.text.push_str(": ");
|
||||
let nested = i.make(offset + sig.text.len(), Some(i.hir_id), scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.text.push(',');
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push(')');
|
||||
|
||||
if let hir::FnRetTy::Return(ref t) = decl.output {
|
||||
sig.text.push_str(" -> ");
|
||||
let nested = t.make(offset + sig.text.len(), None, scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push_str(" {}");
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::Macro(..) => {
|
||||
let mut text = "macro".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
text.push_str(&name);
|
||||
text.push_str(&"! {}");
|
||||
|
||||
Ok(text_sig(text))
|
||||
}
|
||||
hir::ItemKind::Mod(ref _mod) => {
|
||||
let mut text = "mod ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_def_id(self.owner_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
text.push_str(&name);
|
||||
// Could be either `mod foo;` or `mod foo { ... }`, but we'll just pick one.
|
||||
text.push(';');
|
||||
|
||||
Ok(Signature { text, defs, refs: vec![] })
|
||||
}
|
||||
hir::ItemKind::TyAlias(ref ty, ref generics) => {
|
||||
let text = "type ".to_owned();
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
|
||||
sig.text.push_str(" = ");
|
||||
let ty = ty.make(offset + sig.text.len(), id, scx)?;
|
||||
sig.text.push_str(&ty.text);
|
||||
sig.text.push(';');
|
||||
|
||||
Ok(merge_sigs(sig.text.clone(), vec![sig, ty]))
|
||||
}
|
||||
hir::ItemKind::Enum(_, ref generics) => {
|
||||
let text = "enum ".to_owned();
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::Struct(_, ref generics) => {
|
||||
let text = "struct ".to_owned();
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::Union(_, ref generics) => {
|
||||
let text = "union ".to_owned();
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
sig.text.push_str(" {}");
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::Trait(is_auto, unsafety, ref generics, bounds, _) => {
|
||||
let mut text = String::new();
|
||||
|
||||
if is_auto == hir::IsAuto::Yes {
|
||||
text.push_str("auto ");
|
||||
}
|
||||
|
||||
if let hir::Unsafety::Unsafe = unsafety {
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("trait ");
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
|
||||
if !bounds.is_empty() {
|
||||
sig.text.push_str(": ");
|
||||
sig.text.push_str(&bounds_to_string(bounds));
|
||||
}
|
||||
// FIXME where clause
|
||||
sig.text.push_str(" {}");
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::TraitAlias(ref generics, bounds) => {
|
||||
let mut text = String::new();
|
||||
text.push_str("trait ");
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
|
||||
if !bounds.is_empty() {
|
||||
sig.text.push_str(" = ");
|
||||
sig.text.push_str(&bounds_to_string(bounds));
|
||||
}
|
||||
// FIXME where clause
|
||||
sig.text.push(';');
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ItemKind::Impl(hir::Impl {
|
||||
unsafety,
|
||||
polarity,
|
||||
defaultness,
|
||||
defaultness_span: _,
|
||||
constness,
|
||||
ref generics,
|
||||
ref of_trait,
|
||||
ref self_ty,
|
||||
items: _,
|
||||
}) => {
|
||||
let mut text = String::new();
|
||||
if let hir::Defaultness::Default { .. } = defaultness {
|
||||
text.push_str("default ");
|
||||
}
|
||||
if let hir::Unsafety::Unsafe = unsafety {
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("impl");
|
||||
if let hir::Constness::Const = constness {
|
||||
text.push_str(" const");
|
||||
}
|
||||
|
||||
let generics_sig =
|
||||
generics.make(offset + text.len(), Some(self.owner_id.def_id), scx)?;
|
||||
text.push_str(&generics_sig.text);
|
||||
|
||||
text.push(' ');
|
||||
|
||||
let trait_sig = if let Some(ref t) = *of_trait {
|
||||
if let hir::ImplPolarity::Negative(_) = polarity {
|
||||
text.push('!');
|
||||
}
|
||||
let trait_sig = t.path.make(offset + text.len(), id, scx)?;
|
||||
text.push_str(&trait_sig.text);
|
||||
text.push_str(" for ");
|
||||
trait_sig
|
||||
} else {
|
||||
text_sig(String::new())
|
||||
};
|
||||
|
||||
let ty_sig = self_ty.make(offset + text.len(), id, scx)?;
|
||||
text.push_str(&ty_sig.text);
|
||||
|
||||
text.push_str(" {}");
|
||||
|
||||
Ok(merge_sigs(text, vec![generics_sig, trait_sig, ty_sig]))
|
||||
|
||||
// FIXME where clause
|
||||
}
|
||||
hir::ItemKind::ForeignMod { .. } => Err("extern mod"),
|
||||
hir::ItemKind::GlobalAsm(_) => Err("global asm"),
|
||||
hir::ItemKind::ExternCrate(_) => Err("extern crate"),
|
||||
hir::ItemKind::OpaqueTy(ref opaque) => {
|
||||
if opaque.in_trait {
|
||||
Err("opaque type in trait")
|
||||
} else {
|
||||
Err("opaque type")
|
||||
}
|
||||
}
|
||||
// FIXME should implement this (e.g., pub use).
|
||||
hir::ItemKind::Use(..) => Err("import"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::Path<'hir> {
|
||||
type Parent = hir::HirId;
|
||||
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||
|
||||
let (name, start, end) = match res {
|
||||
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Err => {
|
||||
return Ok(Signature { text: path_to_string(self), defs: vec![], refs: vec![] });
|
||||
}
|
||||
Res::Def(DefKind::AssocConst | DefKind::Variant | DefKind::Ctor(..), _) => {
|
||||
let len = self.segments.len();
|
||||
if len < 2 {
|
||||
return Err("Bad path");
|
||||
}
|
||||
// FIXME: really we should descend into the generics here and add SigElements for
|
||||
// them.
|
||||
// FIXME: would be nice to have a def for the first path segment.
|
||||
let seg1 = path_segment_to_string(&self.segments[len - 2]);
|
||||
let seg2 = path_segment_to_string(&self.segments[len - 1]);
|
||||
let start = offset + seg1.len() + 2;
|
||||
(format!("{}::{}", seg1, seg2), start, start + seg2.len())
|
||||
}
|
||||
_ => {
|
||||
let name = path_segment_to_string(self.segments.last().ok_or("Bad path")?);
|
||||
let end = offset + name.len();
|
||||
(name, offset, end)
|
||||
}
|
||||
};
|
||||
|
||||
let id = id_from_def_id(res.def_id());
|
||||
Ok(Signature { text: name, defs: vec![], refs: vec![SigElement { id, start, end }] })
|
||||
}
|
||||
}
|
||||
|
||||
// This does not cover the where clause, which must be processed separately.
|
||||
impl<'hir> Sig for hir::Generics<'hir> {
|
||||
type Parent = LocalDefId;
|
||||
fn make(&self, offset: usize, _parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||
if self.params.is_empty() {
|
||||
return Ok(text_sig(String::new()));
|
||||
}
|
||||
|
||||
let mut text = "<".to_owned();
|
||||
|
||||
let mut defs = Vec::with_capacity(self.params.len());
|
||||
for param in self.params {
|
||||
let mut param_text = String::new();
|
||||
if let hir::GenericParamKind::Const { .. } = param.kind {
|
||||
param_text.push_str("const ");
|
||||
}
|
||||
param_text.push_str(param.name.ident().as_str());
|
||||
defs.push(SigElement {
|
||||
id: id_from_def_id(param.def_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + param_text.as_str().len(),
|
||||
});
|
||||
if let hir::GenericParamKind::Const { ref ty, default } = param.kind {
|
||||
param_text.push_str(": ");
|
||||
param_text.push_str(&ty_to_string(&ty));
|
||||
if let Some(default) = default {
|
||||
param_text.push_str(" = ");
|
||||
param_text.push_str(&id_to_string(&scx.tcx.hir(), default.hir_id));
|
||||
}
|
||||
}
|
||||
text.push_str(¶m_text);
|
||||
text.push(',');
|
||||
}
|
||||
|
||||
text.push('>');
|
||||
Ok(Signature { text, defs, refs: vec![] })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::FieldDef<'hir> {
|
||||
type Parent = LocalDefId;
|
||||
fn make(&self, offset: usize, _parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||
let mut text = String::new();
|
||||
|
||||
text.push_str(&self.ident.to_string());
|
||||
let defs = Some(SigElement {
|
||||
id: id_from_def_id(self.def_id.to_def_id()),
|
||||
start: offset,
|
||||
end: offset + text.len(),
|
||||
});
|
||||
text.push_str(": ");
|
||||
|
||||
let mut ty_sig = self.ty.make(offset + text.len(), Some(self.hir_id), scx)?;
|
||||
text.push_str(&ty_sig.text);
|
||||
ty_sig.text = text;
|
||||
ty_sig.defs.extend(defs.into_iter());
|
||||
Ok(ty_sig)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::Variant<'hir> {
|
||||
type Parent = LocalDefId;
|
||||
fn make(&self, offset: usize, parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||
let mut text = self.ident.to_string();
|
||||
match self.data {
|
||||
hir::VariantData::Struct(fields, r) => {
|
||||
let id = parent_id.ok_or("Missing id for Variant's parent")?;
|
||||
let name_def = SigElement {
|
||||
id: id_from_def_id(id.to_def_id()),
|
||||
start: offset,
|
||||
end: offset + text.len(),
|
||||
};
|
||||
text.push_str(" { ");
|
||||
let mut defs = vec![name_def];
|
||||
let mut refs = vec![];
|
||||
if r {
|
||||
text.push_str("/* parse error */ ");
|
||||
} else {
|
||||
for f in fields {
|
||||
let field_sig = f.make(offset + text.len(), Some(id), scx)?;
|
||||
text.push_str(&field_sig.text);
|
||||
text.push_str(", ");
|
||||
defs.extend(field_sig.defs.into_iter());
|
||||
refs.extend(field_sig.refs.into_iter());
|
||||
}
|
||||
}
|
||||
text.push('}');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Tuple(fields, _, def_id) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_def_id(def_id.to_def_id()),
|
||||
start: offset,
|
||||
end: offset + text.len(),
|
||||
};
|
||||
text.push('(');
|
||||
let mut defs = vec![name_def];
|
||||
let mut refs = vec![];
|
||||
for f in fields {
|
||||
let field_sig = f.make(offset + text.len(), Some(def_id), scx)?;
|
||||
text.push_str(&field_sig.text);
|
||||
text.push_str(", ");
|
||||
defs.extend(field_sig.defs.into_iter());
|
||||
refs.extend(field_sig.refs.into_iter());
|
||||
}
|
||||
text.push(')');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Unit(_, def_id) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_def_id(def_id.to_def_id()),
|
||||
start: offset,
|
||||
end: offset + text.len(),
|
||||
};
|
||||
Ok(Signature { text, defs: vec![name_def], refs: vec![] })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Sig for hir::ForeignItem<'hir> {
|
||||
type Parent = hir::HirId;
|
||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||
let id = Some(self.hir_id());
|
||||
match self.kind {
|
||||
hir::ForeignItemKind::Fn(decl, _, ref generics) => {
|
||||
let mut text = String::new();
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig =
|
||||
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in decl.inputs {
|
||||
sig.text.push_str(": ");
|
||||
let nested = i.make(offset + sig.text.len(), Some(i.hir_id), scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.text.push(',');
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push(')');
|
||||
|
||||
if let hir::FnRetTy::Return(ref t) = decl.output {
|
||||
sig.text.push_str(" -> ");
|
||||
let nested = t.make(offset + sig.text.len(), None, scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push(';');
|
||||
|
||||
Ok(sig)
|
||||
}
|
||||
hir::ForeignItemKind::Static(ref ty, m) => {
|
||||
let mut text = "static ".to_owned();
|
||||
text.push_str(m.prefix_str());
|
||||
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_def_id(self.owner_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
let ty_sig = ty.make(offset + text.len(), id, scx)?;
|
||||
text.push(';');
|
||||
|
||||
Ok(extend_sig(ty_sig, text, defs, vec![]))
|
||||
}
|
||||
hir::ForeignItemKind::Type => {
|
||||
let mut text = "type ".to_owned();
|
||||
let name = self.ident.to_string();
|
||||
let defs = vec![SigElement {
|
||||
id: id_from_def_id(self.owner_id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
}];
|
||||
text.push_str(&name);
|
||||
text.push(';');
|
||||
|
||||
Ok(Signature { text, defs, refs: vec![] })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn name_and_generics(
|
||||
mut text: String,
|
||||
offset: usize,
|
||||
generics: &hir::Generics<'_>,
|
||||
id: hir::OwnerId,
|
||||
name: Ident,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Result {
|
||||
let name = name.to_string();
|
||||
let def = SigElement {
|
||||
id: id_from_def_id(id.to_def_id()),
|
||||
start: offset + text.len(),
|
||||
end: offset + text.len() + name.len(),
|
||||
};
|
||||
text.push_str(&name);
|
||||
let generics: Signature = generics.make(offset + text.len(), Some(id.def_id), scx)?;
|
||||
// FIXME where clause
|
||||
let text = format!("{}{}", text, generics.text);
|
||||
Ok(extend_sig(generics, text, vec![def], vec![]))
|
||||
}
|
||||
|
||||
fn make_assoc_type_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Ident,
|
||||
bounds: Option<hir::GenericBounds<'_>>,
|
||||
default: Option<&hir::Ty<'_>>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Result {
|
||||
let mut text = "type ".to_owned();
|
||||
let name = ident.to_string();
|
||||
let mut defs = vec![SigElement {
|
||||
id: id_from_def_id(id.to_def_id()),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
}];
|
||||
let mut refs = vec![];
|
||||
text.push_str(&name);
|
||||
if let Some(bounds) = bounds {
|
||||
text.push_str(": ");
|
||||
// FIXME should descend into bounds
|
||||
text.push_str(&bounds_to_string(bounds));
|
||||
}
|
||||
if let Some(default) = default {
|
||||
text.push_str(" = ");
|
||||
let ty_sig = default.make(text.len(), Some(id.into()), scx)?;
|
||||
text.push_str(&ty_sig.text);
|
||||
defs.extend(ty_sig.defs.into_iter());
|
||||
refs.extend(ty_sig.refs.into_iter());
|
||||
}
|
||||
text.push(';');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
|
||||
fn make_assoc_const_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Symbol,
|
||||
ty: &hir::Ty<'_>,
|
||||
default: Option<&hir::Expr<'_>>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Result {
|
||||
let mut text = "const ".to_owned();
|
||||
let name = ident.to_string();
|
||||
let mut defs = vec![SigElement {
|
||||
id: id_from_def_id(id.to_def_id()),
|
||||
start: text.len(),
|
||||
end: text.len() + name.len(),
|
||||
}];
|
||||
let mut refs = vec![];
|
||||
text.push_str(&name);
|
||||
text.push_str(": ");
|
||||
|
||||
let ty_sig = ty.make(text.len(), Some(id.into()), scx)?;
|
||||
text.push_str(&ty_sig.text);
|
||||
defs.extend(ty_sig.defs.into_iter());
|
||||
refs.extend(ty_sig.refs.into_iter());
|
||||
|
||||
if let Some(default) = default {
|
||||
text.push_str(" = ");
|
||||
text.push_str(&id_to_string(&scx.tcx.hir(), default.hir_id));
|
||||
}
|
||||
text.push(';');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
|
||||
fn make_method_signature(
|
||||
id: hir::OwnerId,
|
||||
ident: Ident,
|
||||
generics: &hir::Generics<'_>,
|
||||
m: &hir::FnSig<'_>,
|
||||
scx: &SaveContext<'_>,
|
||||
) -> Result {
|
||||
// FIXME code dup with function signature
|
||||
let mut text = String::new();
|
||||
if let hir::Constness::Const = m.header.constness {
|
||||
text.push_str("const ");
|
||||
}
|
||||
if hir::IsAsync::Async == m.header.asyncness {
|
||||
text.push_str("async ");
|
||||
}
|
||||
if let hir::Unsafety::Unsafe = m.header.unsafety {
|
||||
text.push_str("unsafe ");
|
||||
}
|
||||
text.push_str("fn ");
|
||||
|
||||
let mut sig = name_and_generics(text, 0, generics, id, ident, scx)?;
|
||||
|
||||
sig.text.push('(');
|
||||
for i in m.decl.inputs {
|
||||
sig.text.push_str(": ");
|
||||
let nested = i.make(sig.text.len(), Some(i.hir_id), scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.text.push(',');
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push(')');
|
||||
|
||||
if let hir::FnRetTy::Return(ref t) = m.decl.output {
|
||||
sig.text.push_str(" -> ");
|
||||
let nested = t.make(sig.text.len(), None, scx)?;
|
||||
sig.text.push_str(&nested.text);
|
||||
sig.defs.extend(nested.defs.into_iter());
|
||||
sig.refs.extend(nested.refs.into_iter());
|
||||
}
|
||||
sig.text.push_str(" {}");
|
||||
|
||||
Ok(sig)
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
use crate::generated_code;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_lexer::{tokenize, TokenKind};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SpanUtils<'a> {
|
||||
pub sess: &'a Session,
|
||||
}
|
||||
|
||||
impl<'a> SpanUtils<'a> {
|
||||
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
|
||||
SpanUtils { sess }
|
||||
}
|
||||
|
||||
pub fn make_filename_string(&self, file: &SourceFile) -> String {
|
||||
match &file.name {
|
||||
FileName::Real(RealFileName::LocalPath(path)) => {
|
||||
if path.is_absolute() {
|
||||
self.sess.source_map().path_mapping().map_prefix(path).0.display().to_string()
|
||||
} else {
|
||||
self.sess
|
||||
.opts
|
||||
.working_dir
|
||||
.remapped_path_if_available()
|
||||
.join(&path)
|
||||
.display()
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
filename => filename.prefer_remapped().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn snippet(&self, span: Span) -> String {
|
||||
match self.sess.source_map().span_to_snippet(span) {
|
||||
Ok(s) => s,
|
||||
Err(_) => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the span of `*` token withing the larger `span`.
|
||||
pub fn sub_span_of_star(&self, mut span: Span) -> Option<Span> {
|
||||
let begin = self.sess.source_map().lookup_byte_offset(span.lo());
|
||||
let end = self.sess.source_map().lookup_byte_offset(span.hi());
|
||||
// Make the range zero-length if the span is invalid.
|
||||
if begin.sf.start_pos != end.sf.start_pos {
|
||||
span = span.shrink_to_lo();
|
||||
}
|
||||
|
||||
let sf = Lrc::clone(&begin.sf);
|
||||
|
||||
self.sess.source_map().ensure_source_file_source_present(Lrc::clone(&sf));
|
||||
let src =
|
||||
sf.src.clone().or_else(|| sf.external_src.borrow().get_source().map(Lrc::clone))?;
|
||||
let to_index = |pos: BytePos| -> usize { (pos - sf.start_pos).0 as usize };
|
||||
let text = &src[to_index(span.lo())..to_index(span.hi())];
|
||||
let start_pos = {
|
||||
let mut pos = 0;
|
||||
tokenize(text)
|
||||
.map(|token| {
|
||||
let start = pos;
|
||||
pos += token.len;
|
||||
(start, token)
|
||||
})
|
||||
.find(|(_pos, token)| token.kind == TokenKind::Star)?
|
||||
.0
|
||||
};
|
||||
let lo = span.lo() + BytePos(start_pos as u32);
|
||||
let hi = lo + BytePos(1);
|
||||
Some(span.with_lo(lo).with_hi(hi))
|
||||
}
|
||||
|
||||
/// Return true if the span is generated code, and
|
||||
/// it is not a subspan of the root callsite.
|
||||
///
|
||||
/// Used to filter out spans of minimal value,
|
||||
/// such as references to macro internal variables.
|
||||
pub fn filter_generated(&self, span: Span) -> bool {
|
||||
if generated_code(span) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//If the span comes from a fake source_file, filter it.
|
||||
!self.sess.source_map().lookup_char_pos(span.lo()).file.is_real_file()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! filter {
|
||||
($util: expr, $parent: expr) => {
|
||||
if $util.filter_generated($parent) {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
}
|
@ -1629,9 +1629,6 @@ options! {
|
||||
saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||
"make float->int casts UB-free: numbers outside the integer type's range are clipped to \
|
||||
the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
|
||||
save_analysis: bool = (false, parse_bool, [UNTRACKED],
|
||||
"write syntax and type analysis (in JSON format) information, in \
|
||||
addition to normal output (default: no)"),
|
||||
self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
|
||||
parse_switch_with_opt_path, [UNTRACKED],
|
||||
"run the self profiler and output the raw event data"),
|
||||
|
@ -780,7 +780,6 @@ impl<'a> Builder<'a> {
|
||||
install::Clippy,
|
||||
install::Miri,
|
||||
install::LlvmTools,
|
||||
install::Analysis,
|
||||
install::Src,
|
||||
install::Rustc
|
||||
),
|
||||
@ -1802,16 +1801,6 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if mode == Mode::Std && self.config.extended && compiler.is_final_stage(self) {
|
||||
rustflags.arg("-Zsave-analysis");
|
||||
cargo.env(
|
||||
"RUST_SAVE_ANALYSIS_CONFIG",
|
||||
"{\"output_file\": null,\"full_docs\": false,\
|
||||
\"pub_only\": true,\"reachable_only\": false,\
|
||||
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}",
|
||||
);
|
||||
}
|
||||
|
||||
// If Control Flow Guard is enabled, pass the `control-flow-guard` flag to rustc
|
||||
// when compiling the standard library, since this might be linked into the final outputs
|
||||
// produced by rustc. Since this mitigation is only available on Windows, only enable it
|
||||
|
@ -12,6 +12,7 @@ use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
@ -753,7 +754,7 @@ impl Step for Analysis {
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates a tarball of save-analysis metadata, if available.
|
||||
/// Creates a tarball of (degenerate) save-analysis metadata, if available.
|
||||
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
|
||||
let compiler = self.compiler;
|
||||
let target = self.target;
|
||||
@ -761,7 +762,6 @@ impl Step for Analysis {
|
||||
return None;
|
||||
}
|
||||
|
||||
builder.ensure(compile::Std::new(compiler, target));
|
||||
let src = builder
|
||||
.stage_out(compiler, Mode::Std)
|
||||
.join(target.triple)
|
||||
@ -769,6 +769,13 @@ impl Step for Analysis {
|
||||
.join("deps")
|
||||
.join("save-analysis");
|
||||
|
||||
// Write a file indicating that this component has been removed.
|
||||
t!(std::fs::create_dir_all(&src));
|
||||
let mut removed = src.clone();
|
||||
removed.push("removed.json");
|
||||
let mut f = t!(std::fs::File::create(removed));
|
||||
t!(write!(f, r#"{{ "warning": "The `rust-analysis` component has been removed." }}"#));
|
||||
|
||||
let mut tarball = Tarball::new(builder, "rust-analysis", &target.triple);
|
||||
tarball.include_target_in_component_name(true);
|
||||
tarball.add_dir(src, format!("lib/rustlib/{}/analysis", target.triple));
|
||||
|
@ -243,18 +243,6 @@ install!((self, builder, _config),
|
||||
);
|
||||
}
|
||||
};
|
||||
Analysis, alias = "analysis", Self::should_build(_config), only_hosts: false, {
|
||||
// `expect` should be safe, only None with host != build, but this
|
||||
// only uses the `build` compiler
|
||||
let tarball = builder.ensure(dist::Analysis {
|
||||
// Find the actual compiler (handling the full bootstrap option) which
|
||||
// produced the save-analysis data because that data isn't copied
|
||||
// through the sysroot uplifting.
|
||||
compiler: builder.compiler_for(builder.top_stage, builder.config.build, self.target),
|
||||
target: self.target
|
||||
}).expect("missing analysis");
|
||||
install_sh(builder, "analysis", self.compiler.stage, Some(self.target), &tarball);
|
||||
};
|
||||
Rustc, path = "compiler/rustc", true, only_hosts: true, {
|
||||
let tarball = builder.ensure(dist::Rustc {
|
||||
compiler: builder.compiler(builder.top_stage, self.target),
|
||||
|
@ -223,7 +223,6 @@ flag][option-emit] documentation.
|
||||
- "link": The generated crate as specified by the crate-type.
|
||||
- "dep-info": The `.d` file with dependency information in a Makefile-like syntax.
|
||||
- "metadata": The Rust `.rmeta` file containing metadata about the crate.
|
||||
- "save-analysis": A JSON file emitted by the `-Zsave-analysis` feature.
|
||||
*/
|
||||
"emit": "link"
|
||||
}
|
||||
|
@ -192,8 +192,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
"remove_dir_all",
|
||||
"rls-data",
|
||||
"rls-span",
|
||||
"rustc-demangle",
|
||||
"rustc-hash",
|
||||
"rustc-rayon",
|
||||
|
@ -1,8 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
all:
|
||||
# Work in /tmp, because we need to create the `save-analysis-temp` folder.
|
||||
cp a.rs $(TMPDIR)/
|
||||
cd $(TMPDIR) && $(RUSTC) -Zsave-analysis $(TMPDIR)/a.rs 2> $(TMPDIR)/stderr.txt || ( cat $(TMPDIR)/stderr.txt && exit 1 )
|
||||
[ ! -s $(TMPDIR)/stderr.txt ] || ( cat $(TMPDIR)/stderr.txt && exit 1 )
|
||||
[ -f $(TMPDIR)/save-analysis/liba.json ] || ( ls -la $(TMPDIR) && exit 1 )
|
@ -1,9 +0,0 @@
|
||||
#![crate_type = "lib"]
|
||||
pub struct V<S>(#[allow(unused_tuple_struct_fields)] S);
|
||||
pub trait An {
|
||||
type U;
|
||||
}
|
||||
pub trait F<A> {
|
||||
}
|
||||
impl<A: An> F<A> for V<<A as An>::U> {
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
include ../tools.mk
|
||||
all: code
|
||||
krate2: krate2.rs
|
||||
$(RUSTC) $<
|
||||
code: foo.rs krate2
|
||||
$(RUSTC) foo.rs -Zsave-analysis || exit 0
|
@ -1,5 +0,0 @@
|
||||
// sub-module in the same directory as the main crate file
|
||||
|
||||
pub struct SameStruct {
|
||||
pub name: String
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
pub fn hello(x: isize) {
|
||||
println!("macro {} :-(", x);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// sub-module in a sub-directory
|
||||
|
||||
use sub::sub2 as msalias;
|
||||
use sub::sub2;
|
||||
|
||||
static yy: usize = 25;
|
||||
|
||||
mod sub {
|
||||
pub mod sub2 {
|
||||
pub mod sub3 {
|
||||
pub fn hello() {
|
||||
println!("hello from module 3");
|
||||
}
|
||||
}
|
||||
pub fn hello() {
|
||||
println!("hello from a module");
|
||||
}
|
||||
|
||||
pub struct nested_struct {
|
||||
pub field2: u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SubStruct {
|
||||
pub name: String
|
||||
}
|
@ -1,463 +0,0 @@
|
||||
#![crate_name = "test"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate rustc_graphviz;
|
||||
// A simple rust project
|
||||
|
||||
extern crate krate2;
|
||||
extern crate krate2 as krate3;
|
||||
|
||||
use rustc_graphviz::RenderOption;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io::Write;
|
||||
|
||||
use sub::sub2 as msalias;
|
||||
use sub::sub2;
|
||||
use sub::sub2::nested_struct as sub_struct;
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
use std::char::from_u32;
|
||||
|
||||
static uni: &'static str = "Les Miséééééééérables";
|
||||
static yy: usize = 25;
|
||||
|
||||
static bob: Option<graphviz::RenderOption> = None;
|
||||
|
||||
// buglink test - see issue #1337.
|
||||
|
||||
fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
|
||||
let s = sub_struct { field2: 45u32 };
|
||||
|
||||
// import tests
|
||||
fn foo(x: &Write) {}
|
||||
let _: Option<_> = from_u32(45);
|
||||
|
||||
let x = 42usize;
|
||||
|
||||
krate2::hello();
|
||||
krate3::hello();
|
||||
|
||||
let x = (3isize, 4usize);
|
||||
let y = x.1;
|
||||
}
|
||||
|
||||
// Issue #37700
|
||||
const LUT_BITS: usize = 3;
|
||||
pub struct HuffmanTable {
|
||||
ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
|
||||
}
|
||||
|
||||
struct TupStruct(isize, isize, Box<str>);
|
||||
|
||||
fn test_tup_struct(x: TupStruct) -> isize {
|
||||
x.1
|
||||
}
|
||||
|
||||
fn println(s: &str) {
|
||||
std::io::stdout().write_all(s.as_bytes());
|
||||
}
|
||||
|
||||
mod sub {
|
||||
pub mod sub2 {
|
||||
use std::io::Write;
|
||||
pub mod sub3 {
|
||||
use std::io::Write;
|
||||
pub fn hello() {
|
||||
::println("hello from module 3");
|
||||
}
|
||||
}
|
||||
pub fn hello() {
|
||||
::println("hello from a module");
|
||||
}
|
||||
|
||||
pub struct nested_struct {
|
||||
pub field2: u32,
|
||||
}
|
||||
|
||||
pub enum nested_enum {
|
||||
Nest2 = 2,
|
||||
Nest3 = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod SameDir;
|
||||
pub mod SubDir;
|
||||
|
||||
#[path = "SameDir3.rs"]
|
||||
pub mod SameDir2;
|
||||
|
||||
struct nofields;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct some_fields {
|
||||
field1: u32,
|
||||
}
|
||||
|
||||
type SF = some_fields;
|
||||
|
||||
trait SuperTrait {
|
||||
fn qux(&self) {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
trait SomeTrait: SuperTrait {
|
||||
fn Method(&self, x: u32) -> u32;
|
||||
|
||||
fn prov(&self, x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
42
|
||||
}
|
||||
fn provided_method(&self) -> u32 {
|
||||
42
|
||||
}
|
||||
}
|
||||
|
||||
trait SubTrait: SomeTrait {
|
||||
fn stat2(x: &Self) -> u32 {
|
||||
32
|
||||
}
|
||||
}
|
||||
|
||||
trait SizedTrait: Sized {}
|
||||
|
||||
fn error(s: &SizedTrait) {
|
||||
let foo = 42;
|
||||
println!("Hello world! {}", foo);
|
||||
}
|
||||
|
||||
impl SomeTrait for some_fields {
|
||||
fn Method(&self, x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
self.field1
|
||||
}
|
||||
}
|
||||
|
||||
impl SuperTrait for some_fields {}
|
||||
|
||||
impl SubTrait for some_fields {}
|
||||
|
||||
impl some_fields {
|
||||
fn stat(x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
42
|
||||
}
|
||||
fn stat2(x: &some_fields) -> u32 {
|
||||
42
|
||||
}
|
||||
|
||||
fn align_to<T>(&mut self) {}
|
||||
|
||||
fn test(&mut self) {
|
||||
self.align_to::<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
impl SuperTrait for nofields {}
|
||||
impl SomeTrait for nofields {
|
||||
fn Method(&self, x: u32) -> u32 {
|
||||
self.Method(x);
|
||||
43
|
||||
}
|
||||
|
||||
fn provided_method(&self) -> u32 {
|
||||
21
|
||||
}
|
||||
}
|
||||
|
||||
impl SubTrait for nofields {}
|
||||
|
||||
impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
|
||||
|
||||
fn f_with_params<T: SomeTrait>(x: &T) {
|
||||
x.Method(41);
|
||||
}
|
||||
|
||||
type MyType = Box<some_fields>;
|
||||
|
||||
enum SomeEnum<'a> {
|
||||
Ints(isize, isize),
|
||||
Floats(f64, f64),
|
||||
Strings(&'a str, &'a str, &'a str),
|
||||
MyTypes(MyType, MyType),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum SomeOtherEnum {
|
||||
SomeConst1,
|
||||
SomeConst2,
|
||||
SomeConst3,
|
||||
}
|
||||
|
||||
enum SomeStructEnum {
|
||||
EnumStruct { a: isize, b: isize },
|
||||
EnumStruct2 { f1: MyType, f2: MyType },
|
||||
EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
|
||||
}
|
||||
|
||||
fn matchSomeEnum(val: SomeEnum) {
|
||||
match val {
|
||||
SomeEnum::Ints(int1, int2) => {
|
||||
println(&(int1 + int2).to_string());
|
||||
}
|
||||
SomeEnum::Floats(float1, float2) => {
|
||||
println(&(float2 * float1).to_string());
|
||||
}
|
||||
SomeEnum::Strings(.., s3) => {
|
||||
println(s3);
|
||||
}
|
||||
SomeEnum::MyTypes(mt1, mt2) => {
|
||||
println(&(mt1.field1 - mt2.field1).to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeStructEnum(se: SomeStructEnum) {
|
||||
match se {
|
||||
SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()),
|
||||
SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()),
|
||||
SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeStructEnum2(se: SomeStructEnum) {
|
||||
use SomeStructEnum::*;
|
||||
match se {
|
||||
EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
|
||||
EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
|
||||
EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeOtherEnum(val: SomeOtherEnum) {
|
||||
use SomeOtherEnum::{SomeConst2, SomeConst3};
|
||||
match val {
|
||||
SomeOtherEnum::SomeConst1 => {
|
||||
println("I'm const1.");
|
||||
}
|
||||
SomeConst2 | SomeConst3 => {
|
||||
println("I'm const2 or const3.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
|
||||
SameDir2::hello(43);
|
||||
|
||||
println(&yy.to_string());
|
||||
let (x, y): (u32, u32) = (5, 3);
|
||||
println(&x.to_string());
|
||||
println(&z.to_string());
|
||||
let x: u32 = x;
|
||||
println(&x.to_string());
|
||||
let x = "hello";
|
||||
println(x);
|
||||
|
||||
let x = 32.0f32;
|
||||
let _ = (x + ((x * x) + 1.0).sqrt()).ln();
|
||||
|
||||
let s: Box<SomeTrait> = Box::new(some_fields { field1: 43 });
|
||||
let s2: Box<some_fields> = Box::new(some_fields { field1: 43 });
|
||||
let s3 = Box::new(nofields);
|
||||
|
||||
s.Method(43);
|
||||
s3.Method(43);
|
||||
s2.Method(43);
|
||||
|
||||
ex.prov(43);
|
||||
|
||||
let y: u32 = 56;
|
||||
// static method on struct
|
||||
let r = some_fields::stat(y);
|
||||
// trait static method, calls default
|
||||
let r = SubTrait::stat2(&*s3);
|
||||
|
||||
let s4 = s3 as Box<SomeTrait>;
|
||||
s4.Method(43);
|
||||
|
||||
s4.provided_method();
|
||||
s2.prov(45);
|
||||
|
||||
let closure = |x: u32, s: &SomeTrait| {
|
||||
s.Method(23);
|
||||
return x + y;
|
||||
};
|
||||
|
||||
let z = closure(10, &*s);
|
||||
}
|
||||
|
||||
pub struct blah {
|
||||
used_link_args: RefCell<[&'static str; 0]>,
|
||||
}
|
||||
|
||||
#[macro_use]
|
||||
mod macro_use_test {
|
||||
macro_rules! test_rec {
|
||||
(q, $src: expr) => {{
|
||||
print!("{}", $src);
|
||||
test_rec!($src);
|
||||
}};
|
||||
($src: expr) => {
|
||||
print!("{}", $src);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! internal_vars {
|
||||
($src: ident) => {{
|
||||
let mut x = $src;
|
||||
x += 100;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// foo
|
||||
let s = Box::new(some_fields { field1: 43 });
|
||||
hello((43, "a".to_string()), *s);
|
||||
sub::sub2::hello();
|
||||
sub2::sub3::hello();
|
||||
|
||||
let h = sub2::sub3::hello;
|
||||
h();
|
||||
|
||||
// utf8 chars
|
||||
let ut = "Les Miséééééééérables";
|
||||
|
||||
// For some reason, this pattern of macro_rules foiled our generated code
|
||||
// avoiding strategy.
|
||||
macro_rules! variable_str(($name:expr) => (
|
||||
some_fields {
|
||||
field1: $name,
|
||||
}
|
||||
));
|
||||
let vs = variable_str!(32);
|
||||
|
||||
let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
|
||||
let _ = blah { used_link_args: RefCell::new([]) };
|
||||
let s1 = nofields;
|
||||
let s2 = SF { field1: 55 };
|
||||
let s3: some_fields = some_fields { field1: 55 };
|
||||
let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
|
||||
let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
|
||||
println(&s2.field1.to_string());
|
||||
let s5: MyType = Box::new(some_fields { field1: 55 });
|
||||
let s = SameDir::SameStruct { name: "Bob".to_string() };
|
||||
let s = SubDir::SubStruct { name: "Bob".to_string() };
|
||||
let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5);
|
||||
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
|
||||
matchSomeEnum(s6);
|
||||
matchSomeEnum(s7);
|
||||
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
|
||||
matchSomeOtherEnum(s8);
|
||||
let s9: SomeStructEnum =
|
||||
SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) };
|
||||
matchSomeStructEnum(s9);
|
||||
|
||||
for x in &vec![1, 2, 3] {
|
||||
let _y = x;
|
||||
}
|
||||
|
||||
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
|
||||
if let SomeEnum::Strings(..) = s7 {
|
||||
println!("hello!");
|
||||
}
|
||||
|
||||
for i in 0..5 {
|
||||
foo_foo(i);
|
||||
}
|
||||
|
||||
if let Some(x) = None {
|
||||
foo_foo(x);
|
||||
}
|
||||
|
||||
if false {
|
||||
} else if let Some(y) = None {
|
||||
foo_foo(y);
|
||||
}
|
||||
|
||||
while let Some(z) = None {
|
||||
foo_foo(z);
|
||||
}
|
||||
|
||||
let mut x = 4;
|
||||
test_rec!(q, "Hello");
|
||||
assert_eq!(x, 4);
|
||||
internal_vars!(x);
|
||||
}
|
||||
|
||||
fn foo_foo(_: i32) {}
|
||||
|
||||
impl Iterator for nofields {
|
||||
type Item = (usize, usize);
|
||||
|
||||
fn next(&mut self) -> Option<(usize, usize)> {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
trait Pattern<'a> {
|
||||
type Searcher;
|
||||
}
|
||||
|
||||
struct CharEqPattern;
|
||||
|
||||
impl<'a> Pattern<'a> for CharEqPattern {
|
||||
type Searcher = CharEqPattern;
|
||||
}
|
||||
|
||||
struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
|
||||
|
||||
pub trait Error {}
|
||||
|
||||
impl Error + 'static {
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Error + 'static + Send {
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
<Error + 'static>::is::<T>(self)
|
||||
}
|
||||
}
|
||||
extern crate serialize;
|
||||
#[derive(Clone, Copy, Hash, Encodable, Decodable, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
|
||||
struct AllDerives(i32);
|
||||
|
||||
fn test_format_args() {
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
let name = "Joe Blogg";
|
||||
println!("Hello {}", name);
|
||||
print!("Hello {0}", name);
|
||||
print!("{0} + {} = {}", x, y);
|
||||
print!("x is {}, y is {1}, name is {n}", x, y, n = name);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
static EXTERN_FOO: u8;
|
||||
fn extern_foo(a: u8, b: i32) -> String;
|
||||
}
|
||||
|
||||
struct Rls699 {
|
||||
f: u32,
|
||||
}
|
||||
|
||||
fn new(f: u32) -> Rls699 {
|
||||
Rls699 { fs }
|
||||
}
|
||||
|
||||
fn invalid_tuple_struct_access() {
|
||||
bar.0;
|
||||
|
||||
struct S;
|
||||
S.0;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#![ crate_name = "krate2" ]
|
||||
#![ crate_type = "lib" ]
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
pub fn hello() {
|
||||
std::io::stdout().write_all(b"hello world!\n");
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
all: extern_absolute_paths.rs krate2
|
||||
$(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018 --extern krate2
|
||||
cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py
|
||||
|
||||
krate2: krate2.rs
|
||||
$(RUSTC) $<
|
@ -1,6 +0,0 @@
|
||||
use krate2::hello;
|
||||
|
||||
fn main() {
|
||||
hello();
|
||||
::krate2::hello();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#![crate_name = "krate2"]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub fn hello() {
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import json
|
||||
|
||||
crates = json.loads(sys.stdin.readline().strip())["prelude"]["external_crates"]
|
||||
assert any(map(lambda c: c["id"]["name"] == "krate2", crates))
|
@ -1,6 +0,0 @@
|
||||
include ../tools.mk
|
||||
all: code
|
||||
krate2: krate2.rs
|
||||
$(RUSTC) $<
|
||||
code: foo.rs krate2
|
||||
$(RUSTC) foo.rs -Zsave-analysis
|
@ -1,5 +0,0 @@
|
||||
// sub-module in the same directory as the main crate file
|
||||
|
||||
pub struct SameStruct {
|
||||
pub name: String
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
pub fn hello(x: isize) {
|
||||
println!("macro {} :-(", x);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// sub-module in a sub-directory
|
||||
|
||||
use sub::sub2 as msalias;
|
||||
use sub::sub2;
|
||||
|
||||
static yy: usize = 25;
|
||||
|
||||
mod sub {
|
||||
pub mod sub2 {
|
||||
pub mod sub3 {
|
||||
pub fn hello() {
|
||||
println!("hello from module 3");
|
||||
}
|
||||
}
|
||||
pub fn hello() {
|
||||
println!("hello from a module");
|
||||
}
|
||||
|
||||
pub struct nested_struct {
|
||||
pub field2: u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SubStruct {
|
||||
pub name: String
|
||||
}
|
@ -1 +0,0 @@
|
||||
Extra docs for this struct.
|
@ -1,465 +0,0 @@
|
||||
#![crate_name = "test"]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(associated_type_defaults)]
|
||||
|
||||
extern crate rustc_graphviz;
|
||||
// A simple rust project
|
||||
|
||||
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
|
||||
// files.
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_driver;
|
||||
|
||||
extern crate krate2;
|
||||
extern crate krate2 as krate3;
|
||||
|
||||
use rustc_graphviz::RenderOption;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io::Write;
|
||||
|
||||
use sub::sub2 as msalias;
|
||||
use sub::sub2;
|
||||
use sub::sub2::nested_struct as sub_struct;
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
use std::char::from_u32;
|
||||
|
||||
static uni: &'static str = "Les Miséééééééérables";
|
||||
static yy: usize = 25;
|
||||
|
||||
static bob: Option<rustc_graphviz::RenderOption> = None;
|
||||
|
||||
// buglink test - see issue #1337.
|
||||
|
||||
fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
|
||||
let s = sub_struct { field2: 45u32 };
|
||||
|
||||
// import tests
|
||||
fn foo(x: &Write) {}
|
||||
let _: Option<_> = from_u32(45);
|
||||
|
||||
let x = 42usize;
|
||||
|
||||
krate2::hello();
|
||||
krate3::hello();
|
||||
|
||||
let x = (3isize, 4usize);
|
||||
let y = x.1;
|
||||
}
|
||||
|
||||
// Issue #37700
|
||||
const LUT_BITS: usize = 3;
|
||||
pub struct HuffmanTable {
|
||||
ac_lut: Option<[(i16, u8); 1 << LUT_BITS]>,
|
||||
}
|
||||
|
||||
struct TupStruct(isize, isize, Box<str>);
|
||||
|
||||
fn test_tup_struct(x: TupStruct) -> isize {
|
||||
x.1
|
||||
}
|
||||
|
||||
fn println(s: &str) {
|
||||
std::io::stdout().write_all(s.as_bytes());
|
||||
}
|
||||
|
||||
mod sub {
|
||||
pub mod sub2 {
|
||||
use std::io::Write;
|
||||
pub mod sub3 {
|
||||
use std::io::Write;
|
||||
pub fn hello() {
|
||||
::println("hello from module 3");
|
||||
}
|
||||
}
|
||||
pub fn hello() {
|
||||
::println("hello from a module");
|
||||
}
|
||||
|
||||
pub struct nested_struct {
|
||||
pub field2: u32,
|
||||
}
|
||||
|
||||
pub enum nested_enum {
|
||||
Nest2 = 2,
|
||||
Nest3 = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod SameDir;
|
||||
pub mod SubDir;
|
||||
|
||||
#[path = "SameDir3.rs"]
|
||||
pub mod SameDir2;
|
||||
|
||||
struct nofields;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct some_fields {
|
||||
field1: u32,
|
||||
}
|
||||
|
||||
type SF = some_fields;
|
||||
|
||||
trait SuperTrait {
|
||||
fn qux(&self) {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
trait SomeTrait: SuperTrait {
|
||||
fn Method(&self, x: u32) -> u32;
|
||||
|
||||
fn prov(&self, x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
42
|
||||
}
|
||||
fn provided_method(&self) -> u32 {
|
||||
42
|
||||
}
|
||||
}
|
||||
|
||||
trait SubTrait: SomeTrait {
|
||||
fn stat2(x: &Self) -> u32 {
|
||||
32
|
||||
}
|
||||
}
|
||||
|
||||
impl SomeTrait for some_fields {
|
||||
fn Method(&self, x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
self.field1
|
||||
}
|
||||
}
|
||||
|
||||
impl SuperTrait for some_fields {}
|
||||
|
||||
impl SubTrait for some_fields {}
|
||||
|
||||
impl some_fields {
|
||||
fn stat(x: u32) -> u32 {
|
||||
println(&x.to_string());
|
||||
42
|
||||
}
|
||||
fn stat2(x: &some_fields) -> u32 {
|
||||
42
|
||||
}
|
||||
|
||||
fn align_to<T>(&mut self) {}
|
||||
|
||||
fn test(&mut self) {
|
||||
self.align_to::<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
impl SuperTrait for nofields {}
|
||||
impl SomeTrait for nofields {
|
||||
fn Method(&self, x: u32) -> u32 {
|
||||
self.Method(x);
|
||||
43
|
||||
}
|
||||
|
||||
fn provided_method(&self) -> u32 {
|
||||
21
|
||||
}
|
||||
}
|
||||
|
||||
impl SubTrait for nofields {}
|
||||
|
||||
impl SuperTrait for (Box<nofields>, Box<some_fields>) {}
|
||||
|
||||
fn f_with_params<T: SomeTrait>(x: &T) {
|
||||
x.Method(41);
|
||||
}
|
||||
|
||||
type MyType = Box<some_fields>;
|
||||
|
||||
enum SomeEnum<'a> {
|
||||
Ints(isize, isize),
|
||||
Floats(f64, f64),
|
||||
Strings(&'a str, &'a str, &'a str),
|
||||
MyTypes(MyType, MyType),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum SomeOtherEnum {
|
||||
SomeConst1,
|
||||
SomeConst2,
|
||||
SomeConst3,
|
||||
}
|
||||
|
||||
enum SomeStructEnum {
|
||||
EnumStruct { a: isize, b: isize },
|
||||
EnumStruct2 { f1: MyType, f2: MyType },
|
||||
EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> },
|
||||
}
|
||||
|
||||
fn matchSomeEnum(val: SomeEnum) {
|
||||
match val {
|
||||
SomeEnum::Ints(int1, int2) => {
|
||||
println(&(int1 + int2).to_string());
|
||||
}
|
||||
SomeEnum::Floats(float1, float2) => {
|
||||
println(&(float2 * float1).to_string());
|
||||
}
|
||||
SomeEnum::Strings(.., s3) => {
|
||||
println(s3);
|
||||
}
|
||||
SomeEnum::MyTypes(mt1, mt2) => {
|
||||
println(&(mt1.field1 - mt2.field1).to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeStructEnum(se: SomeStructEnum) {
|
||||
match se {
|
||||
SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()),
|
||||
SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()),
|
||||
SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeStructEnum2(se: SomeStructEnum) {
|
||||
use SomeStructEnum::*;
|
||||
match se {
|
||||
EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()),
|
||||
EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()),
|
||||
EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn matchSomeOtherEnum(val: SomeOtherEnum) {
|
||||
use SomeOtherEnum::{SomeConst2, SomeConst3};
|
||||
match val {
|
||||
SomeOtherEnum::SomeConst1 => {
|
||||
println("I'm const1.");
|
||||
}
|
||||
SomeConst2 | SomeConst3 => {
|
||||
println("I'm const2 or const3.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
|
||||
SameDir2::hello(43);
|
||||
|
||||
println(&yy.to_string());
|
||||
let (x, y): (u32, u32) = (5, 3);
|
||||
println(&x.to_string());
|
||||
println(&z.to_string());
|
||||
let x: u32 = x;
|
||||
println(&x.to_string());
|
||||
let x = "hello";
|
||||
println(x);
|
||||
|
||||
let x = 32.0f32;
|
||||
let _ = (x + ((x * x) + 1.0).sqrt()).ln();
|
||||
|
||||
let s: Box<SomeTrait> = Box::new(some_fields { field1: 43 });
|
||||
let s2: Box<some_fields> = Box::new(some_fields { field1: 43 });
|
||||
let s3 = Box::new(nofields);
|
||||
|
||||
s.Method(43);
|
||||
s3.Method(43);
|
||||
s2.Method(43);
|
||||
|
||||
ex.prov(43);
|
||||
|
||||
let y: u32 = 56;
|
||||
// static method on struct
|
||||
let r = some_fields::stat(y);
|
||||
// trait static method, calls default
|
||||
let r = SubTrait::stat2(&*s3);
|
||||
|
||||
let s4 = s3 as Box<SomeTrait>;
|
||||
s4.Method(43);
|
||||
|
||||
s4.provided_method();
|
||||
s2.prov(45);
|
||||
|
||||
let closure = |x: u32, s: &SomeTrait| {
|
||||
s.Method(23);
|
||||
return x + y;
|
||||
};
|
||||
|
||||
let z = closure(10, &*s);
|
||||
}
|
||||
|
||||
pub struct blah {
|
||||
used_link_args: RefCell<[&'static str; 0]>,
|
||||
}
|
||||
|
||||
#[macro_use]
|
||||
mod macro_use_test {
|
||||
macro_rules! test_rec {
|
||||
(q, $src: expr) => {{
|
||||
print!("{}", $src);
|
||||
test_rec!($src);
|
||||
}};
|
||||
($src: expr) => {
|
||||
print!("{}", $src);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! internal_vars {
|
||||
($src: ident) => {{
|
||||
let mut x = $src;
|
||||
x += 100;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// foo
|
||||
let s = Box::new(some_fields { field1: 43 });
|
||||
hello((43, "a".to_string()), *s);
|
||||
sub::sub2::hello();
|
||||
sub2::sub3::hello();
|
||||
|
||||
let h = sub2::sub3::hello;
|
||||
h();
|
||||
|
||||
// utf8 chars
|
||||
let ut = "Les Miséééééééérables";
|
||||
|
||||
// For some reason, this pattern of macro_rules foiled our generated code
|
||||
// avoiding strategy.
|
||||
macro_rules! variable_str(($name:expr) => (
|
||||
some_fields {
|
||||
field1: $name,
|
||||
}
|
||||
));
|
||||
let vs = variable_str!(32);
|
||||
|
||||
let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new());
|
||||
let _ = blah { used_link_args: RefCell::new([]) };
|
||||
let s1 = nofields;
|
||||
let s2 = SF { field1: 55 };
|
||||
let s3: some_fields = some_fields { field1: 55 };
|
||||
let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
|
||||
let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
|
||||
println(&s2.field1.to_string());
|
||||
let s5: MyType = Box::new(some_fields { field1: 55 });
|
||||
let s = SameDir::SameStruct { name: "Bob".to_string() };
|
||||
let s = SubDir::SubStruct { name: "Bob".to_string() };
|
||||
let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5);
|
||||
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
|
||||
matchSomeEnum(s6);
|
||||
matchSomeEnum(s7);
|
||||
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
|
||||
matchSomeOtherEnum(s8);
|
||||
let s9: SomeStructEnum =
|
||||
SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) };
|
||||
matchSomeStructEnum(s9);
|
||||
|
||||
for x in &vec![1, 2, 3] {
|
||||
let _y = x;
|
||||
}
|
||||
|
||||
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
|
||||
if let SomeEnum::Strings(..) = s7 {
|
||||
println!("hello!");
|
||||
}
|
||||
|
||||
for i in 0..5 {
|
||||
foo_foo(i);
|
||||
}
|
||||
|
||||
if let Some(x) = None {
|
||||
foo_foo(x);
|
||||
}
|
||||
|
||||
if false {
|
||||
} else if let Some(y) = None {
|
||||
foo_foo(y);
|
||||
}
|
||||
|
||||
while let Some(z) = None {
|
||||
foo_foo(z);
|
||||
}
|
||||
|
||||
let mut x = 4;
|
||||
test_rec!(q, "Hello");
|
||||
assert_eq!(x, 4);
|
||||
internal_vars!(x);
|
||||
}
|
||||
|
||||
fn foo_foo(_: i32) {}
|
||||
|
||||
impl Iterator for nofields {
|
||||
type Item = (usize, usize);
|
||||
|
||||
fn next(&mut self) -> Option<(usize, usize)> {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
trait Pattern<'a> {
|
||||
type Searcher;
|
||||
}
|
||||
|
||||
struct CharEqPattern;
|
||||
|
||||
impl<'a> Pattern<'a> for CharEqPattern {
|
||||
type Searcher = CharEqPattern;
|
||||
}
|
||||
|
||||
struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);
|
||||
|
||||
pub trait Error {}
|
||||
|
||||
impl Error + 'static {
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Error + 'static + Send {
|
||||
pub fn is<T: Error + 'static>(&self) -> bool {
|
||||
<Error + 'static>::is::<T>(self)
|
||||
}
|
||||
}
|
||||
extern crate rustc_serialize;
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Default)]
|
||||
struct AllDerives(i32);
|
||||
|
||||
fn test_format_args() {
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
let name = "Joe Blogg";
|
||||
println!("Hello {}", name);
|
||||
print!("Hello {0}", name);
|
||||
print!("{0} + {} = {}", x, y);
|
||||
print!("x is {}, y is {1}, name is {n}", x, y, n = name);
|
||||
}
|
||||
|
||||
union TestUnion {
|
||||
f1: u32,
|
||||
}
|
||||
|
||||
struct FrameBuffer;
|
||||
|
||||
struct SilenceGenerator;
|
||||
|
||||
impl Iterator for SilenceGenerator {
|
||||
type Item = FrameBuffer;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = include_str!("extra-docs.md")]
|
||||
struct StructWithDocs;
|
||||
|
||||
trait Foo {
|
||||
type Bar = FrameBuffer;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#![ crate_name = "krate2" ]
|
||||
#![ crate_type = "lib" ]
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
pub fn hello() {
|
||||
std::io::stdout().write_all(b"hello world!\n");
|
||||
}
|
@ -146,7 +146,6 @@
|
||||
-Z sanitizer-memory-track-origins=val -- enable origins tracking in MemorySanitizer
|
||||
-Z sanitizer-recover=val -- enable recovery for selected sanitizers
|
||||
-Z saturating-float-casts=val -- make float->int casts UB-free: numbers outside the integer type's range are clipped to the max/min integer respectively, and NaN is mapped to 0 (default: yes)
|
||||
-Z save-analysis=val -- write syntax and type analysis (in JSON format) information, in addition to normal output (default: no)
|
||||
-Z self-profile=val -- run the self profiler and output the raw event data
|
||||
-Z self-profile-counter=val -- counter used by the self profiler (default: `wall-time`), one of:
|
||||
`wall-time` (monotonic clock, i.e. `std::time::Instant`)
|
||||
|
@ -1,6 +1,4 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// needs-asm-support
|
||||
// Also test for #72960
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: invalid register `invalid`: unknown register
|
||||
--> $DIR/issue-72570.rs:9:18
|
||||
--> $DIR/issue-72570.rs:7:18
|
||||
|
|
||||
LL | asm!("", in("invalid") "".len());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0658]: a non-static lifetime is not allowed in a `const`
|
||||
--> $DIR/const-argument-non-static-lifetime.rs:15:17
|
||||
--> $DIR/const-argument-non-static-lifetime.rs:14:17
|
||||
|
|
||||
LL | let _: &'a ();
|
||||
| ^^
|
||||
|
@ -2,7 +2,6 @@
|
||||
// revisions: full min
|
||||
|
||||
// regression test for #78180
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![cfg_attr(full, feature(generic_const_exprs))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
|
@ -1,6 +1,3 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// Regression test for #69414 ^
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
struct B<T, const N: T>(PhantomData<[T; N]>);
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:6:22
|
||||
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
|
||||
|
|
||||
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
|
||||
| ^ the type must not depend on the parameter `T`
|
||||
|
@ -1,4 +1,3 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
struct Arr<const N: usize>
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-73260.rs:16:12
|
||||
--> $DIR/issue-73260.rs:15:12
|
||||
|
|
||||
LL | let x: Arr<{usize::MAX}> = Arr {};
|
||||
| ^^^^^^^^^^^^^^^^^ expected `false`, found `true`
|
||||
@ -7,7 +7,7 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
||||
= note: expected constant `false`
|
||||
found constant `true`
|
||||
note: required by a bound in `Arr`
|
||||
--> $DIR/issue-73260.rs:6:37
|
||||
--> $DIR/issue-73260.rs:5:37
|
||||
|
|
||||
LL | struct Arr<const N: usize>
|
||||
| --- required by a bound in this
|
||||
@ -16,7 +16,7 @@ LL | Assert::<{N < usize::MAX / 2}>: IsTrue,
|
||||
| ^^^^^^ required by this bound in `Arr`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-73260.rs:16:32
|
||||
--> $DIR/issue-73260.rs:15:32
|
||||
|
|
||||
LL | let x: Arr<{usize::MAX}> = Arr {};
|
||||
| ^^^ expected `false`, found `true`
|
||||
@ -24,7 +24,7 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
||||
= note: expected constant `false`
|
||||
found constant `true`
|
||||
note: required by a bound in `Arr`
|
||||
--> $DIR/issue-73260.rs:6:37
|
||||
--> $DIR/issue-73260.rs:5:37
|
||||
|
|
||||
LL | struct Arr<const N: usize>
|
||||
| --- required by a bound in this
|
||||
|
@ -1,6 +1,3 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// This is also a regression test for #69415 and the above flag is needed.
|
||||
|
||||
use std::mem::ManuallyDrop;
|
||||
|
||||
trait Tr1 { type As1: Copy; }
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:15:22
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:12:22
|
||||
|
|
||||
LL | type A: Iterator<Item: Copy>;
|
||||
| ^^^^^^^^^^
|
||||
@ -8,7 +8,7 @@ LL | type A: Iterator<Item: Copy>;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:19:22
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:16:22
|
||||
|
|
||||
LL | type B: Iterator<Item: 'static>;
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -17,7 +17,7 @@ LL | type B: Iterator<Item: 'static>;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:23:20
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:20:20
|
||||
|
|
||||
LL | struct _St1<T: Tr1<As1: Tr2>> {
|
||||
| ^^^^^^^^
|
||||
@ -26,7 +26,7 @@ LL | struct _St1<T: Tr1<As1: Tr2>> {
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:30:18
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:27:18
|
||||
|
|
||||
LL | enum _En1<T: Tr1<As1: Tr2>> {
|
||||
| ^^^^^^^^
|
||||
@ -35,7 +35,7 @@ LL | enum _En1<T: Tr1<As1: Tr2>> {
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:37:19
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:34:19
|
||||
|
|
||||
LL | union _Un1<T: Tr1<As1: Tr2>> {
|
||||
| ^^^^^^^^
|
||||
@ -44,7 +44,7 @@ LL | union _Un1<T: Tr1<As1: Tr2>> {
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:44:37
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:41:37
|
||||
|
|
||||
LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T;
|
||||
| ^^^^^^^^^^
|
||||
@ -53,7 +53,7 @@ LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:47:22
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:44:22
|
||||
|
|
||||
LL | fn _apit(_: impl Tr1<As1: Copy>) {}
|
||||
| ^^^^^^^^^
|
||||
@ -62,7 +62,7 @@ LL | fn _apit(_: impl Tr1<As1: Copy>) {}
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:49:26
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:46:26
|
||||
|
|
||||
LL | fn _apit_dyn(_: &dyn Tr1<As1: Copy>) {}
|
||||
| ^^^^^^^^^
|
||||
@ -71,7 +71,7 @@ LL | fn _apit_dyn(_: &dyn Tr1<As1: Copy>) {}
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:52:24
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:49:24
|
||||
|
|
||||
LL | fn _rpit() -> impl Tr1<As1: Copy> { S1 }
|
||||
| ^^^^^^^^^
|
||||
@ -80,7 +80,7 @@ LL | fn _rpit() -> impl Tr1<As1: Copy> { S1 }
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:55:31
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:52:31
|
||||
|
|
||||
LL | fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
|
||||
| ^^^^^^^^^
|
||||
@ -89,7 +89,7 @@ LL | fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:58:23
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:55:23
|
||||
|
|
||||
LL | const _cdef: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^
|
||||
@ -98,7 +98,7 @@ LL | const _cdef: impl Tr1<As1: Copy> = S1;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:64:24
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:61:24
|
||||
|
|
||||
LL | static _sdef: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^
|
||||
@ -107,7 +107,7 @@ LL | static _sdef: impl Tr1<As1: Copy> = S1;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type bounds are unstable
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:71:21
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:68:21
|
||||
|
|
||||
LL | let _: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^
|
||||
@ -116,25 +116,25 @@ LL | let _: impl Tr1<As1: Copy> = S1;
|
||||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
|
||||
|
||||
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in const type
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:58:14
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:55:14
|
||||
|
|
||||
LL | const _cdef: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in const type
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:64:15
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:61:15
|
||||
|
|
||||
LL | static _sdef: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:71:12
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:68:12
|
||||
|
|
||||
LL | let _: impl Tr1<As1: Copy> = S1;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `<<Self as _Tr3>::A as Iterator>::Item: Copy` is not satisfied
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:15:28
|
||||
--> $DIR/feature-gate-associated_type_bounds.rs:12:28
|
||||
|
|
||||
LL | type A: Iterator<Item: Copy>;
|
||||
| ^^^^ the trait `Copy` is not implemented for `<<Self as _Tr3>::A as Iterator>::Item`
|
||||
|
@ -1,8 +1,6 @@
|
||||
// check-pass
|
||||
// edition:2018
|
||||
// revisions: default sa
|
||||
//[sa] compile-flags: -Z save-analysis
|
||||
//-^ To make this the regression test for #75962.
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// Also regression test for #69416
|
||||
// Regression test for #3763
|
||||
|
||||
mod my_mod {
|
||||
pub struct MyStruct {
|
||||
|
@ -1,17 +1,17 @@
|
||||
error[E0616]: field `priv_field` of struct `MyStruct` is private
|
||||
--> $DIR/issue-3763.rs:18:32
|
||||
--> $DIR/issue-3763.rs:17:32
|
||||
|
|
||||
LL | let _woohoo = (&my_struct).priv_field;
|
||||
| ^^^^^^^^^^ private field
|
||||
|
||||
error[E0616]: field `priv_field` of struct `MyStruct` is private
|
||||
--> $DIR/issue-3763.rs:21:41
|
||||
--> $DIR/issue-3763.rs:20:41
|
||||
|
|
||||
LL | let _woohoo = (Box::new(my_struct)).priv_field;
|
||||
| ^^^^^^^^^^ private field
|
||||
|
||||
error[E0624]: associated function `happyfun` is private
|
||||
--> $DIR/issue-3763.rs:24:18
|
||||
--> $DIR/issue-3763.rs:23:18
|
||||
|
|
||||
LL | fn happyfun(&self) {}
|
||||
| ------------------ private associated function defined here
|
||||
@ -20,7 +20,7 @@ LL | (&my_struct).happyfun();
|
||||
| ^^^^^^^^ private associated function
|
||||
|
||||
error[E0624]: associated function `happyfun` is private
|
||||
--> $DIR/issue-3763.rs:26:27
|
||||
--> $DIR/issue-3763.rs:25:27
|
||||
|
|
||||
LL | fn happyfun(&self) {}
|
||||
| ------------------ private associated function defined here
|
||||
@ -29,7 +29,7 @@ LL | (Box::new(my_struct)).happyfun();
|
||||
| ^^^^^^^^ private associated function
|
||||
|
||||
error[E0616]: field `priv_field` of struct `MyStruct` is private
|
||||
--> $DIR/issue-3763.rs:27:26
|
||||
--> $DIR/issue-3763.rs:26:26
|
||||
|
|
||||
LL | let nope = my_struct.priv_field;
|
||||
| ^^^^^^^^^^ private field
|
||||
|
@ -1,5 +1,4 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// Also regression test for #69409
|
||||
// Regression test for #69409
|
||||
|
||||
struct Cat {
|
||||
meows : usize,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0615]: attempted to take value of method `speak` on type `Cat`
|
||||
--> $DIR/assign-to-method.rs:22:10
|
||||
--> $DIR/assign-to-method.rs:21:10
|
||||
|
|
||||
LL | nyan.speak = || println!("meow");
|
||||
| ^^^^^ method, not a field
|
||||
@ -7,7 +7,7 @@ LL | nyan.speak = || println!("meow");
|
||||
= help: methods are immutable and cannot be assigned to
|
||||
|
||||
error[E0615]: attempted to take value of method `speak` on type `Cat`
|
||||
--> $DIR/assign-to-method.rs:23:10
|
||||
--> $DIR/assign-to-method.rs:22:10
|
||||
|
|
||||
LL | nyan.speak += || println!("meow");
|
||||
| ^^^^^ method, not a field
|
||||
|
@ -1,2 +0,0 @@
|
||||
{"artifact":"$TEST_BUILD_DIR/save-analysis/emit-notifications.polonius/save-analysis/libemit_notifications.json","emit":"save-analysis"}
|
||||
{"artifact":"$TEST_BUILD_DIR/save-analysis/emit-notifications.polonius/libemit_notifications.rlib","emit":"link"}
|
@ -1,7 +0,0 @@
|
||||
// build-pass (FIXME(62277): could be check-pass?)
|
||||
// compile-flags: -Zsave-analysis --json artifacts
|
||||
// compile-flags: --crate-type rlib --error-format=json
|
||||
// ignore-pass
|
||||
// ^-- needed because otherwise, the .stderr file changes with --pass check
|
||||
|
||||
pub fn foo() {}
|
@ -1,2 +0,0 @@
|
||||
{"artifact":"$TEST_BUILD_DIR/save-analysis/emit-notifications/save-analysis/libemit_notifications.json","emit":"save-analysis"}
|
||||
{"artifact":"$TEST_BUILD_DIR/save-analysis/emit-notifications/libemit_notifications.rlib","emit":"link"}
|
@ -1,8 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
fn main() {
|
||||
match 'a' {
|
||||
char{ch} => true
|
||||
//~^ ERROR expected struct, variant or union type, found builtin type `char`
|
||||
};
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
error[E0574]: expected struct, variant or union type, found builtin type `char`
|
||||
--> $DIR/issue-26459.rs:5:9
|
||||
|
|
||||
LL | char{ch} => true
|
||||
| ^^^^ not a struct, variant or union type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0574`.
|
@ -1,20 +0,0 @@
|
||||
// check-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(warnings)]
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Point {
|
||||
}
|
||||
|
||||
struct NestedA<'a, 'b> {
|
||||
x: &'a NestedB<'b>
|
||||
}
|
||||
|
||||
struct NestedB<'a> {
|
||||
x: &'a i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
// Check that this doesn't ICE when processing associated const (field expr).
|
||||
|
||||
pub fn f() {
|
||||
trait Trait {}
|
||||
impl dyn Trait {
|
||||
const FLAG: u32 = bogus.field; //~ ERROR cannot find value `bogus`
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,9 +0,0 @@
|
||||
error[E0425]: cannot find value `bogus` in this scope
|
||||
--> $DIR/issue-59134-0.rs:8:27
|
||||
|
|
||||
LL | const FLAG: u32 = bogus.field;
|
||||
| ^^^^^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0425`.
|
@ -1,12 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
// Check that this doesn't ICE when processing associated const (type).
|
||||
|
||||
fn func() {
|
||||
trait Trait {
|
||||
type MyType;
|
||||
const CONST: Self::MyType = bogus.field; //~ ERROR cannot find value `bogus`
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,9 +0,0 @@
|
||||
error[E0425]: cannot find value `bogus` in this scope
|
||||
--> $DIR/issue-59134-1.rs:8:37
|
||||
|
|
||||
LL | const CONST: Self::MyType = bogus.field;
|
||||
| ^^^^^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0425`.
|
@ -1,28 +0,0 @@
|
||||
// check-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
pub trait Trait {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
pub struct A;
|
||||
|
||||
trait Generic<T> {}
|
||||
impl<T> Generic<T> for () {}
|
||||
|
||||
// Don't ICE when resolving type paths in return type `impl Trait`
|
||||
fn assoc_in_opaque_type_bounds<U: Trait>() -> impl Generic<U::Assoc> {}
|
||||
|
||||
// Check that this doesn't ICE when processing associated const in formal
|
||||
// argument and return type of functions defined inside function/method scope.
|
||||
pub fn func() {
|
||||
fn _inner1<U: Trait>(_: U::Assoc) {}
|
||||
fn _inner2<U: Trait>() -> U::Assoc { unimplemented!() }
|
||||
|
||||
impl A {
|
||||
fn _inner1<U: Trait>(self, _: U::Assoc) {}
|
||||
fn _inner2<U: Trait>(self) -> U::Assoc { unimplemented!() }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,10 +0,0 @@
|
||||
// check-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
trait Trait { type Assoc; }
|
||||
|
||||
fn main() {
|
||||
struct Data<T: Trait> {
|
||||
x: T::Assoc,
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// check-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
trait Trait { type Assoc; }
|
||||
trait GenericTrait<T> {}
|
||||
struct Wrapper<B> { b: B }
|
||||
|
||||
fn func() {
|
||||
// Processing associated path in impl block definition inside a function
|
||||
// body does not ICE
|
||||
impl<B: Trait> GenericTrait<B::Assoc> for Wrapper<B> {}
|
||||
}
|
||||
|
||||
|
||||
fn main() {}
|
@ -1,21 +0,0 @@
|
||||
// check-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
// edition:2018
|
||||
|
||||
// Async desugaring for return types in (associated) functions introduces a
|
||||
// separate definition internally, which we need to take into account
|
||||
// (or else we ICE).
|
||||
trait Trait { type Assoc; }
|
||||
struct Struct;
|
||||
|
||||
async fn foobar<T: Trait>() -> T::Assoc {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
impl Struct {
|
||||
async fn foo<T: Trait>(&self) -> T::Assoc {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,17 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait Trait {}
|
||||
|
||||
trait Service {
|
||||
type Future: Trait;
|
||||
}
|
||||
|
||||
struct Struct;
|
||||
|
||||
impl Service for Struct {
|
||||
type Future = impl Trait; //~ ERROR: unconstrained opaque type
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,10 +0,0 @@
|
||||
error: unconstrained opaque type
|
||||
--> $DIR/issue-68621.rs:14:19
|
||||
|
|
||||
LL | type Future = impl Trait;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `Future` must be used in combination with a concrete type within the same impl
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,7 +0,0 @@
|
||||
// compile-flags: -Z save-analysis
|
||||
|
||||
fn main() {
|
||||
let _: Box<(dyn ?Sized)>;
|
||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
||||
//~| ERROR at least one trait is required for an object type
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
error: `?Trait` is not permitted in trait object types
|
||||
--> $DIR/issue-72267.rs:4:21
|
||||
|
|
||||
LL | let _: Box<(dyn ?Sized)>;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0224]: at least one trait is required for an object type
|
||||
--> $DIR/issue-72267.rs:4:17
|
||||
|
|
||||
LL | let _: Box<(dyn ?Sized)>;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0224`.
|
@ -1,5 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
use {self}; //~ ERROR E0431
|
||||
|
||||
fn main () {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
error[E0431]: `self` import can only appear in an import list with a non-empty prefix
|
||||
--> $DIR/issue-73020.rs:2:6
|
||||
|
|
||||
LL | use {self};
|
||||
| ^^^^ can only appear in an import list with a non-empty prefix
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0431`.
|
@ -1,13 +0,0 @@
|
||||
// build-pass
|
||||
// compile-flags: -Zsave-analysis
|
||||
enum Enum2 {
|
||||
Variant8 { _field: bool },
|
||||
}
|
||||
|
||||
impl Enum2 {
|
||||
fn new_variant8() -> Enum2 {
|
||||
Self::Variant8 { _field: true }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,28 +0,0 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
// Check that this does not ICE.
|
||||
// Stolen from tests/ui/const-generics/generic_arg_infer/infer-arg-test.rs
|
||||
|
||||
#![feature(generic_arg_infer)]
|
||||
|
||||
struct All<'a, T, const N: usize> {
|
||||
v: &'a T,
|
||||
}
|
||||
|
||||
struct BadInfer<_>;
|
||||
//~^ ERROR expected identifier
|
||||
//~| ERROR parameter `_` is never used
|
||||
|
||||
fn all_fn<'a, T, const N: usize>() {}
|
||||
|
||||
fn bad_infer_fn<_>() {}
|
||||
//~^ ERROR expected identifier
|
||||
|
||||
|
||||
fn main() {
|
||||
let a: All<_, _, _>;
|
||||
//~^ ERROR this struct takes 2 generic arguments but 3 generic arguments were supplied
|
||||
all_fn();
|
||||
let v: [u8; _];
|
||||
let v: [u8; 10] = [0; _];
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
error: expected identifier, found reserved identifier `_`
|
||||
--> $DIR/issue-89066.rs:12:17
|
||||
|
|
||||
LL | struct BadInfer<_>;
|
||||
| ^ expected identifier, found reserved identifier
|
||||
|
||||
error: expected identifier, found reserved identifier `_`
|
||||
--> $DIR/issue-89066.rs:18:17
|
||||
|
|
||||
LL | fn bad_infer_fn<_>() {}
|
||||
| ^ expected identifier, found reserved identifier
|
||||
|
||||
error[E0392]: parameter `_` is never used
|
||||
--> $DIR/issue-89066.rs:12:17
|
||||
|
|
||||
LL | struct BadInfer<_>;
|
||||
| ^ unused parameter
|
||||
|
|
||||
= help: consider removing `_`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
= help: if you intended `_` to be a const parameter, use `const _: usize` instead
|
||||
|
||||
error[E0107]: this struct takes 2 generic arguments but 3 generic arguments were supplied
|
||||
--> $DIR/issue-89066.rs:23:10
|
||||
|
|
||||
LL | let a: All<_, _, _>;
|
||||
| ^^^ - help: remove this generic argument
|
||||
| |
|
||||
| expected 2 generic arguments
|
||||
|
|
||||
note: struct defined here, with 2 generic parameters: `T`, `N`
|
||||
--> $DIR/issue-89066.rs:8:8
|
||||
|
|
||||
LL | struct All<'a, T, const N: usize> {
|
||||
| ^^^ - --------------
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0107, E0392.
|
||||
For more information about an error, try `rustc --explain E0107`.
|
@ -1,9 +1,5 @@
|
||||
// astconv uses `FreshTy(0)` as a dummy `Self` type when instanciating trait objects.
|
||||
// This `FreshTy(0)` can leak into substs, causing ICEs in several places.
|
||||
// Using `save-analysis` triggers type-checking `f` that would be normally skipped
|
||||
// as `type_of` emitted an error.
|
||||
//
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![feature(trait_alias)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0038]: the trait alias `SelfInput` cannot be made into an object
|
||||
--> $DIR/self-in-generics.rs:12:19
|
||||
--> $DIR/self-in-generics.rs:8:19
|
||||
|
|
||||
LL | pub fn f(_f: &dyn SelfInput) {}
|
||||
| ^^^^^^^^^
|
||||
|
@ -1,5 +1,3 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
type Closure = impl FnOnce();
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0277]: expected a `FnOnce<()>` closure, found `()`
|
||||
--> $DIR/issue-63279.rs:7:11
|
||||
--> $DIR/issue-63279.rs:5:11
|
||||
|
|
||||
LL | fn c() -> Closure {
|
||||
| ^^^^^^^ expected an `FnOnce<()>` closure, found `()`
|
||||
@ -8,7 +8,7 @@ LL | fn c() -> Closure {
|
||||
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
||||
error[E0277]: expected a `FnOnce<()>` closure, found `()`
|
||||
--> $DIR/issue-63279.rs:9:11
|
||||
--> $DIR/issue-63279.rs:7:11
|
||||
|
|
||||
LL | || -> Closure { || () }
|
||||
| ^^^^^^^ expected an `FnOnce<()>` closure, found `()`
|
||||
@ -17,26 +17,26 @@ LL | || -> Closure { || () }
|
||||
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-63279.rs:9:21
|
||||
--> $DIR/issue-63279.rs:7:21
|
||||
|
|
||||
LL | || -> Closure { || () }
|
||||
| ^^^^^ expected `()`, found closure
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found closure `[closure@$DIR/issue-63279.rs:9:21: 9:23]`
|
||||
found closure `[closure@$DIR/issue-63279.rs:7:21: 7:23]`
|
||||
help: use parentheses to call this closure
|
||||
|
|
||||
LL | || -> Closure { (|| ())() }
|
||||
| + +++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-63279.rs:9:5
|
||||
--> $DIR/issue-63279.rs:7:5
|
||||
|
|
||||
LL | || -> Closure { || () }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found closure `[closure@$DIR/issue-63279.rs:9:5: 9:18]`
|
||||
found closure `[closure@$DIR/issue-63279.rs:7:5: 7:18]`
|
||||
help: use parentheses to call this closure
|
||||
|
|
||||
LL | (|| -> Closure { || () })()
|
||||
|
@ -1,4 +1,3 @@
|
||||
// compile-flags: -Zsave-analysis
|
||||
// check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait, rustc_attrs)]
|
||||
|
Loading…
Reference in New Issue
Block a user