Fix tests and assertions; add some comments

This commit is contained in:
Nick Cameron 2018-10-11 21:15:18 +13:00
parent 59cb1705d7
commit 63ac2aae51
26 changed files with 274 additions and 187 deletions

View File

@ -298,6 +298,9 @@ pub trait Visitor<'v> : Sized {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: BodyId, s: Span, id: NodeId) {
walk_fn(self, fk, fd, b, s, id)
}
fn visit_use(&mut self, path: &'v Path, id: NodeId, hir_id: HirId) {
walk_use(self, path, id, hir_id)
}
fn visit_trait_item(&mut self, ti: &'v TraitItem) {
walk_trait_item(self, ti)
}
@ -471,8 +474,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
}
}
ItemKind::Use(ref path, _) => {
visitor.visit_id(item.id);
visitor.visit_path(path, item.hir_id);
visitor.visit_use(path, item.id, item.hir_id);
}
ItemKind::Static(ref typ, _, body) |
ItemKind::Const(ref typ, body) => {
@ -554,6 +556,14 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
walk_list!(visitor, visit_attribute, &item.attrs);
}
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V,
path: &'v Path,
item_id: NodeId,
hir_id: HirId) {
visitor.visit_id(item_id);
visitor.visit_path(path, hir_id);
}
pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V,
enum_definition: &'v EnumDef,
generics: &'v Generics,
@ -652,6 +662,9 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
path_span: Span,
segment: &'v PathSegment) {
visitor.visit_ident(segment.ident);
if let Some(id) = segment.id {
visitor.visit_id(id);
}
if let Some(ref args) = segment.args {
visitor.visit_generic_args(path_span, args);
}

View File

