mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Remove unneeded code, filename from tests, fix rebasing issues
This commit is contained in:
parent
28bb8ed9cb
commit
b1992b469c
12 changed files with 85 additions and 34 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -30,7 +30,7 @@ version = "0.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
dependencies = [
|
||||
"winapi 0.3.8",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1791,7 +1791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi 0.3.8",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -27,9 +27,9 @@ use hir_ty::{
|
|||
display::{HirDisplayError, HirFormatter},
|
||||
expr::ExprValidator,
|
||||
method_resolution,
|
||||
method_resolution, ApplicationTy, Canonical, InEnvironment, Substs, TraitEnvironment, Ty,
|
||||
TyDefId, TypeCtor,
|
||||
unsafe_validation::UnsafeValidator,
|
||||
ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty,
|
||||
TyDefId, TypeCtor,
|
||||
};
|
||||
use ra_db::{CrateId, CrateName, Edition, FileId};
|
||||
use ra_prof::profile;
|
||||
|
@ -671,6 +671,10 @@ impl Function {
|
|||
db.function_data(self.id).params.clone()
|
||||
}
|
||||
|
||||
pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).is_unsafe
|
||||
}
|
||||
|
||||
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
||||
let _p = profile("Function::diagnostics");
|
||||
let infer = db.infer(self.id.into());
|
||||
|
|
|
@ -580,7 +580,6 @@ fn missing_unsafe() {
|
|||
fn missing_unsafe_diagnostic_with_unsafe_method_call() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct HasUnsafe;
|
||||
|
||||
impl HasUnsafe {
|
||||
|
@ -606,7 +605,6 @@ fn missing_unsafe() {
|
|||
fn no_missing_unsafe_diagnostic_with_raw_ptr_in_unsafe_block() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
fn nothing_to_see_move_along() {
|
||||
let x = &5 as *const usize;
|
||||
unsafe {
|
||||
|
@ -625,7 +623,6 @@ fn nothing_to_see_move_along() {
|
|||
fn missing_unsafe_diagnostic_with_raw_ptr_outside_unsafe_block() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
fn nothing_to_see_move_along() {
|
||||
let x = &5 as *const usize;
|
||||
unsafe {
|
||||
|
@ -645,7 +642,6 @@ fn nothing_to_see_move_along() {
|
|||
fn no_missing_unsafe_diagnostic_with_unsafe_call_in_unsafe_block() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
unsafe fn unsafe_fn() {
|
||||
let x = &5 as *const usize;
|
||||
let y = *x;
|
||||
|
@ -668,7 +664,6 @@ fn nothing_to_see_move_along() {
|
|||
fn no_missing_unsafe_diagnostic_with_unsafe_method_call_in_unsafe_block() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r"
|
||||
//- /lib.rs
|
||||
struct HasUnsafe;
|
||||
|
||||
impl HasUnsafe {
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{DefWithBodyId, FunctionId};
|
||||
use hir_def::{
|
||||
body::Body,
|
||||
expr::{Expr, ExprId, UnaryOp},
|
||||
DefWithBodyId, FunctionId,
|
||||
};
|
||||
use hir_expand::diagnostics::DiagnosticSink;
|
||||
|
||||
use crate::{
|
||||
|
@ -11,13 +15,6 @@ use crate::{
|
|||
InferenceResult, Ty, TypeCtor,
|
||||
};
|
||||
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use hir_def::{
|
||||
body::Body,
|
||||
expr::{Expr, ExprId, UnaryOp},
|
||||
};
|
||||
|
||||
pub struct UnsafeValidator<'a, 'b: 'a> {
|
||||
func: FunctionId,
|
||||
infer: Arc<InferenceResult>,
|
||||
|
@ -75,13 +72,9 @@ pub fn unsafe_expressions(
|
|||
def: DefWithBodyId,
|
||||
) -> Vec<UnsafeExpr> {
|
||||
let mut unsafe_exprs = vec![];
|
||||
let mut unsafe_block_exprs = FxHashSet::default();
|
||||
let body = db.body(def);
|
||||
for (id, expr) in body.exprs.iter() {
|
||||
match expr {
|
||||
Expr::Unsafe { .. } => {
|
||||
unsafe_block_exprs.insert(id);
|
||||
}
|
||||
Expr::Call { callee, .. } => {
|
||||
let ty = &infer[*callee];
|
||||
if let &Ty::Apply(ApplicationTy {
|
||||
|
|
|
@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #E28C14; }
|
||||
.operator.unsafe { color: #E28C14; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
|
|
|
@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #E28C14; }
|
||||
.operator.unsafe { color: #E28C14; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
|
|
53
crates/ra_ide/src/snapshots/highlight_unsafe.html
Normal file
53
crates/ra_ide/src/snapshots/highlight_unsafe.html
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
<style>
|
||||
body { margin: 0; }
|
||||
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
||||
|
||||
.lifetime { color: #DFAF8F; font-style: italic; }
|
||||
.comment { color: #7F9F7F; }
|
||||
.documentation { color: #629755; }
|
||||
.injected { opacity: 0.65 ; }
|
||||
.struct, .enum { color: #7CB8BB; }
|
||||
.enum_variant { color: #BDE0F3; }
|
||||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
.builtin_type { color: #8CD0D3; }
|
||||
.type_param { color: #DFAF8F; }
|
||||
.attribute { color: #94BFF3; }
|
||||
.numeric_literal { color: #BFEBBF; }
|
||||
.bool_literal { color: #BFE6EB; }
|
||||
.macro { color: #94BFF3; }
|
||||
.module { color: #AFD8AF; }
|
||||
.variable { color: #DCDCCC; }
|
||||
.format_specifier { color: #CC696B; }
|
||||
.mutable { text-decoration: underline; }
|
||||
.unresolved_reference { color: #FC5555; }
|
||||
.escape_sequence { color: #94BFF3; }
|
||||
|
||||
.keyword { color: #F0DFAF; font-weight: bold; }
|
||||
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
||||
.control { font-style: italic; }
|
||||
</style>
|
||||
<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {}
|
||||
|
||||
<span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span>;
|
||||
|
||||
<span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> {
|
||||
<span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span>(&<span class="self_keyword">self</span>) {}
|
||||
}
|
||||
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span>() {
|
||||
<span class="keyword">let</span> <span class="variable declaration">x</span> = &<span class="numeric_literal">5</span> <span class="keyword">as</span> *<span class="keyword">const</span> <span class="builtin_type">usize</span>;
|
||||
<span class="keyword unsafe">unsafe</span> {
|
||||
<span class="function unsafe">unsafe_fn</span>();
|
||||
<span class="struct">HasUnsafeFn</span>.<span class="function unsafe">unsafe_method</span>();
|
||||
<span class="keyword">let</span> <span class="variable declaration">y</span> = <span class="operator unsafe">*</span>(<span class="variable">x</span>);
|
||||
<span class="keyword">let</span> <span class="variable declaration">z</span> = -<span class="variable">x</span>;
|
||||
}
|
||||
}</code></pre>
|
|
@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #E28C14; }
|
||||
.operator.unsafe { color: #E28C14; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
|
|
|
@ -12,8 +12,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #E28C14; }
|
||||
.operator.unsafe { color: #E28C14; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
|
|
|
@ -605,7 +605,13 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
|
|||
Definition::Field(_) => HighlightTag::Field,
|
||||
Definition::ModuleDef(def) => match def {
|
||||
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
||||
hir::ModuleDef::Function(_) => HighlightTag::Function,
|
||||
hir::ModuleDef::Function(func) => {
|
||||
let mut h = HighlightTag::Function.into();
|
||||
if func.is_unsafe(db) {
|
||||
h |= HighlightModifier::Unsafe;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
|
||||
hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
|
||||
hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
|
||||
|
|
|
@ -71,8 +71,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
.string_literal { color: #CC9393; }
|
||||
.field { color: #94BFF3; }
|
||||
.function { color: #93E0E3; }
|
||||
.function.unsafe { color: #E28C14; }
|
||||
.operator.unsafe { color: #E28C14; }
|
||||
.function.unsafe { color: #BC8383; }
|
||||
.operator.unsafe { color: #BC8383; }
|
||||
.parameter { color: #94BFF3; }
|
||||
.text { color: #DCDCCC; }
|
||||
.type { color: #7CB8BB; }
|
||||
|
|
|
@ -77,6 +77,7 @@ impl HighlightTag {
|
|||
HighlightTag::EnumVariant => "enum_variant",
|
||||
HighlightTag::EscapeSequence => "escape_sequence",
|
||||
HighlightTag::Field => "field",
|
||||
HighlightTag::FormatSpecifier => "format_specifier",
|
||||
HighlightTag::Function => "function",
|
||||
HighlightTag::Generic => "generic",
|
||||
HighlightTag::Keyword => "keyword",
|
||||
|
@ -84,6 +85,7 @@ impl HighlightTag {
|
|||
HighlightTag::Macro => "macro",
|
||||
HighlightTag::Module => "module",
|
||||
HighlightTag::NumericLiteral => "numeric_literal",
|
||||
HighlightTag::Operator => "operator",
|
||||
HighlightTag::SelfKeyword => "self_keyword",
|
||||
HighlightTag::SelfType => "self_type",
|
||||
HighlightTag::Static => "static",
|
||||
|
@ -95,8 +97,6 @@ impl HighlightTag {
|
|||
HighlightTag::Union => "union",
|
||||
HighlightTag::Local => "variable",
|
||||
HighlightTag::UnresolvedReference => "unresolved_reference",
|
||||
HighlightTag::FormatSpecifier => "format_specifier",
|
||||
HighlightTag::Operator => "operator",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue