Skip to content

Commit f8c27df

Browse files
committedMar 24, 2025·
Auto merge of rust-lang#138901 - matthiaskrgr:rollup-qbbanhr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#138662 (Implement some basics in UEFI fs) - rust-lang#138800 (remove remnants of const_box feature) - rust-lang#138821 (match lowering cleanup: remove unused unsizing logic from `non_scalar_compare`) - rust-lang#138864 (Rework `--print` options documentation) - rust-lang#138868 (Add do_not_recommend typo help) - rust-lang#138882 (`with_scope` is only ever used for ast modules) - rust-lang#138894 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4510e86 + 4202bf9 commit f8c27df

File tree

14 files changed

+342
-190
lines changed

14 files changed

+342
-190
lines changed
 

‎compiler/rustc_middle/src/thir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@ pub enum PatKind<'tcx> {
800800
},
801801

802802
/// One of the following:
803-
/// * `&str`/`&[u8]` (represented as a valtree), which will be handled as a string/slice pattern
804-
/// and thus exhaustiveness checking will detect if you use the same string/slice twice in
805-
/// different patterns.
803+
/// * `&str` (represented as a valtree), which will be handled as a string pattern and thus
804+
/// exhaustiveness checking will detect if you use the same string twice in different
805+
/// patterns.
806806
/// * integer, bool, char or float (represented as a valtree), which will be handled by
807807
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
808808
/// much simpler.

‎compiler/rustc_mir_build/src/builder/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,8 @@ enum TestKind<'tcx> {
13261326
Eq {
13271327
value: Const<'tcx>,
13281328
// Integer types are handled by `SwitchInt`, and constants with ADT
1329-
// types are converted back into patterns, so this can only be `&str`,
1330-
// `&[T]`, `f32` or `f64`.
1329+
// types and `&[T]` types are converted back into patterns, so this can
1330+
// only be `&str`, `f32` or `f64`.
13311331
ty: Ty<'tcx>,
13321332
},
13331333

‎compiler/rustc_mir_build/src/builder/matches/test.rs

+19-89
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::sync::Arc;
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_hir::{LangItem, RangeEnd};
1313
use rustc_middle::mir::*;
14-
use rustc_middle::ty::adjustment::PointerCoercion;
1514
use rustc_middle::ty::util::IntTypeExt;
1615
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt};
1716
use rustc_middle::{bug, span_bug};
@@ -178,21 +177,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178177
_ => {}
179178
}
180179