@ -1069,6 +1069,9 @@ impl<'a> LoweringContext<'a> {
}
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
// Note that we explicitly do not walk the path. Since we don't really
// lower attributes (we use the AST version) there is nowhere to keep
// the HirIds. We don't actually need HIR version of attributes anyway.
Attribute {
id: attr.id,
style: attr.style,
@ -1682,6 +1685,7 @@ impl<'a> LoweringContext<'a> {
num_lifetimes,
parenthesized_generic_args,
itctx.reborrow(),
None,
)
})
.collect(),
@ -1725,6 +1729,7 @@ impl<'a> LoweringContext<'a> {
0,
ParenthesizedGenericArgs::Warn,
itctx.reborrow(),
None,
));
let qpath = hir::QPath::TypeRelative(ty, segment);
@ -1753,6 +1758,7 @@ impl<'a> LoweringContext<'a> {
p: &Path,
ident: Option<Ident>,
param_mode: ParamMode,
explicit_owner: Option<NodeId>,
) -> hir::Path {
hir::Path {
def,
@ -1766,6 +1772,7 @@ impl<'a> LoweringContext<'a> {
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
explicit_owner,
)
})
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
@ -1776,7 +1783,7 @@ impl<'a> LoweringContext<'a> {
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path {
let def = self.expect_full_def(id);
self.lower_path_extra(def, p, None, param_mode)
self.lower_path_extra(def, p, None, param_mode, None)
}
fn lower_path_segment(
@ -1787,6 +1794,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes: usize,
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext<'_>,
explicit_owner: Option<NodeId>,
) -> hir::PathSegment {
let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
let msg = "parenthesized parameters may only be used with a trait";
@ -1858,9 +1866,15 @@ impl<'a> LoweringContext<'a> {
}
let def = self.expect_full_def(segment.id);
let id = if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(segment.id, owner)
} else {
self.lower_node_id(segment.id)
};
hir::PathSegment::new(
segment.ident,
Some(segment.id),
Some(id.node_id),
Some(def),
generic_args,
infer_types,
@ -2944,6 +2958,12 @@ impl<'a> LoweringContext<'a> {
attrs: &hir::HirVec<Attribute>,
) -> hir::ItemKind {
let path = &tree.prefix;
let segments = prefix
.segments
.iter()
.chain(path.segments.iter())
.cloned()
.collect();
match tree.kind {
UseTreeKind::Simple(rename, id1, id2) => {
@ -2951,12 +2971,7 @@ impl<'a> LoweringContext<'a> {
// First apply the prefix to the path
let mut path = Path {
segments: prefix
.segments
.iter()
.chain(path.segments.iter())
.cloned()
.collect(),
segments,
span: path.span,
};
@ -2976,9 +2991,18 @@ impl<'a> LoweringContext<'a> {
// for later
let ret_def = defs.next().unwrap_or(Def::Err);
// Here, we are looping over namespaces, if they exist for the definition
// being imported. We only handle type and value namespaces because we
// won't be dealing with macros in the rest of the compiler.
// Essentially a single `use` which imports two names is desugared into
// two imports.
for (def, &new_node_id) in defs.zip([id1, id2].iter()) {
let vis = vis.clone();
let name = name.clone();
let mut path = path.clone();
for seg in &mut path.segments {
seg.id = self.sess.next_node_id();
}
let span = path.span;
self.resolver.definitions().create_def_with_parent(
parent_def_index,
@ -2991,7 +3015,8 @@ impl<'a> LoweringContext<'a> {
self.with_hir_id_owner(new_node_id, |this| {
let new_id = this.lower_node_id(new_node_id);
let path = this.lower_path_extra(def, &path, None, ParamMode::Explicit);
let path =
this.lower_path_extra(def, &path, None, ParamMode::Explicit, None);
let item = hir::ItemKind::Use(P(path), hir::UseKind::Single);
let vis_kind = match vis.node {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
@ -3001,7 +3026,6 @@ impl<'a> LoweringContext<'a> {
let id = this.next_id();
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: id.node_id,
hir_id: id.hir_id,
}
@ -3024,19 +3048,15 @@ impl<'a> LoweringContext<'a> {
});
}
let path = P(self.lower_path_extra(ret_def, &path, None, ParamMode::Explicit));
let path =
P(self.lower_path_extra(ret_def, &path, None, ParamMode::Explicit, None));
hir::ItemKind::Use(path, hir::UseKind::Single)
}
UseTreeKind::Glob => {
let path = P(self.lower_path(
id,
&Path {
segments: prefix
.segments
.iter()
.chain(path.segments.iter())
.cloned()
.collect(),
segments,
span: path.span,
},
ParamMode::Explicit,
@ -3044,19 +3064,17 @@ impl<'a> LoweringContext<'a> {
hir::ItemKind::Use(path, hir::UseKind::Glob)
}
UseTreeKind::Nested(ref trees) => {
// Nested imports are desugared into simple imports.
let prefix = Path {
segments: prefix
.segments
.iter()
.chain(path.segments.iter())
.cloned()
.collect(),
segments,
span: prefix.span.to(path.span),
};
// Add all the nested PathListItems in the HIR
// Add all the nested PathListItems to the HIR.
for &(ref use_tree, id) in trees {
self.allocate_hir_id_counter(id, &use_tree);
let LoweredNodeId {
node_id: new_id,
hir_id: new_hir_id,
@ -3064,10 +3082,26 @@ impl<'a> LoweringContext<'a> {
let mut vis = vis.clone();
let mut name = name.clone();
let item =
self.lower_use_tree(use_tree, &prefix, new_id, &mut vis, &mut name, &attrs);
let mut prefix = prefix.clone();
// Give the segments new ids since they are being cloned.
for seg in &mut prefix.segments {
seg.id = self.sess.next_node_id();
}
// Each `use` import is an item and thus are owners of the
// names in the path. Up to this point the nested import is
// the current owner, since we want each desugared import to
// own its own names, we have to adjust the owner before
// lowering the rest of the import.
self.with_hir_id_owner(new_id, |this| {
let item = this.lower_use_tree(use_tree,
&prefix,
new_id,
&mut vis,
&mut name,
attrs);
let vis_kind = match vis.node {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
@ -3076,7 +3110,6 @@ impl<'a> LoweringContext<'a> {
let id = this.next_id();
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: id.node_id,
hir_id: id.hir_id,
}
@ -3089,7 +3122,7 @@ impl<'a> LoweringContext<'a> {
hir::Item {
id: new_id,
hir_id: new_hir_id,
name: name,
name,
attrs: attrs.clone(),
node: item,
vis,
@ -3653,6 +3686,7 @@ impl<'a> LoweringContext<'a> {
0,
ParenthesizedGenericArgs::Err,
ImplTraitContext::disallowed(),
None,
);
let args = args.iter().map(|x| self.lower_expr(x)).collect();
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args)
@ -4506,8 +4540,15 @@ impl<'a> LoweringContext<'a> {
} else {
self.lower_node_id(id)
};
let def = self.expect_full_def(id);
hir::VisibilityKind::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit)),
path: P(self.lower_path_extra(
def,
path,
None,
ParamMode::Explicit,
explicit_owner,
)),
id: lowered_id.node_id,
hir_id: lowered_id.hir_id,
}
@ -4814,8 +4855,15 @@ impl<'a> LoweringContext<'a> {
params: Option<P<hir::GenericArgs>>,
is_value: bool
) -> hir::Path {
self.resolver
.resolve_str_path(span, self.crate_root, components, params, is_value)
let mut path = self.resolver
.resolve_str_path(span, self.crate_root, components, params, is_value);
for seg in path.segments.iter_mut() {
if let Some(id) = seg.id {
seg.id = Some(self.lower_node_id(id).node_id);
}
}
path
}
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::Ty {

View File

@ -210,17 +210,22 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
None => format!("{:?}", node)
};
if hir_id == ::hir::DUMMY_HIR_ID {
debug!("Maybe you forgot to lower the node id {:?}?", id);
}
let forgot_str = if hir_id == ::hir::DUMMY_HIR_ID {
format!("\nMaybe you forgot to lower the node id {:?}?", id)
} else {
String::new()
};
bug!("inconsistent DepNode for `{}`: \
current_dep_node_owner={}, hir_id.owner={}",
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}) {}",
node_str,
self.definitions
.def_path(self.current_dep_node_owner)
.to_string_no_crate(),
self.definitions.def_path(hir_id.owner).to_string_no_crate())
self.current_dep_node_owner,
self.definitions.def_path(hir_id.owner).to_string_no_crate(),
hir_id.owner,
forgot_str)
}
}

View File

@ -88,7 +88,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
walk(self);
if owner_def_index == CRATE_DEF_INDEX {
return
return;
}
// There's always at least one entry for the owning item itself
@ -129,13 +129,16 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
local_id,
self.hir_map.node_to_string(node_id)));
}
self.errors.push(format!(
"ItemLocalIds not assigned densely in {}. \
Max ItemLocalId = {}, missing IDs = {:?}",
Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}",
self.hir_map.def_path(DefId::local(owner_def_index)).to_string_no_crate(),
max,
missing_items));
missing_items,
self.hir_ids_seen
.values()
.map(|n| format!("({:?} {})", n, self.hir_map.node_to_string(*n)))
.collect::<Vec<_>>()));
}
}
}
@ -155,6 +158,7 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
self.errors.push(format!("HirIdValidator: No HirId assigned for NodeId {}: {:?}",
node_id,
self.hir_map.node_to_string(node_id)));
return;
}
if owner != stable_id.owner {

View File

@ -1100,7 +1100,7 @@ impl<'a> print::State<'a> {
Node::AnonConst(a) => self.print_anon_const(&a),
Node::Expr(a) => self.print_expr(&a),
Node::Stmt(a) => self.print_stmt(&a),
Node::PathSegment(_) => bug!("cannot print PathSegment"),
Node::PathSegment(a) => self.print_path_segment(&a),
Node::Ty(a) => self.print_type(&a),
Node::TraitRef(a) => self.print_trait_ref(&a),
Node::Binding(a) |

View File

@ -347,6 +347,11 @@ impl fmt::Display for Path {
pub struct PathSegment {
/// The identifier portion of this path segment.
pub ident: Ident,
// `id` and `def` are optional. We currently only use these in save-analysis,
// any path segments without these will not have save-analysis info and
// therefore will not have 'jump to def' in IDEs, but otherwise will not be
// affected. (In general, we don't bother to get the defs for synthesized
// segments, only for segments which have come from the AST).
pub id: Option<NodeId>,
pub def: Option<Def>,

View File

@ -1633,6 +1633,17 @@ impl<'a> State<'a> {
Ok(())
}
pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> {
if segment.ident.name != keywords::CrateRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args, segment.infer_types, false)
})?;
}
Ok(())
}
pub fn print_qpath(&mut self,
qpath: &hir::QPath,
colons_before_params: bool)

View File

@ -1675,8 +1675,8 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
PathResult::Module(ModuleOrUniformRoot::Module(module)) =>
module.def().unwrap(),
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 =>
*def = path_res.base_def(),
PathResult::NonModule(..) =>
path_res.base_def(),
PathResult::NonModule(..) => {
if let PathResult::Failed(span, msg, _) = self.resolve_path(
None,
&path,
@ -1686,7 +1686,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
CrateLint::No,
) {
error_callback(self, span, ResolutionError::FailedToResolve(&msg));
},
}
Def::Err
}
PathResult::Module(ModuleOrUniformRoot::UniformRoot(_)) |
PathResult::Indeterminate => unreachable!(),
PathResult::Failed(span, msg, _) => {
@ -3042,7 +3044,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
let report_errors = |this: &mut Self, def: Option<Def>| {
// Make the base error.
let expected = source.descr_expected();
let path_str = names_to_string(path);
let path_str = Segment::names_to_string(path);
let item_str = path.last().unwrap().ident;
let code = source.error_code(def.is_some());
let (base_msg, fallback_label, base_span) = if let Some(def) = def {

View File

@ -1314,7 +1314,6 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
"consider making the enum public",
suggestion);
err.emit();
}
}
}
}

