Skip to content

Commit 22719ef

Browse files
committed
Auto merge of #88824 - Manishearth:rollup-7bzk9h6, r=Manishearth
Rollup of 15 pull requests Successful merges: - #85200 (Ignore derived Clone and Debug implementations during dead code analysis) - #86165 (Add proc_macro::Span::{before, after}.) - #87088 (Fix stray notes when the source code is not available) - #87441 (Emit suggestion when passing byte literal to format macro) - #88546 (Emit proper errors when on missing closure braces) - #88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`) - #88632 (Fix issues with Markdown summary options) - #88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields) - #88667 (Tweak `write_fmt` doc.) - #88720 (Rustdoc coverage fields count) - #88732 (RustWrapper: avoid deleted unclear attribute methods) - #88742 (Fix table in docblocks) - #88776 (Workaround blink/chromium grid layout limitation of 1000 rows) - #88807 (Fix typo in docs for iterators) - #88812 (Fix typo `option` -> `options`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b69fe57 + f77311b commit 22719ef

File tree

93 files changed

+976
-212
lines changed

Some content is hidden

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

93 files changed

+976
-212
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
218218
);
219219
if self.fn_self_span_reported.insert(fn_span) {
220220
err.span_note(
221-
self_arg.span,
221+
// Check whether the source is accessible
222+
if self
223+
.infcx
224+
.tcx
225+
.sess
226+
.source_map()
227+
.span_to_snippet(self_arg.span)
228+
.is_ok()
229+
{
230+
self_arg.span
231+
} else {
232+
fn_call_span
233+
},
222234
"calling this operator moves the left-hand side",
223235
);
224236
}
@@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
429441
deref_target_ty
430442
));
431443

432-
err.span_note(deref_target, "deref defined here");
444+
// Check first whether the source is accessible (issue #87060)
445+
if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() {
446+
err.span_note(deref_target, "deref defined here");
447+
}
433448
}
434449

