Skip to content

Commit a17dd36

Browse files
committed
Auto merge of rust-lang#70415 - Centril:rollup-1zttfvl, r=Centril
Rollup of 6 pull requests Successful merges: - rust-lang#69866 (Rename `def_span` to `guess_head_span`) - rust-lang#69878 (Tweak chained operators diagnostic) - rust-lang#70375 (avoid catching InterpError) - rust-lang#70386 (typeck: minor pattern typing improvements) - rust-lang#70389 (borrowck: prefer "value" over "`_`" in diagnostics) - rust-lang#70395 (Update cargo.) Failed merges: r? @ghost
2 parents e4519e2 + 16e9d3f commit a17dd36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+474
-390
lines changed

src/librustc/mir/interpret/allocation.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
367367
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
368368
// Undef check happens *after* we established that the alignment is correct.
369369
// We must not return `Ok()` for unaligned pointers!
370-
if self.check_defined(ptr, size).is_err() {
370+
if self.is_defined(ptr, size).is_err() {
371371
// This inflates undefined bytes to the entire scalar, even if only a few
372372
// bytes are undefined.
373373
return Ok(ScalarMaybeUndef::Undef);
@@ -552,13 +552,19 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
552552
}
553553

554554
/// Undefined bytes.
555-
impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
555+
impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
556+
/// Checks whether the given range is entirely defined.
557+
///
558+
/// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
559+
/// at which the first undefined access begins.
560+
fn is_defined(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Size> {
561+
self.undef_mask.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
562+
}
563+
556564
/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
557565
/// error which will report the first byte which is undefined.
558-
#[inline]
559566
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
560-
self.undef_mask
561-
.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
567+
self.is_defined(ptr, size)
562568
.or_else(|idx| throw_ub!(InvalidUndefBytes(Some(Pointer::new(ptr.alloc_id, idx)))))
563569
}
564570

src/librustc/traits/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ impl<'tcx> ObligationCause<'tcx> {
108108
match self.code {
109109
ObligationCauseCode::CompareImplMethodObligation { .. }
110110
| ObligationCauseCode::MainFunctionType
111-
| ObligationCauseCode::StartFunctionType => tcx.sess.source_map().def_span(self.span),
111+
| ObligationCauseCode::StartFunctionType => {
112+
tcx.sess.source_map().guess_head_span(self.span)
113+
}
112114
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
113115
arm_span,
114116
..

src/librustc/ty/query/plumbing.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'tcx> TyCtxt<'tcx> {
388388
assert!(!stack.is_empty());
389389

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

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

462463
current_query = query_info.job.parent;

src/librustc_ast_passes/ast_validation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a> AstValidator<'a> {
402402

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

519519
fn current_extern_span(&self) -> Span {
520-
self.session.source_map().def_span(self.extern_mod.unwrap().span)
520+
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
521521
}
522522

523523
/// An `fn` in `extern { ... }` cannot have qualfiers, e.g. `async fn`.

src/librustc_ast_passes/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
257257
gate_feature_post!(
258258
&self,
259259
non_ascii_idents,
260-
self.parse_sess.source_map().def_span(sp),
260+
self.parse_sess.source_map().guess_head_span(sp),
261261
"non-ascii idents are not fully supported"
262262
);
263263
}

src/librustc_builtin_macros/proc_macro_harness.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a> CollectProcMacros<'a> {
198198
} else {
199199
"functions tagged with `#[proc_macro_derive]` must be `pub`"
200200
};
201-
self.handler.span_err(self.source_map.def_span(item.span), msg);
201+
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
202202
}
203203
}
204204

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

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

@@ -298,7 +298,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
298298

