Skip to content

Rollup of 9 pull requests #115193

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

Merged
merged 22 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
132a2c6
elaborate a bit on the (lack of) safety in 'Mmap::map'
RalfJung Aug 19, 2023
4332e84
drive-by fix to Python doc comment.
pnkfelix Aug 22, 2023
3c6f4cc
Better diagnostics for people using nix subshell on non-NixOS.
pnkfelix Aug 22, 2023
65217a7
kmc-solid: Import `std::sync::PoisonError` in `std::sys::solid::os`
kawadakk Aug 23, 2023
735e9c0
stable types for predicates
ericmarkmartin Aug 22, 2023
107cb5c
predicates of
ericmarkmartin Aug 22, 2023
81a2492
lint: translate `RenamedOrRemovedLint`
weihanglo Aug 23, 2023
73152a3
refactor: use references to reduce unnecessary clones
weihanglo Aug 23, 2023
ec2c95e
Accommodate tidy.
pnkfelix Aug 24, 2023
2063067
Fix ub-int-array test for big-endian platforms
uweigand Aug 24, 2023
d3c3c17
Add more tests for if_let_guard
matthewjasper Aug 24, 2023
c6ba5d9
Add symbols for Clippy
c410-f3r Aug 24, 2023
8216f17
Move issue 29181, 2804, 17431, 66768
olanti-p Aug 23, 2023
832fb9c
Rollup merge of #114987 - RalfJung:unsound-mmap, r=cjgillot
weihanglo Aug 24, 2023
f846d7d
Rollup merge of #115084 - ericmarkmartin:add-smir-cx-where-clauses, r…
weihanglo Aug 24, 2023
4369e24
Rollup merge of #115117 - pnkfelix:detect-and-report-nix-shell, r=alb…
weihanglo Aug 24, 2023
351445a
Rollup merge of #115124 - solid-rs:patch/kmc-solid/import-poison-erro…
weihanglo Aug 24, 2023
1d52669
Rollup merge of #115152 - weihanglo:lint-refactor, r=compiler-errors
weihanglo Aug 24, 2023
d417ae5
Rollup merge of #115154 - olanti-p:move-issues-24-08-2023, r=compiler…
weihanglo Aug 24, 2023
c996197
Rollup merge of #115167 - uweigand:ubintarray-endian-fix, r=RalfJung
weihanglo Aug 24, 2023
0c1f9c8
Rollup merge of #115172 - matthewjasper:if-let-guard-tests, r=cjgillot
weihanglo Aug 24, 2023
eee76d9
Rollup merge of #115177 - c410-f3r:symbols, r=compiler-errors
weihanglo Aug 24, 2023
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
7 changes: 6 additions & 1 deletion compiler/rustc_data_structures/src/memmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ pub struct Mmap(Vec<u8>);

