Skip to content
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

Rollup of 11 pull requests #122854

Merged
merged 169 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
a4b413d
Add asm label support to AST and HIR
nbdd0121 Dec 25, 2023
dbfbd0e
feat: add `const_is_empty` lint
samueltardieu Feb 19, 2024
89b334d
chore: update some tests to allow `const_is_empty`
samueltardieu Feb 18, 2024
2884970
feat: extend `const_is_empty` with many kinds of constants
samueltardieu Feb 19, 2024
1159e2c
feat: add more tests for the `const_is_empty` lint
samueltardieu Feb 19, 2024
898ed88
feat: make `const_is_empty` lint ignore external constants
samueltardieu Feb 26, 2024
301d293
Move `iter_nth` to `style`, add machine applicable suggestion
Alexendoo Mar 4, 2024
865ac89
Use `rustc_driver::args::raw_args()` in Clippy
beetrees May 15, 2023
a9858da
Fix dependency specifications
sanxiyn Mar 7, 2024
7e83df4
Merge commit '93f0a9a91f58c9b2153868f458402155fb6265bb' into clippy-s…
flip1995 Mar 7, 2024
43f4ec3
[`unused_enumerate_index`]: Use if-let chain
Ethiraric Mar 7, 2024
f3879b3
[`use_self`]: Make it aware of lifetimes
Ethiraric Feb 29, 2024
3a6cac7
add `rewrite_struct` proc-macro and test case
J-ZhengLi Mar 8, 2024
55b757e
Merge from rustc
Mar 8, 2024
1572279
Rollup merge of #119365 - nbdd0121:asm-goto, r=Amanieu
matthiaskrgr Mar 8, 2024
adc91e4
support manually search for docs in case attr was removed by proc macros
J-ZhengLi Mar 8, 2024
0b4b684
Auto merge of #12433 - J-ZhengLi:issue12197, r=dswij
bors Mar 8, 2024
1bd7383
Rollup merge of #121194 - beetrees:rustc-raw-args, r=petrochenkov
matthiaskrgr Mar 8, 2024
158b70a
Distinguish between library and lang UB in assert_unsafe_precondition
saethlin Feb 27, 2024
2dd085f
Allow lint where we don't care
Nadrieril Jan 17, 2024
4e95b4a
[`mut_mut`]: Fix duplicate diags
cookie-s Mar 9, 2024
6890407
Auto merge of #118879 - Nadrieril:lint-range-gap, r=estebank
bors Mar 9, 2024
7473f05
[`no_effect_replace`]: Fix duplicate diagnostics
cookie-s Mar 9, 2024
8d78cd1
Fix duplicate lint emission from [`else_if_without_else`]
CBSpeir Mar 9, 2024
4d15a75
Merge from rustc
Mar 9, 2024
453242c
Auto merge of #12310 - samueltardieu:issue-12307, r=xFrednet
bors Mar 9, 2024
f34804d
Add new `duplicated_attributes` lint
GuillaumeGomez Feb 28, 2024
749e225
Add ui test for new `duplicated_attributes` lint
GuillaumeGomez Feb 28, 2024
d57d001
Update `cargo dev update_lints` command to fix new warning emitted by…
GuillaumeGomez Feb 28, 2024
ae52a9d
Update ui tests
GuillaumeGomez Feb 28, 2024
fa4e3aa
add documentation to the `span_lint_hir` functions
y21 Mar 8, 2024
099e2c0
Auto merge of #12443 - cookie-s:noeffectreoplace-fix-dup-diags, r=Ale…
bors Mar 9, 2024
b2f9c4c
Auto merge of #12442 - cookie-s:fix-mutmut-duplicate-diags, r=y21
bors Mar 9, 2024
ced8bc5
use `span_lint_hir` instead of `span_lint` in more lints
y21 Mar 9, 2024
c173ea6
Auto merge of #12446 - y21:check_fn_span_lint, r=xFrednet
bors Mar 9, 2024
b44ab66
Fix #12438 false positive regression
MarcusGrass Mar 9, 2024
eb5ce85
mention `span_lint_hir` in `span_lint` and add a reason to disallowed…
y21 Mar 9, 2024
0e59259
add new lint `zero_repeat_side_effects`
Jacherr Dec 10, 2023
0c82fd0
fix example code
Jacherr Mar 9, 2024
d8a9068
Auto merge of #12449 - Jacherr:issue-6439, r=llogiq
bors Mar 9, 2024
7ee75f8
Auto merge of #12447 - MarcusGrass:mg/fix-12438-regression, r=y21
bors Mar 9, 2024
5b1f95c
apply review suggestions
y21 Mar 9, 2024
a92037f
[`option_option`]: Fix duplicate diagnostics
cookie-s Mar 9, 2024
1abf441
Add new `match_option_and_default` lint
GuillaumeGomez Mar 8, 2024
fadb254
Add new ui test for `match_option_and_default`
GuillaumeGomez Mar 8, 2024
b0f358f
Update ui test
GuillaumeGomez Mar 8, 2024
98ac5f1
Rename into `manual_unwrap_or_default`
GuillaumeGomez Mar 10, 2024
ed6e629
Fix duplicate lint emission from [manual_retain]
CBSpeir Mar 10, 2024
45f87a0
Auto merge of #121662 - saethlin:precondition-unification, r=RalfJung
bors Mar 10, 2024
6d80398
Merge from rustc
Mar 10, 2024
1847904
Auto merge of #122246 - RalfJung:miri, r=RalfJung
bors Mar 10, 2024
81debac
Auto merge of #12440 - GuillaumeGomez:add-match_option_and_default, r…
bors Mar 10, 2024
86717f2
Auto merge of #12445 - y21:document-diagnostic-utils, r=xFrednet
bors Mar 10, 2024
6c863bc
Remove unused structs in clippy
mu001999 Feb 29, 2024
8e55bbf
[`single_match`]: Fix duplicate diagnostics
WeiTheShinobi Mar 9, 2024
9c51fd9
refactor: readability improvement for `seek` lint
hamirmahal Mar 10, 2024
02156dc
Auto merge of #12458 - hamirmahal:refactor/readability-improvement, r…
bors Mar 11, 2024
6ff4e71
Auto merge of #12448 - WeiTheShinobi:fix_single_match, r=dswij
bors Mar 11, 2024
870e016
Auto merge of #12430 - sanxiyn:direct-minimal-versions, r=Alexendoo
bors Mar 11, 2024
d66a0ec
Fix typo in section '6.10. Macro Expansions' of the Clippy Book
CBSpeir Mar 11, 2024
f685a4b
Auto merge of #12378 - GuillaumeGomez:duplicated_attr, r=blyxyas
bors Mar 11, 2024
e22ca03
Auto merge of #12452 - CBSpeir:dedup-manual-retain, r=blyxyas
bors Mar 11, 2024
100ab49
new restriction lint: `division_remainder_used`
Jacherr Mar 10, 2024
edcf10e
update_lints
Jacherr Mar 11, 2024
10677d6
add `with_empty_docs` attr macro & test cases for issue #12377
J-ZhengLi Mar 12, 2024
3cd6fd1
fix [`empty_docs`] trigger in proc-macro
J-ZhengLi Mar 12, 2024
25fb1f0
Merge from rustc
Mar 12, 2024
b205192
Change `DefKind::Static` to a struct variant
oli-obk Feb 23, 2024
013bf92
Add `nested` bool to `DefKind::Static`.
oli-obk Feb 23, 2024
97f2ade
s/mt/mutability/
oli-obk Mar 11, 2024
f472b50
chore: fix some typos
pavedroad Mar 12, 2024
27c49e1
filetime::FileTime::now() is new in 0.2.9
sanxiyn Mar 12, 2024
60f7f06
Auto merge of #12462 - CBSpeir:clippy-book-typo, r=flip1995
bors Mar 12, 2024
a8a7371
Auto merge of #12417 - Alexendoo:iter-nth, r=flip1995
bors Mar 12, 2024
3a14911
Auto merge of #12469 - pavedroad:master, r=y21
bors Mar 12, 2024
244d7da
[`cast_lossless`]: Suggest type alias instead of the aliased type
Centri3 Aug 2, 2023
92ca7c9
Auto merge of #11287 - Centri3:#11285, r=llogiq
bors Mar 12, 2024
99e8000
Auto merge of #12466 - J-ZhengLi:issue12377, r=blyxyas
bors Mar 12, 2024
65defdb
[`unconditional_recursion`]: catch `From` -> `Into` -> `From`
y21 Mar 10, 2024
11c2bad
CI: replace `cancel-outdated-builds` with `concurrency` groupo
Kobzol Mar 13, 2024
73be486
Auto merge of #12459 - y21:unconditional_recursion_from_into, r=Jarcho
bors Mar 13, 2024
11759d1
Don't emit `doc_markdown` lint for missing backticks if it's inside a…
GuillaumeGomez Mar 12, 2024
cd36b25
Add regression test for #10262
GuillaumeGomez Mar 12, 2024
03d7ae8
Also handle `<blockquote>` and `<q>` HTML tags
GuillaumeGomez Mar 13, 2024
660b058
Auto merge of #12470 - sanxiyn:filetime, r=Alexendoo
bors Mar 13, 2024
7cdeac5
[`unused_enumerate_index`]: trigger on method calls
Ethiraric Mar 7, 2024
adcbb4a
move readonly_write_lock to perf
y21 Mar 13, 2024
1fe8844
fix [`dbg_macro`] FN when `dbg` is inside some complex macros
J-ZhengLi Jan 15, 2024
0535f55
lint nested `dbg!` macros, split tests
J-ZhengLi Feb 20, 2024
fe4e0ac
checks `dbg` inside other macros as well (but no ext macro);
J-ZhengLi Mar 6, 2024
20e4c74
Handle false positive with map_clone
maekawatoshiki Feb 12, 2024
560a5a8
Fix logic
maekawatoshiki Feb 13, 2024
c5d3b62
Fix conflict
maekawatoshiki Mar 14, 2024
5f8d8f1
Simplify logic
maekawatoshiki Mar 14, 2024
a75e271
Auto merge of #12282 - maekawatoshiki:fix, r=xFrednet
bors Mar 14, 2024
e77d7a3
Auto merge of #12477 - Kobzol:ci-concurrency-group, r=flip1995
bors Mar 14, 2024
da2795f
Rename `ast::StmtKind::Local` into `ast::StmtKind::Let`
GuillaumeGomez Mar 14, 2024
0e2897f
Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`
GuillaumeGomez Mar 14, 2024
22577e5
Merge from rustc
Mar 14, 2024
8a78128
Auto merge of #12386 - Ethiraric:fix-12381, r=blyxyas
bors Mar 14, 2024
f55a049
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`
petrochenkov Mar 14, 2024
b667d02
Auto merge of #12472 - GuillaumeGomez:fix-10262, r=blyxyas
bors Mar 14, 2024
dadcd94
[`unused_enumerate_index`]: Keep explicit element type
Ethiraric Mar 13, 2024
5a11fef
Auto merge of #12432 - Ethiraric:fix-12411, r=y21
bors Mar 14, 2024
d3f8f3e
fix span calculation for non-ascii in `needless_return`
y21 Mar 15, 2024
1e30c29
Rollup merge of #122513 - petrochenkov:somehir4, r=fmease
GuillaumeGomez Mar 15, 2024
c9f2482
Auto merge of #12493 - y21:issue12491, r=Alexendoo
bors Mar 15, 2024
9408c59
[`option_option`]: Use span.from_expansion
cookie-s Mar 16, 2024
4e72ca3
[`map_entry`]: call the visitor on the local's `else` block
y21 Mar 16, 2024
59a5ad4
Auto merge of #12441 - CBSpeir:dedup-else-if-without-else, r=dswij
bors Mar 16, 2024
12ecaa8
Auto merge of #12482 - J-ZhengLi:issue12131, r=Jarcho
bors Mar 17, 2024
67fa36a
Auto merge of #12479 - y21:readonly_write_lock_perf, r=Jarcho
bors Mar 17, 2024
d202eb6
Auto merge of #12450 - cookie-s:fix-optopt-duplicate-diags, r=llogiq
bors Mar 17, 2024
e9a50f2
Auto merge of #12451 - Jacherr:issue-12391, r=llogiq
bors Mar 17, 2024
b5dcaae
Auto merge of #12498 - y21:issue12489, r=blyxyas
bors Mar 18, 2024
003c4bc
Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in …
oli-obk Mar 14, 2024
8339474
When displaying multispans, ignore empty lines adjacent to `...`
estebank Mar 5, 2024
0dc8769
Deduplicate `associated_body` and `body_id`
oli-obk Mar 5, 2024
83af0e5
Update version attribute for 1.77 lints
xFrednet Mar 18, 2024
87d45e5
Changelog for Clippy 1.77 :school:
xFrednet Mar 18, 2024
56288a7
Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errors
bors Mar 19, 2024
e7c3e04
chore: fix typo
goodmost Mar 19, 2024
3f338b3
Auto merge of #12510 - goodmost:master, r=Alexendoo
bors Mar 19, 2024
21a97f0
Specify an MSRV of 1.63.0 for assigning_clones
humannum14916 Mar 19, 2024
8c866d3
Add test for MSRV checking for assigning_clones
humannum14916 Mar 19, 2024
7c0b2dd
Add assigning_clones to MSRV config option docs
humannum14916 Mar 19, 2024
76096ef
Auto merge of #122029 - estebank:drive-by-ui-test, r=oli-obk
bors Mar 19, 2024
89aba8d
Auto merge of #12511 - humannum14916:assigning_clones_msrv, r=Alexendoo
bors Mar 19, 2024
477108d
FP: `cast_lossless`: disable lint when casting to (u)128 from any (u)…
Jacherr Mar 15, 2024
5f7b3c5
Only enforce MSRV check on .clone_into() suggestions
humannum14916 Mar 20, 2024
db7c9fe
Add UI test for new MSRV check
humannum14916 Mar 20, 2024
19cb05f
std::net: adding acceptfilter feature for netbsd/freebsd.
devnexen Mar 2, 2024
5b7efe8
Auto merge of #12516 - humannum14916:assigning_clones_msrv, r=Alexendoo
bors Mar 20, 2024
34766a6
Auto merge of #12496 - Jacherr:issue-12492, r=blyxyas
bors Mar 20, 2024
a16a9ed
Auto merge of #12509 - xFrednet:changelog-1-77, r=dswij
bors Mar 20, 2024
f6f89dc
BTree(Set|Map): Guarantee that `IntoIter` will iterate in sorted by k…
ultrabear Mar 21, 2024
f8a093c
document iteration ordering on into_iter method instead of IntoIterat…
ultrabear Mar 21, 2024
beb0c22
document into_iter in top level docs iterator ordering guarantees
ultrabear Mar 21, 2024
8ca7aac
Add tests for shortcomings of associated type bounds
compiler-errors Mar 21, 2024
e505408
Add xFrednet back to the reviewing rotation
xFrednet Mar 21, 2024
32799a5
Auto merge of #12520 - xFrednet:lets-review-again, r=xFrednet
bors Mar 21, 2024
796105e
make failure logs less verbose
onur-ozkan Mar 21, 2024
ae4c5c8
Implement `FusedIterator` for `gen` block
ShoyuVanilla Mar 21, 2024
238cd36
Fix documentation typo "appects" > "affects"
Rua Mar 21, 2024
443f459
Auto merge of #12523 - Rua:typo-fix, r=dswij
bors Mar 21, 2024
daa6553
add test for #122549
matthiaskrgr Mar 21, 2024
6f2c6ef
Change syntax of the never type attribute thingy
WaffleLapkin Mar 21, 2024
35a7845
add test for https://github.com/rust-lang/rust/issues/122098 ICE: in…
matthiaskrgr Mar 21, 2024
c00920c
Avoid noop rewrite of issues.txt
workingjubilee Mar 21, 2024
bdafec3
add test for #121807
matthiaskrgr Mar 21, 2024
847311e
add test for ice "cannot relate region: LUB(ReErased, ReError)"
matthiaskrgr Mar 21, 2024
7d42d73
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Mar 21, 2024
bb86654
Bump nightly version -> 2024-03-21
flip1995 Mar 21, 2024
e1d15b5
Bump Clippy version -> 0.1.79
flip1995 Mar 21, 2024
9d6f416
Auto merge of #12527 - flip1995:rustup, r=flip1995
bors Mar 21, 2024
5a82d16
Merge commit '9d6f41691ed9dbfaec2a2df2661c42451f2fe0d3' into clippy-s…
flip1995 Mar 21, 2024
8e53d53
Update Cargo.lock
flip1995 Mar 21, 2024
93297bf
Add a never type option to make diverging blocks `()`
WaffleLapkin Mar 21, 2024
f0feebb
Rollup merge of #121881 - devnexen:bsd_acceptfilter, r=Amanieu
matthiaskrgr Mar 22, 2024
fa99ebc
Rollup merge of #122817 - ultrabear:ultrabear_btreedoc, r=Nilstrieb
matthiaskrgr Mar 22, 2024
08ac38b
Rollup merge of #122826 - compiler-errors:associated-type-bound-tests…
matthiaskrgr Mar 22, 2024
1757cb5
Rollup merge of #122829 - ShoyuVanilla:gen-block-impl-fused-iter, r=c…
matthiaskrgr Mar 22, 2024
05ae329
Rollup merge of #122831 - onur-ozkan:less-verbose-fail-logs, r=clubby789
matthiaskrgr Mar 22, 2024
c48c35f
Rollup merge of #122837 - matthiaskrgr:fix_122549, r=petrochenkov
matthiaskrgr Mar 22, 2024
d9e90ef
Rollup merge of #122838 - workingjubilee:less-catholic-blessings-to-p…
matthiaskrgr Mar 22, 2024
ce63d7a
Rollup merge of #122841 - matthiaskrgr:moretests, r=wesleywiser
matthiaskrgr Mar 22, 2024
b469a6d
Rollup merge of #122843 - WaffleLapkin:semicolon-vs-the-never, r=comp…
matthiaskrgr Mar 22, 2024
e647543
Rollup merge of #122844 - matthiaskrgr:just_one_more_test_mom, r=comp…
matthiaskrgr Mar 22, 2024
99e5618
Rollup merge of #122845 - flip1995:clippy-subtree-update, r=matthiaskrgr
matthiaskrgr Mar 22, 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
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"