299299
let attr = match found_attr {
300300
None => {
301-
self.check_not_pub_in_root(&item.vis, self.source_map.def_span(item.span));
301+
self.check_not_pub_in_root(&item.vis, self.source_map.guess_head_span(item.span));
302302
let prev_in_root = mem::replace(&mut self.in_root, false);
303303
visit::walk_item(self, item);
304304
self.in_root = prev_in_root;

src/librustc_expand/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn generic_extension<'cx>(
326326
let mut err = cx.struct_span_err(span, &parse_failure_msg(&token));
327327
err.span_label(span, label);
328328
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
329-
err.span_label(cx.source_map().def_span(def_span), "when calling this macro");
329+
err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
330330
}
331331

332332
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`

src/librustc_infer/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn msg_span_from_early_bound_and_free_regions(
200200
};
201201
let (prefix, span) = match *region {
202202
ty::ReEarlyBound(ref br) => {
203-
let mut sp = sm.def_span(tcx.hir().span(node));
203+
let mut sp = sm.guess_head_span(tcx.hir().span(node));
204204
if let Some(param) =
205205
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
206206
{
@@ -209,7 +209,7 @@ fn msg_span_from_early_bound_and_free_regions(
209209
(format!("the lifetime `{}` as defined on", br.name), sp)
210210
}
211211
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
212-
let mut sp = sm.def_span(tcx.hir().span(node));
212+
let mut sp = sm.guess_head_span(tcx.hir().span(node));
213213
if let Some(param) =
214214
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
215215
{
@@ -223,7 +223,7 @@ fn msg_span_from_early_bound_and_free_regions(
223223
}
224224
_ => (
225225
format!("the lifetime `{}` as defined on", region),
226-
sm.def_span(tcx.hir().span(node)),
226+
sm.guess_head_span(tcx.hir().span(node)),
227227
),
228228
},
229229
_ => bug!(),

src/librustc_infer/traits/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2020
requirement: &dyn fmt::Display,
2121
) -> DiagnosticBuilder<'tcx> {
2222
let msg = "impl has stricter requirements than trait";
23-
let sp = self.tcx.sess.source_map().def_span(error_span);
23+
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
2424

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

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

@@ -46,7 +46,7 @@ pub fn report_object_safety_error(
4646
hir::Node::Item(item) => Some(item.ident.span),
4747
_ => None,
4848
});
49-
let span = tcx.sess.source_map().def_span(span);
49+
let span = tcx.sess.source_map().guess_head_span(span);
5050
let mut err = struct_span_err!(
5151
tcx.sess,
5252
span,

src/librustc_lint/builtin.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl EarlyLintPass for WhileTrue {
7676
if let ast::LitKind::Bool(true) = lit.kind {
7777
if !lit.span.from_expansion() {
7878
let msg = "denote infinite loops with `loop { ... }`";
79-
let condition_span = cx.sess.source_map().def_span(e.span);
79+
let condition_span = cx.sess.source_map().guess_head_span(e.span);
8080
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
8181
lint.build(msg)
8282
.span_suggestion_short(
@@ -374,9 +374,13 @@ impl MissingDoc {
374374

375375
let has_doc = attrs.iter().any(|a| has_doc(a));
376376
if !has_doc {
377-
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
378-
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
379-
});
377+
cx.struct_span_lint(
378+
MISSING_DOCS,
379+
cx.tcx.sess.source_map().guess_head_span(sp),
380+
|lint| {
381+
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
382+
},
383+
);
380384
}
381385
}
382386
}
@@ -406,7 +410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
406410
if !has_doc {
407411
cx.struct_span_lint(
408412
MISSING_DOCS,
409-
cx.tcx.sess.source_map().def_span(macro_def.span),
413+
cx.tcx.sess.source_map().guess_head_span(macro_def.span),
410414
|lint| lint.build("missing documentation for macro").emit(),
411415
);
412416
}
@@ -978,7 +982,7 @@ impl UnreachablePub {
978982
if span.from_expansion() {
979983
applicability = Applicability::MaybeIncorrect;
980984
}
981-
let def_span = cx.tcx.sess.source_map().def_span(span);
985+
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
982986
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
983987
let mut err = lint.build(&format!("unreachable `pub` {}", what));
984988
let replacement = if cx.tcx.features().crate_visibility_modifier {

0 commit comments

Comments
 (0)