Skip to content

Commit

Permalink
Merge pull request #1139 from rust-lang/default-2024
Browse files Browse the repository at this point in the history
Make edition 2024 the default
  • Loading branch information
shepmaster authored Feb 20, 2025
2 parents f698118 + a1a782e commit 3dea54d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 70 deletions.
21 changes: 5 additions & 16 deletions compiler/base/orchestrator/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3074,11 +3074,7 @@ mod tests {
r#"fn x() { u16::try_from(1u8); }"#,
[false, false, true, true],
),
(
r#"#![feature(gen_blocks)]
fn x() { gen { yield 1u8 }; }"#,
[false, false, false, true],
),
(r#"fn x() { let gen = true; }"#, [true, true, true, false]),
];

let tests = params.into_iter().flat_map(|(code, works_in)| {
Expand All @@ -3090,7 +3086,6 @@ mod tests {
code: code.into(),
edition,
crate_type: CrateType::Library(LibraryType::Lib),
channel: Channel::Nightly, // To allow 2024 while it is unstable
..ARBITRARY_EXECUTE_REQUEST
};
let response = coordinator.execute(request).await.unwrap();
Expand Down Expand Up @@ -3524,7 +3519,6 @@ mod tests {
let req = CompileRequest {
edition,
code: SUBTRACT_CODE.into(),
channel: Channel::Nightly, // To allow 2024 while it is unstable
..ARBITRARY_HIR_REQUEST
};

Expand Down Expand Up @@ -3855,7 +3849,6 @@ mod tests {
let req = FormatRequest {
edition,
code: code.into(),
channel: Channel::Nightly, // To allow 2024 while it is unstable
..ARBITRARY_FORMAT_REQUEST
};

Expand Down Expand Up @@ -4265,14 +4258,10 @@ mod tests {
});

trait TimeoutExt: Future + Sized {
#[allow(clippy::type_complexity)]
fn with_timeout(
self,
) -> futures::future::Map<
tokio::time::Timeout<Self>,
fn(Result<Self::Output, tokio::time::error::Elapsed>) -> Self::Output,
> {
tokio::time::timeout(*TIMEOUT, self).map(|v| v.expect("The operation timed out"))
async fn with_timeout(self) -> Self::Output {
tokio::time::timeout(*TIMEOUT, self)
.await
.expect("The operation timed out")
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/spec/features/compilation_targets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

scenario "compiling a library to WebAssembly" do
editor.set <<~EOF
#[no_mangle]
#[unsafe(no_mangle)]
pub fn calculator(a: u8) -> u8 { a + 42 }
EOF

Expand Down
10 changes: 2 additions & 8 deletions tests/spec/features/editions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,16 @@

scenario "using the 2024 edition" do
editor.set <<-EOF
#![feature(gen_blocks)]
fn main() {
let mut x = gen { yield 1 };
eprintln!("{:?}", x.next());
eprintln!("{:?}", x.next());
let gen = 1;
}
EOF

in_advanced_options_menu { select '2024' }
click_on("Run")

within(:output, :stderr) do
expect(page).to have_content 'Some(1)'
expect(page).to have_content 'None'
expect(page).to have_content 'found reserved keyword `gen`'
end
end

Expand Down
2 changes: 1 addition & 1 deletion tests/spec/features/url_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

scenario "loading without code or an edition" do
visit '/'
expect(page).to have_edition('2021')
expect(page).to have_edition('2024')
end

def editor
Expand Down
7 changes: 2 additions & 5 deletions ui/frontend/AdvancedOptionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as config from './reducers/configuration';
import { Either as EitherConfig, Select as SelectConfig } from './ConfigElement';
import MenuGroup from './MenuGroup';
import * as selectors from './selectors';
import { Backtrace, Channel, Edition } from './types';
import { Backtrace, Edition } from './types';
import { useAppDispatch, useAppSelector } from './hooks';

const AdvancedOptionsMenu: React.FC = () => {
Expand All @@ -18,9 +18,6 @@ const AdvancedOptionsMenu: React.FC = () => {
const changeEdition = useCallback((e: Edition) => dispatch(config.changeEdition(e)), [dispatch]);
const changeBacktrace = useCallback((b: Backtrace) => dispatch(config.changeBacktrace(b)), [dispatch]);

const channel = useAppSelector((state) => state.configuration.channel);
const switchText = (channel !== Channel.Nightly) ? ' (will select nightly Rust)' : '';

return (
<MenuGroup title="Advanced options">
<SelectConfig
Expand All @@ -32,7 +29,7 @@ const AdvancedOptionsMenu: React.FC = () => {
<option value={Edition.Rust2015}>2015</option>
<option value={Edition.Rust2018}>2018</option>
<option value={Edition.Rust2021}>2021</option>
<option value={Edition.Rust2024}>2024{switchText}</option>
<option value={Edition.Rust2024}>2024</option>
</SelectConfig>

<EitherConfig
Expand Down
19 changes: 9 additions & 10 deletions ui/frontend/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@ import { Portal } from 'react-portal';

import { Close } from './Icon';
import { useAppDispatch, useAppSelector } from './hooks';
import { seenRustSurvey2024 } from './reducers/notifications';
import { seenRust2024IsDefault } from './reducers/notifications';
import { allowLongRun, wsExecuteKillCurrent } from './reducers/output/execute';
import * as selectors from './selectors';

import * as styles from './Notifications.module.css';

const SURVEY_URL = 'https://blog.rust-lang.org/2024/12/05/annual-survey-2024-launch.html';
const EDITION_URL = 'https://doc.rust-lang.org/edition-guide/';

const Notifications: React.FC = () => {
return (
<Portal>
<div className={styles.container}>
<RustSurvey2024Notification />
<Rust2024IsDefaultNotification />
<ExcessiveExecutionNotification />
</div>
</Portal>
);
};

const RustSurvey2024Notification: React.FC = () => {
const showIt = useAppSelector(selectors.showRustSurvey2024Selector);
const Rust2024IsDefaultNotification: React.FC = () => {
const showIt = useAppSelector(selectors.showRust2024IsDefaultSelector);

const dispatch = useAppDispatch();
const seenIt = useCallback(() => dispatch(seenRustSurvey2024()), [dispatch]);
const seenIt = useCallback(() => dispatch(seenRust2024IsDefault()), [dispatch]);

return showIt ? (
<Notification onClose={seenIt}>
Please help us take a look at who the Rust community is composed of, how the Rust project is
doing, and how we can improve the Rust programming experience by completing the{' '}
<a href={SURVEY_URL}>2024 State of Rust Survey</a>. Whether or not you use Rust today, we want
to know your opinions.
As of Rust 1.85, the default edition of Rust is now Rust 2024. Learn more about editions in
the <a href={EDITION_URL}>Edition Guide</a>. To specify which edition to use, use the advanced
compilation options menu.
</Notification>
) : null;
};
Expand Down
6 changes: 3 additions & 3 deletions ui/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { addCrateType, editCode } from './reducers/code';
import {
changeBacktrace,
changeChannel,
changeEditionRaw,
changeEdition,
changeMode,
changePrimaryAction,
} from './reducers/configuration';
Expand Down Expand Up @@ -153,7 +153,7 @@ export function indexPageLoad({
}
}

const edition = maybeEdition || Edition.Rust2021;
const edition = maybeEdition || Edition.Rust2024;

if (code) {
dispatch(editCode(code));
Expand All @@ -163,7 +163,7 @@ export function indexPageLoad({

dispatch(changeChannel(channel));
dispatch(changeMode(mode));
dispatch(changeEditionRaw(edition));
dispatch(changeEdition(edition));
};
}

Expand Down
17 changes: 3 additions & 14 deletions ui/frontend/reducers/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PayloadAction, createSlice } from '@reduxjs/toolkit';

import { ThunkAction } from '../actions';
import {
AssemblyFlavor,
Backtrace,
Expand Down Expand Up @@ -57,7 +56,7 @@ const initialState: State = {
primaryAction: PrimaryActionAuto.Auto,
channel: Channel.Stable,
mode: Mode.Debug,
edition: Edition.Rust2021,
edition: Edition.Rust2024,
backtrace: Backtrace.Disabled,
};

Expand Down Expand Up @@ -85,7 +84,7 @@ const slice = createSlice({
state.demangleAssembly = action.payload;
},

changeEditionRaw: (state, action: PayloadAction<Edition>) => {
changeEdition: (state, action: PayloadAction<Edition>) => {
state.edition = action.payload;
},

Expand Down Expand Up @@ -149,7 +148,7 @@ export const {
changeBacktrace,
changeChannel,
changeDemangleAssembly,
changeEditionRaw,
changeEdition,
changeEditor,
changeKeybinding,
changeMode,
Expand All @@ -162,14 +161,4 @@ export const {
swapTheme,
} = slice.actions;

export const changeEdition =
(edition: Edition): ThunkAction =>
(dispatch) => {
if (edition === Edition.Rust2024) {
dispatch(changeChannel(Channel.Nightly));
}

dispatch(changeEditionRaw(edition));
};

export default slice.reducer;
12 changes: 7 additions & 5 deletions ui/frontend/reducers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface State {
seenRustSurvey2022: boolean; // expired
seenRustSurvey2023: boolean; // expired
seenDarkMode: boolean; // expired
seenRustSurvey2024: boolean;
seenRustSurvey2024: boolean; // expired
seenRust2024IsDefault: boolean;
}

const initialState: State = {
Expand All @@ -25,7 +26,8 @@ const initialState: State = {
seenRustSurvey2022: true,
seenRustSurvey2023: true,
seenDarkMode: true,
seenRustSurvey2024: false,
seenRustSurvey2024: true,
seenRust2024IsDefault: false,
};

const slice = createSlice({
Expand All @@ -34,8 +36,8 @@ const slice = createSlice({
reducers: {
notificationSeen: (state, action: PayloadAction<Notification>) => {
switch (action.payload) {
case Notification.RustSurvey2024: {
state.seenRustSurvey2024 = true;
case Notification.Rust2024IsDefault: {
state.seenRust2024IsDefault = true;
break;
}
}
Expand All @@ -45,6 +47,6 @@ const slice = createSlice({

const { notificationSeen } = slice.actions;

export const seenRustSurvey2024 = () => notificationSeen(Notification.RustSurvey2024);
export const seenRust2024IsDefault = () => notificationSeen(Notification.Rust2024IsDefault);

export default slice.reducer;
12 changes: 6 additions & 6 deletions ui/frontend/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const getChannelLabel = createSelector(channelSelector, (channel) => `${c

export const isEditionDefault = createSelector(
editionSelector,
edition => edition == Edition.Rust2021,
edition => edition == Edition.Rust2024,
);

export const getBacktraceSet = (state: State) => (
Expand Down Expand Up @@ -360,15 +360,15 @@ const notificationsSelector = (state: State) => state.notifications;

const NOW = new Date();

const RUST_SURVEY_2024_END = new Date('2024-12-23T00:00:00Z');
const RUST_SURVEY_2024_OPEN = NOW <= RUST_SURVEY_2024_END;
export const showRustSurvey2024Selector = createSelector(
const RUST_2024_IS_DEFAULT_END = new Date('2025-04-03T00:00:00Z');
const RUST_2024_IS_DEFAULT_OPEN = NOW <= RUST_2024_IS_DEFAULT_END;
export const showRust2024IsDefaultSelector = createSelector(
notificationsSelector,
notifications => RUST_SURVEY_2024_OPEN && !notifications.seenRustSurvey2024,
notifications => RUST_2024_IS_DEFAULT_OPEN && !notifications.seenRust2024IsDefault,
);

export const anyNotificationsToShowSelector = createSelector(
showRustSurvey2024Selector,
showRust2024IsDefaultSelector,
excessiveExecutionSelector,
(...allNotifications) => allNotifications.some(n => n),
);
Expand Down
2 changes: 1 addition & 1 deletion ui/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ export enum Focus {
}

export enum Notification {
RustSurvey2024 = 'rust-survey-2024',
Rust2024IsDefault = 'rust-2024-is-default',
}

0 comments on commit 3dea54d

Please sign in to comment.