Skip to content

Commit

Permalink
Auto merge of #70415 - Centril:rollup-1zttfvl, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #69866 (Rename `def_span` to `guess_head_span`)
 - #69878 (Tweak chained operators diagnostic)
 - #70375 (avoid catching InterpError)
 - #70386 (typeck: minor pattern typing improvements)
 - #70389 (borrowck: prefer "value" over "`_`" in diagnostics)
 - #70395 (Update cargo.)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 26, 2020
2 parents e4519e2 + 16e9d3f commit a17dd36
Show file tree
Hide file tree
Showing 52 changed files with 474 additions and 390 deletions.
16 changes: 11 additions & 5 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
// Undef check happens *after* we established that the alignment is correct.
// We must not return `Ok()` for unaligned pointers!
if self.check_defined(ptr, size).is_err() {
if self.is_defined(ptr, size).is_err() {
// This inflates undefined bytes to the entire scalar, even if only a few
// bytes are undefined.
return Ok(ScalarMaybeUndef::Undef);
Expand Down Expand Up @@ -552,13 +552,19 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
}

/// Undefined bytes.
impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
/// Checks whether the given range is entirely defined.
///
/// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
/// at which the first undefined access begins.
fn is_defined(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Size> {
self.undef_mask.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
}

/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
/// error which will report the first byte which is undefined.
#[inline]
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
self.undef_mask
.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
self.is_defined(ptr, size)
.or_else(|idx| throw_ub!(InvalidUndefBytes(Some(Pointer::new(ptr.alloc_id, idx)))))
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl<'tcx> ObligationCause<'tcx> {
match self.code {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
| ObligationCauseCode::StartFunctionType => tcx.sess.source_map().def_span(self.span),
| ObligationCauseCode::StartFunctionType => {
tcx.sess.source_map().guess_head_span(self.span)
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span,
..
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'tcx> TyCtxt<'tcx> {
assert!(!stack.is_empty());

let fix_span = |span: Span, query: &Query<'tcx>| {
self.sess.source_map().def_span(query.default_span(self, span))
self.sess.source_map().guess_head_span(query.default_span(self, span))
};

// Disable naming impls with types in this path, since that
Expand Down Expand Up @@ -456,7 +456,8 @@ impl<'tcx> TyCtxt<'tcx> {
query_info.info.query.describe(icx.tcx)
),
);
diag.span = icx.tcx.sess.source_map().def_span(query_info.info.span).into();
diag.span =
icx.tcx.sess.source_map().guess_head_span(query_info.info.span).into();
handler.force_print_diagnostic(diag);

current_query = query_info.job.parent;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl<'a> AstValidator<'a> {

fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
if let Defaultness::Default(def_span) = defaultness {
let span = self.session.source_map().def_span(span);
let span = self.session.source_map().guess_head_span(span);
self.err_handler()
.struct_span_err(span, "`default` is only allowed on items in `impl` definitions")
.span_label(def_span, "`default` because of this")
Expand Down Expand Up @@ -517,7 +517,7 @@ impl<'a> AstValidator<'a> {
}

fn current_extern_span(&self) -> Span {
self.session.source_map().def_span(self.extern_mod.unwrap().span)
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
}

/// An `fn` in `extern { ... }` cannot have qualfiers, e.g. `async fn`.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(
&self,
non_ascii_idents,
self.parse_sess.source_map().def_span(sp),
self.parse_sess.source_map().guess_head_span(sp),
"non-ascii idents are not fully supported"
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_builtin_macros/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_derive]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}

Expand All @@ -217,7 +217,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_attribute]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}

Expand All @@ -236,7 +236,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
}
Expand All @@ -247,7 +247,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
let msg =
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {

let attr = match found_attr {
None => {
self.check_not_pub_in_root(&item.vis, self.source_map.def_span(item.span));
self.check_not_pub_in_root(&item.vis, self.source_map.guess_head_span(item.span));
let prev_in_root = mem::replace(&mut self.in_root, false);
visit::walk_item(self, item);
self.in_root = prev_in_root;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn generic_extension<'cx>(
let mut err = cx.struct_span_err(span, &parse_failure_msg(&token));
err.span_label(span, label);
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
err.span_label(cx.source_map().def_span(def_span), "when calling this macro");
err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
}

// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn msg_span_from_early_bound_and_free_regions(
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = sm.def_span(tcx.hir().span(node));
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{
Expand All @@ -209,7 +209,7 @@ fn msg_span_from_early_bound_and_free_regions(
(format!("the lifetime `{}` as defined on", br.name), sp)
}
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
let mut sp = sm.def_span(tcx.hir().span(node));
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
{
Expand All @@ -223,7 +223,7 @@ fn msg_span_from_early_bound_and_free_regions(
}
_ => (
format!("the lifetime `{}` as defined on", region),
sm.def_span(tcx.hir().span(node)),
sm.guess_head_span(tcx.hir().span(node)),
),
},
_ => bug!(),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_infer/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx> {
let msg = "impl has stricter requirements than trait";
let sp = self.tcx.sess.source_map().def_span(error_span);
let sp = self.tcx.sess.source_map().guess_head_span(error_span);

let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);

if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let span = self.tcx.sess.source_map().def_span(trait_item_span);
let span = self.tcx.sess.source_map().guess_head_span(trait_item_span);
err.span_label(span, format!("definition of `{}` from trait", item_name));
}

Expand All @@ -46,7 +46,7 @@ pub fn report_object_safety_error(
hir::Node::Item(item) => Some(item.ident.span),
_ => None,
});
let span = tcx.sess.source_map().def_span(span);
let span = tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!(
tcx.sess,
span,
Expand Down
16 changes: 10 additions & 6 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl EarlyLintPass for WhileTrue {
if let ast::LitKind::Bool(true) = lit.kind {
if !lit.span.from_expansion() {
let msg = "denote infinite loops with `loop { ... }`";
let condition_span = cx.sess.source_map().def_span(e.span);
let condition_span = cx.sess.source_map().guess_head_span(e.span);
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
lint.build(msg)
.span_suggestion_short(
Expand Down Expand Up @@ -374,9 +374,13 @@ impl MissingDoc {

let has_doc = attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
});
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().guess_head_span(sp),
|lint| {
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
},
);
}
}
}
Expand Down Expand Up @@ -406,7 +410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().def_span(macro_def.span),
cx.tcx.sess.source_map().guess_head_span(macro_def.span),
|lint| lint.build("missing documentation for macro").emit(),
);
}
Expand Down Expand Up @@ -978,7 +982,7 @@ impl UnreachablePub {
if span.from_expansion() {
applicability = Applicability::MaybeIncorrect;
}
let def_span = cx.tcx.sess.source_map().def_span(span);
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
let mut err = lint.build(&format!("unreachable `pub` {}", what));
let replacement = if cx.tcx.features().crate_visibility_modifier {
Expand Down
Loading

0 comments on commit a17dd36

Please sign in to comment.