180+
assert_eq!(expect_ty, ty);
181181
if !ty.is_scalar() {
182182
// Use `PartialEq::eq` instead of `BinOp::Eq`
183183
// (the binop can only handle primitives)
184-
self.non_scalar_compare(
184+
// Make sure that we do *not* call any user-defined code here.
185+
// The only type that can end up here is string literals, which have their
186+
// comparison defined in `core`.
187+
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
188+
// on the `PartialEq` impl for `str` to b correct!)
189+
match *ty.kind() {
190+
ty::Ref(_, deref_ty, _) if deref_ty == self.tcx.types.str_ => {}
191+
_ => {
192+
span_bug!(source_info.span, "invalid type for non-scalar compare: {ty}")
193+
}
194+
};
195+
self.string_compare(
185196
block,
186197
success_block,
187198
fail_block,
188199
source_info,
189200
expect,
190-
expect_ty,
191201
Operand::Copy(place),
192-
ty,
193202
);
194203
} else {
195-
assert_eq!(expect_ty, ty);
196204
self.compare(
197205
block,
198206
success_block,
@@ -370,97 +378,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
370378
);
371379
}
372380

373-
/// Compare two values using `<T as std::compare::PartialEq>::eq`.
374-
/// If the values are already references, just call it directly, otherwise
375-
/// take a reference to the values first and then call it.
376-
fn non_scalar_compare(
381+
/// Compare two values of type `&str` using `<str as std::cmp::PartialEq>::eq`.
382+
fn string_compare(
377383
&mut self,
378384
block: BasicBlock,
379385
success_block: BasicBlock,
380386
fail_block: BasicBlock,
381387
source_info: SourceInfo,
382-
mut expect: Operand<'tcx>,
383-
expect_ty: Ty<'tcx>,
384-
mut val: Operand<'tcx>,
385-
mut ty: Ty<'tcx>,
388+
expect: Operand<'tcx>,
389+
val: Operand<'tcx>,
386390
) {
387-
// If we're using `b"..."` as a pattern, we need to insert an
388-
// unsizing coercion, as the byte string has the type `&[u8; N]`.
389-
//
390-
// We want to do this even when the scrutinee is a reference to an
391-
// array, so we can call `<[u8]>::eq` rather than having to find an
392-
// `<[u8; N]>::eq`.
393-
let unsize = |ty: Ty<'tcx>| match ty.kind() {
394-
ty::Ref(region, rty, _) => match rty.kind() {
395-
ty::Array(inner_ty, n) => Some((region, inner_ty, n)),
396-
_ => None,
397-
},
398-
_ => None,
399-
};
400-
let opt_ref_ty = unsize(ty);
401-
let opt_ref_test_ty = unsize(expect_ty);
402-
match (opt_ref_ty, opt_ref_test_ty) {
403-
// nothing to do, neither is an array
404-
(None, None) => {}
405-
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
406-
let tcx = self.tcx;
407-
// make both a slice
408-
ty = Ty::new_imm_ref(tcx, *region, Ty::new_slice(tcx, *elem_ty));
409-
if opt_ref_ty.is_some() {
410-
let temp = self.temp(ty, source_info.span);
411-
self.cfg.push_assign(
412-
block,
413-
source_info,
414-
temp,
415-
Rvalue::Cast(
416-
CastKind::PointerCoercion(
417-
PointerCoercion::Unsize,
418-
CoercionSource::Implicit,
419-
),
420-
val,
421-
ty,
422-
),
423-
);
424-
val = Operand::Copy(temp);
425-
}
426-
if opt_ref_test_ty.is_some() {
427-
let slice = self.temp(ty, source_info.span);
428-
self.cfg.push_assign(
429-
block,
430-
source_info,
431-
slice,
432-
Rvalue::Cast(
433-
CastKind::PointerCoercion(
434-
PointerCoercion::Unsize,
435-
CoercionSource::Implicit,
436-
),
437-
expect,
438-
ty,
439-
),
440-
);
441-
expect = Operand::Move(slice);
442-
}
443-
}
444-
}
445-
446-
// Figure out the type on which we are calling `PartialEq`. This involves an extra wrapping
447-
// reference: we can only compare two `&T`, and then compare_ty will be `T`.
448-
// Make sure that we do *not* call any user-defined code here.
449-
// The only types that can end up here are string and byte literals,
450-
// which have their comparison defined in `core`.
451-
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
452-
// on the `PartialEq` impls for `str` and `[u8]` to b correct!)
453-
let compare_ty = match *ty.kind() {
454-
ty::Ref(_, deref_ty, _)
455-
if deref_ty == self.tcx.types.str_ || deref_ty != self.tcx.types.u8 =>
456-
{
457-
deref_ty
458-
}
459-
_ => span_bug!(source_info.span, "invalid type for non-scalar compare: {}", ty),
460-
};
461-
391+
let str_ty = self.tcx.types.str_;
462392
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
463-
let method = trait_method(self.tcx, eq_def_id, sym::eq, [compare_ty, compare_ty]);
393+
let method = trait_method(self.tcx, eq_def_id, sym::eq, [str_ty, str_ty]);
464394

465395
let bool_ty = self.tcx.types.bool;
466396
let eq_result = self.temp(bool_ty, source_info.span);

‎compiler/rustc_resolve/src/late.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1544,20 +1544,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15441544
ret
15451545
}
15461546

1547-
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548-
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
1549-
// Move down in the graph.
1550-
let orig_module = replace(&mut self.parent_scope.module, module);
1551-
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552-
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553-
let ret = f(this);
1554-
this.parent_scope.module = orig_module;
1555-
ret
1556-
})
1547+
fn with_mod_rib<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548+
let module = self.r.expect_module(self.r.local_def_id(id).to_def_id());
1549+
// Move down in the graph.
1550+
let orig_module = replace(&mut self.parent_scope.module, module);
1551+
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552+
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553+
let ret = f(this);
1554+
this.parent_scope.module = orig_module;
1555+
ret
15571556
})
1558-
} else {
1559-
f(self)
1560-
}
1557+
})
15611558
}
15621559

15631560
fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) {
@@ -2738,7 +2735,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27382735
}
27392736