#[cfg(not(target_arch = "wasm32"))]
impl Mmap {
/// # Safety
///
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed.
///
/// However in practice most callers do not ensure this, so uses of this function are likely unsound.
#[inline]
pub unsafe fn map(file: File) -> io::Result<Self> {
// Safety: this is in fact not safe.
// Safety: the caller must ensure that this is safe.
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
}
}
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`

lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}

lint_check_name_removed = lint `{$lint_name}` has been removed: {$reason}

lint_check_name_renamed = lint `{$lint_name}` has been renamed to `{$replace}`

lint_check_name_unknown = unknown lint: `{$lint_name}`
.help = did you mean: `{$suggestion}`

lint_check_name_unknown_tool = unknown lint tool: `{$tool_name}`

lint_check_name_warning = {$msg}

lint_command_line_source = `forbid` lint level was set on command line

lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike
Expand Down Expand Up @@ -484,8 +486,11 @@ lint_redundant_semicolons =
*[false] this semicolon
}

lint_renamed_or_removed_lint = {$msg}
lint_removed_lint = lint `{$name}` has been removed: {$reason}

lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
.suggestion = use the new name
.help = use the new name `{$replace}`

lint_requested_level = requested on the command line with `{$level} {$lint_name}`

Expand Down
42 changes: 22 additions & 20 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use self::TargetLint::*;

use crate::errors::{
CheckNameDeprecated, CheckNameUnknown, CheckNameUnknownTool, CheckNameWarning, RequestedLevel,
UnsupportedGroup,
CheckNameDeprecated, CheckNameRemoved, CheckNameRenamed, CheckNameUnknown,
CheckNameUnknownTool, RequestedLevel, UnsupportedGroup,
};
use crate::levels::LintLevelsBuilder;
use crate::passes::{EarlyLintPassObject, LateLintPassObject};
Expand Down Expand Up @@ -124,9 +124,10 @@ pub enum CheckLintNameResult<'a> {
NoLint(Option<Symbol>),
/// The lint refers to a tool that has not been registered.
NoTool,
/// The lint is either renamed or removed. This is the warning
/// message, and an optional new name (`None` if removed).
Warning(String, Option<String>),
/// The lint has been renamed to a new name.
Renamed(String),
/// The lint has been removed due to the given reason.
Removed(String),
/// The lint is from a tool. If the Option is None, then either
/// the lint does not exist in the tool or the code was not
/// compiled with the tool and therefore the lint was never
Expand Down Expand Up @@ -342,25 +343,32 @@ impl LintStore {
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
return;
}
let lint_name = lint_name.to_string();
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
CheckLintNameResult::Warning(msg, _) => {
sess.emit_warning(CheckNameWarning {
msg,
CheckLintNameResult::Renamed(replace) => {
sess.emit_warning(CheckNameRenamed {
lint_name,
replace: &replace,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::Removed(reason) => {
sess.emit_warning(CheckNameRemoved {
lint_name,
reason: &reason,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::NoLint(suggestion) => {
sess.emit_err(CheckNameUnknown {
lint_name: lint_name.clone(),
lint_name,
suggestion,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
sess.emit_warning(CheckNameDeprecated {
lint_name: lint_name.clone(),
new_name,
lint_name,
new_name: &new_name,
sub: RequestedLevel { level, lint_name },
});
}
Expand Down Expand Up @@ -445,14 +453,8 @@ impl LintStore {
}
}
match self.by_name.get(&complete_name) {
Some(Renamed(new_name, _)) => CheckLintNameResult::Warning(
format!("lint `{complete_name}` has been renamed to `{new_name}`"),
Some(new_name.to_owned()),
),
Some(Removed(reason)) => CheckLintNameResult::Warning(
format!("lint `{complete_name}` has been removed: {reason}"),
None,
),
Some(Renamed(new_name, _)) => CheckLintNameResult::Renamed(new_name.to_string()),
Some(Removed(reason)) => CheckLintNameResult::Removed(reason.to_string()),
None => match self.lint_groups.get(&*complete_name) {
// If neither the lint, nor the lint group exists check if there is a `clippy::`
// variant of this lint
Expand Down
42 changes: 26 additions & 16 deletions compiler/rustc_lint/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {

#[derive(Subdiagnostic)]
#[note(lint_requested_level)]
pub struct RequestedLevel {
pub struct RequestedLevel<'a> {
pub level: Level,
pub lint_name: String,
pub lint_name: &'a str,
}

#[derive(Diagnostic)]
Expand All @@ -102,13 +102,13 @@ pub struct UnsupportedGroup {
pub lint_group: String,
}

pub struct CheckNameUnknown {
pub lint_name: String,
pub struct CheckNameUnknown<'a> {
pub lint_name: &'a str,
pub suggestion: Option<Symbol>,
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

impl IntoDiagnostic<'_> for CheckNameUnknown {
impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
fn into_diagnostic(
self,
handler: &Handler,
Expand All @@ -127,25 +127,35 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {

#[derive(Diagnostic)]
#[diag(lint_check_name_unknown_tool, code = "E0602")]
pub struct CheckNameUnknownTool {
pub struct CheckNameUnknownTool<'a> {
pub tool_name: Symbol,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_warning)]
pub struct CheckNameWarning {
pub msg: String,
#[diag(lint_check_name_renamed)]
pub struct CheckNameRenamed<'a> {
pub lint_name: &'a str,
pub replace: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_removed)]
pub struct CheckNameRemoved<'a> {
pub lint_name: &'a str,
pub reason: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_deprecated)]
pub struct CheckNameDeprecated {
pub lint_name: String,
pub new_name: String,
pub struct CheckNameDeprecated<'a> {
pub lint_name: &'a str,
pub new_name: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}
26 changes: 17 additions & 9 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
fluent_generated as fluent,
late::unerased_lint_store,
lints::{
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint,
RenamedOrRemovedLint, RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAttributeLint, RemovedLint,
RenamedLint, RenamedLintSuggestion, UnknownLint, UnknownLintSuggestion,
},
};
use rustc_ast as ast;
Expand Down Expand Up @@ -915,18 +915,26 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {

_ if !self.warn_about_weird_lints => {}

CheckLintNameResult::Warning(msg, renamed) => {
CheckLintNameResult::Renamed(new_name) => {
let suggestion =
renamed.as_ref().map(|replace| RenamedOrRemovedLintSuggestion {
suggestion: sp,
replace: replace.as_str(),
});
RenamedLintSuggestion { suggestion: sp, replace: new_name.as_str() };
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
self.emit_spanned_lint(
RENAMED_AND_REMOVED_LINTS,
sp.into(),
RenamedLint { name: name.as_str(), suggestion },
);
}

CheckLintNameResult::Removed(reason) => {
let name = tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
self.emit_spanned_lint(
RENAMED_AND_REMOVED_LINTS,
sp.into(),
RenamedOrRemovedLint { msg, suggestion },
RemovedLint { name: name.as_str(), reason: reason.as_str() },
);
}

CheckLintNameResult::NoLint(suggestion) => {
let name = if let Some(tool_ident) = tool_ident {
format!("{}::{}", tool_ident.name, name)
Expand All @@ -945,7 +953,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
// If this lint was renamed, apply the new lint instead of ignoring the attribute.
// This happens outside of the match because the new lint should be applied even if
// we don't warn about the name change.
if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result {
if let CheckLintNameResult::Renamed(new_name) = lint_result {
// Ignore any errors or warnings that happen because the new name is inaccurate
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
if let CheckLintNameResult::Ok(ids) =
Expand Down
18 changes: 12 additions & 6 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,23 +1012,29 @@ pub struct DeprecatedLintName<'a> {
pub replace: &'a str,
}

// FIXME: Non-translatable msg
#[derive(LintDiagnostic)]
#[diag(lint_renamed_or_removed_lint)]
pub struct RenamedOrRemovedLint<'a> {
pub msg: &'a str,
#[diag(lint_renamed_lint)]
pub struct RenamedLint<'a> {
pub name: &'a str,
#[subdiagnostic]
pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
pub suggestion: RenamedLintSuggestion<'a>,
}

#[derive(Subdiagnostic)]
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
pub struct RenamedOrRemovedLintSuggestion<'a> {
pub struct RenamedLintSuggestion<'a> {
#[primary_span]
pub suggestion: Span,
pub replace: &'a str,
}

#[derive(LintDiagnostic)]
#[diag(lint_removed_lint)]
pub struct RemovedLint<'a> {
pub name: &'a str,
pub reason: &'a str,
}

#[derive(LintDiagnostic)]
#[diag(lint_unknown_lint)]
pub struct UnknownLint {
Expand Down
Loading