View File

@ -1624,10 +1624,6 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
down_cast_data!(fn_data, DefData, item.span);
self.nest_tables(
item.id,
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
);
self.process_generic_params(generics, &fn_data.qualname, item.id);
self.dumper.dump_def(&access, fn_data);
}

View File

@ -57,7 +57,7 @@ use std::env;
use std::fs::File;
use std::path::{Path, PathBuf};
use syntax::ast::{self, Attribute, NodeId, PatKind};
use syntax::ast::{self, Attribute, DUMMY_NODE_ID, NodeId, PatKind};
use syntax::source_map::Spanned;
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
use syntax::print::pprust;
@ -703,6 +703,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
false
}
if path_seg.id == DUMMY_NODE_ID {
return None;
}
let def = self.get_path_def(path_seg.id);
let span = path_seg.ident.span;
filter!(self.span_utils, span);

View File

@ -95,7 +95,7 @@ pub fn add_type_ascription_to_parameter() {
}
#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody, TypeckTables")]
#[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, TypeckTables")]
#[rustc_clean(cfg="cfail3")]
pub fn add_type_ascription_to_parameter() {
let closure = |x: u32| x + 1u32;

View File

@ -22,7 +22,7 @@ fn main() {
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _2: &'10_1rs i32;
// let _2: &'11_1rs i32;
// ...
// let _1: i32;
// ...
@ -31,10 +31,10 @@ fn main() {
// _1 = const 3i32;
// FakeRead(ForLet, _1);
// StorageLive(_2);
// _2 = &'10_1rs _1;
// _2 = &'11_1rs _1;
// FakeRead(ForLet, _2);
// _0 = ();
// EndRegion('10_1rs);
// EndRegion('11_1rs);
// StorageDead(_2);
// StorageDead(_1);
// return;

View File

@ -27,9 +27,9 @@ fn main() {
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _7: &'23_3rs bool;
// let _7: &'26_3rs bool;
// ...
// let _3: &'23_1rs bool;
// let _3: &'26_1rs bool;
// ...
// let _2: bool;
// ...
@ -47,7 +47,7 @@ fn main() {
// _2 = const true;
// FakeRead(ForLet, _2);
// StorageLive(_3);
// _3 = &'23_1rs _2;
// _3 = &'26_1rs _2;
// FakeRead(ForLet, _3);
// StorageLive(_5);
// _5 = _2;
@ -59,7 +59,7 @@ fn main() {
// bb4: {
// _0 = ();
// StorageDead(_5);
// EndRegion('23_1rs);
// EndRegion('26_1rs);
// StorageDead(_3);
// StorageDead(_2);
// return;
@ -68,12 +68,12 @@ fn main() {
// _4 = ();
// StorageDead(_5);
// StorageLive(_7);
// _7 = &'23_3rs _2;
// _7 = &'26_3rs _2;
// FakeRead(ForLet, _7);
// _1 = ();
// EndRegion('23_3rs);
// EndRegion('26_3rs);
// StorageDead(_7);
// EndRegion('23_1rs);
// EndRegion('26_1rs);
// StorageDead(_3);
// StorageDead(_2);
// goto -> bb1;

View File

@ -28,9 +28,9 @@ fn main() {
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _7: &'26_3rs bool;
// let _7: &'30_3rs bool;
// ...
// let _3: &'26_1rs bool;
// let _3: &'30_1rs bool;
// ...
// let mut _1: bool;
// ...
@ -48,7 +48,7 @@ fn main() {
// bb2: {
// _1 = const true;
// StorageLive(_3);
// _3 = &'26_1rs _1;
// _3 = &'30_1rs _1;
// FakeRead(ForLet, _3);
// StorageLive(_5);
// _5 = _1;
@ -60,7 +60,7 @@ fn main() {
// bb4: {
// _0 = ();
// StorageDead(_5);
// EndRegion('26_1rs);
// EndRegion('30_1rs);
// StorageDead(_3);
// StorageDead(_1);
// return;
@ -69,12 +69,12 @@ fn main() {
// _4 = ();
// StorageDead(_5);
// StorageLive(_7);
// _7 = &'26_3rs _1;
// _7 = &'30_3rs _1;
// FakeRead(ForLet, _7);
// _2 = ();
// EndRegion('26_3rs);
// EndRegion('30_3rs);
// StorageDead(_7);
// EndRegion('26_1rs);
// EndRegion('30_1rs);
// StorageDead(_3);
// goto -> bb1;
// }

View File

@ -32,9 +32,9 @@ fn foo(i: i32) {
// START rustc.main.SimplifyCfg-qualify-consts.after.mir
// let mut _0: ();
// ...
// let _6: &'26_4rs i32;
// let _6: &'31_4rs i32;
// ...
// let _3: &'26_2rs i32;
// let _3: &'31_2rs i32;
// ...
// let _2: i32;
// ...
@ -50,7 +50,7 @@ fn foo(i: i32) {
// _2 = const 0i32;
// FakeRead(ForLet, _2);
// StorageLive(_3);
// _3 = &'26_2rs _2;
// _3 = &'31_2rs _2;
// FakeRead(ForLet, _3);
// StorageLive(_5);
// _5 = (*_3);
@ -62,18 +62,18 @@ fn foo(i: i32) {
// bb2: {
// StorageDead(_5);
// StorageLive(_6);
// _6 = &'26_4rs _2;
// _6 = &'31_4rs _2;
// FakeRead(ForLet, _6);
// _0 = ();
// EndRegion('26_4rs);
// EndRegion('31_4rs);
// StorageDead(_6);
// EndRegion('26_2rs);
// EndRegion('31_2rs);
// StorageDead(_3);
// StorageDead(_2);
// drop(_1) -> [return: bb4, unwind: bb1];
// }
// bb3: {
// EndRegion('26_2rs);
// EndRegion('31_2rs);
// drop(_1) -> bb1;
// }
// bb4: {

View File

@ -33,15 +33,15 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// let _1: D;
// ...
// let mut _2: ();
// let mut _3: [closure@NodeId(28) d:&'14s D];
// let mut _4: &'14s D;
// let mut _3: [closure@NodeId(28) d:&'18s D];
// let mut _4: &'18s D;
// bb0: {
// StorageLive(_1);
// _1 = D::{{constructor}}(const 0i32,);
// FakeRead(ForLet, _1);
// StorageLive(_3);
// StorageLive(_4);
// _4 = &'14s _1;
// _4 = &'18s _1;
// _3 = [closure@NodeId(28)] { d: move _4 };
// StorageDead(_4);
// _2 = const foo(move _3) -> [return: bb2, unwind: bb3];
@ -50,13 +50,13 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// resume;
// }
// bb2: {
// EndRegion('14s);
// EndRegion('18s);
// StorageDead(_3);
// _0 = ();
// drop(_1) -> [return: bb4, unwind: bb1];
// }
// bb3: {
// EndRegion('14s);
// EndRegion('18s);
// drop(_1) -> bb1;
// }
// bb4: {
@ -67,11 +67,11 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
// START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(28) d:&'14s D]) -> i32 {
// fn main::{{closure}}(_1: [closure@NodeId(28) d:&'18s D]) -> i32 {
// let mut _0: i32;
//
// bb0: {
// _0 = ((*(_1.0: &'14s D)).0: i32);
// _0 = ((*(_1.0: &'18s D)).0: i32);
// return;
// }
// END rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir

View File

@ -33,15 +33,15 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// let _1: D;
// ...
// let mut _2: ();
// let mut _3: [closure@NodeId(33) d:&'19s D];
// let mut _4: &'19s D;
// let mut _3: [closure@NodeId(33) d:&'24s D];
// let mut _4: &'24s D;
// bb0: {
// StorageLive(_1);
// _1 = D::{{constructor}}(const 0i32,);
// FakeRead(ForLet, _1);
// StorageLive(_3);
// StorageLive(_4);
// _4 = &'19s _1;
// _4 = &'24s _1;
// _3 = [closure@NodeId(33)] { d: move _4 };
// StorageDead(_4);
// _2 = const foo(move _3) -> [return: bb2, unwind: bb3];
@ -50,13 +50,13 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// resume;
// }
// bb2: {
// EndRegion('19s);
// EndRegion('24s);
// StorageDead(_3);
// _0 = ();
// drop(_1) -> [return: bb4, unwind: bb1];
// }
// bb3: {
// EndRegion('19s);
// EndRegion('24s);
// drop(_1) -> bb1;
// }
// bb4: {
@ -66,17 +66,17 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
// START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(33) d:&'19s D]) -> i32 {
// fn main::{{closure}}(_1: [closure@NodeId(33) d:&'24s D]) -> i32 {
// let mut _0: i32;
// ...
// let _2: &'16_0rs D;
// let _2: &'21_0rs D;
// ...
// bb0: {
// StorageLive(_2);
// _2 = &'16_0rs (*(_1.0: &'19s D));
// _2 = &'21_0rs (*(_1.0: &'24s D));
// FakeRead(ForLet, _2);
// _0 = ((*_2).0: i32);
// EndRegion('16_0rs);
// EndRegion('21_0rs);
// StorageDead(_2);
// return;
// }

View File

@ -70,14 +70,14 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// fn main::{{closure}}(_1: [closure@NodeId(33) d:D]) -> i32 {
// let mut _0: i32;
// ...
// let _2: &'16_0rs D;
// let _2: &'21_0rs D;
// ...
// bb0: {
// StorageLive(_2);
// _2 = &'16_0rs (_1.0: D);
// _2 = &'21_0rs (_1.0: D);
// FakeRead(ForLet, _2);
// _0 = ((*_2).0: i32);
// EndRegion('16_0rs);
// EndRegion('21_0rs);
// StorageDead(_2);
// drop(_1) -> [return: bb2, unwind: bb1];
// }

View File

@ -31,18 +31,18 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// fn main() -> () {
// let mut _0: ();
// ...
// let _2: &'21_1rs D;
// let _2: &'26_1rs D;
// ...
// let _1: D;
// ...
// let mut _3: ();
// let mut _4: [closure@NodeId(33) r:&'19s D];
// let mut _4: [closure@NodeId(33) r:&'24s D];
// bb0: {
// StorageLive(_1);
// _1 = D::{{constructor}}(const 0i32,);
// FakeRead(ForLet, _1);
// StorageLive(_2);
// _2 = &'21_1rs _1;
// _2 = &'26_1rs _1;
// FakeRead(ForLet, _2);
// StorageLive(_4);
// _4 = [closure@NodeId(33)] { r: _2 };
@ -52,16 +52,16 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// resume;
// }
// bb2: {
// EndRegion('19s);
// EndRegion('24s);
// StorageDead(_4);
// _0 = ();
// EndRegion('21_1rs);
// EndRegion('26_1rs);
// StorageDead(_2);
// drop(_1) -> [return: bb4, unwind: bb1];
// }
// bb3: {
// EndRegion('19s);
// EndRegion('21_1rs);
// EndRegion('24s);
// EndRegion('26_1rs);
// drop(_1) -> bb1;
// }
// bb4: {
@ -72,11 +72,11 @@ fn foo<F>(f: F) where F: FnOnce() -> i32 {
// END rustc.main.SimplifyCfg-qualify-consts.after.mir
// START rustc.main-{{closure}}.SimplifyCfg-qualify-consts.after.mir
// fn main::{{closure}}(_1: [closure@NodeId(33) r:&'19s D]) -> i32 {
// fn main::{{closure}}(_1: [closure@NodeId(33) r:&'24s D]) -> i32 {
// let mut _0: i32;
//
// bb0: {
// _0 = ((*(_1.0: &'21_1rs D)).0: i32);
// _0 = ((*(_1.0: &'26_1rs D)).0: i32);
// return;
// }
// }

View File

@ -41,7 +41,7 @@ fn main() {
// fn main() -> () {
// let mut _0: ();
// ...
// let mut _4: &'33_0rs i32;
// let mut _4: &'37_0rs i32;
// ...
// let _2: i32;
// ...
@ -79,14 +79,14 @@ fn main() {
// bb5: {
// _0 = ();
// StorageDead(_7);
// EndRegion('33_0rs);
// EndRegion('37_0rs);
// StorageDead(_4);
// StorageDead(_2);
// StorageDead(_1);
// return;
// }
// bb6: {
// _4 = &'33_0rs _2;
// _4 = &'37_0rs _2;
// _6 = ();
// StorageDead(_7);
// _1 = const true;

View File

@ -45,24 +45,24 @@ fn query() -> bool { true }
// scope 1 {
// }
// scope 2 {
// let _2: S<'36_0rs>;
// let _2: S<'49_0rs>;
// }
// let mut _1: ();
// let mut _3: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
// let mut _4: std::option::Option<&'36_0rs S<'36_0rs>>;
// let mut _3: std::cell::Cell<std::option::Option<&'49_0rs S<'49_0rs>>>;
// let mut _4: std::option::Option<&'49_0rs S<'49_0rs>>;
// let mut _5: ();
// let mut _6: &'17s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
// let mut _7: std::option::Option<&'36_0rs S<'36_0rs>>;
// let mut _8: &'36_0rs S<'36_0rs>;
// let mut _9: &'36_0rs S<'36_0rs>;
// let mut _6: &'25s std::cell::Cell<std::option::Option<&'49_0rs S<'49_0rs>>>;
// let mut _7: std::option::Option<&'49_0rs S<'49_0rs>>;
// let mut _8: &'49_0rs S<'49_0rs>;
// let mut _9: &'49_0rs S<'49_0rs>;
// let mut _10: ();
// let mut _11: bool;
// let mut _12: !;
// let mut _13: ();
// let mut _14: &'34s std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>;
// let mut _15: std::option::Option<&'36_0rs S<'36_0rs>>;
// let mut _16: &'36_0rs S<'36_0rs>;
// let mut _17: &'36_0rs S<'36_0rs>;
// let mut _14: &'47s std::cell::Cell<std::option::Option<&'49_0rs S<'49_0rs>>>;
// let mut _15: std::option::Option<&'49_0rs S<'49_0rs>>;
// let mut _16: &'49_0rs S<'49_0rs>;
// let mut _17: &'49_0rs S<'49_0rs>;
// bb0: {
// goto -> bb1;
// }
@ -73,7 +73,7 @@ fn query() -> bool { true }
// StorageLive(_2);
// StorageLive(_3);
// StorageLive(_4);
// _4 = std::option::Option<&'36_0rs S<'36_0rs>>::None;
// _4 = std::option::Option<&'49_0rs S<'49_0rs>>::None;
// _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
// }
// bb3: {
@ -81,22 +81,22 @@ fn query() -> bool { true }
// }
// bb4: {
// StorageDead(_4);
// _2 = S<'36_0rs> { r: move _3 };
// _2 = S<'49_0rs> { r: move _3 };
// StorageDead(_3);
// FakeRead(ForLet, _2);
// StorageLive(_6);
// _6 = &'17s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
// _6 = &'25s (_2.0: std::cell::Cell<std::option::Option<&'49_0rs S<'49_0rs>>>);
// StorageLive(_7);
// StorageLive(_8);
// StorageLive(_9);
// _9 = &'36_0rs _2;
// _8 = &'36_0rs (*_9);
// _7 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _8,);
// _9 = &'49_0rs _2;
// _8 = &'49_0rs (*_9);
// _7 = std::option::Option<&'49_0rs S<'49_0rs>>::Some(move _8,);
// StorageDead(_8);
// _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
// }
// bb5: {
// EndRegion('17s);
// EndRegion('25s);
// StorageDead(_7);
// StorageDead(_6);
// StorageDead(_9);
@ -109,7 +109,7 @@ fn query() -> bool { true }
// bb7: {
// _0 = ();
// StorageDead(_11);
// EndRegion('36_0rs);
// EndRegion('49_0rs);
// StorageDead(_2);
// return;
// }
@ -117,23 +117,23 @@ fn query() -> bool { true }
// _10 = ();
// StorageDead(_11);
// StorageLive(_14);
// _14 = &'34s (_2.0: std::cell::Cell<std::option::Option<&'36_0rs S<'36_0rs>>>);
// _14 = &'47s (_2.0: std::cell::Cell<std::option::Option<&'49_0rs S<'49_0rs>>>);
// StorageLive(_15);
// StorageLive(_16);
// StorageLive(_17);
// _17 = &'36_0rs _2;
// _16 = &'36_0rs (*_17);
// _15 = std::option::Option<&'36_0rs S<'36_0rs>>::Some(move _16,);
// _17 = &'49_0rs _2;
// _16 = &'49_0rs (*_17);
// _15 = std::option::Option<&'49_0rs S<'49_0rs>>::Some(move _16,);
// StorageDead(_16);
// _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
// }
// bb9: {
// EndRegion('34s);
// EndRegion('47s);
// StorageDead(_15);
// StorageDead(_14);
// StorageDead(_17);
// _1 = ();
// EndRegion('36_0rs);
// EndRegion('49_0rs);
// StorageDead(_2);
// goto -> bb1;
// }

View File

@ -41,16 +41,16 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// Notes on the MIR output below:
//
// 1. The `EndRegion('10s)` is allowed to precede the `drop(_3)`
// 1. The `EndRegion('13s)` is allowed to precede the `drop(_3)`
// solely because of the #[may_dangle] mentioned above.
//
// 2. Regarding the occurrence of `EndRegion('12ds)` *after* `StorageDead(_6)`
// (where we have borrows `&'12ds _6`): Eventually:
// 2. Regarding the occurrence of `EndRegion('15ds)` *after* `StorageDead(_6)`
// (where we have borrows `&'15ds _6`): Eventually:
//
// i. this code should be rejected (by mir-borrowck), or
//
// ii. the MIR code generation should be changed so that the
// EndRegion('12ds)` precedes `StorageDead(_6)` in the
// EndRegion('15ds)` precedes `StorageDead(_6)` in the
// control-flow. (Note: arielb1 views drop+storagedead as one
// unit, and does not see this option as a useful avenue to
// explore.), or
@ -66,13 +66,13 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// START rustc.main.QualifyAndPromoteConstants.before.mir
// fn main() -> () {
// let mut _0: ();
// let mut _1: &'12ds S1;
// let mut _2: D1<'12ds, '10s>;
// let mut _3: &'12ds S1;
// let mut _4: &'12ds S1;
// let mut _1: &'15ds S1;
// let mut _2: D1<'15ds, '13s>;
// let mut _3: &'15ds S1;
// let mut _4: &'15ds S1;
// let _5: S1;
// let mut _6: &'10s S1;
// let mut _7: &'10s S1;
// let mut _6: &'13s S1;
// let mut _7: &'13s S1;
// let _8: S1;
// bb0: {
// StorageLive(_2);
@ -80,19 +80,19 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// StorageLive(_4);
// StorageLive(_5);
// _5 = S1::{{constructor}}(const "ex1",);
// _4 = &'12ds _5;
// _3 = &'12ds (*_4);
// _4 = &'15ds _5;
// _3 = &'15ds (*_4);
// StorageLive(_6);
// StorageLive(_7);
// StorageLive(_8);
// _8 = S1::{{constructor}}(const "dang1",);
// _7 = &'10s _8;
// _6 = &'10s (*_7);
// _2 = D1<'12ds, '10s>::{{constructor}}(move _3, move _6);
// EndRegion('10s);
// _7 = &'13s _8;
// _6 = &'13s (*_7);
// _2 = D1<'15ds, '13s>::{{constructor}}(move _3, move _6);
// EndRegion('13s);
// StorageDead(_6);
// StorageDead(_3);
// _1 = (_2.0: &'12ds S1);
// _1 = (_2.0: &'15ds S1);
// drop(_2) -> [return: bb2, unwind: bb1];
// }
// bb1: {
@ -104,7 +104,7 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// StorageDead(_8);
// StorageDead(_4);
// StorageDead(_5);
// EndRegion('12ds);
// EndRegion('15ds);
// _0 = ();
// return;
// }
@ -114,29 +114,29 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// START rustc.main.QualifyAndPromoteConstants.after.mir
// fn main() -> (){
// let mut _0: ();
// let mut _1: &'12ds S1;
// let mut _2: D1<'12ds, '10s>;
// let mut _3: &'12ds S1;
// let mut _4: &'12ds S1;
// let mut _1: &'15ds S1;
// let mut _2: D1<'15ds, '13s>;
// let mut _3: &'15ds S1;
// let mut _4: &'15ds S1;
// let _5: S1;
// let mut _6: &'10s S1;
// let mut _7: &'10s S1;
// let mut _6: &'13s S1;
// let mut _7: &'13s S1;
// let _8: S1;
// bb0: {
// StorageLive(_2);
// StorageLive(_3);
// StorageLive(_4);
// _4 = &'12ds (promoted[1]: S1);
// _3 = &'12ds (*_4);
// _4 = &'15ds (promoted[1]: S1);
// _3 = &'15ds (*_4);
// StorageLive(_6);
// StorageLive(_7);
// _7 = &'10s (promoted[0]: S1);
// _6 = &'10s (*_7);
// _2 = D1<'12ds, '10s>::{{constructor}}(move _3, move _6);
// EndRegion('10s);
// _7 = &'13s (promoted[0]: S1);
// _6 = &'13s (*_7);
// _2 = D1<'15ds, '13s>::{{constructor}}(move _3, move _6);
// EndRegion('13s);
// StorageDead(_6);
// StorageDead(_3);
// _1 = (_2.0: &'12ds S1);
// _1 = (_2.0: &'15ds S1);
// drop(_2) -> [return: bb2, unwind: bb1];
// }
// bb1: {
@ -146,7 +146,7 @@ unsafe impl<'a, #[may_dangle] 'b> Drop for D1<'a, 'b> {
// StorageDead(_2);
// StorageDead(_7);
// StorageDead(_4);
// EndRegion('12ds);
// EndRegion('15ds);
// _0 = ();
// return;
// }

View File

@ -40,19 +40,19 @@ fn main() {
// ...
// bb0: {
// ...
// Validate(Suspend(ReScope(Node(ItemLocalId(10)))), [_1: i32]);
// Validate(Suspend(ReScope(Node(ItemLocalId(13)))), [_1: i32]);
// _6 = &ReErased mut _1;
// Validate(Acquire, [(*_6): i32/ReScope(Node(ItemLocalId(10)))]);
// Validate(Suspend(ReScope(Node(ItemLocalId(10)))), [(*_6): i32/ReScope(Node(ItemLocalId(10)))]);
// Validate(Acquire, [(*_6): i32/ReScope(Node(ItemLocalId(13)))]);
// Validate(Suspend(ReScope(Node(ItemLocalId(13)))), [(*_6): i32/ReScope(Node(ItemLocalId(13)))]);
// _5 = &ReErased mut (*_6);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(10)))]);
// Validate(Release, [_2: (), _3: &ReScope(Node(ItemLocalId(10))) Test, _5: &ReScope(Node(ItemLocalId(10))) mut i32]);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(13)))]);
// Validate(Release, [_2: (), _3: &ReScope(Node(ItemLocalId(13))) Test, _5: &ReScope(Node(ItemLocalId(13))) mut i32]);
// _2 = const Test::foo(move _3, move _5) -> bb1;
// }
//
// bb1: {
// Validate(Acquire, [_2: ()]);
// EndRegion(ReScope(Node(ItemLocalId(10))));
// EndRegion(ReScope(Node(ItemLocalId(13))));
// ...
// return;
// }
@ -64,11 +64,11 @@ fn main() {
// bb0: {
// Validate(Acquire, [_1: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrEnv) [closure@NodeId(65)], _2: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrAnon(0)) mut i32]);
// StorageLive(_3);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 })), [(*_2): i32]);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(31), first_statement_index: 0 })), [(*_2): i32]);
// _3 = &ReErased (*_2);
// Validate(Acquire, [(*_3): i32/ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 }) (imm)]);
// Validate(Acquire, [(*_3): i32/ReScope(Remainder { block: ItemLocalId(31), first_statement_index: 0 }) (imm)]);
// _0 = (*_3);
// EndRegion(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 }));
// EndRegion(ReScope(Remainder { block: ItemLocalId(31), first_statement_index: 0 }));
// StorageDead(_3);
// return;
// }

View File

@ -48,27 +48,27 @@ fn main() {
// StorageLive(_1);
// _1 = Test { x: const 0i32 };
// StorageLive(_2);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 })), [_1: Test]);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(24), first_statement_index: 3 })), [_1: Test]);
// _2 = &ReErased _1;
// Validate(Acquire, [(*_2): Test/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]);
// Validate(Acquire, [(*_2): Test/ReScope(Remainder { block: ItemLocalId(24), first_statement_index: 3 }) (imm)]);
// StorageLive(_4);
// StorageLive(_5);
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]);
// Validate(Suspend(ReScope(Node(ItemLocalId(22)))), [((*_2).0: i32): i32/ReScope(Remainder { block: ItemLocalId(24), first_statement_index: 3 }) (imm)]);
// _5 = &ReErased ((*_2).0: i32);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(22))) (imm)]);
// Validate(Suspend(ReScope(Node(ItemLocalId(22)))), [(*_5): i32/ReScope(Node(ItemLocalId(22))) (imm)]);
// _4 = &ReErased (*_5);
// Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
// Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(18))) i32]);
// Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(22))) (imm)]);
// Validate(Release, [_3: (), _4: &ReScope(Node(ItemLocalId(22))) i32]);
// _3 = const foo(move _4) -> bb1;
// }
// bb1: {
// Validate(Acquire, [_3: ()]);
// EndRegion(ReScope(Node(ItemLocalId(18))));
// EndRegion(ReScope(Node(ItemLocalId(22))));
// StorageDead(_4);
// StorageDead(_5);
// _0 = ();
// EndRegion(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }));
// EndRegion(ReScope(Remainder { block: ItemLocalId(24), first_statement_index: 3 }));
// StorageDead(_2);
// StorageDead(_1);
// return;

View File

@ -53,12 +53,12 @@ fn main() {
// StorageLive(_3);
// StorageLive(_4);
// StorageLive(_5);
// Validate(Suspend(ReScope(Node(ItemLocalId(12)))), [(*_2): i32]);
// Validate(Suspend(ReScope(Node(ItemLocalId(16)))), [(*_2): i32]);
// _5 = &ReErased mut (*_2);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(12)))]);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(16)))]);
// _4 = move _5 as *mut i32 (Misc);
// _3 = move _4;
// EndRegion(ReScope(Node(ItemLocalId(12))));
// EndRegion(ReScope(Node(ItemLocalId(16))));
// StorageDead(_4);
// StorageDead(_5);
// Validate(Release, [_0: bool, _3: *mut i32]);