Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ac159dd
Add help message suggesting explicit reference cast for From/TryFrom
Muhtasim-Rasheed Feb 1, 2026
dc24aae
Modernize diagnostic for indeterminate trait object lifetime bounds
fmease Jan 29, 2026
03dcd99
Format heterogeneous try blocks
ia0 Feb 7, 2026
d5c6866
improve tests
ia0 Feb 7, 2026
f4eca01
Add FCW for derive helper attributes that will conflict with built-in…
nik-rev Feb 8, 2026
90fd768
Make it clearer that `check_pat_lit` only handles literal patterns
Zalathar Jan 4, 2026
91d47a5
Don't import `TyCtxt` from `crate::ty::context`
Zalathar Feb 8, 2026
4234d2d
Move `impl Interner for TyCtxt` to its own submodule
Zalathar Feb 8, 2026
b7bfb76
Indicate that `bidirectional_lang_item_map!` declares functions
Zalathar Feb 8, 2026
20f65fc
Uplift `Predicate::allow_normalization` to `rustc_type_ir`
ShoyuVanilla Feb 9, 2026
33f0b6e
Rollup merge of #151152 - nik-contrib:helper_attr_builtin, r=chenyukang
matthiaskrgr Feb 10, 2026
de14019
Rollup merge of #151954 - Muhtasim-Rasheed:issue-109829-help-message,…
matthiaskrgr Feb 10, 2026
de88157
Rollup merge of #152148 - Zalathar:tcx-interner, r=petrochenkov
matthiaskrgr Feb 10, 2026
580b0df
Rollup merge of #152226 - fmease:modernize-indeterminate-object-lifet…
matthiaskrgr Feb 10, 2026
3752084
Rollup merge of #150688 - Zalathar:check-pat-lit, r=petrochenkov
matthiaskrgr Feb 10, 2026
48e093f
Rollup merge of #152293 - ia0:try_blocks_heterogeneous, r=ytmimi
matthiaskrgr Feb 10, 2026
f1f8dee
Rollup merge of #152396 - ShoyuVanilla:uplift-allow-normalize, r=lcnr
matthiaskrgr Feb 10, 2026
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
10 changes: 10 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use rustc_hir::lints::AttributeLintKind;
use rustc_session::lint::builtin::AMBIGUOUS_DERIVE_HELPERS;

use super::prelude::*;

const PROC_MACRO_ALLOWED_TARGETS: AllowedTargets =
Expand Down Expand Up @@ -126,6 +129,13 @@ fn parse_derive_like<S: Stage>(
cx.expected_identifier(ident.span);
return None;
}
if rustc_feature::is_builtin_attr_name(ident.name) {
cx.emit_lint(
AMBIGUOUS_DERIVE_HELPERS,
AttributeLintKind::AmbiguousDeriveHelpers,
ident.span,
);
}
attributes.push(ident.name);
}
}
Expand Down
32 changes: 19 additions & 13 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use rustc_abi::{ExternAbi, Size};
use rustc_ast::Recovered;
use rustc_data_structures::assert_matches;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, E0228, ErrorGuaranteed, StashKey, struct_span_code_err,
};
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, E0228, ErrorGuaranteed, StashKey};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -318,16 +316,24 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
}

fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx> {
if let RegionInferReason::ObjectLifetimeDefault = reason {
let e = struct_span_code_err!(
self.dcx(),
span,
E0228,
"the lifetime bound for this object type cannot be deduced \
from context; please supply an explicit bound"
)
.emit();
ty::Region::new_error(self.tcx(), e)
if let RegionInferReason::ObjectLifetimeDefault(sugg_sp) = reason {
// FIXME: Account for trailing plus `dyn Trait+`, the need of parens in
// `*const dyn Trait` and `Fn() -> *const dyn Trait`.
let guar = self
.dcx()
.struct_span_err(
span,
"cannot deduce the lifetime bound for this trait object type from context",
)
.with_code(E0228)
.with_span_suggestion_verbose(
sugg_sp,
"please supply an explicit bound",
" + /* 'a */",
Applicability::HasPlaceholders,
)
.emit();
ty::Region::new_error(self.tcx(), guar)
} else {
// This indicates an illegal lifetime in a non-assoc-trait position
ty::Region::new_error_with_message(self.tcx(), span, "unelided lifetime in signature")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Parent lifetime must have failed to resolve. Don't emit a redundant error.
RegionInferReason::ExplicitObjectLifetime
} else {
RegionInferReason::ObjectLifetimeDefault
RegionInferReason::ObjectLifetimeDefault(span.shrink_to_hi())
}
} else {
RegionInferReason::ExplicitObjectLifetime
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub enum RegionInferReason<'a> {
/// Lifetime on a trait object that is spelled explicitly, e.g. `+ 'a` or `+ '_`.
ExplicitObjectLifetime,
/// A trait object's lifetime when it is elided, e.g. `dyn Any`.
ObjectLifetimeDefault,
ObjectLifetimeDefault(Span),
/// Generic lifetime parameter
Param(&'a ty::GenericParamDef),
RegionPredicate,
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};

use rustc_abi::FieldIdx;
use rustc_ast as ast;
use rustc_data_structures::assert_matches;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::codes::*;
use rustc_errors::{
Expand All @@ -24,7 +25,6 @@ use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_session::parse::feature_err;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::source_map::Spanned;
use rustc_span::{BytePos, DUMMY_SP, Ident, Span, kw, sym};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
Expand Down Expand Up @@ -611,7 +611,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.write_ty(*hir_id, ty);
ty
}
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, &pat_info.top_info),
PatKind::Expr(expr @ PatExpr { kind: PatExprKind::Lit { lit, .. }, .. }) => {
self.check_pat_lit(pat.span, expr, &lit.node, expected, &pat_info.top_info)
}
PatKind::Range(lhs, rhs, _) => {
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
}
Expand Down Expand Up @@ -938,31 +940,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn check_pat_lit(
&self,
span: Span,
lt: &hir::PatExpr<'tcx>,
expr: &hir::PatExpr<'tcx>,
lit_kind: &ast::LitKind,
expected: Ty<'tcx>,
ti: &TopInfo<'tcx>,
) -> Ty<'tcx> {
assert_matches!(expr.kind, hir::PatExprKind::Lit { .. });

// We've already computed the type above (when checking for a non-ref pat),
// so avoid computing it again.
let ty = self.node_ty(lt.hir_id);
let ty = self.node_ty(expr.hir_id);

// Byte string patterns behave the same way as array patterns
// They can denote both statically and dynamically-sized byte arrays.
// Additionally, when `deref_patterns` is enabled, byte string literal patterns may have
// types `[u8]` or `[u8; N]`, in order to type, e.g., `deref!(b"..."): Vec<u8>`.
let mut pat_ty = ty;
if let hir::PatExprKind::Lit {
lit: Spanned { node: ast::LitKind::ByteStr(..), .. }, ..
} = lt.kind
{
if matches!(lit_kind, ast::LitKind::ByteStr(..)) {
let tcx = self.tcx;
let expected = self.structurally_resolve_type(span, expected);
match *expected.kind() {
// Allow `b"...": &[u8]`
ty::Ref(_, inner_ty, _)
if self.try_structurally_resolve_type(span, inner_ty).is_slice() =>
{
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
trace!(?expr.hir_id.local_id, "polymorphic byte string lit");
pat_ty = Ty::new_imm_ref(
tcx,
tcx.lifetimes.re_static,
Expand All @@ -988,9 +990,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// When `deref_patterns` is enabled, in order to allow `deref!("..."): String`, we allow
// string literal patterns to have type `str`. This is accounted for when lowering to MIR.
if self.tcx.features().deref_patterns()
&& let hir::PatExprKind::Lit {
lit: Spanned { node: ast::LitKind::Str(..), .. }, ..
} = lt.kind
&& matches!(lit_kind, ast::LitKind::Str(..))
&& self.try_structurally_resolve_type(span, expected).is_str()
{
pat_ty = self.tcx.types.str_;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ pub fn decorate_attribute_lint(
lints::DocAutoCfgExpectsHideOrShow.decorate_lint(diag)
}

&AttributeLintKind::AmbiguousDeriveHelpers => {
lints::AmbiguousDeriveHelpers.decorate_lint(diag)
}

&AttributeLintKind::DocAutoCfgHideShowUnexpectedItem { attr_name } => {
lints::DocAutoCfgHideShowUnexpectedItem { attr_name }.decorate_lint(diag)
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3752,6 +3752,10 @@ pub(crate) struct DocAliasDuplicated {
#[diag("only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`")]
pub(crate) struct DocAutoCfgExpectsHideOrShow;

#[derive(LintDiagnostic)]
#[diag("there exists a built-in attribute with the same name")]
pub(crate) struct AmbiguousDeriveHelpers;

#[derive(LintDiagnostic)]
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items")]
pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
Expand Down
70 changes: 70 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare_lint_pass! {
AARCH64_SOFTFLOAT_NEON,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS,
AMBIGUOUS_DERIVE_HELPERS,
AMBIGUOUS_GLOB_IMPORTED_TRAITS,
AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS,
Expand Down Expand Up @@ -4267,6 +4268,75 @@ declare_lint! {
};
}

declare_lint! {
/// The `ambiguous_derive_helpers` lint detects cases where a derive macro's helper attribute
/// is the same name as that of a built-in attribute.
///
/// ### Example
///
/// ```rust,ignore (proc-macro)
/// #![crate_type = "proc-macro"]
/// #![deny(ambiguous_derive_helpers)]
///
/// use proc_macro::TokenStream;
///
/// #[proc_macro_derive(Trait, attributes(ignore))]
/// pub fn example(input: TokenStream) -> TokenStream {
/// TokenStream::new()
/// }
/// ```
///
/// Produces:
///
/// ```text
/// warning: there exists a built-in attribute with the same name
/// --> file.rs:5:39
/// |
/// 5 | #[proc_macro_derive(Trait, attributes(ignore))]
/// | ^^^^^^
/// |
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
/// = note: for more information, see issue #151152 <https://github.com/rust-lang/rust/issues/151152>
/// = note: `#[deny(ambiguous_derive_helpers)]` (part of `#[deny(future_incompatible)]`) on by default
/// ```
///
/// ### Explanation
///
/// Attempting to use this helper attribute will throw an error:
///
/// ```rust,ignore (needs-dependency)
/// #[derive(Trait)]
/// struct Example {
/// #[ignore]
/// fields: ()
/// }
/// ```
///
/// Produces:
///
/// ```text
/// error[E0659]: `ignore` is ambiguous
/// --> src/lib.rs:5:7
/// |
/// 5 | #[ignore]
/// | ^^^^^^ ambiguous name
/// |
/// = note: ambiguous because of a name conflict with a builtin attribute
/// = note: `ignore` could refer to a built-in attribute
/// note: `ignore` could also refer to the derive helper attribute defined here
/// --> src/lib.rs:3:10
/// |
/// 3 | #[derive(Trait)]
/// | ^^^^^
/// ```
pub AMBIGUOUS_DERIVE_HELPERS,
Warn,
"detects derive helper attributes that are ambiguous with built-in attributes",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError #151276),
};
}

declare_lint! {
/// The `private_interfaces` lint detects types in a primary interface of an item,
/// that are more private than the item itself. Primary interface of an item is all
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ pub enum AttributeLintKind {
attr_name: Symbol,
},
DocInvalid,
AmbiguousDeriveHelpers,
DocUnknownInclude {
span: Span,
inner: &'static str,
Expand Down
Loading
Loading