[{"data":1,"prerenderedAt":1761},["ShallowReactive",2],{"page-\u002Frust\u002F01-introduction-and-setup":3},{"id":4,"title":5,"body":6,"description":1716,"extension":1755,"meta":1756,"navigation":39,"path":1757,"seo":1758,"stem":1759,"__hash__":1760},"content\u002Frust\u002F01-introduction-and-setup.md","01 — Introduction & Setup",{"type":7,"value":8,"toc":1715},"minimark",[9,13,116,226,297,384,437,528,639,732,796,877,954,1065,1148,1257,1332,1408,1468,1538,1631],[10,11,5],"h1",{"id":12},"_01-introduction-setup",[14,15,16,26,63],"question-wrapper",{},[17,18,20,21,25],"h3",{"id":19},"q1-what-is-rustup-primarily-responsible-for","Q1. What is ",[22,23,24],"code",{},"rustup"," primarily responsible for?",[27,28,31,42,48,57],"ul",{"className":29},[30],"contains-task-list",[32,33,36,41],"li",{"className":34},[35],"task-list-item",[37,38],"input",{"disabled":39,"type":40},true,"checkbox"," Compiling Rust source files into binaries",[32,43,45,47],{"className":44},[35],[37,46],{"disabled":39,"type":40}," Managing Rust toolchain installations (stable\u002Fbeta\u002Fnightly) and their components",[32,49,51,53,54],{"className":50},[35],[37,52],{"disabled":39,"type":40}," Managing project dependencies declared in ",[22,55,56],{},"Cargo.toml",[32,58,60,62],{"className":59},[35],[37,61],{"disabled":39,"type":40}," Formatting Rust source code according to style guidelines",[64,65,66,70,78],"details",{},[67,68,69],"summary",{},"Show Answer",[71,72,73,77],"p",{},[74,75,76],"strong",{},"Answer:"," B — Managing Rust toolchain installations (stable\u002Fbeta\u002Fnightly) and their components",[71,79,80,83,84,86,87,90,91,94,95,98,99,102,103,105,106,108,109,112,113,115],{},[74,81,82],{},"Explanation:"," ",[22,85,24],{}," is the toolchain multiplexer\u002Finstaller — it installs and switches between ",[22,88,89],{},"rustc","\u002F",[22,92,93],{},"cargo"," versions and channels, and manages components like ",[22,96,97],{},"clippy"," or ",[22,100,101],{},"rust-src",". Compiling source is ",[22,104,89],{},"'s job (A), managing dependencies is ",[22,107,93],{},"'s job (C), and formatting is ",[22,110,111],{},"rustfmt","'s job (D) — ",[22,114,24],{}," sits a layer above all of these tools rather than performing their work itself.",[14,117,118,130,174],{},[17,119,121,122,125,126,129],{"id":120},"q2-a-developer-runs-rustc-mainrs-directly-instead-of-using-cargo-build-what-is-the-main-practical-difference-for-a-project-with-dependencies","Q2. A developer runs ",[22,123,124],{},"rustc main.rs"," directly instead of using ",[22,127,128],{},"cargo build",". What is the main practical difference for a project with dependencies?",[27,131,133,141,152,163],{"className":132},[30],[32,134,136,138,139],{"className":135},[35],[37,137],{"disabled":39,"type":40}," There is no difference — both resolve crates listed in ",[22,140,56],{},[32,142,144,83,146,148,149,151],{"className":143},[35],[37,145],{"disabled":39,"type":40},[22,147,89],{}," compiles a single file\u002Fcrate root and has no knowledge of ",[22,150,56],{}," dependencies, so external crates won't be found",[32,153,155,83,157,159,160,162],{"className":154},[35],[37,156],{"disabled":39,"type":40},[22,158,89],{}," is strictly for nightly builds while ",[22,161,128],{}," is stable-only",[32,164,166,83,168,170,171],{"className":165},[35],[37,167],{"disabled":39,"type":40},[22,169,124],{}," will automatically download and link any crates used with ",[22,172,173],{},"use",[64,175,176,178,187],{},[67,177,69],{},[71,179,180,182,183,148,185,151],{},[74,181,76],{}," B — ",[22,184,89],{},[22,186,56],{},[71,188,189,83,191,193,194,196,197,199,200,202,203,90,205,208,209,211,212,215,216,219,220,222,223,225],{},[74,190,82],{},[22,192,89],{}," is the raw compiler; it takes a crate root and emits an artifact, but it has no concept of ",[22,195,56],{},", dependency resolution, or crates.io. ",[22,198,93],{}," wraps ",[22,201,89],{},", resolving dependencies from ",[22,204,56],{},[22,206,207],{},"Cargo.lock"," and invoking ",[22,210,89],{}," with the correct ",[22,213,214],{},"--extern"," flags. ",[74,217,218],{},"Idiom:"," running bare ",[22,221,89],{}," is fine for a single throwaway file, but any real project needs ",[22,224,93],{}," to manage dependencies.",[14,227,228,236,263],{},[17,229,231,232,235],{"id":230},"q3-as-of-rust-2024-what-edition-does-cargo-new-my_project-select-by-default-when-using-a-current-stable-toolchain","Q3. As of Rust 2024, what edition does ",[22,233,234],{},"cargo new my_project"," select by default when using a current stable toolchain?",[27,237,239,245,251,257],{"className":238},[30],[32,240,242,244],{"className":241},[35],[37,243],{"disabled":39,"type":40}," 2015, for backward compatibility",[32,246,248,250],{"className":247},[35],[37,249],{"disabled":39,"type":40}," 2018",[32,252,254,256],{"className":253},[35],[37,255],{"disabled":39,"type":40}," 2021",[32,258,260,262],{"className":259},[35],[37,261],{"disabled":39,"type":40}," 2024",[64,264,265,267,272],{},[67,266,69],{},[71,268,269,271],{},[74,270,76],{}," D — 2024",[71,273,274,83,276,279,280,282,283,286,287,289,290,293,294,296],{},[74,275,82],{},[22,277,278],{},"cargo new"," writes the newest stable edition supported by the installed toolchain into ",[22,281,56],{},"'s ",[22,284,285],{},"edition"," field. Since the 2024 edition shipped, current ",[22,288,93],{}," defaults new projects to ",[22,291,292],{},"edition = \"2024\"",". Older answers (2015\u002F2018\u002F2021) were correct defaults at earlier points in Rust's history but are not current — the edition a project targets is fixed by what's written in ",[22,295,56],{},", not by which compiler happens to build it later.",[14,298,299,303,339],{},[17,300,302],{"id":301},"q4-what-command-installs-a-specific-nightly-toolchain-and-sets-it-as-the-default-for-the-current-shelluser","Q4. What command installs a specific nightly toolchain and sets it as the default for the current shell\u002Fuser?",[27,304,306,314,322,331],{"className":305},[30],[32,307,309,83,311],{"className":308},[35],[37,310],{"disabled":39,"type":40},[22,312,313],{},"cargo install nightly",[32,315,317,83,319],{"className":316},[35],[37,318],{"disabled":39,"type":40},[22,320,321],{},"rustup toolchain add nightly",[32,323,325,83,327,330],{"className":324},[35],[37,326],{"disabled":39,"type":40},[22,328,329],{},"rustup default nightly"," (after nothing else)",[32,332,334,83,336],{"className":333},[35],[37,335],{"disabled":39,"type":40},[22,337,338],{},"rustup install nightly && rustup default nightly",[64,340,341,343,350],{},[67,342,69],{},[71,344,345,347,348],{},[74,346,76],{}," D — ",[22,349,338],{},[71,351,352,83,354,357,358,361,362,364,365,367,368,371,372,376,377,379,380,383],{},[74,353,82],{},[22,355,356],{},"rustup install nightly"," (alias for ",[22,359,360],{},"rustup toolchain install nightly",") downloads the nightly toolchain, and ",[22,363,329],{}," makes it the active default. ",[22,366,321],{}," alone (C-style option) only installs it without switching the default. ",[22,369,370],{},"cargo install"," (A) installs Rust ",[373,374,375],"em",{},"binaries\u002Fcrates",", not toolchains — a common beginner mix-up since both start with \"install\". Running ",[22,378,329],{}," with nothing installed first (C) will still work because ",[22,381,382],{},"rustup default"," implicitly installs if missing, but it's not the most explicit\u002Fidiomatic pairing shown here.",[14,385,386,390,421],{},[17,387,389],{"id":388},"q5-which-statement-correctly-distinguishes-the-stable-beta-and-nightly-release-channels","Q5. Which statement correctly distinguishes the stable, beta, and nightly release channels?",[27,391,393,399,409,415],{"className":392},[30],[32,394,396,398],{"className":395},[35],[37,397],{"disabled":39,"type":40}," Beta is for experimental features, nightly is the well-tested production channel",[32,400,402,404,405,408],{"className":401},[35],[37,403],{"disabled":39,"type":40}," Nightly gets new unstable features first and allows ",[22,406,407],{},"#![feature(...)]"," flags; beta is a preview of the next stable release; stable is the production-recommended channel",[32,410,412,414],{"className":411},[35],[37,413],{"disabled":39,"type":40}," Stable and nightly are identical except for release cadence",[32,416,418,420],{"className":417},[35],[37,419],{"disabled":39,"type":40}," Beta only receives security patches, while stable receives new features",[64,422,423,425,432],{},[67,424,69],{},[71,426,427,429,430,408],{},[74,428,76],{}," B — Nightly gets new unstable features first and allows ",[22,431,407],{},[71,433,434,436],{},[74,435,82],{}," Rust ships a new nightly every day (unstable, feature-gated APIs allowed), promotes a nightly to beta roughly every six weeks as a release candidate, and promotes beta to stable after another six weeks. Option A inverts the roles, and option D describes something closer to an LTS\u002Fsecurity-only model, which Rust's channels do not follow.",[14,438,439,447,487],{},[17,440,442,443,446],{"id":441},"q6-what-does-rustup-component-add-clippy-do","Q6. What does ",[22,444,445],{},"rustup component add clippy"," do?",[27,448,450,461,470,478],{"className":449},[30],[32,451,453,455,456,458,459],{"className":452},[35],[37,454],{"disabled":39,"type":40}," Installs the ",[22,457,97],{}," crate as a project dependency in ",[22,460,56],{},[32,462,464,466,467,469],{"className":463},[35],[37,465],{"disabled":39,"type":40}," Adds the ",[22,468,97],{}," lint tool as an available component for the currently active toolchain",[32,471,473,475,476],{"className":472},[35],[37,474],{"disabled":39,"type":40}," Switches the active toolchain to a Clippy-specific fork of ",[22,477,89],{},[32,479,481,483,484,486],{"className":480},[35],[37,482],{"disabled":39,"type":40}," Enables Clippy lints globally for all future ",[22,485,128],{}," invocations automatically",[64,488,489,491,498],{},[67,490,69],{},[71,492,493,495,496,469],{},[74,494,76],{}," B — Adds the ",[22,497,97],{},[71,499,500,502,503,505,506,505,508,505,510,513,514,517,518,521,522,524,525,527],{},[74,501,82],{}," Components (",[22,504,97],{},", ",[22,507,111],{},[22,509,101],{},[22,511,512],{},"rust-analyzer",", etc.) are optional pieces bundled per toolchain; ",[22,515,516],{},"rustup component add"," fetches and enables one for the active toolchain, after which ",[22,519,520],{},"cargo clippy"," becomes available. It is not a project dependency (A) and does not run automatically during ",[22,523,128],{}," (D) — you must explicitly invoke ",[22,526,520],{},".",[14,529,530,545,599],{},[17,531,533,534,537,538,541,542,544],{"id":532},"q7-running-cargo-version-and-rustc-version-on-a-machine-with-rustup-installed-can-show-two-different-underlying-toolchain-versions-why-might-this-legitimately-happen","Q7. Running ",[22,535,536],{},"cargo --version"," and ",[22,539,540],{},"rustc --version"," on a machine with ",[22,543,24],{}," installed can show two different underlying toolchain versions. Why might this legitimately happen?",[27,546,548,559,570,591],{"className":547},[30],[32,549,551,553,554,537,556,558],{"className":550},[35],[37,552],{"disabled":39,"type":40}," It can't happen — ",[22,555,93],{},[22,557,89],{}," are always bundled from the exact same toolchain release",[32,560,562,83,564,566,567,569],{"className":561},[35],[37,563],{"disabled":39,"type":40},[22,565,93],{}," is versioned independently of ",[22,568,89],{}," and is always one major version behind",[32,571,573,575,576,98,579,582,583,90,585,587,588,590],{"className":572},[35],[37,574],{"disabled":39,"type":40}," A per-directory ",[22,577,578],{},"rustup override",[22,580,581],{},"rust-toolchain.toml"," can pin a different toolchain than the global default, and ",[22,584,93],{},[22,586,89],{}," are invoked through ",[22,589,24],{},"'s shims which resolve the toolchain per-invocation",[32,592,594,83,596,598],{"className":593},[35],[37,595],{"disabled":39,"type":40},[22,597,540],{}," always reports the nightly version regardless of the active toolchain",[64,600,601,603,618],{},[67,602,69],{},[71,604,605,607,608,98,610,582,612,90,614,587,616,590],{},[74,606,76],{}," C — A per-directory ",[22,609,578],{},[22,611,581],{},[22,613,93],{},[22,615,89],{},[22,617,24],{},[71,619,620,622,623,537,625,627,628,630,631,633,634,537,636,638],{},[74,621,82],{}," Both ",[22,624,93],{},[22,626,89],{}," on the PATH are actually ",[22,629,24],{}," \"proxy\" shims that decide which real toolchain to invoke based on directory overrides, ",[22,632,581],{},", environment variables, then the global default — so version drift between two separate shell sessions\u002Fdirectories is expected and normal, not a bug. Within a single resolved toolchain, ",[22,635,93],{},[22,637,89],{}," do ship together as a matched pair, contradicting the premise that cargo runs \"one major version behind\" (B).",[14,640,641,658,702],{},[17,642,644,645,647,648,651,652,654,655,657],{"id":643},"q8-a-ci-pipeline-pins-rust-toolchaintoml-with-channel-1720-but-a-contributor-has-only-nightly-installed-locally-via-rustup-what-happens-when-they-run-cargo-build-in-that-directory","Q8. A CI pipeline pins ",[22,646,581],{}," with ",[22,649,650],{},"channel = \"1.72.0\"",", but a contributor has only nightly installed locally via ",[22,653,24],{},". What happens when they run ",[22,656,128],{}," in that directory?",[27,659,661,669,675,687],{"className":660},[30],[32,662,664,83,666,668],{"className":663},[35],[37,665],{"disabled":39,"type":40},[22,667,93],{}," silently falls back to their installed nightly toolchain",[32,670,672,674],{"className":671},[35],[37,673],{"disabled":39,"type":40}," The build fails immediately with a \"no default toolchain configured\" panic",[32,676,678,83,680,682,683,686],{"className":677},[35],[37,679],{"disabled":39,"type":40},[22,681,24],{}," automatically downloads and installs the pinned 1.72.0 toolchain (if ",[22,684,685],{},"auto-install"," is enabled, the default), then uses it for that directory",[32,688,690,83,692,694,695,697,698,701],{"className":689},[35],[37,691],{"disabled":39,"type":40},[22,693,128],{}," ignores ",[22,696,581],{}," unless ",[22,699,700],{},"--locked"," is passed",[64,703,704,706,715],{},[67,705,69],{},[71,707,708,710,711,682,713,686],{},[74,709,76],{}," C — ",[22,712,24],{},[22,714,685],{},[71,716,717,83,719,721,722,724,725,728,729,731],{},[74,718,82],{},[22,720,581],{}," overrides toolchain selection for anyone building inside that directory tree; by default ",[22,723,24],{}," will fetch the missing pinned toolchain automatically rather than silently using whatever is already installed. ",[74,726,727],{},"Portability:"," this is precisely why teams commit ",[22,730,581],{}," — it makes builds reproducible across machines regardless of what each developer happened to install, avoiding the silent-fallback trap in option A which would produce version-dependent, non-reproducible builds.",[14,733,734,742,773],{},[17,735,737,738,741],{"id":736},"q9-a-file-uses-featurelet_chains-at-the-crate-root-and-is-compiled-with-the-default-stable-toolchain-what-happens","Q9. A file uses ",[22,739,740],{},"#![feature(let_chains)]"," at the crate root and is compiled with the default stable toolchain. What happens?",[27,743,745,751,761,767],{"className":744},[30],[32,746,748,750],{"className":747},[35],[37,749],{"disabled":39,"type":40}," It compiles fine — feature flags are just documentation comments to the stable compiler",[32,752,754,756,757,760],{"className":753},[35],[37,755],{"disabled":39,"type":40}," Compile error: ",[22,758,759],{},"#![feature]"," attributes are only permitted on a nightly compiler",[32,762,764,766],{"className":763},[35],[37,765],{"disabled":39,"type":40}," It compiles but emits a deprecation warning",[32,768,770,772],{"className":769},[35],[37,771],{"disabled":39,"type":40}," It silently disables the named feature and continues compiling the rest of the file",[64,774,775,777,784],{},[67,776,69],{},[71,778,779,781,782,760],{},[74,780,76],{}," B — Compile error: ",[22,783,759],{},[71,785,786,788,789,791,792,795],{},[74,787,82],{}," Unstable feature gates are only recognized on the nightly channel; stable and beta compilers reject ",[22,790,407],{}," with a hard error (",[22,793,794],{},"error[E0554]: #![feature] may not be used on the stable release channel","). This is a deliberate stability guarantee — it stops unstable APIs from leaking into code that ships on stable, unlike the tempting but incorrect assumption in A that unknown attributes are just ignored.",[14,797,798,810,846],{},[17,799,801,802,805,806,809],{"id":800},"q10-inside-projectsexperimental-a-developer-runs-rustup-override-set-nightly-what-is-the-scope-of-this-change","Q10. Inside ",[22,803,804],{},"~\u002Fprojects\u002Fexperimental\u002F",", a developer runs ",[22,807,808],{},"rustup override set nightly",". What is the scope of this change?",[27,811,813,819,828,838],{"className":812},[30],[32,814,816,818],{"className":815},[35],[37,817],{"disabled":39,"type":40}," It permanently changes the global default toolchain for the whole system",[32,820,822,824,825,827],{"className":821},[35],[37,823],{"disabled":39,"type":40}," It only affects that one ",[22,826,128],{}," invocation and resets afterward",[32,829,831,833,834,837],{"className":830},[35],[37,832],{"disabled":39,"type":40}," It pins the ",[22,835,836],{},"experimental"," directory (and its subdirectories) to nightly, leaving the global default and other directories untouched",[32,839,841,843,844],{"className":840},[35],[37,842],{"disabled":39,"type":40}," It has no effect unless combined with ",[22,845,329],{},[64,847,848,850,857],{},[67,849,69],{},[71,851,852,854,855,837],{},[74,853,76],{}," C — It pins the ",[22,856,836],{},[71,858,859,83,861,864,865,867,868,870,871,873,874,876],{},[74,860,82],{},[22,862,863],{},"rustup override set"," writes a directory-scoped override (tracked internally by ",[22,866,24],{},", independent of ",[22,869,581],{},") that takes precedence over the global default only within that directory tree. It does not touch ",[22,872,382],{}," (A) — a beginner might assume overrides are global since ",[22,875,382],{}," sounds similar, but the two are deliberately separate mechanisms for different scopes.",[14,878,879,890,925],{},[17,880,882,883,886,887,889],{"id":881},"q11-a-team-upgrades-a-crate-from-the-2018-edition-to-the-2021-edition-by-editing-edition-2021-in-cargotoml-with-no-other-changes-what-is-the-safest-correct-process-and-why","Q11. A team upgrades a crate from the 2018 edition to the 2021 edition by editing ",[22,884,885],{},"edition = \"2021\""," in ",[22,888,56],{}," with no other changes. What is the safest correct process, and why?",[27,891,893,899,905,919],{"className":892},[30],[32,894,896,898],{"className":895},[35],[37,897],{"disabled":39,"type":40}," Editing the field alone is always sufficient and risk-free since editions are purely cosmetic",[32,900,902,904],{"className":901},[35],[37,903],{"disabled":39,"type":40}," Editions require a full rewrite in a new crate, since old syntax is entirely rejected",[32,906,908,910,911,914,915,918],{"className":907},[35],[37,909],{"disabled":39,"type":40}," Run ",[22,912,913],{},"cargo fix --edition"," first to migrate idiom-affecting changes (e.g. array ",[22,916,917],{},"IntoIterator"," behavior, disjoint closure captures), then set the edition and verify tests pass",[32,920,922,924],{"className":921},[35],[37,923],{"disabled":39,"type":40}," Editions cannot be upgraded incrementally; you must vendor the entire dependency tree first",[64,926,927,929,938],{},[67,928,69],{},[71,930,931,933,934,914,936,918],{},[74,932,76],{}," C — Run ",[22,935,913],{},[22,937,917],{},[71,939,940,942,943,946,947,949,950,953],{},[74,941,82],{}," Editions are Rust's mechanism for introducing small, deliberately-scoped breaking changes (e.g. ",[22,944,945],{},"into_iter()"," on arrays yielding values instead of references since 2021) without splitting the ecosystem; ",[22,948,913],{}," automates most of the mechanical migration. Editions are ",[373,951,952],{},"not"," purely cosmetic (A is a tempting but wrong simplification) — real behavioral differences exist, which is exactly why blind field-editing without testing can silently change runtime behavior.",[14,955,956,980,1021],{},[17,957,959,960,647,962,537,965,968,969,971,972,974,975,90,977,979],{"id":958},"q12-a-repositorys-root-contains-a-rust-toolchaintoml-with-channel-stable-and-components-clippy-rustfmt-a-contributor-runs-cargo-build-without-ever-running-rustup-component-add-what-happens-to-clippyrustfmt-availability","Q12. A repository's root contains a ",[22,961,581],{},[22,963,964],{},"channel = \"stable\"",[22,966,967],{},"components = [\"clippy\", \"rustfmt\"]",". A contributor runs ",[22,970,128],{}," without ever running ",[22,973,516],{},". What happens to ",[22,976,97],{},[22,978,111],{}," availability?",[27,981,983,992,1000,1006],{"className":982},[30],[32,984,986,988,989,991],{"className":985},[35],[37,987],{"disabled":39,"type":40}," Nothing — ",[22,990,581],{}," only affects the channel, never components",[32,993,995,83,997,999],{"className":994},[35],[37,996],{"disabled":39,"type":40},[22,998,24],{}," installs the listed components automatically as part of resolving the pinned toolchain for that directory",[32,1001,1003,1005],{"className":1002},[35],[37,1004],{"disabled":39,"type":40}," The build fails because required components are missing",[32,1007,1009,1011,1012,1014,1015,1017,1018],{"className":1008},[35],[37,1010],{"disabled":39,"type":40}," Components listed in ",[22,1013,581],{}," are ignored unless ",[22,1016,93],{}," is run with ",[22,1019,1020],{},"--all-features",[64,1022,1023,1025,1031],{},[67,1024,69],{},[71,1026,1027,182,1029,999],{},[74,1028,76],{},[22,1030,24],{},[71,1032,1033,1035,1036,1039,1040,1042,1043,505,1046,505,1049,1052,1053,1056,1057,1059,1060,90,1062,1064],{},[74,1034,82],{}," The ",[22,1037,1038],{},"[toolchain]"," table in ",[22,1041,581],{}," can declare ",[22,1044,1045],{},"channel",[22,1047,1048],{},"components",[22,1050,1051],{},"targets",", and ",[22,1054,1055],{},"profile","; ",[22,1058,24],{}," provisions all of them automatically the first time the toolchain is resolved in that directory, so a fresh clone gets a fully working ",[22,1061,97],{},[22,1063,111],{}," setup with zero manual steps. This is a widely underused feature — many assume (incorrectly, option A) that the file only pins the compiler version.",[14,1066,1067,1081,1122],{},[17,1068,1070,1071,1074,1075,1077,1078,1080],{"id":1069},"q13-a-crate-declares-rust-version-170-msrv-in-cargotoml-a-contributor-on-rust-165-stable-runs-cargo-build-what-happens","Q13. A crate declares ",[22,1072,1073],{},"rust-version = \"1.70\""," (MSRV) in ",[22,1076,56],{},". A contributor on Rust 1.65 stable runs ",[22,1079,128],{},". What happens?",[27,1082,1084,1096,1105,1116],{"className":1083},[30],[32,1085,1087,83,1089,1091,1092,1095],{"className":1086},[35],[37,1088],{"disabled":39,"type":40},[22,1090,93],{}," silently ignores ",[22,1093,1094],{},"rust-version"," — it's purely informational metadata shown on crates.io, so the build proceeds normally on 1.65",[32,1097,1099,1101,1102,1104],{"className":1098},[35],[37,1100],{"disabled":39,"type":40}," Since Rust 1.65 supports MSRV-aware resolution for the ",[22,1103,1094],{}," field itself in newer cargo versions, and if the code actually uses syntax\u002FAPIs from 1.70, compilation fails with errors about unrecognized syntax or missing items — cargo does not downgrade language features for you",[32,1106,1108,83,1110,1112,1113,1115],{"className":1107},[35],[37,1109],{"disabled":39,"type":40},[22,1111,93],{}," automatically installs Rust 1.70 via ",[22,1114,24],{}," to satisfy the requirement",[32,1117,1119,1121],{"className":1118},[35],[37,1120],{"disabled":39,"type":40}," The build always fails immediately with an MSRV violation error before any compilation is attempted, regardless of what language features are actually used",[64,1123,1124,1126,1131],{},[67,1125,69],{},[71,1127,1128,1130],{},[74,1129,76],{}," B — If the code actually uses syntax\u002FAPIs from 1.70, compilation fails with errors about unrecognized syntax or missing items; cargo does not downgrade language features for you",[71,1132,1133,83,1135,1137,1138,1141,1142,1144,1145,1147],{},[74,1134,82],{},[22,1136,1094],{}," is primarily advisory metadata (and, in newer cargo, can influence dependency version resolution to prefer MSRV-compatible versions), but it does not make cargo auto-install a compiler (C) or hard-fail purely on the declared number (D) — the ",[373,1139,1140],{},"actual"," failure, if any, comes from the older ",[22,1143,89],{}," genuinely not understanding newer syntax or standard library items used in the code. ",[74,1146,727],{}," MSRV mismatches are a common real-world CI trap — the fix is either raising the contributor's toolchain or avoiding the newer language feature in the crate.",[14,1149,1150,1171,1218],{},[17,1151,1153,1154,1156,1157,1160,1161,1163,1164,1167,1168,1170],{"id":1152},"q14-what-happens-if-you-run-rustc-on-a-rs-file-that-has-zero-use-statements-and-a-fn-main-body-with-no-cargotoml-anywhere-nearby","Q14. What happens if you run ",[22,1155,89],{}," on a ",[22,1158,1159],{},".rs"," file that has zero ",[22,1162,173],{}," statements and a ",[22,1165,1166],{},"fn main() {}"," body, with no ",[22,1169,56],{}," anywhere nearby?",[27,1172,1174,1186,1195,1208],{"className":1173},[30],[32,1175,1177,1179,1180,1182,1183,1185],{"className":1176},[35],[37,1178],{"disabled":39,"type":40}," It fails because ",[22,1181,89],{}," always requires a ",[22,1184,56],{}," to know the crate name",[32,1187,1189,1191,1192,1194],{"className":1188},[35],[37,1190],{"disabled":39,"type":40}," It compiles successfully — ",[22,1193,89],{}," can compile a standalone file into a binary using only the standard library, entirely independent of Cargo",[32,1196,1198,1179,1200,1203,1204,1207],{"className":1197},[35],[37,1199],{"disabled":39,"type":40},[22,1201,1202],{},"main.rs"," must live inside a ",[22,1205,1206],{},"src\u002F"," directory",[32,1209,1211,1213,1214,1217],{"className":1210},[35],[37,1212],{"disabled":39,"type":40}," It compiles but produces a ",[22,1215,1216],{},".rlib"," instead of an executable by default",[64,1219,1220,1222,1229],{},[67,1221,69],{},[71,1223,1224,1226,1227,1194],{},[74,1225,76],{}," B — It compiles successfully; ",[22,1228,89],{},[71,1230,1231,83,1233,1235,1236,1239,1240,1243,1244,1246,1247,1249,1250,1252,1253,1256],{},[74,1232,82],{},[22,1234,89],{}," predates and does not require Cargo at all — Cargo is a build-system\u002Fpackage-manager layered on top. A bare ",[22,1237,1238],{},"rustc file.rs"," with only ",[22,1241,1242],{},"std"," usage compiles to an executable by default (binary crate type), with no ",[22,1245,1206],{}," directory or ",[22,1248,56],{}," requirement. Option D confuses the default crate-type: ",[22,1251,1216],{}," output only happens if you pass ",[22,1254,1255],{},"--crate-type=lib"," explicitly.",[14,1258,1259,1263,1308],{},[17,1260,1262],{"id":1261},"q15-which-is-the-recommended-way-to-install-rust-on-a-development-machine-and-why","Q15. Which is the recommended way to install Rust on a development machine, and why?",[27,1264,1266,1281,1290,1299],{"className":1265},[30],[32,1267,1269,1271,1272,537,1274,1276,1277,1280],{"className":1268},[35],[37,1270],{"disabled":39,"type":40}," Install ",[22,1273,89],{},[22,1275,93],{}," separately via the OS package manager (e.g. ",[22,1278,1279],{},"apt install rustc cargo","), since it's pre-integrated with system libraries",[32,1282,1284,1286,1287,1289],{"className":1283},[35],[37,1285],{"disabled":39,"type":40}," Use ",[22,1288,24],{},", since it manages multiple toolchains\u002Fchannels, supports per-project overrides, and keeps the toolchain easily updatable independent of the OS release cycle",[32,1291,1293,1295,1296,1298],{"className":1292},[35],[37,1294],{"disabled":39,"type":40}," Manually download prebuilt ",[22,1297,89],{}," binaries from GitHub Releases and add them to PATH",[32,1300,1302,1304,1305,1307],{"className":1301},[35],[37,1303],{"disabled":39,"type":40}," Compile ",[22,1306,89],{}," from source on first install for maximum compatibility",[64,1309,1310,1312,1319],{},[67,1311,69],{},[71,1313,1314,1316,1317,1289],{},[74,1315,76],{}," B — Use ",[22,1318,24],{},[71,1320,1321,83,1323,1325,1326,1328,1329,1331],{},[74,1322,82],{},[22,1324,24],{}," is the officially recommended installer specifically because OS package managers (A) often ship an outdated, single, system-wide Rust version tied to the distro's release cadence, making per-project toolchain pinning and quick updates painful. ",[74,1327,218],{}," professional Rust workflows almost universally standardize on ",[22,1330,24],{}," for exactly this flexibility, reserving OS packages mainly for minimal container images where a single fixed version is acceptable.",[14,1333,1334,1338,1381],{},[17,1335,1337],{"id":1336},"q16-for-a-team-that-wants-every-contributor-and-ci-runner-to-build-with-the-exact-same-compiler-version-automatically-what-is-the-best-practice-setup","Q16. For a team that wants every contributor and CI runner to build with the exact same compiler version automatically, what is the best-practice setup?",[27,1339,1341,1347,1359,1371],{"className":1340},[30],[32,1342,1344,1346],{"className":1343},[35],[37,1345],{"disabled":39,"type":40}," Document the required version in the README and trust contributors to install it manually",[32,1348,1350,1352,1353,1355,1356,1358],{"className":1349},[35],[37,1351],{"disabled":39,"type":40}," Commit a ",[22,1354,581],{}," file with a pinned ",[22,1357,1045],{}," value at the repository root",[32,1360,1362,1364,1365,1367,1368,1370],{"className":1361},[35],[37,1363],{"disabled":39,"type":40}," Add a ",[22,1366,1094],{}," field to ",[22,1369,56],{}," only",[32,1372,1374,1376,1377,1380],{"className":1373},[35],[37,1375],{"disabled":39,"type":40}," Require everyone to run ",[22,1378,1379],{},"rustup update"," before every build",[64,1382,1383,1385,1394],{},[67,1384,69],{},[71,1386,1387,1389,1390,1355,1392,1358],{},[74,1388,76],{}," B — Commit a ",[22,1391,581],{},[22,1393,1045],{},[71,1395,1396,1398,1399,1401,1402,1404,1405,1407],{},[74,1397,82],{}," Committing ",[22,1400,581],{}," makes toolchain pinning automatic and enforced by tooling rather than relying on documentation discipline (A, easy to go stale) or ",[22,1403,1094],{}," (C, which is advisory\u002FMSRV-oriented, not a hard pin — it doesn't force a specific compiler, just declares a floor). ",[22,1406,1379],{}," (D) does the opposite of pinning — it moves everyone to the latest, which can introduce drift between machines.",[14,1409,1410,1417,1447],{},[17,1411,1413,1414,1416],{"id":1412},"q17-a-library-needs-an-unstable-standard-library-api-only-available-via-feature-on-nightly-what-is-the-idiomatic-recommendation-for-a-crate-intended-for-wide-production-use","Q17. A library needs an unstable standard library API only available via ",[22,1415,407],{}," on nightly. What is the idiomatic recommendation for a crate intended for wide production use?",[27,1418,1420,1426,1432,1438],{"className":1419},[30],[32,1421,1423,1425],{"className":1422},[35],[37,1424],{"disabled":39,"type":40}," Ship it requiring nightly permanently, since nightly is functionally a superset of stable and equally safe for production",[32,1427,1429,1431],{"className":1428},[35],[37,1430],{"disabled":39,"type":40}," Avoid the unstable feature and find a stable-compatible alternative (or gate the nightly-only code path behind an optional feature flag), since requiring nightly forces every downstream consumer onto an unstable, less API-stable compiler",[32,1433,1435,1437],{"className":1434},[35],[37,1436],{"disabled":39,"type":40}," Vendor a copy of the nightly compiler inside the crate's repository",[32,1439,1441,1443,1444,1446],{"className":1440},[35],[37,1442],{"disabled":39,"type":40}," Silently use the feature without any ",[22,1445,407],{}," gate since stable compilers permit unstable APIs on crates.io",[64,1448,1449,1451,1456],{},[67,1450,69],{},[71,1452,1453,1455],{},[74,1454,76],{}," B — Avoid the unstable feature and find a stable-compatible alternative (or gate the nightly-only code path behind an optional feature flag), since requiring nightly forces every downstream consumer onto an unstable, less API-stable compiler",[71,1457,1458,1460,1461,1464,1465,1467],{},[74,1459,82],{}," Widely-used production crates generally avoid hard nightly requirements because nightly's unstable APIs can change or disappear between releases with no deprecation guarantee, unlike stable's strict backward-compatibility promise. Option A is the tempting trap: nightly ",[373,1462,1463],{},"does"," include everything stable has, but \"superset\" doesn't mean \"equally safe\" — the unstable portion is explicitly unguaranteed. Option D is simply false: ",[22,1466,759],{}," gates are mandatory and stable rejects them outright (see Q9).",[14,1469,1470,1474,1513],{},[17,1471,1473],{"id":1472},"q18-when-rust-ships-a-new-edition-eg-2024-what-is-the-recommended-migration-workflow-for-an-existing-crate","Q18. When Rust ships a new edition (e.g. 2024), what is the recommended migration workflow for an existing crate?",[27,1475,1477,1488,1494,1507],{"className":1476},[30],[32,1478,1480,1482,1483,886,1485,1487],{"className":1479},[35],[37,1481],{"disabled":39,"type":40}," Immediately bump ",[22,1484,285],{},[22,1486,56],{}," with no other action, then fix whatever compile errors appear",[32,1489,1491,1493],{"className":1490},[35],[37,1492],{"disabled":39,"type":40}," Never adopt new editions — staying on the original edition forever is the safest long-term choice",[32,1495,1497,910,1499,1501,1502,886,1504,1506],{"className":1496},[35],[37,1498],{"disabled":39,"type":40},[22,1500,913],{}," on the current edition first to apply automated migrations, review the diff, then update ",[22,1503,285],{},[22,1505,56],{},", and finally run the full test suite",[32,1508,1510,1512],{"className":1509},[35],[37,1511],{"disabled":39,"type":40}," Rewrite the crate from scratch targeting the new edition",[64,1514,1515,1517,1527],{},[67,1516,69],{},[71,1518,1519,933,1521,1501,1523,886,1525,1506],{},[74,1520,76],{},[22,1522,913],{},[22,1524,285],{},[22,1526,56],{},[71,1528,1529,83,1531,1533,1534,1537],{},[74,1530,82],{},[22,1532,913],{}," is purpose-built to mechanically apply the safe, known migrations for the ",[373,1535,1536],{},"next"," edition before you actually switch, minimizing manual breakage — jumping straight to editing the field (A) skips this safety net and can leave silent behavioral differences uncaught by the compiler (e.g., changes to closure capture or iterator semantics that compile fine both ways but behave differently). Staying on an old edition forever (B) is a legitimate but conservative choice, not the generally recommended one, since crates interop across editions within a dependency graph anyway.",[14,1539,1540,1547,1592],{},[17,1541,1543,1544,1546],{"id":1542},"q19-what-is-the-idiomatic-way-to-check-code-style-and-common-mistakes-beyond-what-rustc-itself-reports-before-opening-a-pull-request","Q19. What is the idiomatic way to check code style and common mistakes beyond what ",[22,1545,89],{}," itself reports, before opening a pull request?",[27,1548,1550,1562,1577,1583],{"className":1549},[30],[32,1551,1553,1555,1556,1558,1559,1561],{"className":1552},[35],[37,1554],{"disabled":39,"type":40}," Rely solely on ",[22,1557,128],{}," warnings, since ",[22,1560,89],{}," already reports every stylistic and logic issue",[32,1563,1565,910,1567,1570,1571,1573,1574],{"className":1564},[35],[37,1566],{"disabled":39,"type":40},[22,1568,1569],{},"cargo fmt"," to format and ",[22,1572,520],{}," to lint, both installed via ",[22,1575,1576],{},"rustup component add rustfmt clippy",[32,1578,1580,1582],{"className":1579},[35],[37,1581],{"disabled":39,"type":40}," Manually re-read the diff for style issues; automated linting is unnecessary in Rust",[32,1584,1586,1286,1588,1591],{"className":1585},[35],[37,1587],{"disabled":39,"type":40},[22,1589,1590],{},"rustc --lint-all"," as a single command that replaces both formatting and linting",[64,1593,1594,1596,1607],{},[67,1595,69],{},[71,1597,1598,1600,1601,1570,1603,1573,1605],{},[74,1599,76],{}," B — Run ",[22,1602,1569],{},[22,1604,520],{},[22,1606,1576],{},[71,1608,1609,83,1611,1613,1614,1616,1617,1620,1621,1624,1625,1627,1628,1630],{},[74,1610,82],{},[22,1612,89],{},"'s built-in warnings focus on correctness\u002Fsoundness, not style or idiom; ",[22,1615,97],{}," catches a much broader class of stylistic, performance, and common-mistake lints (e.g. needless clones, ",[22,1618,1619],{},".unwrap()"," on ",[22,1622,1623],{},"Result"," in non-test code), while ",[22,1626,111],{}," enforces consistent formatting. ",[22,1629,1590],{}," (D) is not a real flag — a plausible-sounding distractor for anyone assuming the compiler alone covers everything.",[14,1632,1633,1644,1677],{},[17,1634,1636,1637,1639,1640,1643],{"id":1635},"q20-a-developer-notices-cargo-build-debug-profile-produces-a-binary-that-runs-noticeably-slower-than-cargo-build-release-what-best-practice-conclusion-should-they-draw","Q20. A developer notices ",[22,1638,128],{}," (debug profile) produces a binary that runs noticeably slower than ",[22,1641,1642],{},"cargo build --release",". What best-practice conclusion should they draw?",[27,1645,1647,1653,1663,1671],{"className":1646},[30],[32,1648,1650,1652],{"className":1649},[35],[37,1651],{"disabled":39,"type":40}," This indicates a compiler bug and should be reported immediately",[32,1654,1656,1658,1659,1662],{"className":1655},[35],[37,1657],{"disabled":39,"type":40}," Debug builds intentionally skip most optimizations and include extra runtime checks (like overflow checks) to prioritize fast compile times and better debugging; use ",[22,1660,1661],{},"--release"," for performance testing and production artifacts, and the default debug profile for day-to-day development iteration",[32,1664,1666,83,1668,1670],{"className":1665},[35],[37,1667],{"disabled":39,"type":40},[22,1669,1661],{}," only changes the output file name, not actual compiled behavior",[32,1672,1674,1676],{"className":1673},[35],[37,1675],{"disabled":39,"type":40}," Debug and release builds are functionally identical except for binary size",[64,1678,1679,1681,1688],{},[67,1680,69],{},[71,1682,1683,1685,1686,1662],{},[74,1684,76],{}," B — Debug builds intentionally skip most optimizations and include extra runtime checks (like overflow checks) to prioritize fast compile times and better debugging; use ",[22,1687,1661],{},[71,1689,1690,1035,1692,1695,1696,1699,1700,1703,1704,1707,1708,1711,1712,1714],{},[74,1691,82],{},[22,1693,1694],{},"dev"," (default) profile favors compile speed and debuggability (",[22,1697,1698],{},"opt-level = 0",", overflow checks on, debug symbols included), while ",[22,1701,1702],{},"release"," enables optimizations (",[22,1705,1706],{},"opt-level = 3"," by default) and disables overflow checks, trading compile time for runtime speed. ",[74,1709,1710],{},"Performance:"," always benchmark and ship with ",[22,1713,1661],{}," — never draw performance conclusions, and never ship to production, using unoptimized debug builds, since the \"slowness\" observed here is expected behavior, not a defect (ruling out option A).",{"title":1716,"searchDepth":1717,"depth":1717,"links":1718},"",2,[1719,1722,1724,1726,1727,1728,1730,1732,1734,1736,1738,1740,1742,1744,1746,1747,1748,1750,1751,1753],{"id":19,"depth":1720,"text":1721},3,"Q1. What is rustup primarily responsible for?",{"id":120,"depth":1720,"text":1723},"Q2. A developer runs rustc main.rs directly instead of using cargo build. What is the main practical difference for a project with dependencies?",{"id":230,"depth":1720,"text":1725},"Q3. As of Rust 2024, what edition does cargo new my_project select by default when using a current stable toolchain?",{"id":301,"depth":1720,"text":302},{"id":388,"depth":1720,"text":389},{"id":441,"depth":1720,"text":1729},"Q6. What does rustup component add clippy do?",{"id":532,"depth":1720,"text":1731},"Q7. Running cargo --version and rustc --version on a machine with rustup installed can show two different underlying toolchain versions. Why might this legitimately happen?",{"id":643,"depth":1720,"text":1733},"Q8. A CI pipeline pins rust-toolchain.toml with channel = \"1.72.0\", but a contributor has only nightly installed locally via rustup. What happens when they run cargo build in that directory?",{"id":736,"depth":1720,"text":1735},"Q9. A file uses #![feature(let_chains)] at the crate root and is compiled with the default stable toolchain. What happens?",{"id":800,"depth":1720,"text":1737},"Q10. Inside ~\u002Fprojects\u002Fexperimental\u002F, a developer runs rustup override set nightly. What is the scope of this change?",{"id":881,"depth":1720,"text":1739},"Q11. A team upgrades a crate from the 2018 edition to the 2021 edition by editing edition = \"2021\" in Cargo.toml with no other changes. What is the safest correct process, and why?",{"id":958,"depth":1720,"text":1741},"Q12. A repository's root contains a rust-toolchain.toml with channel = \"stable\" and components = [\"clippy\", \"rustfmt\"]. A contributor runs cargo build without ever running rustup component add. What happens to clippy\u002Frustfmt availability?",{"id":1069,"depth":1720,"text":1743},"Q13. A crate declares rust-version = \"1.70\" (MSRV) in Cargo.toml. A contributor on Rust 1.65 stable runs cargo build. What happens?",{"id":1152,"depth":1720,"text":1745},"Q14. What happens if you run rustc on a .rs file that has zero use statements and a fn main() {} body, with no Cargo.toml anywhere nearby?",{"id":1261,"depth":1720,"text":1262},{"id":1336,"depth":1720,"text":1337},{"id":1412,"depth":1720,"text":1749},"Q17. A library needs an unstable standard library API only available via #![feature(...)] on nightly. What is the idiomatic recommendation for a crate intended for wide production use?",{"id":1472,"depth":1720,"text":1473},{"id":1542,"depth":1720,"text":1752},"Q19. What is the idiomatic way to check code style and common mistakes beyond what rustc itself reports, before opening a pull request?",{"id":1635,"depth":1720,"text":1754},"Q20. A developer notices cargo build (debug profile) produces a binary that runs noticeably slower than cargo build --release. What best-practice conclusion should they draw?","md",{},"\u002Frust\u002F01-introduction-and-setup",{"title":5,"description":1716},"rust\u002F01-introduction-and-setup","kxgLBL5APfr6-eUNMjut2naImjz63-a09htBPHAixpA",1787335398334]