435450
if let Some((_, mut old_err)) =

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
510510
match expr_to_spanned_string(ecx, template_expr, msg) {
511511
Ok(template_part) => template_part,
512512
Err(err) => {
513-
if let Some(mut err) = err {
513+
if let Some((mut err, _)) = err {
514514
err.emit();
515515
}
516516
return None;

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,17 +964,19 @@ pub fn expand_preparsed_format_args(
964964
}
965965
Ok(fmt) => fmt,
966966
Err(err) => {
967-
if let Some(mut err) = err {
967+
if let Some((mut err, suggested)) = err {
968968
let sugg_fmt = match args.len() {
969969
0 => "{}".to_string(),
970970
_ => format!("{}{{}}", "{} ".repeat(args.len())),
971971
};
972-
err.span_suggestion(
973-
fmt_sp.shrink_to_lo(),
974-
"you might be missing a string literal to format with",
975-
format!("\"{}\", ", sugg_fmt),
976-
Applicability::MaybeIncorrect,
977-
);
972+
if !suggested {
973+
err.span_suggestion(
974+
fmt_sp.shrink_to_lo(),
975+
"you might be missing a string literal to format with",
976+
format!("\"{}\", ", sugg_fmt),
977+
Applicability::MaybeIncorrect,
978+
);
979+
}
978980
err.emit();
979981
}
980982
return DummyResult::raw_expr(sp, true);

compiler/rustc_expand/src/base.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
1010
use rustc_attr::{self as attr, Deprecation, Stability};
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::sync::{self, Lrc};
13-
use rustc_errors::{DiagnosticBuilder, ErrorReported};
13+
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported};
1414
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1515
use rustc_lint_defs::BuiltinLintDiagnostics;
1616
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
@@ -1136,36 +1136,51 @@ impl<'a> ExtCtxt<'a> {
11361136
}
11371137

11381138
/// Extracts a string literal from the macro expanded version of `expr`,
1139-
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
1140-
/// compilation on error, merely emits a non-fatal error and returns `None`.
1139+
/// returning a diagnostic error of `err_msg` if `expr` is not a string literal.
1140+
/// The returned bool indicates whether an applicable suggestion has already been
1141+
/// added to the diagnostic to avoid emitting multiple suggestions. `Err(None)`
1142+
/// indicates that an ast error was encountered.
11411143
pub fn expr_to_spanned_string<'a>(
11421144
cx: &'a mut ExtCtxt<'_>,
11431145
expr: P<ast::Expr>,
11441146
err_msg: &str,
1145-
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
1147+
) -> Result<(Symbol, ast::StrStyle, Span), Option<(DiagnosticBuilder<'a>, bool)>> {
11461148
// Perform eager expansion on the expression.
11471149
// We want to be able to handle e.g., `concat!("foo", "bar")`.
11481150
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
11491151

11501152
Err(match expr.kind {
11511153
ast::ExprKind::Lit(ref l) => match l.kind {
11521154
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
1155+
ast::LitKind::ByteStr(_) => {
1156+
let mut err = cx.struct_span_err(l.span, err_msg);
1157+
err.span_suggestion(
1158+
expr.span.shrink_to_lo(),
1159+
"consider removing the leading `b`",
1160+
String::new(),
1161+
Applicability::MaybeIncorrect,
1162+
);
1163+
Some((err, true))
1164+
}
11531165
ast::LitKind::Err(_) => None,
1154-
_ => Some(cx.struct_span_err(l.span, err_msg)),
1166+
_ => Some((cx.struct_span_err(l.span, err_msg), false)),
11551167
},
11561168
ast::ExprKind::Err => None,
1157-
_ => Some(cx.struct_span_err(expr.span, err_msg)),
1169+
_ => Some((cx.struct_span_err(expr.span, err_msg), false)),
11581170
})
11591171
}
11601172

1173+
/// Extracts a string literal from the macro expanded version of `expr`,
1174+
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
1175+
/// compilation on error, merely emits a non-fatal error and returns `None`.
11611176
pub fn expr_to_string(
11621177
cx: &mut ExtCtxt<'_>,
11631178
expr: P<ast::Expr>,
11641179
err_msg: &str,
11651180
) -> Option<(Symbol, ast::StrStyle)> {
11661181
expr_to_spanned_string(cx, expr, err_msg)
11671182
.map_err(|err| {
1168-
err.map(|mut err| {
1183+
err.map(|(mut err, _)| {
11691184
err.emit();
11701185
})
11711186
})

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,12 @@ impl server::Span for Rustc<'_> {
758758
let loc = self.sess.source_map().lookup_char_pos(span.hi());
759759
LineColumn { line: loc.line, column: loc.col.to_usize() }
760760
}
761+
fn before(&mut self, span: Self::Span) -> Self::Span {
762+
span.shrink_to_lo()
763+
}
764+
fn after(&mut self, span: Self::Span) -> Self::Span {
765+
span.shrink_to_hi()
766+
}
761767
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
762768
let self_loc = self.sess.source_map().lookup_char_pos(first.lo());
763769
let other_loc = self.sess.source_map().lookup_char_pos(second.lo());

compiler/rustc_feature/src/accepted.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! declare_features {
1616
since: $ver,
1717
issue: to_nonzero($issue),
1818
edition: None,
19-
description: concat!($($doc,)*),
2019
}
2120
),+
2221
];

compiler/rustc_feature/src/active.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ macro_rules! declare_features {
3737
since: $ver,
3838
issue: to_nonzero($issue),
3939
edition: $edition,
40-
description: concat!($($doc,)*),
4140
}
4241
),+];
4342

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
453453
),
454454
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
455455
rustc_attr!(rustc_conversion_suggestion, Normal, template!(Word), INTERNAL_UNSTABLE),
456+
// Prevents field reads in the marked trait or method to be considered
457+
// during dead code analysis.
458+
rustc_attr!(rustc_trivial_field_reads, Normal, template!(Word), INTERNAL_UNSTABLE),
456459

457460
// ==========================================================================
458461
// Internal attributes, Const related:

compiler/rustc_feature/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub struct Feature {
5151
pub since: &'static str,
5252
issue: Option<NonZeroU32>,
5353
pub edition: Option<Edition>,
54-
description: &'static str,
5554
}
5655

5756
#[derive(Copy, Clone, Debug)]

compiler/rustc_feature/src/removed.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! declare_features {
1616
since: $ver,
1717
issue: to_nonzero($issue),
1818
edition: None,
19-
description: concat!($($doc,)*),
2019
}
2120
),+
2221
];
@@ -34,7 +33,6 @@ macro_rules! declare_features {
3433
since: $ver,
3534
issue: to_nonzero($issue),
3635
edition: None,
37-
description: concat!($($doc,)*),
3836
}
3937
),+
4038
];

0 commit comments

Comments
 (0)