about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2024-12-17Rollup merge of #134368 - ehuss:edition-links, r=jieyouxuJacob Pratt-2/+3
Use links to edition guide for edition migrations This switches the migration lints for the 2024 edition to point to the edition guide documentation instead of the tracking issues. I expect the documentation should be easier to understand for a user, compared to most of the issues which don't have any direct information, and can be a bit confusing to navigate, or have outdated information.
2024-12-17Rollup merge of #134202 - nnethercote:rm-existing_doc_keyword, r=GuillaumeGomezJacob Pratt-52/+2
Remove `rustc::existing_doc_keyword` lint The check doesn't require a lint. r? ``@GuillaumeGomez``
2024-12-17Remove `rustc::existing_doc_keyword` lint.Nicholas Nethercote-52/+2
`CheckAttrVisitor::check_doc_keyword` checks `#[doc(keyword = "..")]` attributes to ensure they are on an empty module, and that the value is a non-empty identifier. The `rustc::existing_doc_keyword` lint checks these attributes to ensure that the value is the name of a keyword. It's silly to have two different checking mechanisms for these attributes. This commit does the following. - Changes `check_doc_keyword` to check that the value is the name of a keyword (avoiding the need for the identifier check, which removes a dependency on `rustc_lexer`). - Removes the lint. - Updates tests accordingly. There is one hack: the `SelfTy` FIXME case used to used to be handled by disabling the lint, but now is handled with a special case in `is_doc_keyword`. That hack will go away if/when the FIXME is fixed. Co-Authored-By: Guillaume Gomez <guillaume1.gomez@gmail.com>
2024-12-16update uses of extract_if in the compilerThe 8472-2/+2
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+2
2024-12-16split attributesJonathan Dönszelmann-6/+5
2024-12-16Rollup merge of #134369 - antonok-edm:refering-referring, r=jieyouxuMatthias Krüger-1/+1
Update spelling of "referring" I noticed that `referring` was spelled incorrectly in the output of `unexpected 'cfg' condition name` warnings; it looks like it was also incorrectly spelled in a doc comment. I've update both instances.
2024-12-16Rollup merge of #134357 - Urgau:fn-ptr-134345, r=compiler-errorsMatthias Krüger-34/+59
Fix `trimmed_def_paths` ICE in the function ptr comparison lint This PR fixes an ICE with `trimmed_def_paths` ICE in the function ptr comparison lint, specifically when pretty-printing user types but then not using the resulting pretty-printing. Fixes #134345 r? `@saethlin`
2024-12-15Use links to edition guide for edition migrationsEric Huss-2/+3
2024-12-15spell "referring" correctlyAnton Lazarev-1/+1
2024-12-15Fix trimmed_def_paths ICE in the function ptr comparison lintUrgau-34/+59
2024-12-15Auto merge of #131808 - jdonszelmann:hir-attributes, r=oli-obk,petrochenkovbors-42/+48
Hir attributes This PR needs some explanation, it's somewhat large. - This is step one as described in https://github.com/rust-lang/compiler-team/issues/796. I've added a new `hir::Attribute` which is a lowered version of `ast::Attribute`. Right now, this has few concrete effects, however every place that after this PR parses a `hir::Attribute` should later get a pre-parsed attribute as described in https://github.com/rust-lang/compiler-team/issues/796 and transitively https://github.com/rust-lang/rust/issues/131229. - an extension trait `AttributeExt` is added, which is implemented for both `ast::Attribute` and `hir::Atribute`. This makes `hir::Attributes` mostly compatible with code that used to parse `ast::Attribute`. All its methods are also added as inherent methods to avoid having to import the trait everywhere in the compiler. - Incremental can not not hash `ast::Attribute` at all.
2024-12-15Add hir::AttributeJonathan Dönszelmann-42/+48
2024-12-15Improve check-cfg Cargo macro diagnostic with crate nameUrgau-10/+15
2024-12-15Cleanup lifetimes around `EarlyContextAndPass` and `EarlyCheckNode`Urgau-58/+44
2024-12-15Simplify `opt_span_lint` call in early diagnosticUrgau-36/+4
2024-12-15Access `TyCtxt` from early diagnostic decorationUrgau-49/+60
2024-12-14Rollup merge of #133221 - Urgau:check-cfg-macro-diag, r=jieyouxuMatthias Krüger-14/+98
Add external macros specific diagnostics for check-cfg This PR adds specific check-cfg diagnostics for unexpected cfg in external macros. As well as hiding the some of the Cargo specific help/suggestions as they distraction for external macros and are generally not the right solution. Follow-up to #132577 `@rustbot` label +L-unexpected_cfgs r? compiler
2024-12-13Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obkMatthias Krüger-0/+3
Add AST support for unsafe binders I'm splitting up #130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later. r? `@oli-obk` cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2024-12-13Rollup merge of #133937 - ↵Matthias Krüger-1/+1
estebank:silence-resolve-errors-from-mod-with-parse-errors, r=davidtwco Keep track of parse errors in `mod`s and don't emit resolve errors for paths involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around in the HIR and mark its `DefId` in the `Resolver`. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by expansion of `mod`s with parse errors. Fix https://github.com/rust-lang/rust/issues/97734.
2024-12-13Stabilize async closuresMichael Goulet-4/+0
2024-12-12Add unwrap_unsafe_binder and wrap_unsafe_binder macro operatorsMichael Goulet-0/+3
2024-12-12Rollup merge of #134173 - onur-ozkan:allow-symbol-intern-string-literal, ↵Matthias Krüger-0/+2
r=jieyouxu allow `symbol_intern_string_literal` lint in test modules Since #133545, `x check compiler --stage 1` no longer works because compiler test modules trigger `symbol_intern_string_literal` lint errors. Bootstrap shouldn't control when to ignore or enable this lint in the compiler tree (using `Kind != Test` was ineffective for obvious reasons). Also, conditionally adding this rustflag invalidates the build cache between `x test` and other commands. This PR removes the `Kind` check from bootstrap and handles it directly in the compiler tree in a more natural way.
2024-12-11allow `symbol_intern_string_literal` lint in test modulesonur-ozkan-0/+2
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-1/+1
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-10Rollup merge of #134008 - jswrenn:unsafe-fields-copy, r=compiler-errorsLeón Orell Valerian Liehr-0/+1
Make `Copy` unsafe to implement for ADTs with `unsafe` fields As a rule, the application of `unsafe` to a declaration requires that use-sites of that declaration also entail `unsafe`. For example, a field declared `unsafe` may only be read in the lexical context of an `unsafe` block. For nearly all safe traits, the safety obligations of fields are explicitly discharged when they are mentioned in method definitions. For example, idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields will require `unsafe` to clone those fields. Prior to this commit, `Copy` violated this rule. The trait is marked safe, and although it has no explicit methods, its implementation permits reads of `Self`. This commit resolves this by making `Copy` conditionally safe to implement. It remains safe to implement for ADTs without unsafe fields, but unsafe to implement for ADTs with unsafe fields. Tracking: #132922 r? ```@compiler-errors```
2024-12-09Revert #131669 due to ICEs许杰友 Jieyou Xu (Joe)-352/+65
Revert <https://github.com/rust-lang/rust/pull/131669> due to ICE reports: - <https://github.com/rust-lang/rust/issues/134059> (real-world) - <https://github.com/rust-lang/rust/issues/134060> (fuzzing) The changes can be re-landed with those cases addressed. This reverts commit 703bb982303ecab02fec593899639b4c3faecddd, reversing changes made to f415c07494b98e4559e4b13a9c5f867b0e6b2444.
2024-12-08Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-deadMatthias Krüger-1/+1
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications. cc `@max-niederman`
2024-12-08Rollup merge of #133992 - compiler-errors:walk-fully, r=jieyouxuMatthias Krüger-0/+3
Actually walk into lifetimes and attrs in `EarlyContextAndPass` Visitors that don't also call `walk_*` are kinda a footgun... I believe all the other early lint functions walk into their types correctly at this point.
2024-12-07Make `Copy` unsafe to implement for ADTs with `unsafe` fieldsJack Wrenn-0/+1
As a rule, the application of `unsafe` to a declaration requires that use-sites of that declaration also require `unsafe`. For example, a field declared `unsafe` may only be read in the lexical context of an `unsafe` block. For nearly all safe traits, the safety obligations of fields are explicitly discharged when they are mentioned in method definitions. For example, idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields will require `unsafe` to clone those fields. Prior to this commit, `Copy` violated this rule. The trait is marked safe, and although it has no explicit methods, its implementation permits reads of `Self`. This commit resolves this by making `Copy` conditionally safe to implement. It remains safe to implement for ADTs without unsafe fields, but unsafe to implement for ADTs with unsafe fields. Tracking: #132922
2024-12-07Actually walk into lifetimes and attrs in EarlyContextAndPassMichael Goulet-0/+3
2024-12-06compiler: Tighten up ImproperCTypesLayer recursionJubilee Young-21/+12
2024-12-06lint ImproperCTypes: message tweaks and refactoring from code reviewniacdoial-24/+27
2024-12-06lint ImproperCTypes: confirm that Box<FfiSafeType> and ↵niacdoial-1/+1
Option<Box<FfiSafeType>> are FFI-safe in function declarations too
2024-12-06lint: polish code from the last few commitsniacdoial-25/+60
2024-12-06lint: fix ImproperCTypes edge case for unsized structs due to foreign typesniacdoial-2/+65
2024-12-06lint: rework some ImproperCTypes messages (especially around indirections to ↵niacdoial-21/+115
!Sized)
2024-12-06lint: revamp ImproperCTypes diagnostic architecture for nested notes and ↵niacdoial-45/+146
help messages
2024-12-05Update compiler/rustc_lint/src/lints.rsAnthony Eid-2/+3
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2024-12-05Start work on dangling pointers lintAnthony Eid-0/+1
2024-12-05Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillotLeón Orell Valerian Liehr-4/+170
Add lint against function pointer comparisons This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it. ----- ## `unpredictable_function_pointer_comparisons` *warn-by-default* The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands. ### Example ```rust fn foo() {} let a = foo as fn(); let _ = a == foo; ``` ### Explanation Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together. ---- This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`. ```@rustbot``` labels +I-lang-nominated ~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-03Rollup merge of #133753 - ↵Matthias Krüger-2/+5
dingxiangfei2009:reduce-false-positive-if-let-rescope, r=jieyouxu Reduce false positives on some common cases from if-let-rescope lint r? `@jieyouxu` We would like to identify a very common case in the ecosystem in which we do not need to apply the lint suggestion for the new Edition 2024 `if let` semantics. In this patch we excluded linting from `if let`s in statements and block tail expressions. In these simple cases, new Edition 2024 drop orders are identical to those of Edition 2021 and prior. However, conservatively we should still lint for the other cases, because [this example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2113df5ce78f161d32a1190faf5c7469) shows that the drop order changes are very pronounced, some of which are even sensitive to runtime data.
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-3/+41
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-02Add warn-by-default lint against unpredictable fn pointer comparisonsUrgau-4/+170
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-2/+6
2024-12-02remove outdated commentlcnr-11/+4
2024-12-02reduce false positives on some common cases from if-let-rescopeDing Xiang Fei-2/+5
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-1/+1
2024-11-28Implement lint against `Symbol::intern` on a string literalclubby789-2/+40
2024-11-28Rollup merge of #133487 - pitaj:reserve-guarded-strings, r=fee1-deadGuillaume Gomez-2/+13
fix confusing diagnostic for reserved `##` Closes #131615