Auto merge of #54756 - ljedrz:cleanup_middle, r=michaelwoerister
Cleanup rustc/middle - improve allocations - use `Cow<'static, str>` where applicable - improve some patterns - whitespace & formatting fixes
This commit is contained in:
commit
4efdc04a5d
16 changed files with 637 additions and 707 deletions
|
@ -131,12 +131,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
|
||||
fn mark_live_symbols(&mut self) {
|
||||
let mut scanned = FxHashSet();
|
||||
while !self.worklist.is_empty() {
|
||||
let id = self.worklist.pop().unwrap();
|
||||
if scanned.contains(&id) {
|
||||
while let Some(id) = self.worklist.pop() {
|
||||
if !scanned.insert(id) {
|
||||
continue
|
||||
}
|
||||
scanned.insert(id);
|
||||
|
||||
if let Some(ref node) = self.tcx.hir.find(id) {
|
||||
self.live_symbols.insert(id);
|
||||
|
@ -494,8 +492,8 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
|||
ctor_id: Option<ast::NodeId>)
|
||||
-> bool {
|
||||
if self.live_symbols.contains(&id)
|
||||
|| ctor_id.map_or(false,
|
||||
|ctor| self.live_symbols.contains(&ctor)) {
|
||||
|| ctor_id.map_or(false, |ctor| self.live_symbols.contains(&ctor))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// If it's a type whose items are live, then it's live, too.
|
||||
|
|
|
@ -253,7 +253,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
fn add_library(tcx: TyCtxt<'_, '_, '_>,
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
use hir::map as hir_map;
|
||||
use hir::def_id::{CRATE_DEF_INDEX};
|
||||
use session::{config, Session};
|
||||
|
@ -141,11 +140,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
|
|||
if ctxt.start_fn.is_none() {
|
||||
ctxt.start_fn = Some((item.id, item.span));
|
||||
} else {
|
||||
struct_span_err!(
|
||||
ctxt.session, item.span, E0138,
|
||||
"multiple 'start' functions")
|
||||
.span_label(ctxt.start_fn.unwrap().1,
|
||||
"previous `start` function here")
|
||||
struct_span_err!(ctxt.session, item.span, E0138, "multiple 'start' functions")
|
||||
.span_label(ctxt.start_fn.unwrap().1, "previous `start` function here")
|
||||
.span_label(item.span, "multiple `start` functions")
|
||||
.emit();
|
||||
}
|
||||
|
|
|
@ -35,12 +35,8 @@ impl_stable_hash_for!(enum self::SymbolExportLevel {
|
|||
|
||||
impl SymbolExportLevel {
|
||||
pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool {
|
||||
if threshold == SymbolExportLevel::Rust {
|
||||
// We export everything from Rust dylibs
|
||||
true
|
||||
} else {
|
||||
self == SymbolExportLevel::C
|
||||
}
|
||||
threshold == SymbolExportLevel::Rust // export everything from Rust dylibs
|
||||
|| self == SymbolExportLevel::C
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -801,10 +801,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||
self.walk_pat(discr_cmt.clone(), &pat, mode);
|
||||
}
|
||||
|
||||
if let Some(ref guard) = arm.guard {
|
||||
match guard {
|
||||
hir::Guard::If(ref e) => self.consume_expr(e),
|
||||
}
|
||||
if let Some(hir::Guard::If(ref e)) = arm.guard {
|
||||
self.consume_expr(e)
|
||||
}
|
||||
|
||||
self.consume_expr(&arm.body);
|
||||
|
@ -826,11 +824,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||
cmt_discr: mc::cmt<'tcx>,
|
||||
pat: &hir::Pat,
|
||||
mode: &mut TrackMatchMode) {
|
||||
debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr,
|
||||
pat);
|
||||
debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr, pat);
|
||||
|
||||
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |cmt_pat, pat| {
|
||||
if let PatKind::Binding(..) = pat.node {
|
||||
let bm = *self.mc.tables.pat_binding_modes().get(pat.hir_id)
|
||||
let bm = *self.mc.tables.pat_binding_modes()
|
||||
.get(pat.hir_id)
|
||||
.expect("missing binding mode");
|
||||
match bm {
|
||||
ty::BindByReference(..) =>
|
||||
|
|
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
|
|||
}
|
||||
Err(LayoutError::Unknown(bad)) => {
|
||||
if bad == ty {
|
||||
"this type's size can vary".to_string()
|
||||
"this type's size can vary".to_owned()
|
||||
} else {
|
||||
format!("size can vary because of {}", bad)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ macro_rules! language_item_table {
|
|||
$( $variant:ident, $name:expr, $method:ident; )*
|
||||
) => {
|
||||
|
||||
|
||||
enum_from_u32! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum LangItem {
|
||||
|
@ -145,8 +144,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
|
|||
|
||||
fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
|
||||
// Check for duplicates.
|
||||
match self.items.items[item_index] {
|
||||
Some(original_def_id) if original_def_id != item_def_id => {
|
||||
if let Some(original_def_id) = self.items.items[item_index] {
|
||||
if original_def_id != item_def_id {
|
||||
let name = LangItem::from_u32(item_index as u32).unwrap().name();
|
||||
let mut err = match self.tcx.hir.span_if_local(item_def_id) {
|
||||
Some(span) => struct_span_err!(
|
||||
|
@ -161,17 +160,13 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
|
|||
name)),
|
||||
};
|
||||
if let Some(span) = self.tcx.hir.span_if_local(original_def_id) {
|
||||
span_note!(&mut err, span,
|
||||
"first defined here.");
|
||||
span_note!(&mut err, span, "first defined here.");
|
||||
} else {
|
||||
err.note(&format!("first defined in crate `{}`.",
|
||||
self.tcx.crate_name(original_def_id.krate)));
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
_ => {
|
||||
// OK.
|
||||
}
|
||||
}
|
||||
|
||||
// Matched.
|
||||
|
@ -194,7 +189,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
|
|||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LanguageItems {
|
||||
|
|
|
@ -128,8 +128,8 @@ impl<'a, 'tcx> LibFeatureCollector<'a, 'tcx> {
|
|||
let msg = format!(
|
||||
"feature `{}` is declared {}, but was previously declared {}",
|
||||
feature,
|
||||
if since.is_some() { "stable"} else { "unstable" },
|
||||
if since.is_none() { "stable"} else { "unstable" },
|
||||
if since.is_some() { "stable" } else { "unstable" },
|
||||
if since.is_none() { "stable" } else { "unstable" },
|
||||
);
|
||||
self.tcx.sess.struct_span_err_with_code(span, &msg,
|
||||
DiagnosticId::Error("E0711".into())).emit();
|
||||
|
|
|
@ -170,7 +170,7 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_, '_, '_>) -> Strin
|
|||
VarDefNode(s) => {
|
||||
format!("Var def node [{}]", cm.span_to_string(s))
|
||||
}
|
||||
ExitNode => "Exit node".to_string(),
|
||||
ExitNode => "Exit node".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,6 @@ enum VarKind {
|
|||
|
||||
struct IrMaps<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
||||
num_live_nodes: usize,
|
||||
num_vars: usize,
|
||||
live_node_map: HirIdMap<LiveNode>,
|
||||
|
@ -330,7 +329,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
|
|||
Local(LocalInfo { name, .. }) | Arg(_, name) => {
|
||||
name.to_string()
|
||||
},
|
||||
CleanExit => "<clean-exit>".to_string()
|
||||
CleanExit => "<clean-exit>".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,13 +473,15 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
|
|||
// construction site.
|
||||
let mut call_caps = Vec::new();
|
||||
ir.tcx.with_freevars(expr.id, |freevars| {
|
||||
for fv in freevars {
|
||||
call_caps.extend(freevars.iter().filter_map(|fv| {
|
||||
if let Def::Local(rv) = fv.def {
|
||||
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
|
||||
let var_hid = ir.tcx.hir.node_to_hir_id(rv);
|
||||
call_caps.push(CaptureInfo { ln: fv_ln, var_hid });
|
||||
}
|
||||
Some(CaptureInfo { ln: fv_ln, var_hid })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}));
|
||||
});
|
||||
ir.set_captures(expr.id, call_caps);
|
||||
|
||||
|
@ -918,8 +919,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
self.rwu_table.assign_unpacked(idx, rwu);
|
||||
}
|
||||
|
||||
// _______________________________________________________________________
|
||||
|
||||
fn compute(&mut self, body: &hir::Expr) -> LiveNode {
|
||||
// if there is a `break` or `again` at the top level, then it's
|
||||
// effectively a return---this only occurs in `for` loops,
|
||||
|
@ -941,8 +940,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
let entry_ln = self.propagate_through_expr(body, s.fallthrough_ln);
|
||||
|
||||
// hack to skip the loop unless debug! is enabled:
|
||||
debug!("^^ liveness computation results for body {} (entry={:?})",
|
||||
{
|
||||
debug!("^^ liveness computation results for body {} (entry={:?})", {
|
||||
for ln_idx in 0..self.ir.num_live_nodes {
|
||||
debug!("{:?}", self.ln_str(LiveNode(ln_idx as u32)));
|
||||
}
|
||||
|
@ -1036,7 +1034,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ExprKind::Closure(.., blk_id, _, _) => {
|
||||
debug!("{} is an ExprKind::Closure", self.ir.tcx.hir.node_to_pretty_string(expr.id));
|
||||
debug!("{} is an ExprKind::Closure",
|
||||
self.ir.tcx.hir.node_to_pretty_string(expr.id));
|
||||
|
||||
// The next-node for a break is the successor of the entire
|
||||
// loop. The next-node for a continue is the top of this loop.
|
||||
|
@ -1049,12 +1048,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
|
||||
// the construction of a closure itself is not important,
|
||||
// but we have to consider the closed over variables.
|
||||
let caps = match self.ir.capture_info_map.get(&expr.id) {
|
||||
Some(caps) => caps.clone(),
|
||||
None => {
|
||||
span_bug!(expr.span, "no registered caps");
|
||||
}
|
||||
};
|
||||
let caps = self.ir.capture_info_map.get(&expr.id).cloned().unwrap_or_else(||
|
||||
span_bug!(expr.span, "no registered caps"));
|
||||
|
||||
caps.iter().rev().fold(succ, |succ, cap| {
|
||||
self.init_from_succ(cap.ln, succ);
|
||||
let var = self.variable(cap.var_hid, expr.span);
|
||||
|
@ -1114,15 +1110,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
self.init_empty(ln, succ);
|
||||
let mut first_merge = true;
|
||||
for arm in arms {
|
||||
let body_succ =
|
||||
self.propagate_through_expr(&arm.body, succ);
|
||||
let guard_succ =
|
||||
self.propagate_through_opt_expr(
|
||||
arm.guard.as_ref().map(|g|
|
||||
match g {
|
||||
hir::Guard::If(e) => &**e,
|
||||
}),
|
||||
body_succ);
|
||||
let body_succ = self.propagate_through_expr(&arm.body, succ);
|
||||
|
||||
let guard_succ = self.propagate_through_opt_expr(
|
||||
arm.guard.as_ref().map(|hir::Guard::If(e)| &**e),
|
||||
body_succ
|
||||
);
|
||||
// only consider the first pattern; any later patterns must have
|
||||
// the same bindings, and we also consider the first pattern to be
|
||||
// the "authoritative" set of ids
|
||||
|
@ -1146,7 +1139,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
let target = match label.target_id {
|
||||
Ok(node_id) => self.break_ln.get(&node_id),
|
||||
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
|
||||
}.map(|x| *x);
|
||||
}.cloned();
|
||||
|
||||
// Now that we know the label we're going to,
|
||||
// look it up in the break loop nodes table
|
||||
|
@ -1159,18 +1152,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
|
||||
hir::ExprKind::Continue(label) => {
|
||||
// Find which label this expr continues to
|
||||
let sc = match label.target_id {
|
||||
Ok(node_id) => node_id,
|
||||
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
|
||||
};
|
||||
let sc = label.target_id.unwrap_or_else(|err|
|
||||
span_bug!(expr.span, "loop scope error: {}", err));
|
||||
|
||||
// Now that we know the label we're going to,
|
||||
// look it up in the continue loop nodes table
|
||||
|
||||
match self.cont_ln.get(&sc) {
|
||||
Some(&b) => b,
|
||||
None => span_bug!(expr.span, "continue to unknown label")
|
||||
}
|
||||
self.cont_ln.get(&sc).cloned().unwrap_or_else(||
|
||||
span_bug!(expr.span, "continue to unknown label"))
|
||||
}
|
||||
|
||||
hir::ExprKind::Assign(ref l, ref r) => {
|
||||
|
@ -1226,6 +1214,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
} else {
|
||||
succ
|
||||
};
|
||||
|
||||
self.propagate_through_exprs(args, succ)
|
||||
}
|
||||
|
||||
|
@ -1269,8 +1258,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
let acc = if o.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE };
|
||||
let succ = self.write_place(output, succ, acc);
|
||||
self.propagate_through_place_components(output, succ)
|
||||
}
|
||||
});
|
||||
}});
|
||||
|
||||
// Inputs are executed first. Propagate last because of rev order
|
||||
self.propagate_through_exprs(inputs, succ)
|
||||
|
@ -1349,8 +1337,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// see comment on propagate_through_place()
|
||||
fn write_place(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
|
||||
-> LiveNode {
|
||||
fn write_place(&mut self, expr: &Expr, succ: LiveNode, acc: u32) -> LiveNode {
|
||||
match expr.node {
|
||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||
self.access_path(expr.hir_id, path, succ, acc)
|
||||
|
@ -1392,7 +1379,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
body: &hir::Block,
|
||||
succ: LiveNode)
|
||||
-> LiveNode {
|
||||
|
||||
/*
|
||||
|
||||
We model control flow like this:
|
||||
|
@ -1450,8 +1436,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
self.propagate_through_expr(&cond, ln)
|
||||
}
|
||||
};
|
||||
assert!(cond_ln == new_cond_ln);
|
||||
assert!(body_ln == self.propagate_through_block(body, cond_ln));
|
||||
assert_eq!(cond_ln, new_cond_ln);
|
||||
assert_eq!(body_ln, self.propagate_through_block(body, cond_ln));
|
||||
}
|
||||
|
||||
cond_ln
|
||||
|
@ -1576,7 +1562,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
|
||||
fn should_warn(&self, var: Variable) -> Option<String> {
|
||||
let name = self.ir.variable_name(var);
|
||||
if name.is_empty() || name.as_bytes()[0] == ('_' as u8) {
|
||||
if name.is_empty() || name.as_bytes()[0] == b'_' {
|
||||
None
|
||||
} else {
|
||||
Some(name)
|
||||
|
@ -1617,7 +1603,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
if !self.used_on_entry(ln, var) {
|
||||
let r = self.should_warn(var);
|
||||
if let Some(name) = r {
|
||||
|
||||
// annoying: for parameters in funcs like `fn(x: i32)
|
||||
// {ret}`, there is only one node, so asking about
|
||||
// assigned_on_exit() is not meaningful.
|
||||
|
@ -1627,8 +1612,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
self.assigned_on_exit(ln, var).is_some()
|
||||
};
|
||||
|
||||
let suggest_underscore_msg = format!("consider using `_{}` instead",
|
||||
name);
|
||||
let suggest_underscore_msg = format!("consider using `_{}` instead", name);
|
||||
|
||||
if is_assigned {
|
||||
self.ir.tcx
|
||||
|
|
|
@ -83,6 +83,7 @@ use hir;
|
|||
use syntax::ast::{self, Name};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -720,6 +721,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
return Ok(self.cat_rvalue_node(hir_id, span, expr_ty));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(cmt_ {
|
||||
hir_id,
|
||||
span:span,
|
||||
|
@ -941,19 +943,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
span: Span,
|
||||
expr_ty: Ty<'tcx>)
|
||||
-> cmt_<'tcx> {
|
||||
debug!(
|
||||
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
|
||||
hir_id,
|
||||
span,
|
||||
expr_ty,
|
||||
);
|
||||
debug!("cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
|
||||
hir_id, span, expr_ty);
|
||||
|
||||
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
|
||||
.unwrap_or(false);
|
||||
|
||||
debug!(
|
||||
"cat_rvalue_node: promotable = {:?}",
|
||||
promotable,
|
||||
);
|
||||
debug!("cat_rvalue_node: promotable = {:?}", promotable);
|
||||
|
||||
// Always promote `[T; 0]` (even when e.g. borrowed mutably).
|
||||
let promotable = match expr_ty.sty {
|
||||
|
@ -961,10 +957,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
_ => promotable,
|
||||
};
|
||||
|
||||
debug!(
|
||||
"cat_rvalue_node: promotable = {:?} (2)",
|
||||
promotable,
|
||||
);
|
||||
debug!("cat_rvalue_node: promotable = {:?} (2)", promotable);
|
||||
|
||||
// Compute maximum lifetime of this rvalue. This is 'static if
|
||||
// we can promote to a constant, otherwise equal to enclosing temp
|
||||
|
@ -1022,12 +1015,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
base: &hir::Expr,
|
||||
note: Note,
|
||||
) -> McResult<cmt_<'tcx>> {
|
||||
debug!(
|
||||
"cat_overloaded_place(expr={:?}, base={:?}, note={:?})",
|
||||
debug!("cat_overloaded_place(expr={:?}, base={:?}, note={:?})",
|
||||
expr,
|
||||
base,
|
||||
note,
|
||||
);
|
||||
note);
|
||||
|
||||
// Reconstruct the output assuming it's a reference with the
|
||||
// same region and mutability as the receiver. This holds for
|
||||
|
@ -1037,9 +1028,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
|
||||
let (region, mutbl) = match base_ty.sty {
|
||||
ty::Ref(region, _, mutbl) => (region, mutbl),
|
||||
_ => {
|
||||
span_bug!(expr.span, "cat_overloaded_place: base is not a reference")
|
||||
}
|
||||
_ => span_bug!(expr.span, "cat_overloaded_place: base is not a reference")
|
||||
};
|
||||
let ref_ty = self.tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: place_ty,
|
||||
|
@ -1062,8 +1051,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
let deref_ty = match base_cmt_ty.builtin_deref(true) {
|
||||
Some(mt) => mt.ty,
|
||||
None => {
|
||||
debug!("Explicit deref of non-derefable type: {:?}",
|
||||
base_cmt_ty);
|
||||
debug!("Explicit deref of non-derefable type: {:?}", base_cmt_ty);
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
|
@ -1295,7 +1283,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
(cmt, adt_def.non_enum_variant().fields.len())
|
||||
}
|
||||
ref ty => {
|
||||
span_bug!(pat.span, "tuple struct pattern unexpected type {:?}", ty);
|
||||
span_bug!(pat.span,
|
||||
"tuple struct pattern unexpected type {:?}", ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1308,7 +1297,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
||||
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
||||
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
|
||||
let subcmt = Rc::new(self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||
let subcmt = Rc::new(
|
||||
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||
self.cat_pattern_(subcmt, &subpat, op)?;
|
||||
}
|
||||
}
|
||||
|
@ -1350,7 +1340,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
|
||||
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
|
||||
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
|
||||
let subcmt = Rc::new(self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||
let subcmt = Rc::new(
|
||||
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
|
||||
self.cat_pattern_(subcmt, &subpat, op)?;
|
||||
}
|
||||
}
|
||||
|
@ -1489,59 +1480,59 @@ impl<'tcx> cmt_<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn descriptive_string(&self, tcx: TyCtxt<'_, '_, '_>) -> String {
|
||||
pub fn descriptive_string(&self, tcx: TyCtxt<'_, '_, '_>) -> Cow<'static, str> {
|
||||
match self.cat {
|
||||
Categorization::StaticItem => {
|
||||
"static item".to_string()
|
||||
"static item".into()
|
||||
}
|
||||
Categorization::Rvalue(..) => {
|
||||
"non-place".to_string()
|
||||
"non-place".into()
|
||||
}
|
||||
Categorization::Local(vid) => {
|
||||
if tcx.hir.is_argument(vid) {
|
||||
"argument".to_string()
|
||||
"argument"
|
||||
} else {
|
||||
"local variable".to_string()
|
||||
}
|
||||
"local variable"
|
||||
}.into()
|
||||
}
|
||||
Categorization::Deref(_, pk) => {
|
||||
match self.upvar_cat() {
|
||||
Some(&Categorization::Upvar(ref var)) => {
|
||||
var.to_string()
|
||||
var.to_string().into()
|
||||
}
|
||||
Some(_) => bug!(),
|
||||
None => {
|
||||
match pk {
|
||||
Unique => {
|
||||
"`Box` content".to_string()
|
||||
"`Box` content"
|
||||
}
|
||||
UnsafePtr(..) => {
|
||||
"dereference of raw pointer".to_string()
|
||||
"dereference of raw pointer"
|
||||
}
|
||||
BorrowedPtr(..) => {
|
||||
match self.note {
|
||||
NoteIndex => "indexed content".to_string(),
|
||||
_ => "borrowed content".to_string(),
|
||||
}
|
||||
NoteIndex => "indexed content",
|
||||
_ => "borrowed content"
|
||||
}
|
||||
}
|
||||
}.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
Categorization::Interior(_, InteriorField(..)) => {
|
||||
"field".to_string()
|
||||
"field".into()
|
||||
}
|
||||
Categorization::Interior(_, InteriorElement(InteriorOffsetKind::Index)) => {
|
||||
"indexed content".to_string()
|
||||
"indexed content".into()
|
||||
}
|
||||
Categorization::Interior(_, InteriorElement(InteriorOffsetKind::Pattern)) => {
|
||||
"pattern-bound indexed content".to_string()
|
||||
"pattern-bound indexed content".into()
|
||||
}
|
||||
Categorization::Upvar(ref var) => {
|
||||
var.to_string()
|
||||
var.to_string().into()
|
||||
}
|
||||
Categorization::Downcast(ref cmt, _) => {
|
||||
cmt.descriptive_string(tcx)
|
||||
cmt.descriptive_string(tcx).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,7 +371,9 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
|
|||
return
|
||||
}
|
||||
|
||||
for default_method in self.tcx.provided_trait_methods(trait_def_id) {
|
||||
let provided_trait_methods = self.tcx.provided_trait_methods(trait_def_id);
|
||||
self.worklist.reserve(provided_trait_methods.len());
|
||||
for default_method in provided_trait_methods {
|
||||
let node_id = self.tcx
|
||||
.hir
|
||||
.as_local_node_id(default_method.def_id)
|
||||
|
@ -394,7 +396,6 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
|
|||
#[derive(Clone)]
|
||||
pub struct ReachableSet(pub Lrc<NodeSet>);
|
||||
|
||||
|
||||
fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet {
|
||||
debug_assert!(crate_num == LOCAL_CRATE);
|
||||
|
||||
|
|
|
@ -459,13 +459,13 @@ impl<'tcx> ScopeTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn each_encl_scope<E>(&self, mut e:E) where E: FnMut(Scope, Scope) {
|
||||
pub fn each_encl_scope<E>(&self, mut e: E) where E: FnMut(Scope, Scope) {
|
||||
for (&child, &parent) in &self.parent_map {
|
||||
e(child, parent.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn each_var_scope<E>(&self, mut e:E) where E: FnMut(&hir::ItemLocalId, Scope) {
|
||||
pub fn each_var_scope<E>(&self, mut e: E) where E: FnMut(&hir::ItemLocalId, Scope) {
|
||||
for (child, &parent) in self.var_map.iter() {
|
||||
e(child, parent)
|
||||
}
|
||||
|
@ -515,10 +515,8 @@ impl<'tcx> ScopeTree {
|
|||
|
||||
/// Returns the lifetime of the local variable `var_id`
|
||||
pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Scope {
|
||||
match self.var_map.get(&var_id) {
|
||||
Some(&r) => r,
|
||||
None => { bug!("no enclosing scope for id {:?}", var_id); }
|
||||
}
|
||||
self.var_map.get(&var_id).cloned().unwrap_or_else(||
|
||||
bug!("no enclosing scope for id {:?}", var_id))
|
||||
}
|
||||
|
||||
pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> Option<Scope> {
|
||||
|
@ -559,8 +557,7 @@ impl<'tcx> ScopeTree {
|
|||
scope
|
||||
}
|
||||
|
||||
pub fn scopes_intersect(&self, scope1: Scope, scope2: Scope)
|
||||
-> bool {
|
||||
pub fn scopes_intersect(&self, scope1: Scope, scope2: Scope) -> bool {
|
||||
self.is_subscope_of(scope1, scope2) ||
|
||||
self.is_subscope_of(scope2, scope1)
|
||||
}
|
||||
|
@ -584,14 +581,13 @@ impl<'tcx> ScopeTree {
|
|||
}
|
||||
}
|
||||
|
||||
debug!("is_subscope_of({:?}, {:?})=true",
|
||||
subscope, superscope);
|
||||
debug!("is_subscope_of({:?}, {:?})=true", subscope, superscope);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns the id of the innermost containing body
|
||||
pub fn containing_body(&self, mut scope: Scope)-> Option<hir::ItemLocalId> {
|
||||
pub fn containing_body(&self, mut scope: Scope) -> Option<hir::ItemLocalId> {
|
||||
loop {
|
||||
if let ScopeData::CallSite = scope.data {
|
||||
return Some(scope.item_local_id());
|
||||
|
@ -828,10 +824,8 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk:
|
|||
fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &'tcx hir::Arm) {
|
||||
visitor.terminating_scopes.insert(arm.body.hir_id.local_id);
|
||||
|
||||
if let Some(ref g) = arm.guard {
|
||||
match g {
|
||||
hir::Guard::If(ref expr) => visitor.terminating_scopes.insert(expr.hir_id.local_id),
|
||||
};
|
||||
if let Some(hir::Guard::If(ref expr)) = arm.guard {
|
||||
visitor.terminating_scopes.insert(expr.hir_id.local_id);
|
||||
}
|
||||
|
||||
intravisit::walk_arm(visitor, arm);
|
||||
|
@ -890,11 +884,9 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
|
|||
// This ensures fixed size stacks.
|
||||
|
||||
hir::ExprKind::Binary(
|
||||
source_map::Spanned { node: hir::BinOpKind::And, .. },
|
||||
_, ref r) |
|
||||
source_map::Spanned { node: hir::BinOpKind::And, .. }, _, ref r) |
|
||||
hir::ExprKind::Binary(
|
||||
source_map::Spanned { node: hir::BinOpKind::Or, .. },
|
||||
_, ref r) => {
|
||||
source_map::Spanned { node: hir::BinOpKind::Or, .. }, _, ref r) => {
|
||||
// For shortcircuiting operators, mark the RHS as a terminating
|
||||
// scope since it only executes conditionally.
|
||||
terminating(r.hir_id.local_id);
|
||||
|
|
|
@ -25,6 +25,7 @@ use errors::DiagnosticBuilder;
|
|||
use rustc::lint;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use session::Session;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::mem::replace;
|
||||
use syntax::ast;
|
||||
|
@ -1250,13 +1251,13 @@ fn compute_object_lifetime_defaults(
|
|||
let object_lifetime_default_reprs: String = result
|
||||
.iter()
|
||||
.map(|set| match *set {
|
||||
Set1::Empty => "BaseDefault".to_string(),
|
||||
Set1::One(Region::Static) => "'static".to_string(),
|
||||
Set1::Empty => "BaseDefault".into(),
|
||||
Set1::One(Region::Static) => "'static".into(),
|
||||
Set1::One(Region::EarlyBound(mut i, _, _)) => {
|
||||
generics.params.iter().find_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
if i == 0 {
|
||||
return Some(param.name.ident().to_string());
|
||||
return Some(param.name.ident().to_string().into());
|
||||
}
|
||||
i -= 1;
|
||||
None
|
||||
|
@ -1265,9 +1266,9 @@ fn compute_object_lifetime_defaults(
|
|||
}).unwrap()
|
||||
}
|
||||
Set1::One(_) => bug!(),
|
||||
Set1::Many => "Ambiguous".to_string(),
|
||||
Set1::Many => "Ambiguous".into(),
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.collect::<Vec<Cow<'static, str>>>()
|
||||
.join(",");
|
||||
tcx.sess.span_err(item.span, &object_lifetime_default_reprs);
|
||||
}
|
||||
|
@ -1420,16 +1421,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id));
|
||||
|
||||
for def_id in def_ids {
|
||||
debug!(
|
||||
"check_uses_for_lifetimes_defined_by_scope: def_id = {:?}",
|
||||
def_id,
|
||||
);
|
||||
debug!("check_uses_for_lifetimes_defined_by_scope: def_id = {:?}", def_id);
|
||||
|
||||
let lifetimeuseset = self.lifetime_uses.remove(&def_id);
|
||||
debug!(
|
||||
"check_uses_for_lifetimes_defined_by_scope: lifetimeuseset = {:?}",
|
||||
lifetimeuseset
|
||||
);
|
||||
|
||||
debug!("check_uses_for_lifetimes_defined_by_scope: lifetimeuseset = {:?}",
|
||||
lifetimeuseset);
|
||||
|
||||
match lifetimeuseset {
|
||||
Some(LifetimeUseSet::One(lifetime)) => {
|
||||
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
|
@ -1872,19 +1870,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
node: hir::TraitItemKind::Method(_, ref m),
|
||||
..
|
||||
}) => {
|
||||
match self.tcx
|
||||
if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx
|
||||
.hir
|
||||
.expect_item(self.tcx.hir.get_parent(parent))
|
||||
.node
|
||||
{
|
||||
hir::ItemKind::Trait(.., ref trait_items) => {
|
||||
assoc_item_kind = trait_items
|
||||
.iter()
|
||||
.find(|ti| ti.id.node_id == parent)
|
||||
.map(|ti| ti.kind);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
match *m {
|
||||
hir::TraitMethod::Required(_) => None,
|
||||
hir::TraitMethod::Provided(body) => Some(body),
|
||||
|
@ -1895,20 +1890,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
node: hir::ImplItemKind::Method(_, body),
|
||||
..
|
||||
}) => {
|
||||
match self.tcx
|
||||
if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx
|
||||
.hir
|
||||
.expect_item(self.tcx.hir.get_parent(parent))
|
||||
.node
|
||||
{
|
||||
hir::ItemKind::Impl(.., ref self_ty, ref impl_items) => {
|
||||
impl_self = Some(self_ty);
|
||||
assoc_item_kind = impl_items
|
||||
.iter()
|
||||
.find(|ii| ii.id.node_id == parent)
|
||||
.map(|ii| ii.kind);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Some(body)
|
||||
}
|
||||
|
||||
|
@ -2255,9 +2247,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
|
||||
Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
|
||||
|
||||
Scope::ObjectLifetimeDefault {
|
||||
lifetime: Some(l), ..
|
||||
} => break l,
|
||||
Scope::ObjectLifetimeDefault { lifetime: Some(l), .. } => break l,
|
||||
}
|
||||
};
|
||||
self.insert_lifetime(lifetime_ref, lifetime.shifted(late_depth));
|
||||
|
@ -2329,13 +2319,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
lifetime_i.name.ident(),
|
||||
),
|
||||
).help(&format!(
|
||||
"you can use the `'static` lifetime directly, in place \
|
||||
of `{}`",
|
||||
"you can use the `'static` lifetime directly, in place of `{}`",
|
||||
lifetime_i.name.ident(),
|
||||
)).emit();
|
||||
}
|
||||
hir::LifetimeName::Param(_)
|
||||
| hir::LifetimeName::Implicit => {
|
||||
hir::LifetimeName::Param(_) | hir::LifetimeName::Implicit => {
|
||||
self.resolve_lifetime_ref(lt);
|
||||
}
|
||||
}
|
||||
|
@ -2492,8 +2480,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Detects late-bound lifetimes and inserts them into
|
||||
/// `map.late_bound`.
|
||||
///
|
||||
|
@ -2509,10 +2495,8 @@ fn insert_late_bound_lifetimes(
|
|||
decl: &hir::FnDecl,
|
||||
generics: &hir::Generics,
|
||||
) {
|
||||
debug!(
|
||||
"insert_late_bound_lifetimes(decl={:?}, generics={:?})",
|
||||
decl, generics
|
||||
);
|
||||
debug!("insert_late_bound_lifetimes(decl={:?}, generics={:?})",
|
||||
decl, generics);
|
||||
|
||||
let mut constrained_by_input = ConstrainedCollector {
|
||||
regions: FxHashSet(),
|
||||
|
@ -2526,10 +2510,8 @@ fn insert_late_bound_lifetimes(
|
|||
};
|
||||
intravisit::walk_fn_ret_ty(&mut appears_in_output, &decl.output);
|
||||
|
||||
debug!(
|
||||
"insert_late_bound_lifetimes: constrained_by_input={:?}",
|
||||
constrained_by_input.regions
|
||||
);
|
||||
debug!("insert_late_bound_lifetimes: constrained_by_input={:?}",
|
||||
constrained_by_input.regions);
|
||||
|
||||
// Walk the lifetimes that appear in where clauses.
|
||||
//
|
||||
|
@ -2541,16 +2523,13 @@ fn insert_late_bound_lifetimes(
|
|||
appears_in_where_clause.visit_generics(generics);
|
||||
|
||||
for param in &generics.params {
|
||||
match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => {
|
||||
if let hir::GenericParamKind::Lifetime { .. } = param.kind {
|
||||
if !param.bounds.is_empty() {
|
||||
// `'a: 'b` means both `'a` and `'b` are referenced
|
||||
appears_in_where_clause
|
||||
.regions.insert(hir::LifetimeName::Param(param.name.modern()));
|
||||
}
|
||||
}
|
||||
hir::GenericParamKind::Type { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
debug!(
|
||||
|
@ -2661,10 +2640,10 @@ pub fn report_missing_lifetime_specifiers(
|
|||
if count > 1 { "s" } else { "" }
|
||||
);
|
||||
|
||||
let msg = if count > 1 {
|
||||
format!("expected {} lifetime parameters", count)
|
||||
let msg: Cow<'static, str> = if count > 1 {
|
||||
format!("expected {} lifetime parameters", count).into()
|
||||
} else {
|
||||
"expected lifetime parameter".to_string()
|
||||
"expected lifetime parameter".into()
|
||||
};
|
||||
|
||||
err.span_label(span, msg);
|
||||
|
|
|
@ -164,8 +164,10 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
|
|||
if let (&Some(attr::RustcDeprecation {since: dep_since, ..}),
|
||||
&attr::Stable {since: stab_since}) = (&stab.rustc_depr, &stab.level) {
|
||||
// Explicit version of iter::order::lt to handle parse errors properly
|
||||
for (dep_v, stab_v) in
|
||||
dep_since.as_str().split('.').zip(stab_since.as_str().split('.')) {
|
||||
for (dep_v, stab_v) in dep_since.as_str()
|
||||
.split('.')
|
||||
.zip(stab_since.as_str().split('.'))
|
||||
{
|
||||
if let (Ok(dep_v), Ok(stab_v)) = (dep_v.parse::<u64>(), stab_v.parse()) {
|
||||
match dep_v.cmp(&stab_v) {
|
||||
Ordering::Less => {
|
||||
|
@ -523,16 +525,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
Some(Def::Method(_)) |
|
||||
Some(Def::AssociatedTy(_)) |
|
||||
Some(Def::AssociatedConst(_)) => {
|
||||
match self.associated_item(def_id).container {
|
||||
ty::TraitContainer(trait_def_id) => {
|
||||
if let ty::TraitContainer(trait_def_id) = self.associated_item(def_id).container {
|
||||
// Trait methods do not declare visibility (even
|
||||
// for visibility info in cstore). Use containing
|
||||
// trait instead, so methods of pub traits are
|
||||
// themselves considered pub.
|
||||
def_id = trait_def_id;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -561,8 +560,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
/// `id`.
|
||||
pub fn eval_stability(self, def_id: DefId, id: Option<NodeId>, span: Span) -> EvalResult {
|
||||
if span.allows_unstable() {
|
||||
debug!("stability: \
|
||||
skipping span={:?} since it is internal", span);
|
||||
debug!("stability: skipping span={:?} since it is internal", span);
|
||||
return EvalResult::Allow;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
|
|||
use rustc_mir::util::suggest_ref_mut;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
@ -808,34 +809,34 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
|
||||
match err.code {
|
||||
err_mutbl => {
|
||||
let descr = match err.cmt.note {
|
||||
let descr: Cow<'static, str> = match err.cmt.note {
|
||||
mc::NoteClosureEnv(_) | mc::NoteUpvarRef(_) => {
|
||||
self.cmt_to_string(&err.cmt)
|
||||
self.cmt_to_cow_str(&err.cmt)
|
||||
}
|
||||
_ => match opt_loan_path_is_field(&err.cmt) {
|
||||
(None, true) => {
|
||||
format!("{} of {} binding",
|
||||
self.cmt_to_string(&err.cmt),
|
||||
err.cmt.mutbl.to_user_str())
|
||||
self.cmt_to_cow_str(&err.cmt),
|
||||
err.cmt.mutbl.to_user_str()).into()
|
||||
|
||||
}
|
||||
(None, false) => {
|
||||
format!("{} {}",
|
||||
err.cmt.mutbl.to_user_str(),
|
||||
self.cmt_to_string(&err.cmt))
|
||||
self.cmt_to_cow_str(&err.cmt)).into()
|
||||
|
||||
}
|
||||
(Some(lp), true) => {
|
||||
format!("{} `{}` of {} binding",
|
||||
self.cmt_to_string(&err.cmt),
|
||||
self.cmt_to_cow_str(&err.cmt),
|
||||
self.loan_path_to_string(&lp),
|
||||
err.cmt.mutbl.to_user_str())
|
||||
err.cmt.mutbl.to_user_str()).into()
|
||||
}
|
||||
(Some(lp), false) => {
|
||||
format!("{} {} `{}`",
|
||||
err.cmt.mutbl.to_user_str(),
|
||||
self.cmt_to_string(&err.cmt),
|
||||
self.loan_path_to_string(&lp))
|
||||
self.cmt_to_cow_str(&err.cmt),
|
||||
self.loan_path_to_string(&lp)).into()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1058,11 +1059,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {
|
||||
let descr = self.cmt_to_path_or_string(err.cmt);
|
||||
let mut db = self.lifetime_too_short_for_reborrow(error_span, &descr, Origin::Ast);
|
||||
let descr = match opt_loan_path(&err.cmt) {
|
||||
let descr: Cow<'static, str> = match opt_loan_path(&err.cmt) {
|
||||
Some(lp) => {
|
||||
format!("`{}`", self.loan_path_to_string(&lp))
|
||||
format!("`{}`", self.loan_path_to_string(&lp)).into()
|
||||
}
|
||||
None => self.cmt_to_string(&err.cmt),
|
||||
None => self.cmt_to_cow_str(&err.cmt)
|
||||
};
|
||||
self.tcx.note_and_explain_region(
|
||||
&self.region_scope_tree,
|
||||
|
@ -1477,14 +1478,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn cmt_to_string(&self, cmt: &mc::cmt_<'tcx>) -> String {
|
||||
pub fn cmt_to_cow_str(&self, cmt: &mc::cmt_<'tcx>) -> Cow<'static, str> {
|
||||
cmt.descriptive_string(self.tcx)
|
||||
}
|
||||
|
||||
pub fn cmt_to_path_or_string(&self, cmt: &mc::cmt_<'tcx>) -> String {
|
||||
match opt_loan_path(cmt) {
|
||||
Some(lp) => format!("`{}`", self.loan_path_to_string(&lp)),
|
||||
None => self.cmt_to_string(cmt),
|
||||
None => self.cmt_to_cow_str(cmt).into_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue