Skip to content

Commit add1ce4

Browse files
committed
Auto merge of rust-lang#126974 - matthiaskrgr:rollup-2neyugj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#126158 (Disallow setting some built-in cfg via set the command-line) - rust-lang#126724 (Fix a span in `parse_ty_bare_fn`.) - rust-lang#126812 (Rename `tcx` to `cx` in new solver generic code) - rust-lang#126879 (fix Drop items getting leaked in Filter::next_chunk) - rust-lang#126941 (Migrate `run-make/llvm-ident` to `rmake.rs`) - rust-lang#126954 (resolve: Tweak some naming around import ambiguities) - rust-lang#126968 (Don't ICE during RPITIT refinement checking for resolution errors after normalization) - rust-lang#126973 (Fix bad replacement for unsafe extern block suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a299aa5 + 6b33843 commit add1ce4

File tree

83 files changed

+1016
-522
lines changed

Some content is hidden

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

83 files changed

+1016
-522
lines changed

compiler/rustc_ast/src/ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,8 @@ pub struct BareFnTy {
21262126
pub ext: Extern,
21272127
pub generic_params: ThinVec<GenericParam>,
21282128
pub decl: P<FnDecl>,
2129-
/// Span of the `fn(...) -> ...` part.
2129+
/// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything
2130+
/// after the generic params (if there are any, e.g. `for<'a>`).
21302131
pub decl_span: Span,
21312132
}
21322133

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'a> AstValidator<'a> {
464464
{
465465
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
466466
item_span: span,
467-
block: self.current_extern_span(),
467+
block: self.current_extern_span().shrink_to_lo(),
468468
});
469469
}
470470
}

compiler/rustc_ast_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub enum ExternBlockSuggestion {
221221
pub struct InvalidSafetyOnExtern {
222222
#[primary_span]
223223
pub item_span: Span,
224-
#[suggestion(code = "", applicability = "maybe-incorrect")]
224+
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
225225
pub block: Span,
226226
}
227227

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn make_format_args(
555555
};
556556
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
557557
ecx.buffered_early_lint.push(BufferedEarlyLint {
558-
span: arg_name.span.into(),
558+
span: Some(arg_name.span.into()),
559559
node_id: rustc_ast::CRATE_NODE_ID,
560560
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
561561
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
171171
}
172172
// Resolve any lifetime variables that may have been introduced during normalization.
173173
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
174-
// This code path is not reached in any tests, but may be reachable. If
175-
// this is triggered, it should be converted to `delayed_bug` and the
176-
// triggering case turned into a test.
177-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
174+
// If resolution didn't fully complete, we cannot continue checking RPITIT refinement, and
175+
// delay a bug as the original code contains load-bearing errors.
176+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
177+
return;
178178
};
179179

180180
// For quicker lookup, use an `IndexSet` (we don't use one earlier because

compiler/rustc_lint/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::Manual
745745
.label = argument has type `{$arg_ty}`
746746
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value
747747
748+
lint_unexpected_builtin_cfg = unexpected `--cfg {$cfg}` flag
749+
.controlled_by = config `{$cfg_name}` is only supposed to be controlled by `{$controlled_by}`
750+
.incoherent = manually setting a built-in cfg does create incoherent behaviors
751+
748752
lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_println}` to the top of the `build.rs`
749753
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
750754
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}

compiler/rustc_lint/src/context.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ pub struct EarlyContext<'a> {
532532
}
533533

534534
impl EarlyContext<'_> {
535-
/// Emit a lint at the appropriate level, with an optional associated span and an existing
535+
/// Emit a lint at the appropriate level, with an associated span and an existing
536536
/// diagnostic.
537537
///
538538
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
@@ -543,7 +543,21 @@ impl EarlyContext<'_> {
543543
span: MultiSpan,
544544
diagnostic: BuiltinLintDiag,
545545
) {
546-
self.opt_span_lint(lint, Some(span), |diag| {
546+
self.opt_span_lint_with_diagnostics(lint, Some(span), diagnostic);
547+
}
548+
549+
/// Emit a lint at the appropriate level, with an optional associated span and an existing
550+
/// diagnostic.
551+
///
552+
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
553+
#[rustc_lint_diagnostics]
554+
pub fn opt_span_lint_with_diagnostics(
555+
&self,
556+
lint: &'static Lint,
557+
span: Option<MultiSpan>,
558+
diagnostic: BuiltinLintDiag,
559+
) {
560+
self.opt_span_lint(lint, span, |diag| {
547561
diagnostics::decorate_lint(self.sess(), diagnostic, diag);
548562
});
549563
}

compiler/rustc_lint/src/context/diagnostics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -437,5 +437,8 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
437437
BuiltinLintDiag::OutOfScopeMacroCalls { path } => {
438438
lints::OutOfScopeMacroCalls { path }.decorate_lint(diag)
439439
}
440+
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
441+
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
442+
}
440443
}
441444
}

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
4646
fn inlined_check_id(&mut self, id: ast::NodeId) {
4747
for early_lint in self.context.buffered.take(id) {
4848
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
49-
self.context.span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
49+
self.context.opt_span_lint_with_diagnostics(lint_id.lint, span, diagnostic);
5050
}
5151
}
5252

compiler/rustc_lint/src/lints.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,16 @@ pub mod unexpected_cfg_value {
23212321
}
23222322
}
23232323

2324+
#[derive(LintDiagnostic)]
2325+
#[diag(lint_unexpected_builtin_cfg)]
2326+
#[note(lint_controlled_by)]
2327+
#[note(lint_incoherent)]
2328+
pub struct UnexpectedBuiltinCfg {
2329+
pub(crate) cfg: String,
2330+
pub(crate) cfg_name: Symbol,
2331+
pub(crate) controlled_by: &'static str,
2332+
}
2333+
23242334
#[derive(LintDiagnostic)]
23252335
#[diag(lint_macro_use_deprecated)]
23262336
#[help]

compiler/rustc_lint_defs/src/builtin.rs

+34
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ declare_lint_pass! {
105105
UNCONDITIONAL_RECURSION,
106106
UNCOVERED_PARAM_IN_PROJECTION,
107107
UNDEFINED_NAKED_FUNCTION_ABI,
108+
UNEXPECTED_BUILTIN_CFGS,
108109
UNEXPECTED_CFGS,
109110
UNFULFILLED_LINT_EXPECTATIONS,
110111
UNINHABITED_STATIC,
@@ -3269,6 +3270,39 @@ declare_lint! {
32693270
"detects unexpected names and values in `#[cfg]` conditions",
32703271
}
32713272

3273+
declare_lint! {
3274+
/// The `unexpected_builtin_cfgs` lint detects builtin cfgs set via the `--cfg` flag.
3275+
///
3276+
/// ### Example
3277+
///
3278+
/// ```text
3279+
/// rustc --cfg unix
3280+
/// ```
3281+
///
3282+
/// ```rust,ignore (needs command line option)
3283+
/// fn main() {}
3284+
/// ```
3285+
///
3286+
/// This will produce:
3287+
///
3288+
/// ```text
3289+
/// error: unexpected `--cfg unix` flag
3290+
/// |
3291+
/// = note: config `unix` is only supposed to be controlled by `--target`
3292+
/// = note: manually setting a built-in cfg does create incoherent behaviors
3293+
/// = note: `#[deny(unexpected_builtin_cfgs)]` on by default
3294+
/// ```
3295+
///
3296+
/// ### Explanation
3297+
///
3298+
/// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
3299+
/// the appropriate `rustc` flag that controls the config. For example setting the `windows`
3300+
/// cfg but on Linux based target.
3301+
pub UNEXPECTED_BUILTIN_CFGS,
3302+
Deny,
3303+
"detects builtin cfgs set via the `--cfg`"
3304+
}
3305+
32723306
declare_lint! {
32733307
/// The `repr_transparent_external_private_fields` lint
32743308
/// detects types marked `#[repr(transparent)]` that (transitively)

compiler/rustc_lint_defs/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,19 @@ pub enum BuiltinLintDiag {
747747
OutOfScopeMacroCalls {
748748
path: String,
749749
},
750+
UnexpectedBuiltinCfg {
751+
cfg: String,
752+
cfg_name: Symbol,
753+
controlled_by: &'static str,
754+
},
750755
}
751756

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

759764
/// The `NodeId` of the AST node that generated the lint.
760765
pub node_id: NodeId,
@@ -792,7 +797,7 @@ impl LintBuffer {
792797
self.add_early_lint(BufferedEarlyLint {
793798
lint_id: LintId::of(lint),
794799
node_id,
795-
span: span.into(),
800+
span: Some(span.into()),
796801
diagnostic,
797802
});
798803
}

compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ where
3232
&mut self,
3333
goal: Goal<I, (I::Term, I::Term, ty::AliasRelationDirection)>,
3434
) -> QueryResult<I> {
35-
let tcx = self.cx();
35+
let cx = self.cx();
3636
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3737
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
3838

3939
// Structurally normalize the lhs.
4040
let lhs = if let Some(alias) = lhs.to_alias_term() {
4141
let term = self.next_term_infer_of_kind(lhs);
42-
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
42+
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
4343
term
4444
} else {
4545
lhs
@@ -48,7 +48,7 @@ where
4848
// Structurally normalize the rhs.
4949
let rhs = if let Some(alias) = rhs.to_alias_term() {
5050
let term = self.next_term_infer_of_kind(rhs);
51-
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
51+
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
5252
term
5353
} else {
5454
rhs

0 commit comments

Comments
 (0)