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 7 pull requests #95827

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
39bff4b
don't report int/float ambiguity when we have previous errors
compiler-errors Apr 7, 2022
2f46de2
Add current_thread_unique_ptr() in std::sys_common.
m-ou-se Apr 6, 2022
619163e
Add futex-based ReentrantMutex on Linux.
m-ou-se Apr 6, 2022
d5e0eaf
Make current_thread_unique_ptr work during thread destruction.
m-ou-se Apr 6, 2022
6888fb1
Move current_thread_unique_ptr to the only module that uses it.
m-ou-se Apr 6, 2022
dc82718
Initialize thread local with const{}.
m-ou-se Apr 6, 2022
aeb01c3
Add debug asserts to futex ReentrantMutex impl.
m-ou-se Apr 6, 2022
0664b8a
Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).
m-ou-se Apr 6, 2022
5974c18
[macro_metavar_expr] Add tests to ensure the feature requirement
c410-f3r Apr 7, 2022
d0cc986
check_doc_keyword: don't alloc string for emptiness check
klensy Apr 5, 2022
43d0497
Fix invalid array access in `beautify_doc_string`
GuillaumeGomez Apr 8, 2022
5e8bd9b
Add test for empty doc comments with a backline
GuillaumeGomez Apr 8, 2022
1040cab
WIP PROOF-OF-CONCEPT: Make the compiler complain about all int<->ptr …
Gankra Mar 21, 2022
98a4834
Split `fuzzy_provenance_casts` into lossy and fuzzy, feature gate and…
niluxv Apr 2, 2022
f6c7f10
Remove extra space before a where clause in the documentation
Urgau Apr 8, 2022
c5693d3
Rollup merge of #95599 - niluxv:strict-provenance-lint, r=michaelwoer…
Dylan-DPC Apr 8, 2022
b367ce8
Rollup merge of #95697 - klensy:no-strings, r=petrochenkov
Dylan-DPC Apr 8, 2022
66b3081
Rollup merge of #95727 - m-ou-se:futex-reentrantmutex, r=Amanieu
Dylan-DPC Apr 8, 2022
8b5a795
Rollup merge of #95751 - compiler-errors:ambig-int, r=jackh726
Dylan-DPC Apr 8, 2022
7328ae9
Rollup merge of #95764 - c410-f3r:metavar-test, r=petrochenkov
Dylan-DPC Apr 8, 2022
1a0aaee
Rollup merge of #95804 - GuillaumeGomez:empty-doc-comment-with-backli…
Dylan-DPC Apr 8, 2022
00c3d88
Rollup merge of #95813 - Urgau:rustdoc-where-clause-space, r=Guillaum…
Dylan-DPC Apr 8, 2022
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
5 changes: 4 additions & 1 deletion compiler/rustc_ast/src/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
// when we try to compute the "horizontal trim".
let lines = if kind == CommentKind::Block {
// Whatever happens, we skip the first line.
let mut i = if lines[0].trim_start().starts_with('*') { 0 } else { 1 };
let mut i = lines
.get(0)
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
.unwrap_or(0);
let mut j = lines.len();

while i < j && lines[i].trim().is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn expand_compile_error<'cx>(
return DummyResult::any(sp);
};

cx.span_err(sp, &var);
cx.span_err(sp, var.as_str());

DummyResult::any(sp)
}
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn expand_option_env<'cx>(
};