[[package]]
name = "clippy"
version = "0.1.78"
version = "0.1.79"
dependencies = [
"anstream",
"clippy_config",
Expand Down Expand Up @@ -602,7 +602,7 @@ dependencies = [

[[package]]
name = "clippy_config"
version = "0.1.78"
version = "0.1.79"
dependencies = [
"rustc-semver",
"serde",
Expand All @@ -625,7 +625,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.78"
version = "0.1.79"
dependencies = [
"arrayvec",
"cargo_metadata 0.18.1",
Expand All @@ -650,7 +650,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.78"
version = "0.1.79"
dependencies = [
"arrayvec",
"clippy_config",
Expand Down Expand Up @@ -971,7 +971,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

[[package]]
name = "declare_clippy_lint"
version = "0.1.78"
version = "0.1.79"
dependencies = [
"itertools 0.12.1",
"quote",
Expand Down Expand Up @@ -2205,7 +2205,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
dependencies = [
"cfg-if",
"windows-targets 0.52.4",
"windows-targets 0.48.5",
]

[[package]]
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

rustc_attr!(
rustc_never_type_mode, Normal, template!(NameValueStr: "fallback_to_unit|fallback_to_niko|fallback_to_never|no_fallback"), ErrorFollowing,
rustc_never_type_options,
Normal,
template!(List: r#"/*opt*/ fallback = "unit|niko|never|no""#),
ErrorFollowing,
EncodeCrossCrate::No,
"`rustc_never_type_fallback` is used to experiment with never type fallback and work on \
"`rustc_never_type_options` is used to experiment with never type fallback and work on \
never type stabilization, and will never be stable"
),

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ language_item_table! {
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;

Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);

Expand Down
36 changes: 4 additions & 32 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use rustc_data_structures::{
graph::{iterate::DepthFirstSearch, vec_graph::VecGraph},
unord::{UnordBag, UnordMap, UnordSet},
};
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_middle::ty::{self, Ty};
use rustc_span::sym;

enum DivergingFallbackBehavior {
#[derive(Copy, Clone)]
pub enum DivergingFallbackBehavior {
/// Always fallback to `()` (aka "always spontaneous decay")
FallbackToUnit,
/// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken.
Expand Down Expand Up @@ -78,9 +77,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
return false;
}

let diverging_behavior = self.diverging_fallback_behavior();
let diverging_fallback =
self.calculate_diverging_fallback(&unresolved_variables, diverging_behavior);
let diverging_fallback = self
.calculate_diverging_fallback(&unresolved_variables, self.diverging_fallback_behavior);

// We do fallback in two passes, to try to generate
// better error messages.
Expand All @@ -94,32 +92,6 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
fallback_occurred
}

fn diverging_fallback_behavior(&self) -> DivergingFallbackBehavior {
let Some((mode, span)) = self
.tcx
.get_attr(CRATE_DEF_ID, sym::rustc_never_type_mode)
.map(|attr| (attr.value_str().unwrap(), attr.span))
else {
if self.tcx.features().never_type_fallback {
return DivergingFallbackBehavior::FallbackToNiko;
}

return DivergingFallbackBehavior::FallbackToUnit;
};

match mode {
sym::fallback_to_unit => DivergingFallbackBehavior::FallbackToUnit,
sym::fallback_to_niko => DivergingFallbackBehavior::FallbackToNiko,
sym::fallback_to_never => DivergingFallbackBehavior::FallbackToNever,
sym::no_fallback => DivergingFallbackBehavior::NoFallback,
_ => {
self.tcx.dcx().span_err(span, format!("unknown never type mode: `{mode}` (supported: `fallback_to_unit`, `fallback_to_niko`, `fallback_to_never` and `no_fallback`)"));

DivergingFallbackBehavior::FallbackToUnit
}
}
}

fn fallback_effects(&self) -> bool {
let unsolved_effects = self.unsolved_effects();

Expand Down
27 changes: 26 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext}
use std::iter;
use std::mem;

#[derive(Clone, Copy, Default)]
pub enum DivergingBlockBehavior {
/// This is the current stable behavior:
///
/// ```rust
/// {
/// return;
/// } // block has type = !, even though we are supposedly dropping it with `;`
/// ```
#[default]
Never,

/// Alternative behavior:
///
/// ```ignore (very-unstable-new-attribute)
/// #![rustc_never_type_options(diverging_block_default = "unit")]
/// {
/// return;
/// } // block has type = (), since we are dropping `!` from `return` with `;`
/// ```
Unit,
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(in super::super) fn check_casts(&mut self) {
// don't hold the borrow to deferred_cast_checks while checking to avoid borrow checker errors
Expand Down Expand Up @@ -1710,7 +1733,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
//
// #41425 -- label the implicit `()` as being the
// "found type" here, rather than the "expected type".
if !self.diverges.get().is_always() {
if !self.diverges.get().is_always()
|| matches!(self.diverging_block_behavior, DivergingBlockBehavior::Unit)
{
// #50009 -- Do not point at the entire fn block span, point at the return type
// span, as it is the cause of the requirement, and
// `consider_hint_about_removing_semicolon` will point at the last expression
Expand Down
73 changes: 72 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ mod checks;
mod suggestions;

use crate::coercion::DynamicCoerceMany;
use crate::fallback::DivergingFallbackBehavior;
use crate::fn_ctxt::checks::DivergingBlockBehavior;
use crate::{CoroutineTypes, Diverges, EnclosingBreakables, Inherited};
use hir::def_id::CRATE_DEF_ID;
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand All @@ -18,7 +21,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::Session;
use rustc_span::symbol::Ident;
use rustc_span::{self, Span, DUMMY_SP};
use rustc_span::{self, sym, Span, DUMMY_SP};
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};

use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -108,6 +111,9 @@ pub struct FnCtxt<'a, 'tcx> {
pub(super) inh: &'a Inherited<'tcx>,

pub(super) fallback_has_occurred: Cell<bool>,

pub(super) diverging_fallback_behavior: DivergingFallbackBehavior,
pub(super) diverging_block_behavior: DivergingBlockBehavior,
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand All @@ -116,6 +122,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
) -> FnCtxt<'a, 'tcx> {
let (diverging_fallback_behavior, diverging_block_behavior) =
parse_never_type_options_attr(inh.tcx);
FnCtxt {
body_id,
param_env,
Expand All @@ -131,6 +139,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}),
inh,
fallback_has_occurred: Cell::new(false),
diverging_fallback_behavior,
diverging_block_behavior,
}
}

Expand Down Expand Up @@ -374,3 +384,64 @@ impl<'tcx> LoweredTy<'tcx> {
LoweredTy { raw, normalized }
}
}

fn parse_never_type_options_attr(
tcx: TyCtxt<'_>,
) -> (DivergingFallbackBehavior, DivergingBlockBehavior) {
use DivergingFallbackBehavior::*;

// Error handling is dubious here (unwraps), but that's probably fine for an internal attribute.
// Just don't write incorrect attributes <3

let mut fallback = None;
let mut block = None;

let items = tcx
.get_attr(CRATE_DEF_ID, sym::rustc_never_type_options)
.map(|attr| attr.meta_item_list().unwrap())
.unwrap_or_default();

for item in items {
if item.has_name(sym::fallback) && fallback.is_none() {
let mode = item.value_str().unwrap();
match mode {
sym::unit => fallback = Some(FallbackToUnit),
sym::niko => fallback = Some(FallbackToNiko),
sym::never => fallback = Some(FallbackToNever),
sym::no => fallback = Some(NoFallback),
_ => {
tcx.dcx().span_err(item.span(), format!("unknown never type fallback mode: `{mode}` (supported: `unit`, `niko`, `never` and `no`)"));
}
};
continue;
}

if item.has_name(sym::diverging_block_default) && fallback.is_none() {
let mode = item.value_str().unwrap();
match mode {
sym::unit => block = Some(DivergingBlockBehavior::Unit),
sym::never => block = Some(DivergingBlockBehavior::Never),
_ => {
tcx.dcx().span_err(item.span(), format!("unknown diverging block default: `{mode}` (supported: `unit` and `never`)"));
}
};
continue;
}

tcx.dcx().span_err(
item.span(),
format!(
"unknown never type option: `{}` (supported: `fallback`)",
item.name_or_empty()
),
);
}

let fallback = fallback.unwrap_or_else(|| {
if tcx.features().never_type_fallback { FallbackToNiko } else { FallbackToUnit }
});

let block = block.unwrap_or_default();

(fallback, block)
}
11 changes: 6 additions & 5 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ symbols! {
FromResidual,
FsOpenOptions,
FsPermissions,
FusedIterator,
Future,
FutureOutput,
GlobalAlloc,
Expand Down Expand Up @@ -690,6 +691,7 @@ symbols! {
dispatch_from_dyn,
div,
div_assign,
diverging_block_default,
do_not_recommend,
doc,
doc_alias,
Expand Down Expand Up @@ -815,9 +817,7 @@ symbols! {
fadd_algebraic,
fadd_fast,
fake_variadic,
fallback_to_never,
fallback_to_niko,
fallback_to_unit,
fallback,
fdiv_algebraic,
fdiv_fast,
feature,
Expand Down Expand Up @@ -886,6 +886,7 @@ symbols! {
fsub_algebraic,
fsub_fast,
fundamental,
fused_iterator,
future,
future_trait,
gdb_script_file,
Expand Down Expand Up @@ -1228,6 +1229,7 @@ symbols! {
new_v1,
new_v1_formatted,
next,
niko,
nll,
no,
no_builtins,
Expand All @@ -1236,7 +1238,6 @@ symbols! {
no_crate_inject,
no_debug,
no_default_passes,
no_fallback,
no_implicit_prelude,
no_inline,
no_link,
Expand Down Expand Up @@ -1554,7 +1555,7 @@ symbols! {
rustc_mir,
rustc_must_implement_one_of,
rustc_never_returns_null_ptr,
rustc_never_type_mode,
rustc_never_type_options,
rustc_no_mir_inline,
rustc_nonnull_optimization_guaranteed,
rustc_nounwind,
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_trait_selection/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ pub(super) trait GoalKind<'tcx>:
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx>;

/// A coroutine (that comes from a `gen` desugaring) is known to implement
/// `FusedIterator`
fn consider_builtin_fused_iterator_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx>;

fn consider_builtin_async_iterator_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand Down Expand Up @@ -497,6 +504,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
G::consider_builtin_future_candidate(self, goal)
} else if lang_items.iterator_trait() == Some(trait_def_id) {
G::consider_builtin_iterator_candidate(self, goal)
} else if lang_items.fused_iterator_trait() == Some(trait_def_id) {
G::consider_builtin_fused_iterator_candidate(self, goal)
} else if lang_items.async_iterator_trait() == Some(trait_def_id) {
G::consider_builtin_async_iterator_candidate(self, goal)
} else if lang_items.coroutine_trait() == Some(trait_def_id) {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
)
}

fn consider_builtin_fused_iterator_candidate(
_ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> {
bug!("`FusedIterator` does not have an associated type: {:?}", goal);
}

fn consider_builtin_async_iterator_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
Expand Down
Loading
Loading