Skip to content

Rollup of 8 pull requests #126974

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f2ade37
Add `input_file` method on `LlvmFileCheck`
GuillaumeGomez Jun 25, 2024
221dd30
Migrate `run-make/llvm-ident` to `rmake.rs`
GuillaumeGomez Jun 25, 2024
9156251
Make `Span` optional in `BufferedEarlyLint`
Urgau Jun 22, 2024
4fc8318
Disallow setting built-in cfgs via set the command-line
Urgau Jun 8, 2024
b6074ff
resolve: Tweak some naming around import ambiguities
petrochenkov Jun 25, 2024
6402909
delay bug in RPITIT refinement checking with resolution errors
lqd Jun 25, 2024
133e7b1
fix Drop items getting leaked in Filter::next_chunk
the8472 Jun 23, 2024
2be2d77
add comments explaining optimizations for Filter::next_chunk
the8472 Jun 24, 2024
0d7aef9
regression test for leaks in the the Filter::next_chunk implementation
the8472 Jun 25, 2024
275d922
Rename tcx to cx
compiler-errors Jun 21, 2024
cf0251d
Fix a span in `parse_ty_bare_fn`.
nnethercote Jun 17, 2024
0addda6
Fix bad replacement for unsafe extern block suggestion
chenyukang Jun 26, 2024
af11efc
Rollup merge of #126158 - Urgau:disallow-cfgs, r=petrochenkov
matthiaskrgr Jun 26, 2024
6207e6d
Rollup merge of #126724 - nnethercote:fix-parse_ty_bare_fn-span, r=co…
matthiaskrgr Jun 26, 2024
62d689c
Rollup merge of #126812 - compiler-errors:tcx-cx, r=lcnr
matthiaskrgr Jun 26, 2024
4abb0e7
Rollup merge of #126879 - the8472:next-chunk-filter-drop, r=cuviper
matthiaskrgr Jun 26, 2024
6f9b0af
Rollup merge of #126941 - GuillaumeGomez:migrate-run-make-llvm-ident,…
matthiaskrgr Jun 26, 2024
f926c0a
Rollup merge of #126954 - petrochenkov:globamb, r=compiler-errors
matthiaskrgr Jun 26, 2024
54d49eb
Rollup merge of #126968 - lqd:issue-126670, r=compiler-errors
matthiaskrgr Jun 26, 2024
6b33843
Rollup merge of #126973 - chenyukang:yukang-fix-126756-unsafe-suggest…
matthiaskrgr Jun 26, 2024
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
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,8 @@ pub struct BareFnTy {
pub ext: Extern,
pub generic_params: ThinVec<GenericParam>,
pub decl: P<FnDecl>,
/// Span of the `fn(...) -> ...` part.
/// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything
/// after the generic params (if there are any, e.g. `for<'a>`).
pub decl_span: Span,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a> AstValidator<'a> {
{
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
item_span: span,
block: self.current_extern_span(),
block: self.current_extern_span().shrink_to_lo(),
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub enum ExternBlockSuggestion {
pub struct InvalidSafetyOnExtern {
#[primary_span]
pub item_span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect")]
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
pub block: Span,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ fn make_format_args(
};
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
ecx.buffered_early_lint.push(BufferedEarlyLint {
span: arg_name.span.into(),
span: Some(arg_name.span.into()),
node_id: rustc_ast::CRATE_NODE_ID,
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
}
// Resolve any lifetime variables that may have been introduced during normalization.
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
// If resolution didn't fully complete, we cannot continue checking RPITIT refinement, and
// delay a bug as the original code contains load-bearing errors.
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
return;
};

// For quicker lookup, use an `IndexSet` (we don't use one earlier because
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::Manual
.label = argument has type `{$arg_ty}`
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value

lint_unexpected_builtin_cfg = unexpected `--cfg {$cfg}` flag
.controlled_by = config `{$cfg_name}` is only supposed to be controlled by `{$controlled_by}`
.incoherent = manually setting a built-in cfg does create incoherent behaviors

lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_println}` to the top of the `build.rs`
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
lint_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub struct EarlyContext<'a> {
}

impl EarlyContext<'_> {
/// Emit a lint at the appropriate level, with an optional associated span and an existing
/// Emit a lint at the appropriate level, with an associated span and an existing
/// diagnostic.
///
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
Expand All @@ -543,7 +543,21 @@ impl EarlyContext<'_> {
span: MultiSpan,
diagnostic: BuiltinLintDiag,
) {
self.opt_span_lint(lint, Some(span), |diag| {
self.opt_span_lint_with_diagnostics(lint, Some(span), diagnostic);
}

/// Emit a lint at the appropriate level, with an optional associated span and an existing
/// diagnostic.
///
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics]
pub fn opt_span_lint_with_diagnostics(
&self,
lint: &'static Lint,
span: Option<MultiSpan>,
diagnostic: BuiltinLintDiag,
) {
self.opt_span_lint(lint, span, |diag| {
diagnostics::decorate_lint(self.sess(), diagnostic, diag);
});
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,8 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
BuiltinLintDiag::OutOfScopeMacroCalls { path } => {
lints::OutOfScopeMacroCalls { path }.decorate_lint(diag)
}
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
fn inlined_check_id(&mut self, id: ast::NodeId) {
for early_lint in self.context.buffered.take(id) {
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
self.context.span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
self.context.opt_span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
}
}

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,16 @@ pub mod unexpected_cfg_value {
}
}

#[derive(LintDiagnostic)]
#[diag(lint_unexpected_builtin_cfg)]
#[note(lint_controlled_by)]
#[note(lint_incoherent)]
pub struct UnexpectedBuiltinCfg {
pub(crate) cfg: String,
pub(crate) cfg_name: Symbol,
pub(crate) controlled_by: &'static str,
}

#[derive(LintDiagnostic)]
#[diag(lint_macro_use_deprecated)]
#[help]
Expand Down
34 changes: 34 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ declare_lint_pass! {
UNCONDITIONAL_RECURSION,
UNCOVERED_PARAM_IN_PROJECTION,
UNDEFINED_NAKED_FUNCTION_ABI,
UNEXPECTED_BUILTIN_CFGS,
UNEXPECTED_CFGS,
UNFULFILLED_LINT_EXPECTATIONS,
UNINHABITED_STATIC,
Expand Down Expand Up @@ -3269,6 +3270,39 @@ declare_lint! {
"detects unexpected names and values in `#[cfg]` conditions",
}

declare_lint! {
/// The `unexpected_builtin_cfgs` lint detects builtin cfgs set via the `--cfg` flag.
///
/// ### Example
///
/// ```text
/// rustc --cfg unix
/// ```
///
/// ```rust,ignore (needs command line option)
/// fn main() {}
/// ```
///
/// This will produce:
///
/// ```text
/// error: unexpected `--cfg unix` flag
/// |
/// = note: config `unix` is only supposed to be controlled by `--target`
/// = note: manually setting a built-in cfg does create incoherent behaviors
/// = note: `#[deny(unexpected_builtin_cfgs)]` on by default
/// ```
///
/// ### Explanation
///
/// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
/// the appropriate `rustc` flag that controls the config. For example setting the `windows`
/// cfg but on Linux based target.
pub UNEXPECTED_BUILTIN_CFGS,
Deny,
"detects builtin cfgs set via the `--cfg`"
}

declare_lint! {
/// The `repr_transparent_external_private_fields` lint
/// detects types marked `#[repr(transparent)]` that (transitively)
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,14 +747,19 @@ pub enum BuiltinLintDiag {
OutOfScopeMacroCalls {
path: String,
},
UnexpectedBuiltinCfg {
cfg: String,
cfg_name: Symbol,
controlled_by: &'static str,
},
}

/// Lints that are buffered up early on in the `Session` before the
/// `LintLevels` is calculated.
#[derive(Debug)]
pub struct BufferedEarlyLint {
/// The span of code that we are linting on.
pub span: MultiSpan,
pub span: Option<MultiSpan>,

/// The `NodeId` of the AST node that generated the lint.
pub node_id: NodeId,
Expand Down Expand Up @@ -792,7 +797,7 @@ impl LintBuffer {
self.add_early_lint(BufferedEarlyLint {
lint_id: LintId::of(lint),
node_id,
span: span.into(),
span: Some(span.into()),
diagnostic,
});
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/solve/alias_relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ where
&mut self,
goal: Goal<I, (I::Term, I::Term, ty::AliasRelationDirection)>,
) -> QueryResult<I> {
let tcx = self.cx();
let cx = self.cx();
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());

// Structurally normalize the lhs.
let lhs = if let Some(alias) = lhs.to_alias_term() {
let term = self.next_term_infer_of_kind(lhs);
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
term
} else {
lhs
Expand All @@ -48,7 +48,7 @@ where
// Structurally normalize the rhs.
let rhs = if let Some(alias) = rhs.to_alias_term() {
let term = self.next_term_infer_of_kind(rhs);
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
term
} else {
rhs
Expand Down
Loading
Loading