let sp = cx.with_def_site_ctxt(sp);
let value = env::var(&var.as_str()).ok().as_deref().map(Symbol::intern);
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((Symbol::intern(&var), value));
let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
let e = match value {
None => {
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn expand_include<'cx>(
return DummyResult::any(sp);
};
// The file will be added to the code map by the parser
let file = match resolve_path(cx, file, sp) {
let file = match resolve_path(cx, file.as_str(), sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn expand_include_str(
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_str!") else {
return DummyResult::any(sp);
};
let file = match resolve_path(cx, file, sp) {
let file = match resolve_path(cx, file.as_str(), sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
Expand Down Expand Up @@ -210,7 +210,7 @@ pub fn expand_include_bytes(
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_bytes!") else {
return DummyResult::any(sp);
};
let file = match resolve_path(cx, file, sp) {
let file = match resolve_path(cx, file.as_str(), sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ fn load_imported_symbols_for_jit(
match data[cnum.as_usize() - 1] {
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
Linkage::Static => {
let name = &crate_info.crate_name[&cnum];
let mut err = sess.struct_err(&format!("Can't load static lib {}", name.as_str()));
let name = crate_info.crate_name[&cnum];
let mut err = sess.struct_err(&format!("Can't load static lib {}", name));
err.note("rustc_codegen_cranelift can only load dylibs in JIT mode.");
err.emit();
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn each_linked_rlib(
Some(_) => {}
None => return Err("could not find formats for rlibs".to_string()),
}
let name = &info.crate_name[&cnum];
let name = info.crate_name[&cnum];
let used_crate_source = &info.used_crate_source[&cnum];
if let Some((path, _)) = &used_crate_source.rlib {
f(cnum, &path);
Expand Down Expand Up @@ -467,7 +467,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
let mut all_native_libs = vec![];

let res = each_linked_rlib(&codegen_results.crate_info, &mut |cnum, path| {
let name = &codegen_results.crate_info.crate_name[&cnum];
let name = codegen_results.crate_info.crate_name[&cnum];
let native_libs = &codegen_results.crate_info.native_libraries[&cnum];

// Here when we include the rlib into our staticlib we need to make a
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ impl CrateInfo {
for &cnum in crates.iter() {
info.native_libraries
.insert(cnum, tcx.native_libraries(cnum).iter().map(Into::into).collect());
info.crate_name.insert(cnum, tcx.crate_name(cnum).to_string());
info.crate_name.insert(cnum, tcx.crate_name(cnum));
info.used_crate_source.insert(cnum, tcx.used_crate_source(cnum).clone());
if tcx.is_compiler_builtins(cnum) {
info.compiler_builtins = Some(cnum);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct CrateInfo {
pub profiler_runtime: Option<CrateNum>,
pub is_no_builtins: FxHashSet<CrateNum>,
pub native_libraries: FxHashMap<CrateNum, Vec<NativeLib>>,
pub crate_name: FxHashMap<CrateNum, String>,
pub crate_name: FxHashMap<CrateNum, Symbol>,
pub used_libraries: Vec<NativeLib>,
pub used_crate_source: FxHashMap<CrateNum, Lrc<CrateSource>>,
pub used_crates: Vec<CrateNum>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ pub fn get_single_str_from_tts(
sp: Span,
tts: TokenStream,
name: &str,
) -> Option<String> {
) -> Option<Symbol> {
let mut p = cx.new_parser_from_tts(tts);
if p.token == token::Eof {
cx.span_err(sp, &format!("{} takes 1 argument", name));
Expand All @@ -1233,7 +1233,7 @@ pub fn get_single_str_from_tts(
if p.token != token::Eof {
cx.span_err(sp, &format!("{} takes 1 argument", name));
}
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s.to_string())
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s)
}

/// Extracts comma-separated expressions from `tts`.
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ declare_features! (
(active, static_nobundle, "1.16.0", Some(37403), None),
/// Allows attributes on expressions and non-item statements.
(active, stmt_expr_attributes, "1.6.0", Some(15701), None),
/// Allows lints part of the strict provenance effort.
(active, strict_provenance, "1.61.0", Some(95228), None),
/// Allows the use of `#[target_feature]` on safe functions.
(active, target_feature_11, "1.45.0", Some(69098), None),
/// Allows using `#[thread_local]` on `static` items.
Expand Down
23 changes: 9 additions & 14 deletions compiler/rustc_incremental/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
//! was re-used.

use rustc_ast as ast;
use rustc_data_structures::stable_set::FxHashSet;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
use rustc_middle::ty::TyCtxt;
use rustc_session::cgu_reuse_tracker::*;
use rustc_span::symbol::{sym, Symbol};
use std::collections::BTreeSet;

#[allow(missing_docs)]
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
Expand All @@ -36,12 +36,8 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
return;
}

let available_cgus = tcx
.collect_and_partition_mono_items(())
.1
.iter()
.map(|cgu| cgu.name().to_string())
.collect::<BTreeSet<String>>();
let available_cgus =
tcx.collect_and_partition_mono_items(()).1.iter().map(|cgu| cgu.name()).collect();

let ams = AssertModuleSource { tcx, available_cgus };

Expand All @@ -53,7 +49,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {

struct AssertModuleSource<'tcx> {
tcx: TyCtxt<'tcx>,
available_cgus: BTreeSet<String>,
available_cgus: FxHashSet<Symbol>,
}

impl<'tcx> AssertModuleSource<'tcx> {
Expand Down Expand Up @@ -124,18 +120,17 @@ impl<'tcx> AssertModuleSource<'tcx> {

debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name);

if !self.available_cgus.contains(cgu_name.as_str()) {
if !self.available_cgus.contains(&cgu_name) {
let mut cgu_names: Vec<&str> =
self.available_cgus.iter().map(|cgu| cgu.as_str()).collect();
cgu_names.sort();
self.tcx.sess.span_err(
attr.span,
&format!(
"no module named `{}` (mangled: {}). Available modules: {}",
user_path,
cgu_name,
self.available_cgus
.iter()
.map(|cgu| cgu.to_string())
.collect::<Vec<_>>()
.join(", ")
cgu_names.join(", ")
),
);
}
Expand Down
92 changes: 92 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,96 @@ declare_lint! {
};
}

declare_lint! {
/// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
/// and a pointer.
///
/// ### Example
///
/// ```rust
/// #![feature(strict_provenance)]
/// #![warn(fuzzy_provenance_casts)]
///
/// fn main() {
/// let _dangling = 16_usize as *const u8;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint is part of the strict provenance effort, see [issue #95228].
/// Casting an integer to a pointer is considered bad style, as a pointer
/// contains, besides the *address* also a *provenance*, indicating what
/// memory the pointer is allowed to read/write. Casting an integer, which
/// doesn't have provenance, to a pointer requires the compiler to assign
/// (guess) provenance. The compiler assigns "all exposed valid" (see the
/// docs of [`ptr::from_exposed_addr`] for more information about this
/// "exposing"). This penalizes the optimiser and is not well suited for
/// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
/// platforms).
///
/// It is much better to use [`ptr::with_addr`] instead to specify the
/// provenance you want. If using this function is not possible because the
/// code relies on exposed provenance then there is as an escape hatch
/// [`ptr::from_exposed_addr`].
///
/// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
/// [`ptr::with_addr`]: https://doc.rust-lang.org/core/ptr/fn.with_addr
/// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr
pub FUZZY_PROVENANCE_CASTS,
Allow,
"a fuzzy integer to pointer cast is used",
@feature_gate = sym::strict_provenance;
}

declare_lint! {
/// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
/// and an integer.
///
/// ### Example
///
/// ```rust
/// #![feature(strict_provenance)]
/// #![warn(lossy_provenance_casts)]
///
/// fn main() {
/// let x: u8 = 37;
/// let _addr: usize = &x as *const u8 as usize;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint is part of the strict provenance effort, see [issue #95228].
/// Casting a pointer to an integer is a lossy operation, because beyond
/// just an *address* a pointer may be associated with a particular
/// *provenance*. This information is used by the optimiser and for dynamic
/// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
///
/// Since this cast is lossy, it is considered good style to use the
/// [`ptr::addr`] method instead, which has a similar effect, but doesn't
/// "expose" the pointer provenance. This improves optimisation potential.
/// See the docs of [`ptr::addr`] and [`ptr::expose_addr`] for more information
/// about exposing pointer provenance.
///
/// If your code can't comply with strict provenance and needs to expose
/// the provenance, then there is [`ptr::expose_addr`] as an escape hatch,
/// which preserves the behaviour of `as usize` casts while being explicit
/// about the semantics.
///
/// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
/// [`ptr::addr`]: https://doc.rust-lang.org/core/ptr/fn.addr
/// [`ptr::expose_addr`]: https://doc.rust-lang.org/core/ptr/fn.expose_addr
pub LOSSY_PROVENANCE_CASTS,
Allow,
"a lossy pointer to integer cast is used",
@feature_gate = sym::strict_provenance;
}

declare_lint! {
/// The `const_evaluatable_unchecked` lint detects a generic constant used
/// in a type.
Expand Down Expand Up @@ -3101,6 +3191,8 @@ declare_lint_pass! {
UNSAFE_OP_IN_UNSAFE_FN,
INCOMPLETE_INCLUDE,
CENUM_IMPL_DROP_CAST,
FUZZY_PROVENANCE_CASTS,
LOSSY_PROVENANCE_CASTS,
CONST_EVALUATABLE_UNCHECKED,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
MUST_NOT_SUSPEND,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::ItemLocalId;
use rustc_macros::HashStable;
use rustc_span::symbol::Symbol;

#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
pub enum Region {
Expand All @@ -23,7 +24,7 @@ pub enum Region {
pub enum LifetimeScopeForPath {
// Contains all lifetime names that are in scope and could possibly be used in generics
// arguments of path.
NonElided(Vec<String>),
NonElided(Vec<Symbol>),

// Information that allows us to suggest args of the form `<'_>` in case
// no generic arguments were provided for a path.
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ fn write_scope_tree(
}
indented_decl.push(';');

let local_name =
if local == RETURN_PLACE { " return place".to_string() } else { String::new() };
let local_name = if local == RETURN_PLACE { " return place" } else { "" };

writeln!(
w,
Expand Down
Loading