27402737
ItemKind::Mod(..) => {
2741-
self.with_scope(item.id, |this| {
2738+
self.with_mod_rib(item.id, |this| {
27422739
if mod_inner_docs {
27432740
this.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
27442741
}

‎compiler/rustc_resolve/src/macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{
2828
UNUSED_MACRO_RULES, UNUSED_MACROS,
2929
};
3030
use rustc_session::parse::feature_err;
31-
use rustc_span::edit_distance::edit_distance;
31+
use rustc_span::edit_distance::find_best_match_for_name;
3232
use rustc_span::edition::Edition;
3333
use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
3434
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
@@ -652,13 +652,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
652652
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
653653
&& let [namespace, attribute, ..] = &*path.segments
654654
&& namespace.ident.name == sym::diagnostic
655-
&& !(attribute.ident.name == sym::on_unimplemented
656-
|| attribute.ident.name == sym::do_not_recommend)
655+
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
657656
{
658-
let distance =
659-
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
660-
661-
let typo_name = distance.map(|_| sym::on_unimplemented);
657+
let typo_name = find_best_match_for_name(
658+
&[sym::on_unimplemented, sym::do_not_recommend],
659+
attribute.ident.name,
660+
Some(5),
661+
);
662662

663663
self.tcx.sess.psess.buffer_lint(
664664
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,

‎library/alloc/src/boxed.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11491149
///
11501150
/// [memory layout]: self#memory-layout
11511151
#[unstable(feature = "allocator_api", issue = "32838")]
1152-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11531152
#[inline]
1154-
pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
1153+
pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
11551154
Box(unsafe { Unique::new_unchecked(raw) }, alloc)
11561155
}
11571156

@@ -1203,9 +1202,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12031202
/// [memory layout]: self#memory-layout
12041203
#[unstable(feature = "allocator_api", issue = "32838")]
12051204
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1206-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
12071205
#[inline]
1208-
pub const unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
1206+
pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
12091207
// SAFETY: guaranteed by the caller.
12101208
unsafe { Box::from_raw_in(raw.as_ptr(), alloc) }
12111209
}
@@ -1550,9 +1548,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15501548
/// to call it as `Box::allocator(&b)` instead of `b.allocator()`. This
15511549
/// is so that there is no conflict with a method on the inner type.
15521550
#[unstable(feature = "allocator_api", issue = "32838")]
1553-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
15541551
#[inline]
1555-
pub const fn allocator(b: &Self) -> &A {
1552+
pub fn allocator(b: &Self) -> &A {
15561553
&b.1
15571554
}
15581555

@@ -1639,8 +1636,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
16391636
/// let bar = Pin::from(foo);
16401637
/// ```
16411638
#[stable(feature = "box_into_pin", since = "1.63.0")]
1642-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
1643-
pub const fn into_pin(boxed: Self) -> Pin<Self>
1639+
pub fn into_pin(boxed: Self) -> Pin<Self>
16441640
where
16451641
A: 'static,
16461642
{

‎library/std/src/sys/fs/uefi.rs

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use r_efi::protocols::file;
2+
13
use crate::ffi::OsString;
24
use crate::fmt;
35
use crate::hash::Hash;
@@ -22,7 +24,12 @@ pub struct ReadDir(!);
2224
pub struct DirEntry(!);
2325

2426
#[derive(Clone, Debug)]
25-
pub struct OpenOptions {}
27+
pub struct OpenOptions {
28+
mode: u64,
29+
append: bool,
30+
truncate: bool,
31+
create_new: bool,
32+
}
2633

2734
#[derive(Copy, Clone, Debug, Default)]
2835
pub struct FileTimes {}
@@ -141,15 +148,58 @@ impl DirEntry {
141148

142149
impl OpenOptions {
143150
pub fn new() -> OpenOptions {
144-
OpenOptions {}
151+
OpenOptions { mode: 0, append: false, create_new: false, truncate: false }
152+
}
153+
154+
pub fn read(&mut self, read: bool) {
155+
if read {
156+
self.mode |= file::MODE_READ;
157+
} else {
158+
self.mode &= !file::MODE_READ;
159+
}
160+
}
161+
162+
pub fn write(&mut self, write: bool) {
163+
if write {
164+
// Valid Combinations: Read, Read/Write, Read/Write/Create
165+
self.read(true);
166+
self.mode |= file::MODE_WRITE;
167+
} else {
168+
self.mode &= !file::MODE_WRITE;
169+
}
170+
}
171+
172+
pub fn append(&mut self, append: bool) {
173+
// Docs state that `.write(true).append(true)` has the same effect as `.append(true)`
174+
if append {
175+
self.write(true);
176+
}
177+
self.append = append;
145178
}
146179

147-
pub fn read(&mut self, _read: bool) {}
148-
pub fn write(&mut self, _write: bool) {}
149-
pub fn append(&mut self, _append: bool) {}
150-
pub fn truncate(&mut self, _truncate: bool) {}
151-
pub fn create(&mut self, _create: bool) {}
152-
pub fn create_new(&mut self, _create_new: bool) {}
180+
pub fn truncate(&mut self, truncate: bool) {
181+
self.truncate = truncate;
182+
}
183+
184+
pub fn create(&mut self, create: bool) {
185+
if create {
186+
self.mode |= file::MODE_CREATE;
187+
} else {
188+
self.mode &= !file::MODE_CREATE;
189+
}
190+
}
191+
192+
pub fn create_new(&mut self, create_new: bool) {
193+
self.create_new = create_new;
194+
}
195+
196+
#[expect(dead_code)]
197+
const fn is_mode_valid(&self) -> bool {
198+
// Valid Combinations: Read, Read/Write, Read/Write/Create
199+
self.mode == file::MODE_READ
200+
|| self.mode == (file::MODE_READ | file::MODE_WRITE)
201+
|| self.mode == (file::MODE_READ | file::MODE_WRITE | file::MODE_CREATE)
202+
}
153203
}
154204

155205
impl File {
@@ -311,12 +361,12 @@ pub fn stat(_p: &Path) -> io::Result<FileAttr> {
311361
unsupported()
312362
}
313363

314-
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
315-
unsupported()
364+
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
365+
stat(p)
316366
}
317367

318-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
319-
unsupported()
368+
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
369+
crate::path::absolute(p)
320370
}
321371

322372
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {

‎src/doc/book

Submodule book updated 203 files

‎src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [What is rustc?](what-is-rustc.md)
44
- [Command-line Arguments](command-line-arguments.md)
5+
- [Print Options](command-line-arguments/print-options.md)
56
- [Codegen Options](codegen-options/index.md)
67
- [Jobserver](jobserver.md)
78
- [Lints](lints/index.md)

‎src/doc/rustc/src/command-line-arguments.md

+1-52
Original file line numberDiff line numberDiff line change
@@ -247,58 +247,7 @@ types to stdout at the same time will result in an error.
247247
<a id="option-print"></a>
248248
## `--print`: print compiler information
249249

250-
This flag prints out various information about the compiler. This flag may be
251-
specified multiple times, and the information is printed in the order the
252-
flags are specified. Specifying a `--print` flag will usually disable the
253-
[`--emit`](#option-emit) step and will only print the requested information.
254-
The valid types of print values are:
255-
256-
- `crate-name` — The name of the crate.
257-
- `file-names` — The names of the files created by the `link` emit kind.
258-
- `sysroot` — Path to the sysroot.
259-
- `target-libdir` — Path to the target libdir.
260-
- `host-tuple` — The target-tuple string of the host compiler (e.g. `x86_64-unknown-linux-gnu`)
261-
- `cfg` — List of cfg values. See [conditional compilation] for more
262-
information about cfg values.
263-
- `target-list` — List of known targets. The target may be selected with the
264-
`--target` flag.
265-
- `target-cpus` — List of available CPU values for the current target. The
266-
target CPU may be selected with the [`-C target-cpu=val`
267-
flag](codegen-options/index.md#target-cpu).
268-
- `target-features` — List of available target features for the current
269-
target. Target features may be enabled with the [`-C target-feature=val`
270-
flag](codegen-options/index.md#target-feature). This flag is unsafe. See
271-
[known issues](targets/known-issues.md) for more details.
272-
- `relocation-models` — List of relocation models. Relocation models may be
273-
selected with the [`-C relocation-model=val`
274-
flag](codegen-options/index.md#relocation-model).
275-
- `code-models` — List of code models. Code models may be selected with the
276-
[`-C code-model=val` flag](codegen-options/index.md#code-model).
277-
- `tls-models` — List of Thread Local Storage models supported. The model may
278-
be selected with the `-Z tls-model=val` flag.
279-
- `native-static-libs` — This may be used when creating a `staticlib` crate
280-
type. If this is the only flag, it will perform a full compilation and
281-
include a diagnostic note that indicates the linker flags to use when
282-
linking the resulting static library. The note starts with the text
283-
`native-static-libs:` to make it easier to fetch the output.
284-
- `link-args` — This flag does not disable the `--emit` step. When linking,
285-
this flag causes `rustc` to print the full linker invocation in a
286-
human-readable form. This can be useful when debugging linker options. The
287-
exact format of this debugging output is not a stable guarantee, other than
288-
that it will include the linker executable and the text of each command-line
289-
argument passed to the linker.
290-
- `deployment-target` — The currently selected [deployment target] (or minimum OS version)
291-
for the selected Apple platform target. This value can be used or passed along to other
292-
components alongside a Rust build that need this information, such as C compilers.
293-
This returns rustc's minimum supported deployment target if no `*_DEPLOYMENT_TARGET` variable
294-
is present in the environment, or otherwise returns the variable's parsed value.
295-
296-
A filepath may optionally be specified for each requested information kind, in
297-
the format `--print KIND=PATH`, just like for `--emit`. When a path is
298-
specified, information will be written there instead of to stdout.
299-
300-
[conditional compilation]: ../reference/conditional-compilation.html
301-
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html
250+
This flag will allow you to set [print options](command-line-arguments/print-options.md).
302251

303252
<a id="option-g-debug"></a>
304253
## `-g`: include debug information
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Print Options
2+
3+
All of these options are passed to `rustc` via the `--print` flag.
4+
5+
Those options prints out various information about the compiler. Multiple options can be
6+
specified, and the information is printed in the order the options are specified.
7+
8+
Specifying an option will usually disable the [`--emit`](../command-line-arguments.md#option-emit)
9+
step and will only print the requested information.
10+
11+
A filepath may optionally be specified for each requested information kind, in the format
12+
`--print KIND=PATH`, just like for `--emit`. When a path is specified, information will be
13+
written there instead of to stdout.
14+
15+
## `crate-name`
16+
17+
The name of the crate.
18+
19+
Generally coming from either from the `#![crate_name = "..."]` attribute,
20+
[`--crate-name` flag](../command-line-arguments.md#option-crate-name) or the filename.
21+
22+
Example:
23+
24+
```bash
25+
$ rustc --print crate-name --crate-name my_crate a.rs
26+
my_crate
27+
```
28+
29+
## `file-names`
30+
31+
The names of the files created by the `link` emit kind.
32+
33+
## `sysroot`
34+
35+
Abosulte path to the sysroot.
36+
37+
Example (with rustup and the stable toolchain):
38+
39+
```bash
40+
$ rustc --print sysroot a.rs
41+
/home/[REDACTED]/.rustup/toolchains/stable-x86_64-unknown-linux-gnu
42+
```
43+
44+
## `target-libdir`
45+
46+
Path to the target libdir.
47+
48+
Example (with rustup and the stable toolchain):
49+
50+
```bash
51+
$ rustc --print target-libdir a.rs
52+
/home/[REDACTED]/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib
53+
```
54+
55+
## `host-tuple`
56+
57+
The target-tuple string of the host compiler.
58+
59+
Example:
60+
61+
```bash
62+
$ rustc --print host-tuple a.rs
63+
x86_64-unknown-linux-gnu
64+
```
65+
66+
Example with the `--target` flag:
67+
68+
```bash
69+
$ rustc --print host-tuple --target "armv7-unknown-linux-gnueabihf" a.rs
70+
x86_64-unknown-linux-gnu
71+
```
72+
73+
## `cfg`
74+
75+
List of cfg values. See [conditional compilation] for more information about cfg values.
76+
77+
Example (for `x86_64-unknown-linux-gnu`):
78+
79+
```bash
80+
$ rustc --print cfg a.rs
81+
debug_assertions
82+
panic="unwind"
83+
target_abi=""
84+
target_arch="x86_64"
85+
target_endian="little"
86+
target_env="gnu"
87+
target_family="unix"
88+
target_feature="fxsr"
89+
target_feature="sse"
90+
target_feature="sse2"
91+
target_has_atomic="16"
92+
target_has_atomic="32"
93+
target_has_atomic="64"
94+
target_has_atomic="8"
95+
target_has_atomic="ptr"
96+
target_os="linux"
97+
target_pointer_width="64"
98+
target_vendor="unknown"
99+
unix
100+
```
101+
102+
## `target-list`
103+
104+
List of known targets. The target may be selected with the `--target` flag.
105+
106+
## `target-cpus`
107+
108+
List of available CPU values for the current target. The target CPU may be selected with
109+
the [`-C target-cpu=val` flag](../codegen-options/index.md#target-cpu).
110+
111+
## `target-features`
112+
113+
List of available target features for the *current target*.
114+
115+
Target features may be enabled with the **unsafe**
116+
[`-C target-feature=val` flag](../codegen-options/index.md#target-feature).
117+
118+
See [known issues](../targets/known-issues.md) for more details.
119+
120+
## `relocation-models`
121+
122+
List of relocation models. Relocation models may be selected with the
123+
[`-C relocation-model=val` flag](../codegen-options/index.md#relocation-model).
124+
125+
Example:
126+
127+
```bash
128+
$ rustc --print relocation-models a.rs
129+
Available relocation models:
130+
static
131+
pic
132+
pie
133+
dynamic-no-pic
134+
ropi
135+
rwpi
136+
ropi-rwpi
137+
default
138+
```
139+
140+
## `code-models`
141+
142+
List of code models. Code models may be selected with the
143+
[`-C code-model=val` flag](../codegen-options/index.md#code-model).
144+
145+
Example:
146+
147+
```bash
148+
$ rustc --print code-models a.rs
149+
Available code models:
150+
tiny
151+
small
152+
kernel
153+
medium
154+
large
155+
```
156+
157+
## `tls-models`
158+
159+
List of Thread Local Storage models supported. The model may be selected with the
160+
`-Z tls-model=val` flag.
161+
162+
Example:
163+
164+
```bash
165+
$ rustc --print tls-models a.rs
166+
Available TLS models:
167+
global-dynamic
168+
local-dynamic
169+
initial-exec
170+
local-exec
171+
emulated
172+
```
173+
174+
## `native-static-libs`
175+
176+
This may be used when creating a `staticlib` crate type.
177+
178+
If this is the only flag, it will perform a full compilation and include a diagnostic note
179+
that indicates the linker flags to use when linking the resulting static library.
180+
181+
The note starts with the text `native-static-libs:` to make it easier to fetch the output.
182+
183+
Example:
184+
185+
```bash
186+
$ rustc --print native-static-libs --crate-type staticlib a.rs
187+
note: Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.
188+
189+
note: native-static-libs: -lgcc_s -lutil [REDACTED] -lpthread -lm -ldl -lc
190+
```
191+
192+
## `link-args`
193+
194+
This flag does not disable the `--emit` step. This can be useful when debugging linker options.
195+
196+
When linking, this flag causes `rustc` to print the full linker invocation in a human-readable
197+
form. The exact format of this debugging output is not a stable guarantee, other than that it
198+
will include the linker executable and the text of each command-line argument passed to the
199+
linker.
200+
201+
## `deployment-target`
202+
203+
The currently selected [deployment target] (or minimum OS version) for the selected Apple
204+
platform target.
205+
206+
This value can be used or passed along to other components alongside a Rust build that need
207+
this information, such as C compilers. This returns rustc's minimum supported deployment target
208+
if no `*_DEPLOYMENT_TARGET` variable is present in the environment, or otherwise returns the
209+
variable's parsed value.
210+
211+
[conditional compilation]: ../../reference/conditional-compilation.html
212+
[deployment target]: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Configuring/configuring.html

‎tests/ui/diagnostic_namespace/suggest_typos.rs

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ trait Y{}
1616
//~^^HELP an attribute with a similar name exists
1717
trait Z{}
1818

19+
#[diagnostic::dont_recommend]
20+
//~^ERROR unknown diagnostic attribute
21+
//~^^HELP an attribute with a similar name exists
22+
impl X for u8 {}
23+
1924
fn main(){}

‎tests/ui/diagnostic_namespace/suggest_typos.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ help: an attribute with a similar name exists
3737
LL | #[diagnostic::on_unimplemented]
3838
| ++
3939

40-
error: aborting due to 3 previous errors
40+
error: unknown diagnostic attribute
41+
--> $DIR/suggest_typos.rs:19:15
42+
|
43+
LL | #[diagnostic::dont_recommend]
44+
| ^^^^^^^^^^^^^^
45+
|
46+
help: an attribute with a similar name exists
47+
|
48+
LL - #[diagnostic::dont_recommend]
49+
LL + #[diagnostic::do_not_recommend]
50+
|
51+
52+
error: aborting due to 4 previous errors
4153

0 commit comments

Comments
 (0)
Please sign in to comment.