Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #85150

Merged
merged 19 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
439ef6d
Fix suggestions for missing return type lifetime parameters
FabianWolff May 7, 2021
8a878f0
ensure failing promoteds in const/static bodies are handled correctly
RalfJung May 9, 2021
7a01160
more erroneous-const tests
RalfJung May 9, 2021
8f14592
Improve "panic message is not a string literal" warning
ptrojahn May 7, 2021
380bbe8
Make unchecked_{add,sub,mul} inherent methods unstably const
clarfonthey May 9, 2021
3c0c387
Implement @jackh726's suggestions
FabianWolff May 9, 2021
e6b12c8
Fix `Step` feature flag, make tidy lint more useful to find things li…
clarfonthey May 9, 2021
74e0e45
io::Seek: Mention that seeking can fail due to buffer flush fail
ijackson May 10, 2021
c3ca148
io::Seek: Provide rewind()
ijackson May 10, 2021
debf987
:arrow_up: rust-analyzer
lnicola May 10, 2021
3113b6b
Fix typo in doc
ijackson May 10, 2021
7ae852e
io::Seek::rewind: Set tracking issue
ijackson May 10, 2021
2448c76
More minor fixes suggested by @jackh726
FabianWolff May 10, 2021
0740015
Rollup merge of #85050 - FabianWolff:issue-84592, r=jackh726
Dylan-DPC May 10, 2021
37c6038
Rollup merge of #85075 - ptrojahn:panic_warning, r=jackh726
Dylan-DPC May 10, 2021
7107c89
Rollup merge of #85096 - clarfonthey:const_unchecked, r=oli-obk
Dylan-DPC May 10, 2021
ae8a438
Rollup merge of #85112 - RalfJung:promoted-errors, r=oli-obk
Dylan-DPC May 10, 2021
c5e612c
Rollup merge of #85146 - ijackson:seek-rewind, r=m-ou-se
Dylan-DPC May 10, 2021
e763401
Rollup merge of #85147 - lnicola:rust-analyzer-2021-05-10, r=jonas-sc…
Dylan-DPC May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ impl Diagnostic {
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
) -> &mut Self {
self.multipart_suggestion_with_style(
msg,
suggestion,
applicability,
SuggestionStyle::ShowCode,
)
}

/// [`Diagnostic::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
pub fn multipart_suggestion_with_style(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Self {
assert!(!suggestion.is_empty());
self.suggestions.push(CodeSuggestion {
Expand All @@ -292,7 +308,7 @@ impl Diagnostic {
.collect(),
}],
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
style,
applicability,
tool_metadata: Default::default(),
});
Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_lint/src/non_fmt_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_errors::{pluralize, Applicability};
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_parse_format::{ParseMode, Parser, Piece};
use rustc_span::{sym, symbol::kw, InnerSpan, Span, Symbol};
use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol};

declare_lint! {
/// The `non_fmt_panic` lint detects `panic!(..)` invocations where the first
Expand Down Expand Up @@ -67,7 +67,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc

// The argument is *not* a string literal.

let (span, panic) = panic_call(cx, f);
let (span, panic, symbol_str) = panic_call(cx, f);

// Find the span of the argument to `panic!()`, before expansion in the
// case of `panic!(some_macro!())`.
Expand Down Expand Up @@ -95,7 +95,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
}
if arg_macro.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) {
// A case of `panic!(format!(..))`.
l.note("the panic!() macro supports formatting, so there's no need for the format!() macro here");
l.note(format!("the {}!() macro supports formatting, so there's no need for the format!() macro here", symbol_str).as_str());
if let Some((open, close, _)) = find_delimiters(cx, arg_span) {
l.multipart_suggestion(
"remove the `format!(..)` macro call",
Expand Down Expand Up @@ -160,7 +160,7 @@ fn check_panic_str<'tcx>(
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();

let (span, _) = panic_call(cx, f);
let (span, _, _) = panic_call(cx, f);

if n_arguments > 0 && fmt_parser.errors.is_empty() {
let arg_spans: Vec<_> = match &fmt_parser.arg_places[..] {
Expand Down Expand Up @@ -230,7 +230,7 @@ fn find_delimiters<'tcx>(cx: &LateContext<'tcx>, span: Span) -> Option<(Span, Sp
))
}

fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol) {
fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol, SymbolStr) {
let mut expn = f.span.ctxt().outer_expn_data();

let mut panic_macro = kw::Empty;
Expand All @@ -248,5 +248,10 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
}
}

(expn.call_site, panic_macro)
let macro_symbol = if let hygiene::ExpnKind::Macro(_, symbol) = expn.kind {
symbol
} else {
Symbol::intern("panic")
};
(expn.call_site, panic_macro, macro_symbol.as_str())
}
Loading